commit c8ede203f35b2a68c79737c983a5dc4046d67365 from: Stefan Sperling date: Thu Aug 08 06:25:09 2019 UTC make stage -p offer 'q' option only for edits, not additions and deletions commit - 0e2f58844fa2e67309a87eb14a98b419fe0fc0b0 commit + c8ede203f35b2a68c79737c983a5dc4046d67365 blob - 3ca2425ff03215d7f8e90aa852ec7536799a984a blob + 3f39bc910f78147e8018edefbed523871fd89043 --- got/got.c +++ got/got.c @@ -5201,10 +5201,10 @@ show_change(unsigned char status, const char *path, FI 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 sta 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 sta 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; blob - 03a13774080ceeaf4c89e1d00e6c88807d94baad blob + 83c66f0ba6329c5e2da2747a82ae24dbdf3000cd --- regress/cmdline/stage.sh +++ 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