make 'got update' remove directories in a checkout with path prefix
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 68 69 70 71 72 73 74
diff --git a/lib/worktree.c b/lib/worktree.c
index b9ce306..68c4f29 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -798,9 +798,7 @@ remove_missing_files(struct got_worktree *worktree, const char *path,
a.fileindex = fileindex;
a.entries = entries;
a.missing_entries.nentries = 0;
- a.current_subdir = path;
- while (a.current_subdir[0] == '/')
- a.current_subdir++;
+ a.current_subdir = apply_path_prefix(worktree, path);
TAILQ_INIT(&a.missing_entries.entries);
err = got_fileindex_for_each_entry(fileindex, collect_missing_file, &a);
if (err)
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index cc23e63..7364849 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -190,7 +190,54 @@ function test_update_deletes_dir {
test_done "$testroot" "$ret"
}
+function test_update_deletes_dir_with_path_prefix {
+ local testroot=`test_init update_deletes_dir_with_path_prefix`
+ local first_rev=`git_show_head $testroot/repo`
+
+ mkdir $testroot/repo/epsilon/psi
+ echo mu > $testroot/repo/epsilon/psi/mu
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
+
+ # check out the epsilon/ sub-tree
+ got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
+ if [ "$?" != "0" ]; then
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ # update back to first commit and expect psi/mu to be deleted
+ echo "D psi/mu" > $testroot/stdout.expected
+ echo "Updated to commit $first_rev" >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ if [ "$?" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ if [ -e $testroot/wt/psi ]; then
+ echo "removed dir psi still exists on disk" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo "zeta" >> $testroot/content.expected
+ cat $testroot/wt/zeta > $testroot/content
+
+ cmp $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_update_basic
run_test test_update_adds_file
run_test test_update_deletes_file
run_test test_update_deletes_dir
+run_test test_update_deletes_dir_with_path_prefix