2005-07-08 21:57:21 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2005-11-24 11:12:11 +03:00
|
|
|
# This is included in commands that either have to be run from the toplevel
|
|
|
|
# of the repository, or with GIT_DIR environment variable properly.
|
|
|
|
# If the GIT_DIR does not look like the right correct git-repository,
|
|
|
|
# it dies.
|
2005-07-08 21:57:21 +04:00
|
|
|
|
2005-09-13 06:47:07 +04:00
|
|
|
# Having this variable in your environment would break scripts because
|
|
|
|
# you would cause "cd" to be be taken to unexpected places. If you
|
|
|
|
# like CDPATH, define it for your interactive shell sessions without
|
|
|
|
# exporting it.
|
|
|
|
unset CDPATH
|
|
|
|
|
2005-07-08 21:57:21 +04:00
|
|
|
die() {
|
2005-10-01 01:26:57 +04:00
|
|
|
echo >&2 "$@"
|
2005-07-08 21:57:21 +04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2005-12-11 12:55:49 +03:00
|
|
|
usage() {
|
|
|
|
die "Usage: $0 $USAGE"
|
|
|
|
}
|
|
|
|
|
2006-12-28 10:34:48 +03:00
|
|
|
set_reflog_action() {
|
|
|
|
if [ -z "${GIT_REFLOG_ACTION:+set}" ]
|
|
|
|
then
|
|
|
|
GIT_REFLOG_ACTION="$*"
|
|
|
|
export GIT_REFLOG_ACTION
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-01-07 13:17:52 +03:00
|
|
|
is_bare_repository () {
|
2007-06-03 18:46:36 +04:00
|
|
|
git-rev-parse --is-bare-repository
|
2007-01-07 13:17:52 +03:00
|
|
|
}
|
|
|
|
|
2007-01-12 23:44:08 +03:00
|
|
|
cd_to_toplevel () {
|
|
|
|
cdup=$(git-rev-parse --show-cdup)
|
|
|
|
if test ! -z "$cdup"
|
|
|
|
then
|
|
|
|
cd "$cdup" || {
|
|
|
|
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-12-31 07:32:38 +03:00
|
|
|
require_work_tree () {
|
2007-06-03 18:48:16 +04:00
|
|
|
test $(git-rev-parse --is-inside-work-tree) = true &&
|
2007-01-23 15:30:20 +03:00
|
|
|
test $(git-rev-parse --is-inside-git-dir) = false ||
|
2006-12-31 07:32:38 +03:00
|
|
|
die "fatal: $0 cannot be used without a working tree."
|
|
|
|
}
|
|
|
|
|
2007-06-25 04:04:11 +04:00
|
|
|
get_author_ident_from_commit () {
|
|
|
|
pick_author_script='
|
|
|
|
/^author /{
|
|
|
|
s/'\''/'\''\\'\'\''/g
|
|
|
|
h
|
|
|
|
s/^author \([^<]*\) <[^>]*> .*$/\1/
|
|
|
|
s/'\''/'\''\'\'\''/g
|
|
|
|
s/.*/GIT_AUTHOR_NAME='\''&'\''/p
|
|
|
|
|
|
|
|
g
|
|
|
|
s/^author [^<]* <\([^>]*\)> .*$/\1/
|
|
|
|
s/'\''/'\''\'\'\''/g
|
|
|
|
s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
|
|
|
|
|
|
|
|
g
|
|
|
|
s/^author [^<]* <[^>]*> \(.*\)$/\1/
|
|
|
|
s/'\''/'\''\'\'\''/g
|
|
|
|
s/.*/GIT_AUTHOR_DATE='\''&'\''/p
|
|
|
|
|
|
|
|
q
|
|
|
|
}
|
|
|
|
'
|
|
|
|
encoding=$(git config i18n.commitencoding || echo UTF-8)
|
|
|
|
git show -s --pretty=raw --encoding="$encoding" "$1" |
|
|
|
|
LANG=C LC_ALL=C sed -ne "$pick_author_script"
|
|
|
|
}
|
|
|
|
|
2005-12-11 12:55:49 +03:00
|
|
|
if [ -z "$LONG_USAGE" ]
|
|
|
|
then
|
|
|
|
LONG_USAGE="Usage: $0 $USAGE"
|
|
|
|
else
|
|
|
|
LONG_USAGE="Usage: $0 $USAGE
|
|
|
|
|
|
|
|
$LONG_USAGE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
2006-04-15 02:54:51 +04:00
|
|
|
-h|--h|--he|--hel|--help)
|
2005-12-11 12:55:49 +03:00
|
|
|
echo "$LONG_USAGE"
|
|
|
|
exit
|
|
|
|
esac
|
|
|
|
|
2006-08-12 05:47:50 +04:00
|
|
|
# Make sure we are in a valid repository of a vintage we understand.
|
2005-12-11 12:55:49 +03:00
|
|
|
if [ -z "$SUBDIRECTORY_OK" ]
|
|
|
|
then
|
|
|
|
: ${GIT_DIR=.git}
|
2007-01-12 23:24:16 +03:00
|
|
|
GIT_DIR=$(GIT_DIR="$GIT_DIR" git-rev-parse --git-dir) || {
|
|
|
|
exit=$?
|
|
|
|
echo >&2 "You need to run this command from the toplevel of the working tree."
|
|
|
|
exit $exit
|
|
|
|
}
|
2005-12-11 12:55:49 +03:00
|
|
|
else
|
|
|
|
GIT_DIR=$(git-rev-parse --git-dir) || exit
|
|
|
|
fi
|
2006-08-12 05:47:50 +04:00
|
|
|
: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
|