X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-sh-setup.sh;h=9ac657a70e67315f46a0c42611d7e6d78f538031;hb=892c41b98ae2e6baf3aa13901cb10db9ac67d2f3;hp=025ef2d5f6b37d89dab1d602e1d8d1a80ab7f42e;hpb=b4a081b428c607f98c5d0a0eec8d543dc1f2abcd;p=git.git diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 025ef2d5f..9ac657a70 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -20,6 +20,35 @@ usage() { die "Usage: $0 $USAGE" } +set_reflog_action() { + if [ -z "${GIT_REFLOG_ACTION:+set}" ] + then + GIT_REFLOG_ACTION="$*" + export GIT_REFLOG_ACTION + fi +} + +is_bare_repository () { + git-rev-parse --is-bare-repository +} + +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 +} + +require_work_tree () { + test $(is_bare_repository) = false && + test $(git-rev-parse --is-inside-git-dir) = false || + die "fatal: $0 cannot be used without a working tree." +} + if [ -z "$LONG_USAGE" ] then LONG_USAGE="Usage: $0 $USAGE" @@ -30,22 +59,21 @@ $LONG_USAGE" fi case "$1" in - --h|--he|--hel|--help) + -h|--h|--he|--hel|--help) echo "$LONG_USAGE" exit esac +# Make sure we are in a valid repository of a vintage we understand. if [ -z "$SUBDIRECTORY_OK" ] then : ${GIT_DIR=.git} - : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} - - # Make sure we are in a valid repository of a vintage we understand. - GIT_DIR="$GIT_DIR" git repo-config --get core.nosuch >/dev/null - if test $? = 128 - then - exit - fi + 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 + } else GIT_DIR=$(git-rev-parse --git-dir) || exit fi +: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}