make stage -p offer 'q' option only for edits, not additions and deletions
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
diff --git a/got/got.c b/got/got.c
index 3ca2425..3f39bc9 100644
--- a/got/got.c
+++ b/got/got.c
@@ -5201,10 +5201,10 @@ show_change(unsigned char status, const char *path, FILE *patch_file)
switch (status) {
case GOT_STATUS_ADD:
- printf("A %s\nstage this addition? [y/n/q] ", path);
+ printf("A %s\nstage this addition? [y/n] ", path);
break;
case GOT_STATUS_DELETE:
- printf("D %s\nstage deletion? [y/n/q] ", path);
+ printf("D %s\nstage deletion? [y/n] ", path);
break;
case GOT_STATUS_MODIFY:
if (fseek(patch_file, 0L, SEEK_SET) == -1)
@@ -5254,15 +5254,15 @@ choose_patch(int *choice, void *arg, unsigned char status, const char *path,
if (strcmp(line, "y") == 0) {
*choice = GOT_PATCH_CHOICE_YES;
printf("y\n");
- }
- if (strcmp(line, "n") == 0) {
+ } else if (strcmp(line, "n") == 0) {
*choice = GOT_PATCH_CHOICE_NO;
printf("n\n");
- }
- if (strcmp(line, "q") == 0) {
+ } else if (strcmp(line, "q") == 0 &&
+ status == GOT_STATUS_MODIFY) {
*choice = GOT_PATCH_CHOICE_QUIT;
printf("q\n");
- }
+ } else
+ printf("invalid response '%s'\n", line);
free(line);
return NULL;
}
@@ -5274,15 +5274,22 @@ choose_patch(int *choice, void *arg, unsigned char status, const char *path,
resp = getchar();
if (resp == '\n')
resp = getchar();
- if (resp != 'y' && resp != 'n' && resp != 'q')
- printf("invalid response '%c'\n", resp);
+ if (status == GOT_STATUS_MODIFY) {
+ if (resp != 'y' && resp != 'n' && resp != 'q') {
+ printf("invalid response '%c'\n", resp);
+ resp = ' ';
+ }
+ } else if (resp != 'y' && resp != 'n') {
+ printf("invalid response '%c'\n", resp);
+ resp = ' ';
+ }
}
if (resp == 'y')
*choice = GOT_PATCH_CHOICE_YES;
else if (resp == 'n')
*choice = GOT_PATCH_CHOICE_NO;
- else if (resp == 'q')
+ else if (resp == 'q' && status == GOT_STATUS_MODIFY)
*choice = GOT_PATCH_CHOICE_QUIT;
return NULL;
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index 03a1377..83c66f0 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -1435,7 +1435,7 @@ function test_stage_patch_added {
epsilon/new > $testroot/stdout)
echo "A epsilon/new" > $testroot/stdout.expected
- echo "stage this addition? [y/n/q] y" >> $testroot/stdout.expected
+ echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"
if [ "$ret" != "0" ]; then
@@ -1494,7 +1494,7 @@ function test_stage_patch_removed {
echo -n > $testroot/stdout.expected
echo "D beta" > $testroot/stdout.expected
- echo "stage deletion? [y/n/q] y" >> $testroot/stdout.expected
+ echo "stage deletion? [y/n] y" >> $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"
if [ "$ret" != "0" ]; then