Skip to content

Commit 02e4989

Browse files
committed
Mirror Git's editor config
Because: * Currently the hook simply uses $EDITOR. The Git editor can be set in a range of different ways, so `$EDITOR` may not always be the editor used by Git. This change: * Mirror's Git's editor config with the same fallbacks, ref: https://github.com/git/git/blob/v2.11.0/editor.c#L10-L30 Fixes #9
1 parent 260dfdf commit 02e4989

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

hook.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
COMMIT_MSG_FILE="$1"
1313
COMMIT_MSG_LINES=
14+
HOOK_EDITOR=
1415
SKIP_DISPLAY_WARNINGS=0
1516
WARNINGS=
1617

@@ -35,6 +36,18 @@ set_colors() {
3536
fi
3637
}
3738

39+
#
40+
# Set the hook editor, using the same approach as git.
41+
#
42+
43+
set_editor() {
44+
HOOK_EDITOR=$GIT_EDITOR
45+
test -z "${HOOK_EDITOR}" && HOOK_EDITOR=$(git config --get core.editor)
46+
test -z "${HOOK_EDITOR}" && HOOK_EDITOR=$VISUAL
47+
test -z "${HOOK_EDITOR}" && HOOK_EDITOR=$EDITOR
48+
test -z "${HOOK_EDITOR}" && HOOK_EDITOR='vi'
49+
}
50+
3851
#
3952
# Output prompt help information.
4053
#
@@ -223,6 +236,8 @@ validate_commit_message() {
223236

224237
set_colors
225238

239+
set_editor
240+
226241
if tty >/dev/null 2>&1; then
227242
TTY=$(tty)
228243
else
@@ -248,7 +263,7 @@ while true; do
248263

249264
# Check if the reply is valid
250265
case "$REPLY" in
251-
E*|e*) $EDITOR "$COMMIT_MSG_FILE" < $TTY; continue ;;
266+
E*|e*) $HOOK_EDITOR "$COMMIT_MSG_FILE" < $TTY; continue ;;
252267
Y*|y*) exit 0 ;;
253268
N*|n*) exit 1 ;;
254269
*) SKIP_DISPLAY_WARNINGS=1; prompt_help; continue ;;

0 commit comments

Comments
 (0)