fix 'got status' with an obstructed file given as argument; found by Omar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/lib/worktree.c b/lib/worktree.c
index 0b45714..26ce9d0 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3645,6 +3645,7 @@ worktree_status(struct got_worktree *worktree, const char *path,
struct diff_dir_cb_arg arg;
char *ondisk_path = NULL;
struct got_pathlist_head ignores;
+ struct got_fileindex_entry *ie;
TAILQ_INIT(&ignores);
@@ -3652,6 +3653,14 @@ worktree_status(struct got_worktree *worktree, const char *path,
worktree->root_path, path[0] ? "/" : "", path) == -1)
return got_error_from_errno("asprintf");
+ ie = got_fileindex_entry_get(fileindex, path, strlen(path));
+ if (ie) {
+ err = report_single_file_status(path, ondisk_path,
+ fileindex, status_cb, status_arg, repo,
+ report_unchanged, &ignores, no_ignores);
+ goto done;
+ }
+
fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC);
if (fd == -1) {
if (errno != ENOTDIR && errno != ENOENT && errno != EACCES &&
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index 9e58172..f96cb55 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -152,6 +152,16 @@ test_status_obstructed() {
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got status epsilon/zeta > $testroot/stdout)
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
fi
test_done "$testroot" "$ret"
}