{"thread":{"id":"935","subject":"[PATCH 1/1] Add support for an optional .nextmsg file to git-commit-script","startedAt":"2005-06-14T11:42:43Z","lastAt":"2005-06-14T14:44:43Z","messageCount":2,"participants":["Jon Seymour","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"4943","messageId":"20050614114243.12267.qmail@blackcubes.dyndns.org","threadId":"935","inReplyTo":null,"subject":"[PATCH 1/1] Add support for an optional .nextmsg file to git-commit-script","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-06-14T11:42:43Z","receivedAt":"2005-06-14T11:42:43Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nThis change allows a commit message to be prepared prior to git-commit-script being\ninvoked. During git commit the user is then given an opportunity to edit the\nexisting message, if any, and must confirm the commit by deleting a sentinel\nline from the top of the edit buffer.\n\nIf the user does not delete the sentinel line, the commit is aborted and the\ntext of the message is saved for future editing.\n\nThe purpose of this change is to enable undo/redo tools to repopulate a commit\nmessage from a previous commit that has been undone and then allow the user to\nmake small edits to the previous commit message prior recommitting the change.\n\nIf the .nextmsg file does not exist, git-commit-script behaves as before.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n\n git-commit-script |   25 +++++++++++++++++++++++--\n 1 files changed, 23 insertions(+), 2 deletions(-)\n\ndiff --git a/git-commit-script b/git-commit-script\n--- a/git-commit-script\n+++ b/git-commit-script\n@@ -1,5 +1,12 @@\n #!/bin/sh\n+SENTINEL=\"*** delete this line to confirm the commit ***\"\n : ${GIT_DIR=.git}\n+:> .editmsg\n+\n+if [ -f .nextmsg ]\n+then\n+    cat .nextmsg   >>.editmsg\n+fi\n PARENTS=\"HEAD\"\n if [ -f $GIT_DIR/MERGE_HEAD ]; then\n \techo \"#\"\n@@ -9,17 +16,31 @@ if [ -f $GIT_DIR/MERGE_HEAD ]; then\n \techo \"# and try again\"\n \techo \"#\"\n \tPARENTS=\"HEAD -p MERGE_HEAD\"\n-fi > .editmsg\n+fi >> .editmsg\n git-status-script >> .editmsg\n if [ \"$?\" != \"0\" ]\n then\n \tcat .editmsg\n \texit 1\n fi\n+if [ -f .nextmsg ]\n+then\n+    echo \"$SENTINEL\" >>.editmsg\n+fi\n ${VISUAL:-${EDITOR:-vi}} .editmsg\n-grep -v '^#' < .editmsg | git-stripspace > .cmitmsg\n+if [ -f .nextmsg ]\n+then\n+    egrep -v \"(^#|\\\\$SENTINEL)\" < .editmsg > .nextmsg\n+    if grep \"\\\\$SENTINEL\" < .editmsg >/dev/null\n+    then\n+\t:> .editmsg\n+\techo \"commit aborted - to confirm, delete the sentinel line in the message\"\n+    fi\n+fi\n+egrep -v \"^#|$SENTINEL\" < .editmsg | git-stripspace > .cmitmsg\n [ -s .cmitmsg ] || exit 1\n tree=$(git-write-tree) || exit 1\n commit=$(cat .cmitmsg | git-commit-tree $tree -p $PARENTS) || exit 1\n echo $commit > $GIT_DIR/HEAD\n rm -f -- $GIT_DIR/MERGE_HEAD\n+[ -f .nextmsg ] && rm .nextmsg\n------------\n"},{"id":"4947","messageId":"7v64wh576s.fsf@assigned-by-dhcp.cox.net","threadId":"935","inReplyTo":"20050614114243.12267.qmail@blackcubes.dyndns.org","subject":"Re: [PATCH 1/1] Add support for an optional .nextmsg file to git-commit-script","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-06-14T14:44:43Z","receivedAt":"2005-06-14T14:44:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"JS\" == Jon Seymour <jon.seymour@gmail.com> writes:\n\nJS> This change allows a commit message to be prepared prior to git-commit-script being\nJS> invoked. During git commit the user is then given an opportunity to edit the\nJS> existing message, if any, and must confirm the commit by deleting a sentinel\nJS> line from the top of the edit buffer.\n\nJS>  #!/bin/sh\nJS> +SENTINEL=\"*** delete this line to confirm the commit ***\"\nJS> ..\nJS> +egrep -v \"^#|$SENTINEL\" < .editmsg | git-stripspace > .cmitmsg\n\nA handful comments.\n\n(1) Although it happens to work in this case, I do not like\n    scripts that use grep without quoting metacharacters in a\n    string.  You have two egreps that phrases the above slightly\n    differently.  Make up your mind ;-) and pick one.\n\n(2) What happens if I later want to make a commit with this commit\n    log?\n\n    [PATCH] Reword the sentinel line.\n\n    Instead of saying \"*** delete this line to confirm the commit ***\",\n    just say \"# If you want to abort the commit, make this file empty.\".\n\n(3) The original implementation knows that the commit is to be\n    aborted when resulting .cmitmsg is empty.  You may want to\n    tell the user in the comment in the commit template about\n    it, instead of using the sentinel line.\n\n(4) Instead of teaching git-commit-script about the .nextmsg\n    file, it may be cleaner to split it into two parts:\n\n    - one that prepares the .cmitmsg file for editing;\n\n    - the other that invokes the editor on prepared a .cmitmsg\n      file, checks if the message file is edited and asks for\n      confirmation to abort if the file is unchanged, and does the\n      actual commit.\n\n   The new git-commit-script would prepare its .cmitmsg the way it\n   does now and only call the latter half.  Your re-commit script\n   can do the first half differently from what git-commit-script\n   does, and call the same latter half.\n\nP.S. I see you are using \"git format-patch\"; I'd suggest you\nhand edit \" 1/1\" out of [PATCH 1/1] subject line for a patch\nlike this that is not part of a series.  I did not special case\n1/1 to do it myself because I often have a handful independent\npatches and end up removing 1/7 2/7 ... etc. anyway.\n\n\n"}]}