2005-07-08 17:57:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2005-11-24 08:12:11 +00: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 17:57:21 +00:00
|
|
|
|
2005-09-13 02:47:07 +00: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 17:57:21 +00:00
|
|
|
die() {
|
2005-09-30 21:26:57 +00:00
|
|
|
echo >&2 "$@"
|
2005-07-08 17:57:21 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2005-12-11 09:55:49 +00:00
|
|
|
usage() {
|
|
|
|
die "Usage: $0 $USAGE"
|
|
|
|
}
|
|
|
|
|
2006-12-28 07:34:48 +00:00
|
|
|
set_reflog_action() {
|
|
|
|
if [ -z "${GIT_REFLOG_ACTION:+set}" ]
|
|
|
|
then
|
|
|
|
GIT_REFLOG_ACTION="$*"
|
|
|
|
export GIT_REFLOG_ACTION
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-01-07 10:17:52 +00:00
|
|
|
is_bare_repository () {
|
2007-01-29 00:16:53 +00:00
|
|
|
git-config --bool --get core.bare ||
|
2007-01-07 10:17:52 +00:00
|
|
|
case "$GIT_DIR" in
|
|
|
|
.git | */.git) echo false ;;
|
|
|
|
*) echo true ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2007-01-12 20:44:08 +00: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 04:32:38 +00:00
|
|
|
require_work_tree () {
|
2007-01-23 12:30:20 +00:00
|
|
|
test $(is_bare_repository) = false &&
|
|
|
|
test $(git-rev-parse --is-inside-git-dir) = false ||
|
2006-12-31 04:32:38 +00:00
|
|
|
die "fatal: $0 cannot be used without a working tree."
|
|
|
|
}
|
|
|
|
|
2005-12-11 09:55:49 +00: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-14 22:54:51 +00:00
|
|
|
-h|--h|--he|--hel|--help)
|
2005-12-11 09:55:49 +00:00
|
|
|
echo "$LONG_USAGE"
|
|
|
|
exit
|
|
|
|
esac
|
|
|
|
|
2006-08-12 01:47:50 +00:00
|
|
|
# Make sure we are in a valid repository of a vintage we understand.
|
2005-12-11 09:55:49 +00:00
|
|
|
if [ -z "$SUBDIRECTORY_OK" ]
|
|
|
|
then
|
|
|
|
: ${GIT_DIR=.git}
|
2007-01-12 20:24:16 +00: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 09:55:49 +00:00
|
|
|
else
|
|
|
|
GIT_DIR=$(git-rev-parse --git-dir) || exit
|
|
|
|
fi
|
2006-08-12 01:47:50 +00:00
|
|
|
: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
|