summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-11-24 00:12:11 -0800
committerJunio C Hamano <junkio@cox.net>2005-11-25 13:49:17 -0800
commitae2b0f15180d4b044828c836bcab6a990efa5c8e (patch)
treef316bfd81eaa2064c1d9e01a336eaed8d7a5bd4f
parente8cc80d03934cc607e3a4d89a05350c238dbf9c5 (diff)
downloadgit-ae2b0f15180d4b044828c836bcab6a990efa5c8e.tar.gz
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 <junkio@cox.net>
-rwxr-xr-xgit-am.sh2
-rwxr-xr-xgit-applymbox.sh2
-rwxr-xr-xgit-applypatch.sh2
-rwxr-xr-xgit-bisect.sh2
-rwxr-xr-xgit-branch.sh2
-rwxr-xr-xgit-checkout.sh2
-rwxr-xr-xgit-cherry.sh2
-rwxr-xr-xgit-commit.sh2
-rwxr-xr-xgit-count-objects.sh2
-rwxr-xr-xgit-fetch.sh2
-rwxr-xr-xgit-format-patch.sh2
-rwxr-xr-xgit-lost-found.sh2
-rwxr-xr-xgit-merge.sh2
-rwxr-xr-xgit-octopus.sh2
-rwxr-xr-xgit-prune.sh2
-rwxr-xr-xgit-pull.sh2
-rwxr-xr-xgit-push.sh2
-rwxr-xr-xgit-rebase.sh2
-rwxr-xr-xgit-repack.sh2
-rwxr-xr-xgit-reset.sh2
-rwxr-xr-xgit-resolve.sh2
-rwxr-xr-xgit-revert.sh2
-rwxr-xr-xgit-sh-setup.sh15
-rwxr-xr-xgit-status.sh2
-rwxr-xr-xgit-tag.sh2
-rwxr-xr-xgit-verify-tag.sh2
26 files changed, 34 insertions, 31 deletions
diff --git a/git-am.sh b/git-am.sh
index 8f073c90f6..660b3a4b61 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=<dir>] [--utf8] [--binary] [--3way] <mbox>"
diff --git a/git-applymbox.sh b/git-applymbox.sh
index 6de6932879..24d4a8cb4e 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/<num> | mbox) [signoff]"
diff --git a/git-applypatch.sh b/git-applypatch.sh
index 66fd19ae2d..f0549960fb 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 1ab2f187dc..d92993b94e 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 2594518e9f..4cd5da16f7 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 <branch>] | [[-f] <branch> [start-point]]
diff --git a/git-checkout.sh b/git-checkout.sh
index 9509ab4b9a..4cf30e2c05 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 <new_branch>] [<branch>] [<paths>...]"
diff --git a/git-cherry.sh b/git-cherry.sh
index aad2e6171f..867522b37f 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] <upstream> [<head>]
diff --git a/git-commit.sh b/git-commit.sh
index 27aea80a43..3d250ec853 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 <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
diff --git a/git-count-objects.sh b/git-count-objects.sh
index fc61a1a987..d6e9a3221f 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 2>/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 6586e773e6..14ea295113 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 351790c449..bc56876531 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 3892f52005..9dd7430018 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 255476e2de..d352a3cf65 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 d2471af3c8..2edbf52c42 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 c4de7f5f25..1fd8c731cd 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 3b875ad438..3a139849fb 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 edc0b8317a..140c8f85d5 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] <repository> [<refspec>]"
diff --git a/git-rebase.sh b/git-rebase.sh
index 5289762883..2bc3a12995 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 c0f271d101..430ddc5a70 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 2086d26d34..72ef303aed 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] [<commit-ish>]'
diff --git a/git-resolve.sh b/git-resolve.sh
index 7d8fb54f95..fcc5ad7349 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 <head> <remote> <merge-message>"
diff --git a/git-revert.sh b/git-revert.sh
index 4ba6912f0d..c1aebb159c 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 dbb98842bf..e343349c00 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 837f334d87..b90ffc198d 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 1375945307..16efc5b70a 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 <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index ed4c893968..3c65f4a6b5 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."