Created
May 26, 2011 05:03
-
-
Save jamezpolley/992584 to your computer and use it in GitHub Desktop.
Port of hgeditor to work with git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -x | |
# | |
# based on http://selenic.com/git/raw-file/tip/hgeditor | |
# and http://stackoverflow.com/questions/4750148/git-show-index-diff-in-commit-message-as-comment | |
# | |
# This is an example of using GITEDITOR to create of diff to review the | |
# changes while commiting. | |
# | |
# If you want to pass your favourite editor some other parameters | |
# only for Git, modify this: | |
case "${EDITOR}" in | |
"") | |
EDITOR="vi" | |
;; | |
emacs) | |
EDITOR="$EDITOR -nw" | |
;; | |
gvim|vim) | |
EDITOR="$EDITOR -f -O" | |
;; | |
esac | |
GITTMP="" | |
cleanup_exit() { | |
rm -rf "$GITTMP" | |
} | |
# Remove temporary files even if we get interrupted | |
trap "cleanup_exit" 0 # normal exit | |
trap "exit 255" HUP INT QUIT ABRT TERM | |
GITTMP=$(mktemp -d ${TMPDIR-/tmp}/giteditor.XXXXXX) | |
[ x$GITTMP != x -a -d $GITTMP ] || { | |
echo "Could not create temporary directory! Exiting." 1>&2 | |
exit 1 | |
} | |
( | |
git diff --no-ext-diff --staged -p >> "$GITTMP/diff" | |
) | |
cat "$1" > "$GITTMP/msg" | |
MD5=$(which md5sum 2>/dev/null) || \ | |
MD5=$(which md5 2>/dev/null) | |
[ -x "${MD5}" ] && CHECKSUM=`${MD5} "$GITTMP/msg"` | |
if [ -s "$GITTMP/diff" ]; then | |
$EDITOR "$GITTMP/msg" "$GITTMP/diff" || exit $? | |
else | |
$EDITOR "$GITTMP/msg" || exit $? | |
fi | |
[ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13) | |
mv "$GITTMP/msg" "$1" | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment