From ae2b0f15180d4b044828c836bcab6a990efa5c8e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 24 Nov 2005 00:12:11 -0800 Subject: 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 8f073c9..660b3a4 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 6de6932..24d4a8c 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 66fd19a..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 1ab2f18..d92993b 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 2594518..4cd5da1 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 9509ab4..4cf30e2 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 aad2e61..867522b 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 27aea80..3d250ec 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 fc61a1a..d6e9a32 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 6586e77..14ea295 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 351790c..bc56876 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 3892f52..9dd7430 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 255476e..d352a3c 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 d2471af..2edbf52 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 c4de7f5..1fd8c73 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 3b875ad..3a13984 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 edc0b83..140c8f8 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 5289762..2bc3a12 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 c0f271d..430ddc5 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 2086d26..72ef303 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 7d8fb54..fcc5ad7 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 4ba6912..c1aebb1 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 dbb9884..e343349 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 837f334..b90ffc1 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 1375945..16efc5b 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 ed4c893..3c65f4a 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." -- cgit v0.10.2-6-g49f6