make 'got revert' to ignore unversioned files instead of aborting with 'bad path' and add a regress to check the revert isn't aborted anymore
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
diff --git a/lib/worktree.c b/lib/worktree.c
old mode 100644
new mode 100640
index 1d163b4..715b19e
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3143,6 +3143,10 @@ revert_file(void *arg, unsigned char status, unsigned char staged_status,
staged_status != GOT_STATUS_NO_CHANGE)
return NULL;
+ if (status == GOT_STATUS_UNVERSIONED)
+ return (*a->progress_cb)(a->progress_arg,
+ GOT_STATUS_UNVERSIONED, relpath);
+
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
return got_error(GOT_ERR_BAD_PATH);
diff --git a/regress/cmdline/revert.sh b/regress/cmdline/revert.sh
old mode 100755
new mode 100740
index 170bc3b..03dde36
--- a/regress/cmdline/revert.sh
+++ b/regress/cmdline/revert.sh
@@ -318,7 +318,56 @@ function test_revert_directory {
diff -u $testroot/content.expected $testroot/content
fi
test_done "$testroot" "$ret"
+}
+
+function test_revert_directory_unknown {
+ local testroot=`test_init revert_directory_unknown`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified alpha" > $testroot/wt/alpha
+ echo "new untracked file" > $testroot/wt/epsilon/new_file
+ echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
+ (cd $testroot/wt && got revert -R . > $testroot/stdout)
+
+ echo 'R alpha' > $testroot/stdout.expected
+ echo '? epsilon/new_file' >> $testroot/stdout.expected
+ echo 'R epsilon/zeta' >> $testroot/stdout.expected
+ 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 "new untracked file" > $testroot/content.expected
+ cat $testroot/wt/epsilon/new_file > $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 "zeta" > $testroot/content.expected
+ cat $testroot/wt/epsilon/zeta > $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"
}
function test_revert_patch {
@@ -879,6 +928,7 @@ run_test test_revert_multiple
run_test test_revert_file_in_new_subdir
run_test test_revert_no_arguments
run_test test_revert_directory
+run_test test_revert_directory_unknown
run_test test_revert_patch
run_test test_revert_patch_added
run_test test_revert_patch_removed