Commit 194cb7cb2a0f223daf0baa74a1e85bbbb44c10fd

Stefan Sperling 2021-01-19T07:38:37

fix bug where 'got up -c commit path' deleted unrelated files from work tree Problem reported by Timo Myyrä

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