3 # This is included in commands that either have to be run from the toplevel
4 # of the repository, or with GIT_DIR environment variable properly.
5 # If the GIT_DIR does not look like the right correct git-repository,
8 # Having this variable in your environment would break scripts because
9 # you would cause "cd" to be taken to unexpected places. If you
10 # like CDPATH, define it for your interactive shell sessions without
20 die
"Usage: $0 $USAGE"
24 if [ -z "${GIT_REFLOG_ACTION:+set}" ]
26 GIT_REFLOG_ACTION
="$*"
27 export GIT_REFLOG_ACTION
32 : "${GIT_EDITOR:=$(git config core.editor)}"
33 : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
34 case "$GIT_EDITOR,$TERM" in
36 echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
37 echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
38 echo >&2 "Please set one of these variables to an appropriate"
39 echo >&2 "editor or run $0 with options that will not cause an"
40 echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
44 eval "${GIT_EDITOR:=vi}" '"$@"'
47 is_bare_repository
() {
48 git rev-parse
--is-bare-repository
52 cdup
=$
(git rev-parse
--show-cdup)
56 echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
62 require_work_tree
() {
63 test $
(git rev-parse
--is-inside-work-tree) = true ||
64 die
"fatal: $0 cannot be used without a working tree."
67 get_author_ident_from_commit
() {
72 s/^author \([^<]*\) <[^>]*> .*$/\1/
74 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
77 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
79 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
82 s/^author [^<]* <[^>]*> \(.*\)$/\1/
84 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
89 encoding=$(git config i18n.commitencoding || echo UTF-8)
90 git show -s --pretty=raw --encoding="$encoding" "$1" |
91 LANG=C LC_ALL=C sed -ne "$pick_author_script"
94 if [ -z "$LONG_USAGE" ]
96 LONG_USAGE="Usage: $0 $USAGE"
98 LONG_USAGE="Usage: $0 $USAGE
104 -h|--h|--he|--hel|--help)
109 # Make sure we are in a valid repository of a vintage we understand.
110 if [ -z "$SUBDIRECTORY_OK" ]
113 GIT_DIR=$(GIT_DIR="$GIT_DIR" git rev-parse --git-dir) || {
115 echo >&2 "You need to run this command from the toplevel of the working tree."
119 GIT_DIR=$(git rev-parse --git-dir) || {
121 echo >&2 "Failed to find a valid git directory."
126 test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || {
127 echo >&2 "Unable to determine absolute path of git directory"
131 : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}