ensure that stage -p choice 'q' doesn't skip subsequent files
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
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