From: Junio C Hamano Date: Thu, 24 Nov 2005 08:12:11 +0000 (-0800) Subject: git-sh-setup: die if outside git repository. X-Git-Tag: v0.99.9k^2~3 X-Git-Url: https://git.octo.it/?p=git.git;a=commitdiff_plain;h=ae2b0f15180d4b044828c836bcab6a990efa5c8e git-sh-setup: die if outside git repository. Now all the users of this script detect its exit status and die, complaining that it is outside git repository. So move the code that dies from all callers to git-sh-setup script. Signed-off-by: Junio C Hamano --- diff --git a/git-am.sh b/git-am.sh index 8f073c90..660b3a4b 100755 --- a/git-am.sh +++ b/git-am.sh @@ -1,7 +1,7 @@ #!/bin/sh # # -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { echo >&2 "usage: $0 [--signoff] [--dotest=] [--utf8] [--binary] [--3way] " diff --git a/git-applymbox.sh b/git-applymbox.sh index 6de69328..24d4a8cb 100755 --- a/git-applymbox.sh +++ b/git-applymbox.sh @@ -18,7 +18,7 @@ ## ## git-am is supposed to be the newer and better tool for this job. -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { echo >&2 "applymbox [-u] [-k] [-q] [-m] (-c .dotest/ | mbox) [signoff]" diff --git a/git-applypatch.sh b/git-applypatch.sh index 66fd19ae..f0549960 100755 --- a/git-applypatch.sh +++ b/git-applypatch.sh @@ -10,7 +10,7 @@ ## $3 - "info" file with Author, email and subject ## $4 - optional file containing signoff to add ## -. git-sh-setup || die "Not a git archive." +. git-sh-setup final=.dotest/final-commit ## diff --git a/git-bisect.sh b/git-bisect.sh index 1ab2f187..d92993b9 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -1,5 +1,5 @@ #!/bin/sh -. git-sh-setup || dir "Not a git archive" +. git-sh-setup usage() { echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize] diff --git a/git-branch.sh b/git-branch.sh index 2594518e..4cd5da16 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -1,6 +1,6 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { echo >&2 "usage: $(basename $0)"' [-d ] | [[-f] [start-point]] diff --git a/git-checkout.sh b/git-checkout.sh index 9509ab4b..4cf30e2c 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -1,5 +1,5 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { die "usage: git checkout [-f] [-b ] [] [...]" diff --git a/git-cherry.sh b/git-cherry.sh index aad2e617..867522b3 100755 --- a/git-cherry.sh +++ b/git-cherry.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano. # -. git-sh-setup || die "Not a git archive." +. git-sh-setup usage="usage: $0 "'[-v] [] diff --git a/git-commit.sh b/git-commit.sh index 27aea80a..3d250ec8 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Linus Torvalds # -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { die 'git commit [-a] [-s] [-v | --no-verify] [-m | -F | (-C|-c) ] [-e] [...]' diff --git a/git-count-objects.sh b/git-count-objects.sh index fc61a1a9..d6e9a322 100755 --- a/git-count-objects.sh +++ b/git-count-objects.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano # -. git-sh-setup || die "Not a git repository" +. git-sh-setup dc /dev/null || { # This is not a real DC at all -- it just knows how diff --git a/git-fetch.sh b/git-fetch.sh index 6586e773..14ea2951 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -1,6 +1,6 @@ #!/bin/sh # -. git-sh-setup || die "Not a git archive" +. git-sh-setup . git-parse-remote _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" diff --git a/git-format-patch.sh b/git-format-patch.sh index 351790c4..bc568765 100755 --- a/git-format-patch.sh +++ b/git-format-patch.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano # -. git-sh-setup || die "Not a git archive." +. git-sh-setup usage () { echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox] diff --git a/git-lost-found.sh b/git-lost-found.sh index 3892f520..9dd74300 100755 --- a/git-lost-found.sh +++ b/git-lost-found.sh @@ -1,6 +1,6 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive." +. git-sh-setup laf="$GIT_DIR/lost-found" rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit diff --git a/git-merge.sh b/git-merge.sh index 255476e2..d352a3cf 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano # -. git-sh-setup || die "Not a git archive" +. git-sh-setup LF=' ' diff --git a/git-octopus.sh b/git-octopus.sh index d2471af3..2edbf52c 100755 --- a/git-octopus.sh +++ b/git-octopus.sh @@ -4,7 +4,7 @@ # # Resolve two or more trees recorded in $GIT_DIR/FETCH_HEAD. # -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { die "usage: git octopus" diff --git a/git-prune.sh b/git-prune.sh index c4de7f5f..1fd8c731 100755 --- a/git-prune.sh +++ b/git-prune.sh @@ -1,6 +1,6 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" +. git-sh-setup dryrun= echo= diff --git a/git-pull.sh b/git-pull.sh index 3b875ad4..3a139849 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -4,7 +4,7 @@ # # Fetch one or more remote refs and merge it/them into the current HEAD. -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { echo >&2 "usage: $0"' [-n] [--no-commit] [--no-summary] [--help] diff --git a/git-push.sh b/git-push.sh index edc0b831..140c8f85 100755 --- a/git-push.sh +++ b/git-push.sh @@ -1,5 +1,5 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { die "Usage: git push [--all] [--force] []" diff --git a/git-rebase.sh b/git-rebase.sh index 52897628..2bc3a129 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano. # -. git-sh-setup || die "Not a git archive." +. git-sh-setup # The other head is given other=$(git-rev-parse --verify "$1^0") || exit diff --git a/git-repack.sh b/git-repack.sh index c0f271d1..430ddc5a 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Linus Torvalds # -. git-sh-setup || die "Not a git archive" +. git-sh-setup no_update_info= all_into_one= remove_redundant= local= while case "$#" in 0) break ;; esac diff --git a/git-reset.sh b/git-reset.sh index 2086d26d..72ef303a 100755 --- a/git-reset.sh +++ b/git-reset.sh @@ -1,5 +1,5 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { die 'Usage: git reset [--mixed | --soft | --hard] []' diff --git a/git-resolve.sh b/git-resolve.sh index 7d8fb54f..fcc5ad73 100755 --- a/git-resolve.sh +++ b/git-resolve.sh @@ -4,7 +4,7 @@ # # Resolve two trees. # -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { die "git-resolve " diff --git a/git-revert.sh b/git-revert.sh index 4ba6912f..c1aebb15 100755 --- a/git-revert.sh +++ b/git-revert.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Linus Torvalds # Copyright (c) 2005 Junio C Hamano # -. git-sh-setup || die "Not a git archive" +. git-sh-setup case "$0" in *-revert* ) diff --git a/git-sh-setup.sh b/git-sh-setup.sh index dbb98842..e343349c 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -1,10 +1,9 @@ #!/bin/sh # -# Set up GIT_DIR and GIT_OBJECT_DIRECTORY -# and return true if everything looks ok -# -: ${GIT_DIR=.git} -: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} +# 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. # Having this variable in your environment would break scripts because # you would cause "cd" to be be taken to unexpected places. If you @@ -12,6 +11,9 @@ # exporting it. unset CDPATH +: ${GIT_DIR=.git} +: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} + die() { echo >&2 "$@" exit 1 @@ -22,4 +24,5 @@ refs/*) : ;; *) false ;; esac && [ -d "$GIT_DIR/refs" ] && -[ -d "$GIT_OBJECT_DIRECTORY/" ] +[ -d "$GIT_OBJECT_DIRECTORY/" ] || + die "Not a git repository." diff --git a/git-status.sh b/git-status.sh index 837f334d..b90ffc19 100755 --- a/git-status.sh +++ b/git-status.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2005 Linus Torvalds # -. git-sh-setup || die "Not a git archive" +GIT_DIR=$(git-rev-parse --git-dir) || exit report () { header="# diff --git a/git-tag.sh b/git-tag.sh index 13759453..16efc5b7 100755 --- a/git-tag.sh +++ b/git-tag.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright (c) 2005 Linus Torvalds -. git-sh-setup || die "Not a git archive" +. git-sh-setup usage () { echo >&2 "Usage: git-tag [-a | -s | -u ] [-f | -d] [-m ] []" diff --git a/git-verify-tag.sh b/git-verify-tag.sh index ed4c8939..3c65f4a6 100755 --- a/git-verify-tag.sh +++ b/git-verify-tag.sh @@ -1,5 +1,5 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" +. git-sh-setup type="$(git-cat-file -t "$1" 2>/dev/null)" || die "$1: no such object."