git-sh-setup: die if outside git repository.
authorJunio C Hamano <junkio@cox.net>
Thu, 24 Nov 2005 08:12:11 +0000 (00:12 -0800)
committerJunio C Hamano <junkio@cox.net>
Fri, 25 Nov 2005 21:49:17 +0000 (13:49 -0800)
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>
26 files changed:
git-am.sh
git-applymbox.sh
git-applypatch.sh
git-bisect.sh
git-branch.sh
git-checkout.sh
git-cherry.sh
git-commit.sh
git-count-objects.sh
git-fetch.sh
git-format-patch.sh
git-lost-found.sh
git-merge.sh
git-octopus.sh
git-prune.sh
git-pull.sh
git-push.sh
git-rebase.sh
git-repack.sh
git-reset.sh
git-resolve.sh
git-revert.sh
git-sh-setup.sh
git-status.sh
git-tag.sh
git-verify-tag.sh

index 8f073c90f6dce20e6e4f3a0b3046cc25dfd503e0..660b3a4b6113f58ff33fd2db2cdeac25ce32f95d 100755 (executable)
--- 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>"
index 6de6932879e9f1298f69e2826f13e1ee231ecea0..24d4a8cb4eb95a5201c205be879d3ac6a62a8a15 100755 (executable)
@@ -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]"
index 66fd19ae2df2e1f44b709a20802342c88d9d2cf2..f0549960fbd706f06fff5b2c602450917505a1ad 100755 (executable)
@@ -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
 ##
index 1ab2f187dcfd1ab9b81bbc3ebb3605601b4d29f0..d92993b94e4264d9c13547f8bc3a1d9c6c77017a 100755 (executable)
@@ -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]
index 2594518e9f7a812a77aaba5b10f3194a7eced423..4cd5da16f74cee6e277d33bce74242496eca94fe 100755 (executable)
@@ -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]]
index 9509ab4b9a53fd132ae74de241c3f60744b6162c..4cf30e2c0529e90886e6edfd485cec67a278e224 100755 (executable)
@@ -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>...]"
index aad2e6171f920c4ad6e83a521837f32d2402da68..867522b37ff4fd85f963019a025ba07789ffef37 100755 (executable)
@@ -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>]
 
index 27aea80a43acf7ee7994b53ef05828edd84f3f73..3d250ec853dad3ff7e714025026ca90f2c77e7bb 100755 (executable)
@@ -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>...]'
index fc61a1a987d45bc73bcee805e9010c5ac96ea66a..d6e9a3221f1f63142d9490e9abdfc5c8ac8d6348 100755 (executable)
@@ -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
index 6586e773e6b3979463d5cc6537e6ddc5700de25a..14ea295113be9381ce9d4af52f022ce99c75506f 100755 (executable)
@@ -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"
index 351790c4494ec88c01063a4c97c487f9e015c339..bc5687653150ff1e27720173b137d759d60c74c6 100755 (executable)
@@ -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]
index 3892f52005d1e36676681806a87ef35dc0689f22..9dd7430018f4bfb76c29e77e7fb9365acaa3bd9b 100755 (executable)
@@ -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
index 255476e2deda1e5c7f9654fd92ba9d1950b1a3b7..d352a3cf65e45e0da0a8ee1989e9acb522e132b5 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-. git-sh-setup || die "Not a git archive"
+. git-sh-setup
 
 LF='
 '
index d2471af3c8a002c175bf9b1370039b9e7d4ab946..2edbf52c42d329bc1cd091f0ec07f6ccf032478e 100755 (executable)
@@ -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"
index c4de7f5f250b647065c97dabbb234216f5c8c718..1fd8c731cdd3651e3cd3c527915db7a4c4324be0 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. git-sh-setup || die "Not a git archive"
+. git-sh-setup
 
 dryrun=
 echo=
index 3b875ad438c21df50c0b1f26bc8fac5ab1bc9740..3a139849fbfc545b7c479dd2889a0285fab646d5 100755 (executable)
@@ -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]
index edc0b8317a6d566895c4a2df6a3f7d86773ca138..140c8f85d55c5654cfc9077fecfd03ad067a6862 100755 (executable)
@@ -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>]"
index 5289762883f07e2737e1dbf3acfa106d101687f3..2bc3a12995ec5f18cf666289a6691fa2e4d3fb47 100755 (executable)
@@ -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
index c0f271d1015d4d6abfa332a3baa427f125be3581..430ddc5a706945035149464d0bea8f25acc21d3c 100755 (executable)
@@ -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
index 2086d26d343c59d36df79d874d65f58d6d7d8b10..72ef303aedc69a1d9cdd946a91059638cb2e550a 100755 (executable)
@@ -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>]'
index 7d8fb54f952e3f85c8c77b8fd9c67afbe76f0316..fcc5ad7349e3f77a6817e499b331b262c4a07b57 100755 (executable)
@@ -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>"
index 4ba6912f0de972a95ec040aa9fb09af78ab2765b..c1aebb159cab86f419ff2aaab2a8f1d9d79a9a72 100755 (executable)
@@ -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* )
index dbb98842bf6327210c604ae65a128cdfc785b32c..e343349c0087aefbb42d17ace9102a72d2fb437a 100755 (executable)
@@ -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."
index 837f334d8760c9ff4af4de5d057e97d7af3cfc61..b90ffc198d97bccfc7f484e8555b01ba9bf5217b 100755 (executable)
@@ -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="#
index 13759453077b025d7815354c61269c2a9847e68f..16efc5b70ac7ea4f0770530845e35091e71feab6 100755 (executable)
@@ -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>]"
index ed4c89396841d8292185b0504ef62ef36007f354..3c65f4a6b51707601bc8f66657e6e79cc33094fd 100755 (executable)
@@ -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."