Commit 88f33a19290ffcb0a75f9b6cdd25c1207e46b858

Stefan Sperling 2019-08-08T08:54:18

ensure that stage -p choice 'q' doesn't skip subsequent files

diff --git a/lib/worktree.c b/lib/worktree.c
index 73c9e65..56705cf 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -5475,8 +5475,12 @@ stage_path(void *arg, unsigned char status,
 			    ie->path, NULL, 1, 1);
 			if (err)
 				break;
-			if (choice != GOT_PATCH_CHOICE_YES)
+			if (choice == GOT_PATCH_CHOICE_NO)
 				break;
+			if (choice != GOT_PATCH_CHOICE_YES) {
+				err = got_error(GOT_ERR_PATCH_CHOICE);
+				break;
+			}
 		}
 		stage = GOT_FILEIDX_STAGE_DELETE;
 		got_fileindex_entry_stage_set(ie, stage);
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index 3d1f624..595696a 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -1537,8 +1537,9 @@ function test_stage_patch_quit {
 	local testroot=`test_init stage_patch_quit`
 
 	jot 16 > $testroot/repo/numbers
-	(cd $testroot/repo && git add numbers)
-	git_commit $testroot/repo -m "added numbers file"
+	echo zzz > $testroot/repo/zzz
+	(cd $testroot/repo && git add numbers zzz)
+	git_commit $testroot/repo -m "added files"
 	local commit_id=`git_show_head $testroot/repo`
 
 	got checkout $testroot/repo $testroot/wt > /dev/null
@@ -1551,9 +1552,11 @@ function test_stage_patch_quit {
 	sed -i -e 's/^2$/a/' $testroot/wt/numbers
 	sed -i -e 's/^7$/b/' $testroot/wt/numbers
 	sed -i -e 's/^16$/c/' $testroot/wt/numbers
+	(cd $testroot/wt && got rm zzz > /dev/null)
 
-	# stage first hunk and quit; and don't pass a path argument
-	printf "y\nq\n" > $testroot/patchscript
+	# stage first hunk and quit; and don't pass a path argument to
+	# ensure that we don't skip asking about the 'zzz' file after 'quit'
+	printf "y\nq\nn\n" > $testroot/patchscript
 	(cd $testroot/wt && got stage -F $testroot/patchscript -p \
 		> $testroot/stdout)
 	ret="$?"
@@ -1587,6 +1590,8 @@ stage this change? [y/n/q] y
 -----------------------------------------------
 M  numbers (change 2 of 3)
 stage this change? [y/n/q] q
+D  zzz
+stage deletion? [y/n] n
 EOF
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
@@ -1598,6 +1603,7 @@ EOF
 
 	(cd $testroot/wt && got status > $testroot/stdout)
 	echo "MM numbers" > $testroot/stdout.expected
+	echo "D  zzz" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then