Documentation/gitattributes.txt: typofix
[git/platforms.git] / git-sh-setup.sh
blobc51985e4c36022a1f58146e49cc82336c39df05a
1 #!/bin/sh
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.
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.
12 unset CDPATH
14 die() {
15 echo >&2 "$@"
16 exit 1
19 usage() {
20 die "Usage: $0 $USAGE"
23 set_reflog_action() {
24 if [ -z "${GIT_REFLOG_ACTION:+set}" ]
25 then
26 GIT_REFLOG_ACTION="$*"
27 export GIT_REFLOG_ACTION
31 git_editor() {
32 GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})}
33 case "$GIT_EDITOR,$TERM" in
34 ,dumb)
35 echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
36 echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
37 echo >&2 "Please set one of these variables to an appropriate"
38 echo >&2 "editor or run $0 with options that will not cause an"
39 echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
40 exit 1
42 esac
43 "${GIT_EDITOR:-vi}" "$1"
46 is_bare_repository () {
47 git rev-parse --is-bare-repository
50 cd_to_toplevel () {
51 cdup=$(git rev-parse --show-cdup)
52 if test ! -z "$cdup"
53 then
54 cd "$cdup" || {
55 echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
56 exit 1
61 require_work_tree () {
62 test $(git rev-parse --is-inside-work-tree) = true &&
63 test $(git rev-parse --is-inside-git-dir) = false ||
64 die "fatal: $0 cannot be used without a working tree."
67 get_author_ident_from_commit () {
68 pick_author_script='
69 /^author /{
70 s/'\''/'\''\\'\'\''/g
72 s/^author \([^<]*\) <[^>]*> .*$/\1/
73 s/'\''/'\''\'\'\''/g
74 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
77 s/^author [^<]* <\([^>]*\)> .*$/\1/
78 s/'\''/'\''\'\'\''/g
79 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
82 s/^author [^<]* <[^>]*> \(.*\)$/\1/
83 s/'\''/'\''\'\'\''/g
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" ]
95 then
96 LONG_USAGE="Usage: $0 $USAGE"
97 else
98 LONG_USAGE="Usage: $0 $USAGE
100 $LONG_USAGE"
103 case "$1" in
104 -h|--h|--he|--hel|--help)
105 echo "$LONG_USAGE"
106 exit
107 esac
109 # Make sure we are in a valid repository of a vintage we understand.
110 if [ -z "$SUBDIRECTORY_OK" ]
111 then
112 : ${GIT_DIR=.git}
113 GIT_DIR=$(GIT_DIR="$GIT_DIR" git rev-parse --git-dir) || {
114 exit=$?
115 echo >&2 "You need to run this command from the toplevel of the working tree."
116 exit $exit
118 else
119 GIT_DIR=$(git rev-parse --git-dir) || exit
121 : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}