make 'got status' find top-level .cvsignore when invoked from a subdir
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/lib/worktree.c b/lib/worktree.c
index 61c8208..58f47bc 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2433,15 +2433,16 @@ match_ignores(struct got_pathlist_head *ignores, const char *path)
}
static const struct got_error *
-add_ignores(struct got_pathlist_head *ignores, const char *path)
+add_ignores(struct got_pathlist_head *ignores, const char *root_path,
+ const char *path)
{
const struct got_error *err = NULL;
char *ignorespath;
FILE *ignoresfile = NULL;
/* TODO: read .gitignores as well... */
- if (asprintf(&ignorespath, "%s%s.cvsignore", path, path[0] ? "/" : "")
- == -1)
+ if (asprintf(&ignorespath, "%s/%s%s.cvsignore", root_path, path,
+ path[0] ? "/" : "") == -1)
return got_error_from_errno("asprintf");
ignoresfile = fopen(ignorespath, "r");
@@ -2480,7 +2481,7 @@ status_new(void *arg, struct dirent *de, const char *parent_path)
}
if (de->d_type == DT_DIR)
- err = add_ignores(&a->ignores, path);
+ err = add_ignores(&a->ignores, a->worktree->root_path, path);
else if (got_path_is_child(path, a->status_path, a->status_path_len)
&& !match_ignores(&a->ignores, path))
err = (*a->status_cb)(a->status_arg, GOT_STATUS_UNVERSIONED,
@@ -2553,7 +2554,7 @@ worktree_status(struct got_worktree *worktree, const char *path,
arg.cancel_cb = cancel_cb;
arg.cancel_arg = cancel_arg;
TAILQ_INIT(&arg.ignores);
- err = add_ignores(&arg.ignores, "");
+ err = add_ignores(&arg.ignores, worktree->root_path, path);
if (err == NULL)
err = got_fileindex_diff_dir(fileindex, workdir,
worktree->root_path, path, repo, &fdiff_cb, &arg);
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index e4d71a9..99766ac 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -509,6 +509,20 @@ function test_status_cvsignore {
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo '? .cvsignore' > $testroot/stdout.expected
+ echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
+ echo '? epsilon/boo' >> $testroot/stdout.expected
+ echo '? foop' >> $testroot/stdout.expected
+ (cd $testroot/wt/gamma && got status > $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"
}