fix bug where 'got up -c commit path' deleted unrelated files from work tree Problem reported by Timo Myyrä
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104
diff --git a/lib/fileindex.c b/lib/fileindex.c
index 5796af5..d1e3839 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -848,8 +848,7 @@ diff_fileindex_tree(struct got_fileindex *fileindex,
} else if (cmp < 0) {
next = walk_fileindex(fileindex, *ie);
if (got_path_is_child((*ie)->path, path,
- path_len) && (entry_name == NULL ||
- strcmp(te_name, entry_name) == 0)) {
+ path_len) && entry_name == NULL) {
err = cb->diff_old(cb_arg, *ie, path);
if (err || entry_name)
break;
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index a52e267..dd8f31f 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -2254,6 +2254,80 @@ test_update_symlink_conflicts() {
}
+test_update_single_file() {
+ local testroot=`test_init update_single_file 1`
+
+ echo c1 > $testroot/repo/c
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "adding executable file"
+ local commit_id1=`git_show_head $testroot/repo`
+
+ echo a > $testroot/repo/a
+ echo b > $testroot/repo/b
+ echo c2 > $testroot/repo/c
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "adding executable file"
+ local commit_id2=`git_show_head $testroot/repo`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "U c" > $testroot/stdout.expected
+ echo -n "Updated to commit $commit_id1" >> $testroot/stdout.expected
+ echo >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got update -c $commit_id1 c \
+ > $testroot/stdout)
+
+ 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 c1 > $testroot/content.expected
+ cat $testroot/wt/c > $testroot/content
+
+ cmp -s $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "U c" > $testroot/stdout.expected
+ echo -n "Updated to commit $commit_id2" >> $testroot/stdout.expected
+ echo >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got update c > $testroot/stdout)
+
+ 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 c2 > $testroot/content.expected
+ cat $testroot/wt/c > $testroot/content
+
+ cmp -s $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ fi
+ test_done "$testroot" "$ret"
+}
+
+
test_parseargs "$@"
run_test test_update_basic
run_test test_update_adds_file
@@ -2293,3 +2367,4 @@ run_test test_update_conflict_wt_file_vs_repo_submodule
run_test test_update_adds_symlink
run_test test_update_deletes_symlink
run_test test_update_symlink_conflicts
+run_test test_update_single_file