verify stage -p behaviour with incomplete response script
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
diff --git a/got/got.c b/got/got.c
index 022dc36..39818d9 100644
--- a/got/got.c
+++ b/got/got.c
@@ -5241,6 +5241,9 @@ choose_patch(int *choice, void *arg, unsigned char status, const char *path,
if (patch_script_file) {
char *nl;
+ err = show_change(status, path, patch_file, n, nchanges);
+ if (err)
+ return err;
linelen = getline(&line, &linesize, patch_script_file);
if (linelen == -1) {
if (ferror(patch_script_file))
@@ -5250,9 +5253,6 @@ choose_patch(int *choice, void *arg, unsigned char status, const char *path,
nl = strchr(line, '\n');
if (nl)
*nl = '\0';
- err = show_change(status, path, patch_file, n, nchanges);
- if (err)
- return err;
if (strcmp(line, "y") == 0) {
*choice = GOT_PATCH_CHOICE_YES;
printf("y\n");
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index 595696a..8c98d12 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -1641,6 +1641,100 @@ EOF
}
+function test_stage_patch_incomplete_script {
+ local testroot=`test_init stage_incomplete_script`
+
+ jot 16 > $testroot/repo/numbers
+ 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
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ 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
+
+ # stage first hunk and then stop responding; got should error out
+ printf "y\n" > $testroot/patchscript
+ (cd $testroot/wt && got stage -F $testroot/patchscript -p \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got stage command succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+ cat > $testroot/stdout.expected <<EOF
+-----------------------------------------------
+@@ -1,5 +1,5 @@
+ 1
+-2
++a
+ 3
+ 4
+ 5
+-----------------------------------------------
+M numbers (change 1 of 3)
+stage this change? [y/n/q] y
+-----------------------------------------------
+@@ -4,7 +4,7 @@
+ 4
+ 5
+ 6
+-7
++b
+ 8
+ 9
+ 10
+-----------------------------------------------
+M numbers (change 2 of 3)
+EOF
+ echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
+ echo "got: invalid patch choice" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ 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
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+ echo "M numbers" > $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
+
+ (cd $testroot/wt && got diff -s > $testroot/stdout)
+ echo -n > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+
+}
+
run_test test_stage_basic
run_test test_stage_no_changes
run_test test_stage_list
@@ -1661,3 +1755,4 @@ run_test test_stage_patch
run_test test_stage_patch_added
run_test test_stage_patch_removed
run_test test_stage_patch_quit
+run_test test_stage_patch_incomplete_script