fix a path matching bug in collect_missing_file()
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/lib/worktree.c b/lib/worktree.c
index 408e0bd..ff90b0e 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -760,6 +760,8 @@ collect_missing_file(void *args, struct got_fileindex_entry *entry)
return NULL;
start = entry->path + strlen(a->current_subdir);
+ if (a->current_subdir[0] != '\0' && start[0] != '/')
+ return NULL;
while (start[0] == '/')
start++;
end = strchr(start, '/');
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index eb351e5..2faad6b 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -240,9 +240,72 @@ function test_update_deletes_dir_recursively {
test_done "$testroot" "0"
}
+function test_update_with_sibling_dirs_with_common_prefix {
+ local testroot=`test_init update_with_sibling_dirs_with_common_prefix`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ if [ "$?" != "0" ]; then
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ mkdir $testroot/repo/epsilon2
+ echo mu > $testroot/repo/epsilon2/mu
+ (cd $testroot/repo && git add epsilon2/mu)
+ git_commit $testroot/repo -m "adding sibling of epsilon"
+ echo change > $testroot/repo/epsilon/zeta
+ git_commit $testroot/repo -m "changing epsilon/zeta"
+
+ echo "U epsilon/zeta" > $testroot/stdout.expected
+ echo "A epsilon2/mu" >> $testroot/stdout.expected
+ echo -n "Updated to commit " >> $testroot/stdout.expected
+ git_show_head $testroot/repo >> $testroot/stdout.expected
+ echo >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got update > $testroot/stdout)
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ if [ "$?" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ echo "another change" > $testroot/repo/epsilon/zeta
+ git_commit $testroot/repo -m "changing epsilon/zeta again"
+
+ echo "U epsilon/zeta" > $testroot/stdout.expected
+ echo -n "Updated to commit " >> $testroot/stdout.expected
+ git_show_head $testroot/repo >> $testroot/stdout.expected
+ echo >> $testroot/stdout.expected
+
+ # Bug: This update used to do delete/add epsilon2/mu again:
+ # U epsilon/zeta
+ # D epsilon2/mu <--- not intended
+ # A epsilon2/mu <--- not intended
+ (cd $testroot/wt && got update > $testroot/stdout)
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ if [ "$?" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ if [ "$?" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$?"
+ return 1
+ fi
+
+ test_done "$testroot" "0"
+}
+
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
run_test test_update_deletes_dir_recursively
+run_test test_update_with_sibling_dirs_with_common_prefix