commit 194cb7cb2a0f223daf0baa74a1e85bbbb44c10fd from: Stefan Sperling date: Tue Jan 19 07:38:37 2021 UTC fix bug where 'got up -c commit path' deleted unrelated files from work tree Problem reported by Timo Myyrä commit - 99495ddb79841fe89b0746d35a49bb81e9220096 commit + 194cb7cb2a0f223daf0baa74a1e85bbbb44c10fd blob - 5796af500a49c702c5c1d95f32551f881ad0f9b5 blob + d1e3839c06a7f70e71410592024f426053df2ced --- lib/fileindex.c +++ 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; blob - a52e26753f5fdda870b159596d715fa7bae988c0 blob + dd8f31f1ab6cb4e1c7bba94b8c2abc6f0e08b67a --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -2253,7 +2253,81 @@ test_update_symlink_conflicts() { test_done "$testroot" "0" } + +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_submodul run_test test_update_adds_symlink run_test test_update_deletes_symlink run_test test_update_symlink_conflicts +run_test test_update_single_file