commit 2a06fe5f59f1b7b42f63bd9afe5187935c341321 from: Stefan Sperling date: Sat Aug 24 10:58:07 2019 UTC indicate non-existent paths in 'got status' and make 'got diff' error for them commit - b8bad2ba42b397e4040667df22fbd795f6c796f6 commit + 2a06fe5f59f1b7b42f63bd9afe5187935c341321 blob - bc24b56fe9ee8b371a400a11357acd2fe46e4a65 blob + 45c8c5cc48c35aa3cd1e7e967be8cc112febeff7 --- got/got.1 +++ got/got.1 @@ -243,6 +243,9 @@ using the following status codes: .It \(a~ Ta versioned file is obstructed by a non-regular file .It ? Ta unversioned item not tracked by .Nm +.It N Ta non-existent +.Ar path +specified on the command line .El .Pp If no blob - 9ae1a22c521640c7b65b692d41af663d2e4fb9df blob + 34e071967697fcabd8e050f2be3856f67a3cacee --- got/got.c +++ got/got.c @@ -1823,6 +1823,8 @@ print_diff(void *arg, unsigned char status, unsigned c } else { if (staged_status == GOT_STATUS_DELETE) return NULL; + if (status == GOT_STATUS_NONEXISTENT) + return got_error_set_errno(ENOENT, path); if (status != GOT_STATUS_MODIFY && status != GOT_STATUS_ADD && status != GOT_STATUS_DELETE && @@ -3844,6 +3846,20 @@ usage_remove(void) { fprintf(stderr, "usage: %s remove [-f] file-path ...\n", getprogname()); exit(1); +} + +static const struct got_error * +print_remove_status(void *arg, unsigned char status, + unsigned char staged_status, const char *path, + struct got_object_id *blob_id, struct got_object_id *staged_blob_id, + struct got_object_id *commit_id) +{ + if (status == GOT_STATUS_NONEXISTENT) + return NULL; + if (status == staged_status && (status == GOT_STATUS_DELETE)) + status = GOT_STATUS_NO_CHANGE; + printf("%c%c %s\n", status, staged_status, path); + return NULL; } static const struct got_error * @@ -3904,7 +3920,7 @@ cmd_remove(int argc, char *argv[]) goto done; error = got_worktree_schedule_delete(worktree, &paths, - delete_local_mods, print_status, NULL, repo); + delete_local_mods, print_remove_status, NULL, repo); if (error) goto done; done: blob - 1bd4eff4c92e7c57dc9166775ec5c8efd2916fec blob + 096c4e4ceac795c28e6da4fba2b9be6fd783015b --- include/got_worktree.h +++ include/got_worktree.h @@ -31,6 +31,7 @@ struct got_fileindex; #define GOT_STATUS_MISSING '!' #define GOT_STATUS_UNVERSIONED '?' #define GOT_STATUS_OBSTRUCTED '~' +#define GOT_STATUS_NONEXISTENT 'N' #define GOT_STATUS_REVERT 'R' #define GOT_STATUS_CANNOT_DELETE 'd' #define GOT_STATUS_BUMP_BASE 'b' blob - 30b65e930802c67ccebb4b4023d1ba02f176761e blob + 9a7c693b6fe913d70e282679c979cb7a7af850c3 --- lib/worktree.c +++ lib/worktree.c @@ -2508,6 +2508,8 @@ void *status_arg, struct got_repository *repo) if (lstat(ondisk_path, &sb) == -1) { if (errno != ENOENT) return got_error_from_errno2("lstat", ondisk_path); + return (*status_cb)(status_arg, GOT_STATUS_NONEXISTENT, + GOT_STATUS_NO_CHANGE, path, NULL, NULL, NULL); return NULL; } @@ -5560,6 +5562,8 @@ check_stage_ok(void *arg, unsigned char status, if (status == GOT_STATUS_UNVERSIONED) return NULL; + if (status == GOT_STATUS_NONEXISTENT) + return got_error_set_errno(ENOENT, relpath); ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath)); if (ie == NULL) @@ -5703,6 +5707,9 @@ stage_path(void *arg, unsigned char status, case GOT_STATUS_CONFLICT: err = got_error_path(relpath, GOT_ERR_STAGE_CONFLICT); break; + case GOT_STATUS_NONEXISTENT: + err = got_error_set_errno(ENOENT, relpath); + break; default: err = got_error_path(relpath, GOT_ERR_FILE_STATUS); break; blob - e7cea61d9e58dea9e040440ecd3b58e1fd85df0e blob + 455469c47cd574f5fca1a82ebd6b9e3e680dc5e8 --- regress/cmdline/diff.sh +++ regress/cmdline/diff.sh @@ -62,7 +62,30 @@ function test_diff_basic { ret="$?" if [ "$ret" != "0" ]; then diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 fi + + # diff non-existent path + (cd $testroot/wt && got diff nonexistent > $testroot/stdout \ + 2> $testroot/stderr) + + echo -n > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + echo "got: nonexistent: No such file or directory" \ + > $testroot/stderr.expected + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi test_done "$testroot" "$ret" } blob - e7fb40ff27a838ef389cac5d09189a21b2d212d1 blob + abe364148a3057cd534860385de545c80bb5367b --- regress/cmdline/stage.sh +++ regress/cmdline/stage.sh @@ -156,7 +156,8 @@ function test_stage_nonexistent { (cd $testroot/wt && got stage nonexistent-file \ > $testroot/stdout 2> $testroot/stderr) - echo "got: no changes to stage" > $testroot/stderr.expected + echo "got: nonexistent-file: No such file or directory" \ + > $testroot/stderr.expected cmp -s $testroot/stderr.expected $testroot/stderr ret="$?" if [ "$ret" != "0" ]; then blob - ec4a92da12fc55731c312cca75266994641a944b blob + 1cdd63392f3e865270de6ffdb9b10cb96f773a41 --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -1052,7 +1052,7 @@ function test_update_conflict_wt_rm_vs_repo_rm { fi # beta is now gone... we don't flag tree conflicts yet - echo -n > $testroot/stdout.expected + echo "N beta" > $testroot/stdout.expected echo -n > $testroot/stderr.expected (cd $testroot/wt && got status beta > $testroot/stdout \ 2> $testroot/stderr)