summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-add.sh13
-rwxr-xr-xgit-am.sh10
-rwxr-xr-xgit-applymbox.sh6
-rwxr-xr-xgit-applypatch.sh4
-rwxr-xr-xgit-bisect.sh24
-rwxr-xr-xgit-branch.sh21
-rwxr-xr-xgit-checkout.sh6
-rwxr-xr-xgit-cherry.sh13
-rwxr-xr-xgit-clone.sh2
-rwxr-xr-xgit-commit.sh5
-rwxr-xr-xgit-fetch.sh5
-rwxr-xr-xgit-format-patch.sh25
-rwxr-xr-xgit-grep.sh7
-rwxr-xr-xgit-lost-found.sh10
-rwxr-xr-xgit-merge.sh6
-rwxr-xr-xgit-prune.sh3
-rwxr-xr-xgit-pull.sh13
-rwxr-xr-xgit-push.sh7
-rwxr-xr-xgit-rebase.sh5
-rwxr-xr-xgit-repack.sh3
-rwxr-xr-xgit-request-pull.sh12
-rwxr-xr-xgit-reset.sh6
-rwxr-xr-xgit-resolve.sh6
-rwxr-xr-xgit-revert.sh19
-rwxr-xr-xgit-sh-setup.sh34
-rwxr-xr-xgit-status.sh11
-rwxr-xr-xgit-tag.sh14
-rwxr-xr-xgit-verify-tag.sh12
-rwxr-xr-xt/t3200-branch.sh4
29 files changed, 142 insertions, 164 deletions
diff --git a/git-add.sh b/git-add.sh
index fdec86d1a4..f719b4b1a8 100755
--- a/git-add.sh
+++ b/git-add.sh
@@ -1,13 +1,8 @@
#!/bin/sh
-die () {
- echo >&2 "$*"
- exit 1
-}
-
-usage() {
- die "usage: git add [-n] [-v] <file>..."
-}
+USAGE='[-n] [-v] <file>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
show_only=
verbose=
@@ -29,8 +24,6 @@ while : ; do
shift
done
-GIT_DIR=$(git-rev-parse --git-dir) || exit
-
if test -f "$GIT_DIR/info/exclude"
then
git-ls-files -z \
diff --git a/git-am.sh b/git-am.sh
index 6ed527c7a9..39f255209e 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -1,14 +1,10 @@
#!/bin/sh
#
#
-. git-sh-setup
-usage () {
- echo >&2 "usage: $0 [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>"
- echo >&2 " or, when resuming"
- echo >&2 " $0 [--skip | --resolved]"
- exit 1;
-}
+USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>
+ or, when resuming [--skip | --resolved]'
+. git-sh-setup
stop_here () {
echo "$1" >"$dotest/next"
diff --git a/git-applymbox.sh b/git-applymbox.sh
index c686cc8d27..61c8c024c6 100755
--- a/git-applymbox.sh
+++ b/git-applymbox.sh
@@ -18,13 +18,9 @@
##
## git-am is supposed to be the newer and better tool for this job.
+USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
. git-sh-setup
-usage () {
- echo >&2 "applymbox [-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]"
- exit 1
-}
-
keep_subject= query_apply= continue= utf8= resume=t
while case "$#" in 0) break ;; esac
do
diff --git a/git-applypatch.sh b/git-applypatch.sh
index a112e1a504..e8ba34a0ad 100755
--- a/git-applypatch.sh
+++ b/git-applypatch.sh
@@ -10,8 +10,12 @@
## $3 - "info" file with Author, email and subject
## $4 - optional file containing signoff to add
##
+
+USAGE='<msg> <patch> <info> [<signoff>]'
. git-sh-setup
+case "$#" in 3|4) usage ;; esac
+
final=.dotest/final-commit
##
## If this file exists, we ask before applying
diff --git a/git-bisect.sh b/git-bisect.sh
index 05dae8ad13..51e1e4417d 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -1,4 +1,15 @@
#!/bin/sh
+
+USAGE='[start|bad|good|next|reset|visualize]'
+LONG_USAGE='git bisect start [<pathspec>] reset bisect state and start bisection.
+git bisect bad [<rev>] mark <rev> a known-bad revision.
+git bisect good [<rev>...] mark <rev>... known-good revisions.
+git bisect next find next bisection to test and check it out.
+git bisect reset [<branch>] finish bisection search and go back to branch.
+git bisect visualize show bisect status in gitk.
+git bisect replay <logfile> replay bisection log
+git bisect log show bisect log.'
+
. git-sh-setup
sq() {
@@ -11,19 +22,6 @@ sq() {
' "$@"
}
-usage() {
- echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]
-git bisect start [<pathspec>] reset bisect state and start bisection.
-git bisect bad [<rev>] mark <rev> a known-bad revision.
-git bisect good [<rev>...] mark <rev>... known-good revisions.
-git bisect next find next bisection to test and check it out.
-git bisect reset [<branch>] finish bisection search and go back to branch.
-git bisect visualize show bisect status in gitk.
-git bisect replay <logfile> replay bisection log
-git bisect log show bisect log.'
- exit 1
-}
-
bisect_autostart() {
test -d "$GIT_DIR/refs/bisect" || {
echo >&2 'You need to start by "git bisect start"'
diff --git a/git-branch.sh b/git-branch.sh
index 5306b2719f..0266f46223 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -1,21 +1,12 @@
#!/bin/sh
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
-
-die () {
- echo >&2 "$*"
- exit 1
-}
-
-usage () {
- echo >&2 "usage: $(basename $0)"' [-d <branch>] | [[-f] <branch> [start-point]]
-
-If no arguments, show available branches and mark current branch with a star.
+USAGE='[-d <branch>] | [[-f] <branch> [start-point]]'
+LONG_USAGE='If no arguments, show available branches and mark current branch with a star.
If one argument, create a new branch <branchname> based off of current HEAD.
-If two arguments, create a new branch <branchname> based off of <start-point>.
-'
- exit 1
-}
+If two arguments, create a new branch <branchname> based off of <start-point>.'
+
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
diff --git a/git-checkout.sh b/git-checkout.sh
index 4cf30e2c05..f241d4ba6b 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -1,9 +1,7 @@
#!/bin/sh
-. git-sh-setup
-usage () {
- die "usage: git checkout [-f] [-b <new_branch>] [<branch>] [<paths>...]"
-}
+USAGE='[-f] [-b <new_branch>] [<branch>] [<paths>...]'
+. git-sh-setup
old=$(git-rev-parse HEAD)
new=
diff --git a/git-cherry.sh b/git-cherry.sh
index 867522b37f..5e9bd0caf2 100755
--- a/git-cherry.sh
+++ b/git-cherry.sh
@@ -3,11 +3,8 @@
# Copyright (c) 2005 Junio C Hamano.
#
-. git-sh-setup
-
-usage="usage: $0 "'[-v] <upstream> [<head>]
-
- __*__*__*__*__> <upstream>
+USAGE='[-v] <upstream> [<head>]'
+LONG_USAGE=' __*__*__*__*__> <upstream>
/
fork-point
\__+__+__+__+__+__+__+__> <head>
@@ -16,8 +13,8 @@ Each commit between the fork-point and <head> is examined, and
compared against the change each commit between the fork-point and
<upstream> introduces. If the change seems to be in the upstream,
it is shown on the standard output with prefix "+". Otherwise
-it is shown with prefix "-".
-'
+it is shown with prefix "-".'
+. git-sh-setup
case "$1" in -v) verbose=t; shift ;; esac
@@ -35,7 +32,7 @@ case "$#" in
2) upstream=`git-rev-parse --verify "$1"` &&
ours=`git-rev-parse --verify "$2"` || exit
;;
-*) echo >&2 "$usage"; exit 1 ;;
+*) usage ;;
esac
# Note that these list commits in reverse order;
diff --git a/git-clone.sh b/git-clone.sh
index e49028f684..280cc2e81e 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -9,7 +9,7 @@
unset CDPATH
usage() {
- echo >&2 "* git clone [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
+ echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
exit 1
}
diff --git a/git-commit.sh b/git-commit.sh
index 3d250ec853..7e39c107cf 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -3,12 +3,9 @@
# Copyright (c) 2005 Linus Torvalds
#
+USAGE='[-a] [-s] [-v | --no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
. git-sh-setup
-usage () {
- die 'git commit [-a] [-s] [-v | --no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
-}
-
all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
while case "$#" in 0) break;; esac
do
diff --git a/git-fetch.sh b/git-fetch.sh
index 14ea295113..767ca61ca6 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -1,5 +1,7 @@
#!/bin/sh
#
+
+USAGE='<fetch-options> <repository> <refspec>...'
. git-sh-setup
. git-parse-remote
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
@@ -34,6 +36,9 @@ do
-v|--verbose)
verbose=Yes
;;
+ -*)
+ usage
+ ;;
*)
break
;;
diff --git a/git-format-patch.sh b/git-format-patch.sh
index 921feee59c..01508e3b04 100755
--- a/git-format-patch.sh
+++ b/git-format-patch.sh
@@ -3,19 +3,8 @@
# Copyright (c) 2005 Junio C Hamano
#
-. git-sh-setup
-
-# Force diff to run in C locale.
-LANG=C LC_ALL=C
-export LANG LC_ALL
-
-usage () {
- echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
- [--check] [--signoff] [-<diff options>...]
- [--help]
- ( from..to ... | upstream [ our-head ] )
-
-Prepare each commit with its patch since our-head forked from upstream,
+USAGE='[-n | -k] [-o <dir> | --stdout] [--signoff] [--check] [--mbox] [--diff-options] <upstream> [<our-head>]'
+LONG_USAGE='Prepare each commit with its patch since our-head forked from upstream,
one file per patch, for e-mail submission. Each output file is
numbered sequentially from 1, and uses the first line of the commit
message (massaged for pathname safety) as the filename.
@@ -28,10 +17,12 @@ as "[PATCH N/M] Subject", unless you have only one patch.
When --mbox is specified, the output is formatted to resemble
UNIX mailbox format, and can be concatenated together for processing
-with applymbox.
-'
- exit 1
-}
+with applymbox.'
+. git-sh-setup
+
+# Force diff to run in C locale.
+LANG=C LC_ALL=C
+export LANG LC_ALL
diff_opts=
LF='
diff --git a/git-grep.sh b/git-grep.sh
index 44c16130bd..2ed8e955d6 100755
--- a/git-grep.sh
+++ b/git-grep.sh
@@ -3,6 +3,10 @@
# Copyright (c) Linus Torvalds, 2005
#
+USAGE='<option>... <pattern> <path>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
pattern=
flags=()
git_flags=()
@@ -40,8 +44,7 @@ while : ; do
shift
done
[ "$pattern" ] || {
- echo >&2 "usage: 'git grep <pattern> [pathspec*]'"
- exit 1
+ usage
}
git-ls-files -z "${git_flags[@]}" "$@" |
xargs -0 grep "${flags[@]}" -e "$pattern"
diff --git a/git-lost-found.sh b/git-lost-found.sh
index 2beec2aa63..ba6d587f31 100755
--- a/git-lost-found.sh
+++ b/git-lost-found.sh
@@ -1,6 +1,14 @@
#!/bin/sh
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+USAGE=''
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
+if [ "$#" != "0" ]
+then
+ usage
+fi
+
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 d25ae4b82d..e50fbb1160 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -3,15 +3,13 @@
# Copyright (c) 2005 Junio C Hamano
#
+
+USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
. git-sh-setup
LF='
'
-usage () {
- die "git-merge [-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+"
-}
-
all_strategies='recursive octopus resolve stupid ours'
default_strategies='recursive'
use_strategies=
diff --git a/git-prune.sh b/git-prune.sh
index 7e7f0ad56d..7b61d05c4b 100755
--- a/git-prune.sh
+++ b/git-prune.sh
@@ -1,5 +1,6 @@
#!/bin/sh
+USAGE='[-n] [--] [<head>...]'
. git-sh-setup
dryrun=
@@ -9,7 +10,7 @@ do
case "$1" in
-n) dryrun=-n echo=echo ;;
--) break ;;
- -*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
+ -*) usage ;;
*) break ;;
esac
shift;
diff --git a/git-pull.sh b/git-pull.sh
index 3a139849fb..0991d5f14c 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -4,19 +4,10 @@
#
# Fetch one or more remote refs and merge it/them into the current HEAD.
+USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
+LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
. git-sh-setup
-usage () {
- echo >&2 "usage: $0"' [-n] [--no-commit] [--no-summary] [--help]
- [-s strategy]...
- [<fetch-options>]
- <repo> <head>...
-
-Fetch one or more remote refs and merge it/them into the current HEAD.
-'
- exit 1
-}
-
strategy_args= no_summary= no_commit=
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
do
diff --git a/git-push.sh b/git-push.sh
index 140c8f85d5..1c5cf80f87 100755
--- a/git-push.sh
+++ b/git-push.sh
@@ -1,10 +1,7 @@
#!/bin/sh
-. git-sh-setup
-
-usage () {
- die "Usage: git push [--all] [--force] <repository> [<refspec>]"
-}
+USAGE='[--all] [--force] <repository> [<refspec>...]'
+. git-sh-setup
# Parse out parameters and then stop at remote, so that we can
# translate it using .git/branches information
diff --git a/git-rebase.sh b/git-rebase.sh
index 638ff0dbc0..8a5f44aa5e 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -3,6 +3,7 @@
# Copyright (c) 2005 Junio C Hamano.
#
+USAGE='<upstream> [<head>]'
. git-sh-setup
# Make sure we do not have .dotest
@@ -19,7 +20,7 @@ you still have something valuable there.'
fi
# The other head is given. Make sure it is valid.
-other=$(git-rev-parse --verify "$1^0") || exit
+other=$(git-rev-parse --verify "$1^0") || usage
# Make sure we have HEAD that is valid.
head=$(git-rev-parse --verify "HEAD^0") || exit
@@ -36,7 +37,7 @@ esac
# If the branch to rebase is given, first switch to it.
case "$#" in
2)
- git-checkout "$2" || exit
+ git-checkout "$2" || usage
esac
# If the HEAD is a proper descendant of $other, we do not even need
diff --git a/git-repack.sh b/git-repack.sh
index 430ddc5a70..1fafb6ecf6 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -3,6 +3,7 @@
# Copyright (c) 2005 Linus Torvalds
#
+USAGE='[-a] [-d] [-l] [-n]'
. git-sh-setup
no_update_info= all_into_one= remove_redundant= local=
@@ -13,7 +14,7 @@ do
-a) all_into_one=t ;;
-d) remove_redundant=t ;;
-l) local=t ;;
- *) break ;;
+ *) usage ;;
esac
shift
done
diff --git a/git-request-pull.sh b/git-request-pull.sh
index ae6cd272ba..2c48bfb299 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -4,13 +4,11 @@
# This file is licensed under the GPL v2, or a later version
# at the discretion of Linus Torvalds.
-usage()
-{
- echo "$0 <commit> <url> [ <head> ]"
- echo " Summarizes the changes since <commit> to the standard output,"
- echo " and includes <url> in the message generated."
- exit 1
-}
+USAGE='<commit> <url> [<head>]'
+LONG_USAGE='Summarizes the changes since <commit> to the standard output,
+and includes <url> in the message generated.'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
revision=$1
url=$2
diff --git a/git-reset.sh b/git-reset.sh
index 72ef303aed..eb44ee8cc1 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -1,9 +1,7 @@
#!/bin/sh
-. git-sh-setup
-usage () {
- die 'Usage: git reset [--mixed | --soft | --hard] [<commit-ish>]'
-}
+USAGE='[--mixed | --soft | --hard] [<commit-ish>]'
+. git-sh-setup
tmp=/var/tmp/reset.$$
trap 'rm -f $tmp-*' 0 1 2 3 15
diff --git a/git-resolve.sh b/git-resolve.sh
index fcc5ad7349..9263070054 100755
--- a/git-resolve.sh
+++ b/git-resolve.sh
@@ -4,11 +4,9 @@
#
# Resolve two trees.
#
-. git-sh-setup
-usage () {
- die "git-resolve <head> <remote> <merge-message>"
-}
+USAGE='<head> <remote> <merge-message>'
+. git-sh-setup
dropheads() {
rm -f -- "$GIT_DIR/MERGE_HEAD" \
diff --git a/git-revert.sh b/git-revert.sh
index 9d499c4807..63d201be1b 100755
--- a/git-revert.sh
+++ b/git-revert.sh
@@ -3,29 +3,20 @@
# Copyright (c) 2005 Linus Torvalds
# Copyright (c) 2005 Junio C Hamano
#
-. git-sh-setup
case "$0" in
*-revert* )
test -t 0 && edit=-e
- me=revert ;;
+ me=revert
+ USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
*-cherry-pick* )
edit=
- me=cherry-pick ;;
+ me=cherry-pick
+ USAGE='[--edit] [-n] [-r] <commit-ish>' ;;
* )
die "What are you talking about?" ;;
esac
-
-usage () {
- case "$me" in
- cherry-pick)
- die "usage git $me [--edit] [-n] [-r] <commit-ish>"
- ;;
- revert)
- die "usage git $me [--edit | --no-edit] [-n] <commit-ish>"
- ;;
- esac
-}
+. git-sh-setup
no_commit= replay=
while case "$#" in 0) break ;; esac
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index b4f10224ba..1e638e493d 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -11,13 +11,37 @@
# exporting it.
unset CDPATH
-: ${GIT_DIR=.git}
-: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
-
die() {
echo >&2 "$@"
exit 1
}
-# Make sure we are in a valid repository of a vintage we understand.
-GIT_DIR="$GIT_DIR" git-var GIT_AUTHOR_IDENT >/dev/null || exit
+usage() {
+ die "Usage: $0 $USAGE"
+}
+
+if [ -z "$LONG_USAGE" ]
+then
+ LONG_USAGE="Usage: $0 $USAGE"
+else
+ LONG_USAGE="Usage: $0 $USAGE
+
+$LONG_USAGE"
+fi
+
+case "$1" in
+ --h|--he|--hel|--help)
+ echo "$LONG_USAGE"
+ exit
+esac
+
+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-var GIT_AUTHOR_IDENT >/dev/null || exit
+else
+ GIT_DIR=$(git-rev-parse --git-dir) || exit
+fi
diff --git a/git-status.sh b/git-status.sh
index 2dda0c505c..50ccd24efb 100755
--- a/git-status.sh
+++ b/git-status.sh
@@ -2,7 +2,16 @@
#
# Copyright (c) 2005 Linus Torvalds
#
-GIT_DIR=$(git-rev-parse --git-dir) || exit
+
+USAGE=''
+SUBDIRECTORY_OK='Yes'
+
+. git-sh-setup
+
+if [ "$#" != "0" ]
+then
+ usage
+fi
report () {
header="#
diff --git a/git-tag.sh b/git-tag.sh
index 2435a75f7a..6d0c973239 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -1,17 +1,9 @@
#!/bin/sh
# Copyright (c) 2005 Linus Torvalds
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
-
-usage () {
- echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
- exit 1
-}
-
-die () {
- echo >&2 "$*"
- exit 1
-}
+USAGE='[-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
annotate=
signed=
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index 1f44da5349..726b1e706b 100755
--- a/git-verify-tag.sh
+++ b/git-verify-tag.sh
@@ -1,11 +1,13 @@
#!/bin/sh
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+USAGE='<tag>'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
-die () {
- echo >&2 "$*"
- exit 1
-}
+if [ "$#" != "1" ]
+then
+ usage
+fi
type="$(git-cat-file -t "$1" 2>/dev/null)" ||
die "$1: no such object."
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 36f7749bed..c3de151942 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -16,8 +16,8 @@ test_expect_success \
git-update-index --add A &&
git-commit -m "Initial commit."'
-test_expect_failure \
- 'git branch --help should return error code' \
+test_expect_success \
+ 'git branch --help should return success now.' \
'git-branch --help'
test_expect_failure \