Commit 5ebbe2da authored by Brad King's avatar Brad King

Set GIT_DIR if not already set

Although it seems reasonable to expect GIT_DIR to be set when
hooks are invoked, the "git help hooks" documentation does not
guarantee it.  On msysGit 1.7.8 (and perhaps others) "git gui"
runs prepare-commit-msg without setting GIT_DIR.  Set GIT_DIR
at the beginning of each commit hook if it is not already set.
parent b966ceb4
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2011 Kitware, Inc.
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -15,6 +15,8 @@
# limitations under the License.
#=============================================================================
. "${BASH_SOURCE%/*}/hooks-config.bash"
# Prepare a copy of the message:
# - strip comment lines
# - stop at "diff --git" (git commit -v)
......@@ -35,8 +37,6 @@ die() {
exit 1
}
. "$GIT_DIR/hooks/hooks-config.bash"
#-----------------------------------------------------------------------------
# Check the commit message layout with a simple state machine.
......
#=============================================================================
# Copyright 2010-2011 Kitware, Inc.
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -14,6 +14,11 @@
# limitations under the License.
#=============================================================================
# Make sure GIT_DIR is set.
if test -z "$GIT_DIR"; then
export GIT_DIR=$(git rev-parse --git-dir)
fi
# Load hooks configuration from source tree.
config=".hooks-config.bash" && test -r "$config" && . "$config"
......
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2011 Kitware, Inc.
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -15,6 +15,8 @@
# limitations under the License.
#=============================================================================
. "${BASH_SOURCE%/*}/hooks-config.bash"
die() {
echo 'pre-commit hook failure' 1>&2
echo '-----------------------' 1>&2
......@@ -23,8 +25,6 @@ die() {
exit 1
}
. "$GIT_DIR/hooks/hooks-config.bash"
zero='0000000000000000000000000000000000000000'
#-----------------------------------------------------------------------------
......
......@@ -15,7 +15,7 @@
# limitations under the License.
#=============================================================================
. "$GIT_DIR/hooks/hooks-config.bash"
. "${BASH_SOURCE%/*}/hooks-config.bash"
# Invoke the Gerrit Change-Id hook here for "git merge" because
# it does not run the normal commit-msg hook.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment