{"thread":{"id":"17291","subject":"[PATCH] Added giteditor script to show diff while editing commit message.","startedAt":"2009-01-21T20:47:21Z","lastAt":"2009-01-22T07:49:02Z","messageCount":11,"participants":["ted@tedpavlic.com","Ted Pavlic","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"101441","messageId":"1232570841-25641-1-git-send-email-ted@tedpavlic.com","threadId":"17291","inReplyTo":null,"subject":"[PATCH] Added giteditor script to show diff while editing commit message.","fromName":"","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-21T20:47:21Z","receivedAt":"2009-01-21T20:47:21Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"From: Ted Pavlic <ted@tedpavlic.com>\n\nThis new script (contrib/giteditor/giteditor) is an example GIT_EDITOR\nthat causes the editor to open the commit message as well as a \"git diff\n--cached\". As a result, a window showing a diff of what is being\ncommitted is opened alongside the commit message.\n\nThis script also detects when \"stg edit\" is being called and uses \"stg\nshow\" instead.\n\nThis script is highly influenced by the \"hgeditor\" script distributed\nwith the Mercurial SCM.\n\nSigned-off-by: Ted Pavlic <ted@tedpavlic.com>\n---\n contrib/giteditor/README    |    9 ++++\n contrib/giteditor/giteditor |  111 +++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 120 insertions(+), 0 deletions(-)\n create mode 100644 contrib/giteditor/README\n create mode 100755 contrib/giteditor/giteditor\n\ndiff --git a/contrib/giteditor/README b/contrib/giteditor/README\nnew file mode 100644\nindex 0000000..b769c3e\n--- /dev/null\n+++ b/contrib/giteditor/README\n@@ -0,0 +1,9 @@\n+A GIT_EDITOR to show diff alongside commit message. User can review diff\n+within commit edit window. Works with StGit (\"stg edit\") as well.\n+\n+To use this script, set it as the value of GIT_EDITOR (or core.editor).\n+\n+\n+Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>\n+Highly influenced by hgeditor script distributed with Mercurial SCM.\n+Distributed under the GNU General Public License, version 2.0.\ndiff --git a/contrib/giteditor/giteditor b/contrib/giteditor/giteditor\nnew file mode 100755\nindex 0000000..13ca5f6\n--- /dev/null\n+++ b/contrib/giteditor/giteditor\n@@ -0,0 +1,111 @@\n+#!/bin/sh\n+#\n+# A GIT_EDITOR to show diff alongside commit message. User can review\n+# diff within commit edit window. Works with StGit (\"stg edit\") as well.\n+#\n+# Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>\n+# Highly influenced by hgeditor script distributed with Mercurial SCM.\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# To use this script, set it as the value of GIT_EDITOR (or\n+# core.editor).\n+#\n+\n+# Find git\n+[ -z \"${GIT}\" ] && GIT=\"git\"\n+\n+# Find stg\n+[ -z \"${STG}\" ] && STG=\"stg\"\n+\n+# Use an editor. To prevent loops, avoid GIT_EDITOR and core.editor.\n+EDITOR=${GIT_EDITOR_EDITOR} || \\\n+    EDITOR=${VISUAL} || \\\n+    EDITOR=${EDITOR} || \\\n+    EDITOR=\"vi\";\n+\n+# If we recognize a popular editor, add necessary flags\n+case \"${EDITOR}\" in\n+    emacs)\n+        EDITOR=\"${EDITOR} -nw\"\n+        ;;\n+    mvim|gvim|vim)\n+        EDITOR=\"${EDITOR} -f -o\"\n+        ;;\n+esac\n+\n+# Remove temporary files even if we get interrupted\n+GITTMP=\"\"\n+cleanup_exit() { \n+    [ -n \"${GITTMP}\" ] && rm -rf \"${GITTMP}\" \n+}\n+trap \"cleanup_exit\" 0 # normal exit\n+trap \"exit 255\" 1 2 3 6 15 # HUP INT QUIT ABRT TERM\n+\n+# End GITTMP in \".git\" so that \"*.git/\" syntax highlighting recognition\n+# doesn't break\n+GITTMP=\"${TMPDIR-/tmp}/giteditor.$RANDOM.$RANDOM.$RANDOM.$$.git\"\n+(umask 077 && mkdir \"${GITTMP}\") || {\n+    echo \"Could not create temporary directory! Exiting.\" 1>&2\n+    exit 1\n+}\n+\n+# For git, COMMITMSG=COMMIT_EDITMSG\n+# For stg, COMMITMSG=.stgit-edit.txt\n+# etc.\n+COMMITMSG=$( basename \"$1\" )\n+\n+case \"${COMMITMSG}\" in\n+    .stgit-edit.txt) \n+        DIFFCMD=\"${STG}\"\n+        DIFFARGS=\"show\"\n+        ;;\n+    *) \n+        DIFFCMD=\"${GIT}\"\n+        DIFFARGS=\"diff --cached\"\n+        ;;\n+esac\n+\n+if [ -f \"$1\" ]; then\n+    # We were passed an existing commit message\n+\n+    \"${DIFFCMD}\" ${DIFFARGS} >> \"${GITTMP}/diff\"\n+## Uncomment if you only want to see diff of what changed\n+## (note that it only works if DIFFCMD is git)\n+#    (\n+#        grep '^#.*modified:' \"$1\" | cut -b 15- | while read changed; do\n+#            \"${DIFFCMD}\" ${DIFFARGS} \"${changed}\" >> \"${GITTMP}/diff\"\n+#        done\n+#    )\n+\n+     cat \"$1\" > \"${GITTMP}/${COMMITMSG}\"\n+\n+else\n+\n+    # Give us a blank COMMITMSG to edit\n+    touch \"${GITTMP}/${COMMITMSG}\"\n+\n+    # Generate the diff\n+    \"${DIFFCMD}\" ${DIFFARGS} >> \"${GITTMP}/diff\"\n+    #touch \"${GITTMP}/diff\"\n+\n+fi\n+\n+# Use MD5 to see if commit message changed (necessary?)\n+MD5=$(which md5sum 2>/dev/null) || \\\n+    MD5=$(which md5 2>/dev/null)\n+\n+[ -x \"${MD5}\" ] && CHECKSUM=$( ${MD5} \"${GITTMP}/${COMMITMSG}\" )\n+if [ -s \"${GITTMP}/diff\" ]; then\n+    # Diff is non-empty, so edit msg and diff\n+    ${EDITOR} \"${GITTMP}/${COMMITMSG}\" \"${GITTMP}/diff\" || exit $?\n+else\n+    # Empty diff. Only edit msg\n+    ${EDITOR} \"${GITTMP}/${COMMITMSG}\" || exit $?\n+fi\n+[ -x \"${MD5}\" ] && (echo \"${CHECKSUM}\" | ${MD5} -c >/dev/null 2>&1 && exit 13)\n+\n+# Commit message changed, so dump it on original message from Git\n+mv \"${GITTMP}/${COMMITMSG}\" \"$1\"\n+\n+# (recall that GITTMP directory gets cleaned up by trap above)\n+exit $?\n-- \n1.6.1.213.g28da8\n"},{"id":"101447","messageId":"49778E77.6010906@tedpavlic.com","threadId":"17291","inReplyTo":"0E82F261-2D96-4204-9906-C5E8D47E9A5D@wincent.com","subject":"Re: [PATCH] Added giteditor script to show diff while editing commit message.","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-21T21:07:03Z","receivedAt":"2009-01-21T21:07:03Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":">> This script also detects when \"stg edit\" is being called and uses \"stg\n>> show\" instead.\n> You do know about \"git commit -v\", right? (Although that displays\n> commit message and diff in a single buffer, not two separate ones like\n> your script does.)\n\nActually, I didn't. I was looking for something like hgeditor for git, \nand I found something on vim.org that almost hit the mark but no mention \nof \"commit -v\".\n\nThat being said, I like having the diff up in a separate window. Plus, \n\"git commit -v\" doesn't help me when I want to \"stg edit\".\n\nThanks --\nTed\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n\n   Please visit my ALS association page:\n         http://web.alsa.org/goto/tedpavlic\n   My family appreciates your support in the fight to defeat ALS.\n"},{"id":"101460","messageId":"alpine.DEB.1.00.0901212216310.3586@pacific.mpi-cbg.de","threadId":"17291","inReplyTo":"1232570841-25641-1-git-send-email-ted@tedpavlic.com","subject":"Re: [PATCH] Added giteditor script to show diff while editing commit message.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-21T21:46:30Z","receivedAt":"2009-01-21T21:46:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nthe subject could use some work.  For example, I would prefix it with \n\"contrib:\", and -- imitating other commit messages -- use the imperative \nform \"Add\" instead of the frowned-upon past tense.\n\nOn Wed, 21 Jan 2009, ted@tedpavlic.com wrote:\n\n> From: Ted Pavlic <ted@tedpavlic.com>\n\nAs this is exactly what your email said in its header, it is redundant \ninformation.  Worse, it is information that made me look back to know why \nit needs to be there.  Distracting.\n\n> diff --git a/contrib/giteditor/README b/contrib/giteditor/README\n> new file mode 100644\n> index 0000000..b769c3e\n> --- /dev/null\n> +++ b/contrib/giteditor/README\n> @@ -0,0 +1,9 @@\n> +A GIT_EDITOR to show diff alongside commit message. User can review diff\n> +within commit edit window. Works with StGit (\"stg edit\") as well.\n> +\n> +To use this script, set it as the value of GIT_EDITOR (or core.editor).\n> +\n> +\n> +Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>\n> +Highly influenced by hgeditor script distributed with Mercurial SCM.\n> +Distributed under the GNU General Public License, version 2.0.\n\nWhat information does the README add that is not in the script itself?\n\nIf there is none, please refrain from adding the README to begin with.\n\n> diff --git a/contrib/giteditor/giteditor b/contrib/giteditor/giteditor\n> new file mode 100755\n> index 0000000..13ca5f6\n> --- /dev/null\n> +++ b/contrib/giteditor/giteditor\n> @@ -0,0 +1,111 @@\n> +#!/bin/sh\n> +#\n> +# A GIT_EDITOR to show diff alongside commit message.\n\nMaybe \"Set GIT_EDITOR to giteditor if you want to see a diff of what will \nbe committed in the editor\"?\n\n> +# Find git\n> +[ -z \"${GIT}\" ] && GIT=\"git\"\n\nYes, I know it is contrib/, but you may want to adopt Git's coding style \nearly.\n\nBesides, I find it funny that you want to override git with $GIT.\n\n> +# Use an editor. To prevent loops, avoid GIT_EDITOR and core.editor.\n> +EDITOR=${GIT_EDITOR_EDITOR} || \\\n> +    EDITOR=${VISUAL} || \\\n> +    EDITOR=${EDITOR} || \\\n> +    EDITOR=\"vi\";\n> +\n> +# If we recognize a popular editor, add necessary flags\n> +case \"${EDITOR}\" in\n> +    emacs)\n> +        EDITOR=\"${EDITOR} -nw\"\n\nMhm.  Should this not be the user's choice?  Some like emacs to start up \nin a window.\n\n> +# Remove temporary files even if we get interrupted\n> +GITTMP=\"\"\n\nGITTMP= would be completely sufficient.  Not to mention the consistency \nwith Git's shell code.\n\n> +# End GITTMP in \".git\" so that \"*.git/\" syntax highlighting recognition\n> +# doesn't break\n> +GITTMP=\"${TMPDIR-/tmp}/giteditor.$RANDOM.$RANDOM.$RANDOM.$$.git\"\n> +(umask 077 && mkdir \"${GITTMP}\") || {\n> +    echo \"Could not create temporary directory! Exiting.\" 1>&2\n> +    exit 1\n> +}\n\nUmm.  Why?  Why do you need a temporary .git directory?\n\n> +if [ -f \"$1\" ]; then\n> +    # We were passed an existing commit message\n> +\n> +    \"${DIFFCMD}\" ${DIFFARGS} >> \"${GITTMP}/diff\"\n> +## Uncomment if you only want to see diff of what changed\n> +## (note that it only works if DIFFCMD is git)\n> +#    (\n> +#        grep '^#.*modified:' \"$1\" | cut -b 15- | while read changed; do\n> +#            \"${DIFFCMD}\" ${DIFFARGS} \"${changed}\" >> \"${GITTMP}/diff\"\n> +#        done\n> +#    )\n\n--diff-filter=M\n\n> +\n> +     cat \"$1\" > \"${GITTMP}/${COMMITMSG}\"\n> +\n> +else\n> +\n> +    # Give us a blank COMMITMSG to edit\n> +    touch \"${GITTMP}/${COMMITMSG}\"\n\nWhy not just touch it, instead of testing if the file exists first?\n\n> +\n> +    # Generate the diff\n> +    \"${DIFFCMD}\" ${DIFFARGS} >> \"${GITTMP}/diff\"\n> +    #touch \"${GITTMP}/diff\"\n\nCommented out code in a submitted patch?\n\n> +\n> +fi\n> +\n> +# Use MD5 to see if commit message changed (necessary?)\n> +MD5=$(which md5sum 2>/dev/null) || \\\n> +    MD5=$(which md5 2>/dev/null)\n> +\n> +[ -x \"${MD5}\" ] && CHECKSUM=$( ${MD5} \"${GITTMP}/${COMMITMSG}\" )\n> +if [ -s \"${GITTMP}/diff\" ]; then\n> +    # Diff is non-empty, so edit msg and diff\n> +    ${EDITOR} \"${GITTMP}/${COMMITMSG}\" \"${GITTMP}/diff\" || exit $?\n\nvi users will hate you, as you do not give them a chance to edit the \nmessage after having seen the diff.\n\n> +else\n> +    # Empty diff. Only edit msg\n> +    ${EDITOR} \"${GITTMP}/${COMMITMSG}\" || exit $?\n> +fi\n> +[ -x \"${MD5}\" ] && (echo \"${CHECKSUM}\" | ${MD5} -c >/dev/null 2>&1 && exit 13)\n\ngit commit will abort anyway if the commit message has not changed.  Plus, \nit does a better job, as it checks only the non-commented-out text.\n\nBTW why on earth do you put every single variable name in curly brackets?\n\n> +\n> +# Commit message changed, so dump it on original message from Git\n> +mv \"${GITTMP}/${COMMITMSG}\" \"$1\"\n\nAnd why did you not use \"$1\" all the time?\n\n> +\n> +# (recall that GITTMP directory gets cleaned up by trap above)\n> +exit $?\n\nJust writing \"exit\" is the same in effect, but preferred in Git shell \ncoding.\n\nBesides all that criticism, there is also a fundamental issue.  The diff \nis in a separate file.\n\nInstead, I suggest having something like this:\n\n-- snip --\n#!/bin/sh\n\n# set GIT_EDITOR or core.editor to this script if you want to see a diff\n# instead of the output of \"git status\".\n\n# filter out the \"git status\" output (keeping the \"On branch\" line)\nmv \"$1\" \"$1\".tmp\ngrep -v \"^# [^O]\" < \"$1\".tmp > \"$1\"\nrm \"$1\".tmp\n\n# append the diff\ncase \"$1\" in\n*.stgit-edit.txt)\n\tstg show\n;;\n*)\n\tgit diff --cached\n;;\nesac | sed -e 's/^/# /' >> \"$1\"\n\nexec ${VISUAL:-${EDITOR:-vi}} \"$1\"\n-- snap --\n\nHth,\nDscho\n"},{"id":"101467","messageId":"4977A2C9.1070502@tedpavlic.com","threadId":"17291","inReplyTo":"alpine.DEB.1.00.0901212216310.3586@pacific.mpi-cbg.de","subject":"Re: [PATCH] Added giteditor script to show diff while editing commit message.","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-21T22:33:45Z","receivedAt":"2009-01-21T22:33:45Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"Thanks for your comments. I've responded below. I just want to \ntop-respond to your comment that the fundamental problem is that the \ndiff is in a separate file. In fact, this is the point of the script. I \nwant to be able to scroll through the diff output independent of the \ncommit message.\n\n(alternatively, I realize I could do \"git commit -v\" and then use my \neditor's \"split window\" support, but that wouldn't help me with \"stg edit\")\n\n> the subject could use some work.  For example, I would prefix it with\n...\n>> From: Ted Pavlic<ted@tedpavlic.com>\n>\n> As this is exactly what your email said in its header, it is redundant\n> information.  Worse, it is information that made me look back to know why\n> it needs to be there.  Distracting.\n\nI add --from to my gitsend alias to prevent git send-email from \nprompting me for a \"From\". Is there a way to have git send-email simply \nnot prompt me for \"From\"?\n\n> What information does the README add that is not in the script itself?\n> If there is none, please refrain from adding the README to begin with.\n\nOK. I noticed plenty of other not-very-useful READMEs in contrib/, and \nso I figured it was a pro forma file.\n\n>> +# Find git\n>> +[ -z \"${GIT}\" ]&&  GIT=\"git\"\n> Yes, I know it is contrib/, but you may want to adopt Git's coding style\n> early.\n\nOk. Switching to test.\n\n> Besides, I find it funny that you want to override git with $GIT.\n\nIsn't it possible that someone has git somewhere else?\n\n>> +# If we recognize a popular editor, add necessary flags\n>> +case \"${EDITOR}\" in\n>> +    emacs)\n>> +        EDITOR=\"${EDITOR} -nw\"\n>\n> Mhm.  Should this not be the user's choice?  Some like emacs to start up\n> in a window.\n\nI don't use emacs, but it was my impression that the \"no window\" flag \nwas added to make sure that emacs doesn't fork. That's why \"-f\" is used \nin the vim line.\n\n>> +# End GITTMP in \".git\" so that \"*.git/\" syntax highlighting recognition\n>> +# doesn't break\n>> +GITTMP=\"${TMPDIR-/tmp}/giteditor.$RANDOM.$RANDOM.$RANDOM.$$.git\"\n>> +(umask 077&&  mkdir \"${GITTMP}\") || {\n>> +    echo \"Could not create temporary directory! Exiting.\" 1>&2\n>> +    exit 1\n>> +}\n>\n> Umm.  Why?  Why do you need a temporary .git directory?\n\nThe script generates a new \"diff\" file that I would rather drop \nelsewhere (e.g., in a /tmp directory) rather than here in the current \ndirectory.\n\nHowever, maybe you're right. After all, stg drops \".stgit-edit.txt\" in \nthe working directory. I suppose I could use gitdir, but I wasn't sure \nif it was safe to pollute gitdir.\n\nIn the next version, I'll get rid of the temp directory and put the file \nhere.\n\n>> +    # Diff is non-empty, so edit msg and diff\n>> +    ${EDITOR} \"${GITTMP}/${COMMITMSG}\" \"${GITTMP}/diff\" || exit $?\n>\n> vi users will hate you, as you do not give them a chance to edit the\n> message after having seen the diff.\n\nI don't see what you mean. I am a vi user (exclusively), and this script \nworks very well for me.\n\nThe \"-f -o\" flags above ensure that gvim will not fork. I'll add \"vi\" to \nthe search string that automatically add \"-f -o\". Will that satisfy you?\n\nAt the moment, giteditor works exactly like EDITOR (or VISUAL) for me, \nbut it opens up a second buffer (split in the bottom window in my case) \nwith the diff in it. I'm given the opportunity to save.\n\n> git commit will abort anyway if the commit message has not changed.  Plus,\n> it does a better job, as it checks only the non-commented-out text.\n\nOkay. Using $1 exclusively.\n\n> BTW why on earth do you put every single variable name in curly brackets?\n\nI always thought that was good practice. It prevents ambiguity, and *I* \ndon't think it's an eyesore.\n\n> Besides all that criticism, there is also a fundamental issue.  The diff\n> is in a separate file.\n\nThat's the point. If I wanted to put the diff in the commit buffer, I \nwould have used \"git commit -v\". I think many would like to be able to \nscroll through the diff without having to scroll through the commit.\n\nIs there no value in having the diff in a separate file?\n\nThanks --\nTed\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n\n   Please visit my ALS association page:\n         http://web.alsa.org/goto/tedpavlic\n   My family appreciates your support in the fight to defeat ALS.\n"},{"id":"101471","messageId":"1232577906-868-1-git-send-email-ted@tedpavlic.com","threadId":"17291","inReplyTo":"4977A2C9.1070502@tedpavlic.com","subject":"[PATCH] contrib: A script to show diff in new window while editing commit message.","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-21T22:45:06Z","receivedAt":"2009-01-21T22:45:06Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"This new script (contrib/giteditor/giteditor) is an example GIT_EDITOR\nthat causes the editor to open the commit message as well as a \"git diff\n--cached\" in a separate window. This behavior differs from \"git commit\n-v\" in that the diff can be browsed independently of the commit message\nwithout having to invoke a split window view in an editor.\n\nThis script also detects when \"stg edit\" is being called and uses \"stg\nshow\" instead. Hence, it implements a kind of \"stg show -v\".\n\nThis script is highly influenced by the \"hgeditor\" script distributed\nwith the Mercurial SCM.\n\nIt could be improved by supporting a command-line flag that would mimic\nthe \"git commit -v\"-type behavior of opening the diff in the same window\nas the commit message. This would extend existing commands like \"stg\nedit\" that do not already have a \"-v\"-type option.\n\nSigned-off-by: Ted Pavlic <ted@tedpavlic.com>\n---\n\nThis version attempts to answer the concerns brought up by Johannes\nSchindlin.\n\n contrib/giteditor/giteditor |   68 +++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 68 insertions(+), 0 deletions(-)\n create mode 100755 contrib/giteditor/giteditor\n\ndiff --git a/contrib/giteditor/giteditor b/contrib/giteditor/giteditor\nnew file mode 100755\nindex 0000000..501a11c\n--- /dev/null\n+++ b/contrib/giteditor/giteditor\n@@ -0,0 +1,68 @@\n+#!/bin/sh\n+#\n+# Set GIT_EDITOR (or core.editor) to this script to see a diff alongside\n+# commit message. This script differs from \"git commit -v\" in that the\n+# diff shows up in a separate buffer. Additionally, this script works\n+# with \"stg edit\" as well.\n+#\n+# Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>\n+# Highly influenced by hgeditor script distributed with Mercurial SCM.\n+# Distributed under the GNU General Public License, version 2.0.\n+\n+# Find git\n+test -z \"${GIT}\" && GIT=\"git\"\n+\n+# Find stg\n+test -z \"${STG}\" && STG=\"stg\"\n+\n+# Use an editor. To prevent loops, avoid GIT_EDITOR and core.editor.\n+EDITOR=${GIT_EDITOR_EDITOR-${VISUAL-${EDITOR-vi}}}\n+\n+# If we recognize a popular editor, add necessary flags (e.g., to\n+# prevent forking)\n+case \"${EDITOR}\" in\n+    emacs)\n+        EDITOR=\"${EDITOR} -nw\"\n+        ;;\n+    mvim|gvim|vim|vi)\n+        EDITOR=\"${EDITOR} -f -o\"\n+        ;;\n+esac\n+\n+# Remove temporary files even if we get interrupted\n+DIFFOUTPUT=\"giteditor.${RANDOM}.${RANDOM}.${RANDOM}.$$.diff\"\n+cleanup_exit() { \n+    rm -f \"${DIFFOUTPUT}\" \n+}\n+trap \"cleanup_exit\" 0       # normal exit\n+trap \"exit 255\" 1 2 3 6 15  # HUP INT QUIT ABRT TERM\n+\n+# For git, COMMITMSG=COMMIT_EDITMSG\n+# For stg, COMMITMSG=.stgit-edit.txt\n+# etc.\n+COMMITMSG=$(basename \"$1\")\n+case \"${COMMITMSG}\" in\n+    .stgit-edit.txt)        # From \"stg edit\" \n+        DIFFCMD=\"${STG}\"\n+        DIFFARGS=\"show\"\n+        ;;\n+    *)                      # Fall through to \"git commit\" case\n+        DIFFCMD=\"${GIT}\"\n+        DIFFARGS=\"diff --cached\"\n+        # To focus on files that changed, use:\n+        #DIFFARGS=\"diff --cached --diff-filter=M\"\n+        ;;\n+esac\n+\n+\"${DIFFCMD}\" ${DIFFARGS} > ${DIFFOUTPUT}\n+\n+if test -s \"${DIFFOUTPUT}\"; then\n+    # Diff is non-empty, so edit msg and diff\n+    ${EDITOR} \"$1\" \"${DIFFOUTPUT}\" || exit $?\n+else\n+    # Empty diff. Only edit msg\n+    ${EDITOR} \"$1\" || exit $?\n+fi\n+\n+# (recall that DIFFOUTPUT file gets cleaned up by trap above)\n+exit\n-- \n1.6.1.213.g28da8\n"},{"id":"101472","messageId":"alpine.DEB.1.00.0901212343100.3586@pacific.mpi-cbg.de","threadId":"17291","inReplyTo":"4977A2C9.1070502@tedpavlic.com","subject":"Re: [PATCH] Added giteditor script to show diff while editing commit message.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-21T22:52:30Z","receivedAt":"2009-01-21T22:52:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 21 Jan 2009, Ted Pavlic wrote:\n\n> Thanks for your comments. I've responded below. I just want to \n> top-respond to your comment that the fundamental problem is that the \n> diff is in a separate file. In fact, this is the point of the script. I \n> want to be able to scroll through the diff output independent of the \n> commit message.\n\nOnce again, note that e.g. vi will not cope with the way you try to \nachieve that.\n\n> > > From: Ted Pavlic<ted@tedpavlic.com>\n> >\n> > From: me\n> \n> > Besides, I find it funny that you want to override git with $GIT.\n> \n> Isn't it possible that someone has git somewhere else?\n\nThe script is called from within Git.  So you can rest assured that \"git\" \nis in the PATH, I guess.  Except in configurations where you have a \nproperly installed GIT_EXEC_PATH, and run Git using an absolute path.\n\nIf you want to cater for such a case, sure go ahead :-)\n\n> > > +# doesn't break\n> > > +GITTMP=\"${TMPDIR-/tmp}/giteditor.$RANDOM.$RANDOM.$RANDOM.$$.git\"\n> > > +(umask 077&&  mkdir \"${GITTMP}\") || {\n> > > +    echo \"Could not create temporary directory! Exiting.\" 1>&2\n> > > +    exit 1\n> > > +}\n> >\n> > Umm.  Why?  Why do you need a temporary .git directory?\n> \n> The script generates a new \"diff\" file that I would rather drop elsewhere\n> (e.g., in a /tmp directory) rather than here in the current directory.\n\nWhy not .git/?  That would be the _natural_ place to put it.\n\n> > > +    # Diff is non-empty, so edit msg and diff\n> > > +    ${EDITOR} \"${GITTMP}/${COMMITMSG}\" \"${GITTMP}/diff\" || exit $?\n> >\n> > vi users will hate you, as you do not give them a chance to edit the\n> > message after having seen the diff.\n> \n> I don't see what you mean. I am a vi user (exclusively), and this script \n> works very well for me.\n\nI cannot go back to the commit message when I said \":n\" to get to the \ndiff.\n\n> > Besides all that criticism, there is also a fundamental issue.  The \n> > diff is in a separate file.\n> \n> That's the point. If I wanted to put the diff in the commit buffer, I \n> would have used \"git commit -v\". I think many would like to be able to \n> scroll through the diff without having to scroll through the commit.\n> \n> Is there no value in having the diff in a separate file?\n\nIn my case, no, for 2 reasons:\n\n- I can always open a new shell (in ssh connections, I use screen) to get \n  the diff, and even better: I can restrict it to certain files, and I can \n  use the nice bookmarks \"less\" provides; dunno if vi would have them.\n\n- My preference is definitely to look at the diff before committing, to be \n  certain that I did not fsck up.  And nothing would annoy me more than to \n  be in the middle of editing a commit message while I am looking at the \n  diff and telling myself \"that is a stupid mistake, let's fix it\" knowing \n  that the commit will not pick up the fix.\n\n  So seeing the diff while composing the commit message is definitely too \n  late for me.\n\nCiao,\nDscho\n"},{"id":"101482","messageId":"7vy6x4b48e.fsf@gitster.siamese.dyndns.org","threadId":"17291","inReplyTo":"1232577906-868-1-git-send-email-ted@tedpavlic.com","subject":"Re: [PATCH] contrib: A script to show diff in new window while editing commit message.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-21T23:59:13Z","receivedAt":"2009-01-21T23:59:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ted Pavlic <ted@tedpavlic.com> writes:\n\n> It could be improved by supporting a command-line flag that would mimic\n> the \"git commit -v\"-type behavior of opening the diff in the same window\n> as the commit message. This would extend existing commands like \"stg\n> edit\" that do not already have a \"-v\"-type option.\n\nIf a single-buffer operation is an improvement, then I do not see the\npoint of this script.\n\n * Some people would like two-buffer operation and they may use this\n   script as their core.editor.\n\n * Other people (including me) would find it very natural to use \"\\C-x 2\"\n   if they need to look at two places of the same buffer, because that is\n   what they are used to do when editing a long file every day.  They just\n   use \"commit -v\" without bothering with this script.\n\n * Yet other people (like Dscho) would find it too late to have a chance\n   for final review when writing a commit log message anyway, and won't\n   use either.\n\nAnd I think choice is good.\n\nHaving said that, if the lack of \"final chance to review the diff\" in some\nStGIT subcommand is the real problem you are trying to solve, I think it\nis better solved by fixing StGIT.  If this script can be used as a\nsubstitute for the real solution, that may be a welcome unintended side\neffect, but I do not think you should make it the main selling point of\nthe script.  After all people may not want to use this script when they\nare working directly with git, but still would want StGIT fixed.\n"},{"id":"101489","messageId":"4977CFDF.4040200@tedpavlic.com","threadId":"17291","inReplyTo":"alpine.DEB.1.00.0901212343100.3586@pacific.mpi-cbg.de","subject":"Re: [PATCH] Added giteditor script to show diff while editing commit message.","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-22T01:46:07Z","receivedAt":"2009-01-22T01:46:07Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":">> Thanks for your comments. I've responded below. I just want to\n>> top-respond to your comment that the fundamental problem is that the\n>> diff is in a separate file. In fact, this is the point of the script. I\n>> want to be able to scroll through the diff output independent of the\n>> commit message.\n> Once again, note that e.g. vi will not cope with the way you try to\n> achieve that.\n\nIt does for me just fine. In vi, I hit ^W^W and move from commit message \nto diff and back. What's the problem with that? In gvim I'm able to \nclick back and forth.\n\nI have been using this method for a long time with hg, and now I've been \nusing it with git. This isn't theory --- it's been working in practice \nfor me. Am I missing something?\n\n> Why not .git/?  That would be the _natural_ place to put it.\n\nWhy doesn't stg do that? I figured stg would be a well-established \nprogram to pattern behavior off of.\n\nI'll rev-parse the git dir and place the file there.\n\n>>> vi users will hate you, as you do not give them a chance to edit the\n>>> message after having seen the diff.\n>> I don't see what you mean. I am a vi user (exclusively), and this script\n>> works very well for me.\n> I cannot go back to the commit message when I said \":n\" to get to the\n> diff.\n\nvi opens for me and I see two windows. The top window shows the commit \nmessage and the bottom window shows the diff.\n\nI hit ^W^W (or ^W<Down>) and I find myself scrolling around in the diff. \nI hit ^W^W again (or ^W<Up>) and I find myself scrolling around in the \ncommit.\n\nSimilarly, gvim lets me mouse around both --- clicking from window to \nwindow.\n\nIf you must use \":n\", I don't know why you can't use \":prev\" to go back. <?>\n\n>> Is there no value in having the diff in a separate file?\n> In my case, no, for 2 reasons:\n> - I can always open a new shell (in ssh connections, I use screen) to get\n>    the diff, and even better: I can restrict it to certain files, and I can\n>    use the nice bookmarks \"less\" provides; dunno if vi would have them.\n\nvi does.\n\n> - My preference is definitely to look at the diff before committing, to be\n>    certain that I did not fsck up.  And nothing would annoy me more than to\n>    be in the middle of editing a commit message while I am looking at the\n>    diff and telling myself \"that is a stupid mistake, let's fix it\" knowing\n>    that the commit will not pick up the fix.\n\nWhen giving a detailed message bulletting out everything that goes into \na commit, sometimes it's nice to have a very nearby look at the diff.\n\n>    So seeing the diff while composing the commit message is definitely too\n>    late for me.\n\nNevertheless, the secondary purpose of the contributed script is to show \nhow GIT_EDITOR can be used to wrap around other editors. (that's the \npurpose of Mercurial's distributed \"hgeditor\" script as well)\n\n--Ted\n\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n\n   Please visit my ALS association page:\n         http://web.alsa.org/goto/tedpavlic\n   My family appreciates your support in the fight to defeat ALS.\n"},{"id":"101490","messageId":"4977EA8B.8000403@tedpavlic.com","threadId":"17291","inReplyTo":"7vy6x4b48e.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] contrib: A script to show diff in new window while editing commit message.","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-22T03:39:55Z","receivedAt":"2009-01-22T03:39:55Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":">   * Some people would like two-buffer operation and they may use this\n>     script as their core.editor.\n\nThat's what I do, and evidently that's what enough Mercurial users do to \nwarrant them putting \"hgeditor\" in their main distro (not even in the \n\"contrib\" directory). I just figured there must be at least a few other \npeople out there like me, but maybe I'm wrong. <?>\n\n>   * Other people (including me) would find it very natural to use \"\\C-x 2\"\n>     if they need to look at two places of the same buffer, because that is\n>     what they are used to do when editing a long file every day.  They just\n>     use \"commit -v\" without bothering with this script.\n\nAs I mention in the script, splitting windows (which is easy to do in \nVim) is another very natural way to go. That being said, not all editors \nhave terrific split window support. Plus, if you're going to do it \noften, it makes sense to wire up your editor to do it for you each time.\n\n>   * Yet other people (like Dscho) would find it too late to have a chance\n>     for final review when writing a commit log message anyway, and won't\n>     use either.\n\nI'm not using the diff as a code review. I'm using it to help me make \nsure my commit message is complete.\n\n> Having said that, if the lack of \"final chance to review the diff\" in some\n> StGIT subcommand is the real problem you are trying to solve, I think it\n...\n\nHaving the \"stg edit\" support is just a bonus (for me). The main point \nwas showing how to use GIT_EDITOR to bring up a split window. As with \nMercurial's hgeditor, part of the point of the script is to demonstrate \nhow to customize the commit process.\n\nThanks --\n--Ted\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n\n   Please visit my ALS association page:\n         http://web.alsa.org/goto/tedpavlic\n   My family appreciates your support in the fight to defeat ALS.\n"},{"id":"101491","messageId":"1232596208-7384-1-git-send-email-ted@tedpavlic.com","threadId":"17291","inReplyTo":"7vy6x4b48e.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] contrib: A script to show diff in new window while editing commit message.","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-22T03:50:08Z","receivedAt":"2009-01-22T03:50:08Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"This new script (contrib/giteditor/giteditor) is an example GIT_EDITOR\nthat causes the editor to open the commit message as well as a \"git diff\n--cached\" in a separate window. This behavior differs from \"git commit\n-v\" in that the diff can be browsed independently of the commit message\nwithout having to invoke a split window view in an editor.\n\nThis script also detects when \"stg edit\" is being called and uses \"stg\nshow\" instead. Hence, it implements a kind of \"stg edit -v\".\n\nThis script is highly influenced by the \"hgeditor\" script distributed\nwith the Mercurial SCM.\n\nSigned-off-by: Ted Pavlic <ted@tedpavlic.com>\n---\n\nThis new commit responds to some of the issues brought up by Junio C\nHemano (and Johannes Schindelin). In particular, it removes the\nparagraph from the commit message discussing how it could be \"improved.\" \n\nAlso, this new version uses a \"DIFFPIPE\" to strip the old commit message\nfrom the top of the \"stg show\" output so that the \"stg edit\" behavior\nmatches the \"git commit\" behavior. \n\nFinally, this version adds a comment giving an idea for personalizing by\nadding the temporary directory creation back in (as a way to prevent\neditor backup files from piling up inside .git).\n\n contrib/giteditor/giteditor |   86 +++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 86 insertions(+), 0 deletions(-)\n create mode 100755 contrib/giteditor/giteditor\n\ndiff --git a/contrib/giteditor/giteditor b/contrib/giteditor/giteditor\nnew file mode 100755\nindex 0000000..5369732\n--- /dev/null\n+++ b/contrib/giteditor/giteditor\n@@ -0,0 +1,86 @@\n+#!/bin/sh\n+#\n+# Set GIT_EDITOR (or core.editor) to this script to see a diff alongside\n+# commit message. This script differs from \"git commit -v\" in that the\n+# diff shows up in a separate buffer. Additionally, this script works\n+# with \"stg edit\" as well.\n+#\n+# Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>\n+# Highly influenced by hgeditor script distributed with Mercurial SCM.\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# Possible personalizations:\n+#\n+# * If your GIT_DIR gets polluted with backup files created by your\n+#   editor when COMMIT_EDITMSG is saved, then have this script copy\n+#   COMMIT_EDITMSG (i.e., $1) to a temporary directory and then back to\n+#   COMMIT_EDITMSG when done. When the script cleans up after itself, it\n+#   can delete the temporary directory and any leftover backup files.\n+#   Note that the vim setting 'nobackup' disables saving backup files,\n+#   and this setting can be set automatically on gitcommit-type files\n+#   and files matching .stgit-*.txt with an appropriate ftdetect entry.\n+\n+# Find git\n+test -z \"${GIT}\" && GIT=\"git\"\n+\n+# Find stg\n+test -z \"${STG}\" && STG=\"stg\"\n+\n+# Find the nearest git-dir\n+GITDIR=$(git rev-parse --git-dir) || exit\n+\n+# Use an editor. To prevent loops, avoid GIT_EDITOR and core.editor.\n+EDITOR=\"${GIT_EDITOR_EDITOR-${VISUAL-${EDITOR-vi}}}\"\n+\n+# If we recognize a popular editor, add necessary flags (e.g., to\n+# prevent forking)\n+case \"${EDITOR}\" in\n+    emacs)\n+        EDITOR=\"${EDITOR} -nw\"\n+        ;;\n+    mvim|gvim|vim|vi)\n+        EDITOR=\"${EDITOR} -f -o\"\n+        ;;\n+esac\n+\n+# Remove temporary files even if we get interrupted\n+DIFFOUTPUT=\"${GITDIR}/giteditor.${RANDOM}.${RANDOM}.${RANDOM}.$$.diff\"\n+cleanup_exit() { \n+    rm -f \"${DIFFOUTPUT}\" \n+}\n+trap \"cleanup_exit\" 0       # normal exit\n+trap \"exit 255\" 1 2 3 6 15  # HUP INT QUIT ABRT TERM\n+\n+# For git, COMMITMSG=COMMIT_EDITMSG\n+# For stg, COMMITMSG=.stgit-edit.txt\n+# etc.\n+COMMITMSG=$(basename \"$1\")\n+DIFFPIPE=\"cat\"\n+case \"${COMMITMSG}\" in\n+    .stgit-edit.txt)        # From \"stg edit\" \n+        DIFFCMD=\"${STG}\"\n+        DIFFARGS=\"show\"\n+        DIFFPIPE=\"tail +$(wc -l \"$1\"|awk '{print $1+3}')\"\n+        ;;\n+    *)                      # Fall through to \"git commit\" case\n+        DIFFCMD=\"${GIT}\"\n+        DIFFARGS=\"diff --cached\"\n+        # To focus on files that changed, use:\n+        #DIFFARGS=\"diff --cached --diff-filter=M\"\n+        ;;\n+esac\n+\n+# Do the diff and save the result in DIFFOUTPUT\n+\"${DIFFCMD}\" ${DIFFARGS} | ${DIFFPIPE} > ${DIFFOUTPUT}\n+\n+# If DIFFOUTPUT is nonempty, open it alongside commit message\n+if test -s \"${DIFFOUTPUT}\"; then\n+    # Diff is non-empty, so edit msg and diff\n+    ${EDITOR} \"$1\" \"${DIFFOUTPUT}\" || exit\n+else\n+    # Empty diff. Only edit msg\n+    ${EDITOR} \"$1\" || exit\n+fi\n+\n+# (recall that DIFFOUTPUT file gets cleaned up by trap above)\n+exit\n-- \n1.6.1.213.g28da8\n"},{"id":"101510","messageId":"7vk58naihd.fsf@gitster.siamese.dyndns.org","threadId":"17291","inReplyTo":"1232596208-7384-1-git-send-email-ted@tedpavlic.com","subject":"Re: [PATCH] contrib: A script to show diff in new window while editing commit message.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-22T07:49:02Z","receivedAt":"2009-01-22T07:49:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ted Pavlic <ted@tedpavlic.com> writes:\n\n> This new script (contrib/giteditor/giteditor) is an example GIT_EDITOR\n> that causes the editor to open the commit message as well as a \"git diff\n> --cached\" in a separate window. This behavior differs from \"git commit\n> -v\" in that the diff can be browsed independently of the commit message\n> without having to invoke a split window view in an editor.\n>\n> This script also detects when \"stg edit\" is being called and uses \"stg\n> show\" instead. Hence, it implements a kind of \"stg edit -v\".\n>\n> This script is highly influenced by the \"hgeditor\" script distributed\n> with the Mercurial SCM.\n>\n> Signed-off-by: Ted Pavlic <ted@tedpavlic.com>\n> ---\n>\n> This new commit responds to some of the issues brought up by Junio C\n> Hemano (and Johannes Schindelin). In particular, it removes the\n> paragraph from the commit message discussing how it could be \"improved.\" \n>\n> Also, this new version uses a \"DIFFPIPE\" to strip the old commit message\n> from the top of the \"stg show\" output so that the \"stg edit\" behavior\n> matches the \"git commit\" behavior. \n>\n> Finally, this version adds a comment giving an idea for personalizing by\n> adding the temporary directory creation back in (as a way to prevent\n> editor backup files from piling up inside .git).\n>\n>  contrib/giteditor/giteditor |   86 +++++++++++++++++++++++++++++++++++++++++++\n>  1 files changed, 86 insertions(+), 0 deletions(-)\n>  create mode 100755 contrib/giteditor/giteditor\n>\n> diff --git a/contrib/giteditor/giteditor b/contrib/giteditor/giteditor\n> new file mode 100755\n> index 0000000..5369732\n> --- /dev/null\n> +++ b/contrib/giteditor/giteditor\n> @@ -0,0 +1,86 @@\n> +#!/bin/sh\n> +#\n> +# Set GIT_EDITOR (or core.editor) to this script to see a diff alongside\n> +# commit message. This script differs from \"git commit -v\" in that the\n> +# diff shows up in a separate buffer. Additionally, this script works\n> +# with \"stg edit\" as well.\n> +#\n> +# Copyright (c) 2009 by Theodore P. Pavlic <ted@tedpavlic.com>\n> +# Highly influenced by hgeditor script distributed with Mercurial SCM.\n> +# Distributed under the GNU General Public License, version 2.0.\n> +#\n> +# Possible personalizations:\n> +#\n> +# * If your GIT_DIR gets polluted with backup files created by your\n> +#   editor when COMMIT_EDITMSG is saved, then have this script copy\n> +#   COMMIT_EDITMSG (i.e., $1) to a temporary directory and then back to\n> +#   COMMIT_EDITMSG when done. When the script cleans up after itself, it\n> +#   can delete the temporary directory and any leftover backup files.\n> +#   Note that the vim setting 'nobackup' disables saving backup files,\n> +#   and this setting can be set automatically on gitcommit-type files\n> +#   and files matching .stgit-*.txt with an appropriate ftdetect entry.\n\nI am not sure what problem you are trying to offer a solution here.  Are\nyou suggesting a trick to avoid .git/COMMIT_EDITMSG~ left behind by Emacs?\n\n> +# Find git\n> +test -z \"${GIT}\" && GIT=\"git\"\n\nWhy?\n\n> +# Find stg\n> +test -z \"${STG}\" && STG=\"stg\"\n\nWhy?\n\n> +# Find the nearest git-dir\n> +GITDIR=$(git rev-parse --git-dir) || exit\n> +\n> +# Use an editor. To prevent loops, avoid GIT_EDITOR and core.editor.\n> +EDITOR=\"${GIT_EDITOR_EDITOR-${VISUAL-${EDITOR-vi}}}\"\n\nAt the beginning of this file, you have a nice insn to set GIT_EDITOR, but\nthis GIT_EDITOR_EDITOR to customize what underlying editor you end up\nlaunching should also be documented in the same place.\n\nI do not think you need the dq pair around the right hand side.\n\n> +# If we recognize a popular editor, add necessary flags (e.g., to\n> +# prevent forking)\n> +case \"${EDITOR}\" in\n> +    emacs)\n> +        EDITOR=\"${EDITOR} -nw\"\n> +        ;;\n> +    mvim|gvim|vim|vi)\n> +        EDITOR=\"${EDITOR} -f -o\"\n> +        ;;\n> +esac\n\n - Please align case arm labels with case and esac, like this (I do not\n   mind 4-space indentation if that is what you are used to):\n\n\tcase \"$foo\" in\n        bar)\n        \t... do bar things ...\n                ;;\n\t...\n\tesac\n\n - Braces around variables are noisy and distracting;\n\n - Why force emacs users to -nw?  If _you_ personally like -nw, shouldn't\n   you be able to simply do:\n\n\tGIT_EDITOR_EDITOR=\"emacs -nw\"\n\n   in your environment?  After all, when you use $EDITOR later, you do not\n   quote it and let $IFS separate the flags the variable may have in\n   addition to the name of (or path to) the executable.\n\n> +# Remove temporary files even if we get interrupted\n> +DIFFOUTPUT=\"${GITDIR}/giteditor.${RANDOM}.${RANDOM}.${RANDOM}.$$.diff\"\n\nThe script begins with #!/bin/sh but isn't ${RANDOM} a Bash-ism?  Either\nyou should begin it with #!/bin/bash, or avoid bash-ism, if you do not\nwant to alienate poeple whose /bin/sh is not bash.\n\n> +cleanup_exit() { \n> +    rm -f \"${DIFFOUTPUT}\" \n> +}\n> +trap \"cleanup_exit\" 0       # normal exit\n> +trap \"exit 255\" 1 2 3 6 15  # HUP INT QUIT ABRT TERM\n\nIt may have been useful while debugging this script, but is the temporary\nfile that precious to it needs to be kept upon HUP and friends?\n\n> +# For git, COMMITMSG=COMMIT_EDITMSG\n> +# For stg, COMMITMSG=.stgit-edit.txt\n> +# etc.\n> +COMMITMSG=$(basename \"$1\")\n> +DIFFPIPE=\"cat\"\n> +case \"${COMMITMSG}\" in\n> +    .stgit-edit.txt)        # From \"stg edit\" \n> +        DIFFCMD=\"${STG}\"\n> +        DIFFARGS=\"show\"\n> +        DIFFPIPE=\"tail +$(wc -l \"$1\"|awk '{print $1+3}')\"\n> +        ;;\n> +    *)                      # Fall through to \"git commit\" case\n> +        DIFFCMD=\"${GIT}\"\n> +        DIFFARGS=\"diff --cached\"\n> +        # To focus on files that changed, use:\n> +        #DIFFARGS=\"diff --cached --diff-filter=M\"\n> +        ;;\n> +esac\n> +\n\nThis '*' case is horribly wrong.\n\nWhat happens if other parts of git (or third party tools around git) runs\ncore.editor for things other than the commit log messages (or anything you\ndo not know how to prepare a sensible diff to show)?  Shouldn't you act as\nif you were not there at all to avoid surprising the end user with an\nunexpected diff output?\n\nFor example, doesn't \"git rebase -i\" launch core.editor to let you edit\nthe pick/edit/squash insn sequence?  What diff are you showing in such a\ncase, and how would that help your users?\n\n> +# Do the diff and save the result in DIFFOUTPUT\n> +\"${DIFFCMD}\" ${DIFFARGS} | ${DIFFPIPE} > ${DIFFOUTPUT}\n\nBecause your \"extra information in another file\" processing depends\nheavily on what the edited file is (you are already generating the diff\ndifferently for \"git commit\" and \"stg edit\"), I think having this outside\nthe above case statement is a false factoring; it would be easier to read\nand maintain if they are defined in each case arm.  I would probably write\nthis part like this:\n\n\tcase \"$COMMITMSG\" in\n        .stgit-edit.txt)\n        \tdo whatever appropriate for \"stg edit\"  and emit to stdout\n                ;;\n\tCOMMIT_EDITMSG)\n        \tif git rev-parse -q --verify HEAD >/dev/null\n                then\n                \tgit diff --cached\n\t\telse\n                        git diff --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n                fi\n                ;;\n\t*)\n        \t: we do not know how to handle this one\n                ;;\n\tesac >\"$DIFFOUTPUT\"\n\nYou need to quote \"$DIFFOUTPUT\"; it is a path in $GIT_DIR which means it\ncan have $IFS character.\n\n> +# If DIFFOUTPUT is nonempty, open it alongside commit message\n> +if test -s \"${DIFFOUTPUT}\"; then\n> +    # Diff is non-empty, so edit msg and diff\n> +    ${EDITOR} \"$1\" \"${DIFFOUTPUT}\" || exit\n> +else\n> +    # Empty diff. Only edit msg\n> +    ${EDITOR} \"$1\" || exit\n\nIn the latter case, it may be cleaner to:\n\n\trm -f \"$DIFFOUTPUT\"\n        exec ${EDITOR} \"$1\"\n\nOne more thing.  You may want to study how git_editor() in git-sh-setup\nscriptlet solves the issue of (1) the path to the editor executable may\nhave $IFS character that the end user may want to quote, and (2) the end\nuser may want to include options to the editor in the varaible, by using\neval.\n\n> +fi\n> +\n> +# (recall that DIFFOUTPUT file gets cleaned up by trap above)\n> +exit\n"}]}