Commit 3d69ad8dfb2fedd8d5abee1365505c2479e00180

Sebastien Marie 2019-08-17T15:28:04

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

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