1#!/bin/sh 2# 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, 6# it dies. 7 8# Having this variable in your environment would break scripts because 9# you would cause "cd" to be be taken to unexpected places. If you 10# like CDPATH, define it for your interactive shell sessions without 11# exporting it. 12unset CDPATH 13 14die() { 15echo>&2"$@" 16exit1 17} 18 19usage() { 20 die "Usage:$0$USAGE" 21} 22 23set_reflog_action() { 24if[-z"${GIT_REFLOG_ACTION:+set}"] 25then 26 GIT_REFLOG_ACTION="$*" 27export GIT_REFLOG_ACTION 28fi 29} 30 31git_editor() { 32 GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})} 33case"$GIT_EDITOR,$TERM"in 34,dumb) 35echo>&2"No editor specified in GIT_EDITOR, core.editor, VISUAL," 36echo>&2"or EDITOR. Tried to fall back to vi but terminal is dumb." 37echo>&2"Please set one of these variables to an appropriate" 38echo>&2"editor or run$0with options that will not cause an" 39echo>&2"editor to be invoked (e.g., -m or -F for git-commit)." 40exit1 41;; 42esac 43"${GIT_EDITOR:-vi}""$1" 44} 45 46is_bare_repository () { 47 git rev-parse --is-bare-repository 48} 49 50cd_to_toplevel () { 51 cdup=$(git rev-parse --show-cdup) 52iftest!-z"$cdup" 53then 54cd"$cdup"|| { 55echo>&2"Cannot chdir to$cdup, the toplevel of the working tree" 56exit1 57} 58fi 59} 60 61require_work_tree () { 62test$(git rev-parse --is-inside-work-tree)= true || 63 die "fatal:$0cannot be used without a working tree." 64} 65 66get_author_ident_from_commit () { 67 pick_author_script=' 68 /^author /{ 69 s/'\''/'\''\\'\'\''/g 70 h 71 s/^author \([^<]*\) <[^>]*> .*$/\1/ 72 s/'\''/'\''\'\'\''/g 73 s/.*/GIT_AUTHOR_NAME='\''&'\''/p 74 75 g 76 s/^author [^<]* <\([^>]*\)> .*$/\1/ 77 s/'\''/'\''\'\'\''/g 78 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p 79 80 g 81 s/^author [^<]* <[^>]*> \(.*\)$/\1/ 82 s/'\''/'\''\'\'\''/g 83 s/.*/GIT_AUTHOR_DATE='\''&'\''/p 84 85 q 86} 87' 88 encoding=$(git config i18n.commitencoding || echo UTF-8) 89 git show -s --pretty=raw --encoding="$encoding" "$1" | 90 LANG=C LC_ALL=C sed -ne "$pick_author_script" 91} 92 93if [ -z "$LONG_USAGE" ] 94then 95 LONG_USAGE="Usage:$0$USAGE" 96else 97 LONG_USAGE="Usage:$0$USAGE 98 99$LONG_USAGE" 100fi 101 102case "$1" in 103 -h|--h|--he|--hel|--help) 104 echo "$LONG_USAGE" 105 exit 106esac 107 108# Make sure we are in a valid repository of a vintage we understand. 109if [ -z "$SUBDIRECTORY_OK" ] 110then 111 :${GIT_DIR=.git} 112 GIT_DIR=$(GIT_DIR="$GIT_DIR" git rev-parse --git-dir)|| { 113 exit=$? 114 echo >&2 "You need to run this command from the toplevel of the working tree." 115 exit$exit 116 } 117else 118 GIT_DIR=$(git rev-parse --git-dir)|| exit 119fi 120:${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}