commit - 88f33a19290ffcb0a75f9b6cdd25c1207e46b858
commit + eba70f3832e0457ba487bbe50a3d8e30dca1f15f
blob - 022dc3679c92b06dec343178983f00ab324b3b4e
blob + 39818d9031549d1ff45d02cc9b403152803c9bab
--- got/got.c
+++ got/got.c
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))
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");
blob - 595696a78469f07142ccd9d777a2be68101c4e1b
blob + 8c98d122af2904c314017694c0b4dbf8d0026a2d
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
}
+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
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