{"thread":{"id":"951","subject":"[PATCH 3/3] Adds support to git-commit-script for an optional .nextmsg file. [rev 4]","startedAt":"2005-06-15T14:38:14Z","lastAt":"2005-06-15T14:38:14Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"4975","messageId":"20050615143814.27266.qmail@blackcubes.dyndns.org","threadId":"951","inReplyTo":null,"subject":"[PATCH 3/3] Adds support to git-commit-script for an optional .nextmsg file. [rev 4]","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-06-15T14:38:14Z","receivedAt":"2005-06-15T14:38:14Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nIf ${GIT_DIR}/.nextmsg exists, the text will be copied into the .editmsg file\ntogether with a sentinel line prior to invoking the editor.\n\nAfter editing, the edited text (but not the status lines) are saved\nback to the ${GIT_DIR}/.nextmsg file.\n\nIf the sentinel line still exists in .editmsg after editing, the\nfile is truncated, thereby causing the commit to abort (per previous\nbehaviour).\n\nThe ${GIT_DIR}/.nextmsg file is deleted if, and only if,\nthe commit was successful.\n\nThe behaviour of git-commit-script is unchanged with respect to the\nprevious versions if ${GIT_DIR}/.nextmsg does not exist.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n\n git-commit-script        |   32 +++++++++++++++++++++++++++++++-\n t/t1200-commit-script.sh |   41 ++++++++++++++++++++++++++++++++++++++---\n 2 files changed, 69 insertions(+), 4 deletions(-)\n\ndiff --git a/git-commit-script b/git-commit-script\n--- a/git-commit-script\n+++ b/git-commit-script\n@@ -36,12 +36,41 @@ print_status() {\n \tfi\n }\n \n+merge_next_message()\n+{\n+\tstatus=$1\n+\tnext=$2\n+\tmv -f $status .status.$$ || exit 1\n+\tcat >$status <<EOF\n+$SENTINEL\n+#---\n+$(cat $next)\n+#---\n+$(cat .status.$$)\n+EOF\n+\trm .status.$$\n+}\n+\n+save_next_message()\n+{\n+\tstatus=$1\n+\tnext=$2\n+\tgrep -v \"^#\" < $status > $next\n+\tif grep \"^$SENTINEL\" < $status >/dev/null; then\n+\t\t:> $status\n+\t\techo \"commit aborted - you must delete the SENTINEL line to confirm the commit\"\n+\tfi\n+}\n+\n edit_message() {\n \tstatus=$1\n \tmsg=$2\n+\tnext=$3\n \n \t:> $msg\n+\t[ -f \"$next\" ] && merge_next_message \"$status\" \"$next\"\n \t${VISUAL:-${EDITOR:-vi}} \"$status\"\n+\t[ -f \"$next\" ] && save_next_message \"$status\" \"$next\"\n \tgrep -v '^#' < $status | git-stripspace >$msg\n \t[ -s $msg ] || exit 1\n }\n@@ -76,9 +105,10 @@ if ! print_status > .editmsg; then\n \texit 1\n fi\n \n-if edit_message .editmsg .cmitmsg; then\n+if edit_message .editmsg .cmitmsg ${GIT_DIR}/.nextmsg ; then\n \texec_commit .cmitmsg\n \t[ -f .editmsg ] && rm .editmsg\n \t[ -f .cmitmsg ] && rm .cmitmsg\n+\t[ -f ${GIT_DIR}/.nextmsg ] && rm ${GIT_DIR}/.nextmsg\n \texit 0\n fi\ndiff --git a/t/t1200-commit-script.sh b/t/t1200-commit-script.sh\n--- a/t/t1200-commit-script.sh\n+++ b/t/t1200-commit-script.sh\n@@ -75,6 +75,15 @@ run_with_vars()\n      TZ= \"$@\" 2>/dev/null\n }\n \n+reset()\n+{\n+     [ -f .git/HEAD ] && rm .git/HEAD\n+     [ -f .git/MERGE_HEAD ] && rm .git/MERGE_HEAD\n+     [ -f .git/index ] && rm .git/index\n+     [ -f treeid ] && rm treeid\n+     [ -f commit ] && rm commit\n+}\n+\n test_phase1()\n {\n      condition=$1\n@@ -146,8 +155,34 @@ test_phase3()\n \n }\n \n-test_phase1 \"simulated user\" ./do_nothing_editor\n-test_phase2 \"simulated user\" ./add_one_line_editor\n-test_phase3 \"simulated used\" ./add_one_line_editor\n+test_phase1 \"without .nextmsg\" ./do_nothing_editor\n+test_phase2 \"without .nextmsg\" ./add_one_line_editor\n+test_phase3 \"without .nextmsg\" ./add_one_line_editor\n+\n+reset\n+\n+one_line > .git/.nextmsg\n+test_phase1 \"with .nextmsg\" ./do_nothing_editor\n+test_expect_success \".nextmsg file kept\" \"[ -f .git/.nextmsg -a \\\"$(cat .git/.nextmsg)\\\" == \\\"$(one_line)\\\" ]\"\n+\n+one_line    > .git/.nextmsg\n+test_phase2 \"with .nextmsg\" ./delete_sentinel_editor\n+test_expect_success \".nextmsg file deleted\" '! [ -f .git/.nextmsg ]'\n+\n+one_line    > .git/.nextmsg\n+test_phase3 \"with .nextmsg\" ./delete_sentinel_editor\n+test_expect_success \".nextmsg file deleted\" '! [ -f .git/.nextmsg ]'\n+\n+reset\n+\n+: > .git/.nextmsg\n+test_phase1 \"with .nextmsg, change preserved, sentinel kept\" ./add_one_line_editor\n+test_expect_success \"edit preserved - sentinel not deleted\" \"[ -f .git/.nextmsg -a \\\"$(cat .git/.nextmsg | tr -d \\\\012 )\\\" == \\\"$(one_line)\\\" ]\"\n+\n+reset\n+\n+: > .git/.nextmsg\n+test_phase1 \"with .nextmsg, no data, no edit, sentinel kept\" ./do_nothing_editor\n+test_expect_success \"no change - sentinel not deleted\" \"[ -f .git/.nextmsg -a \\\"$(cat .git/.nextmsg)\\\" == \\\"\\\" ]\"\n \n test_done\n------------\n"}]}