Skip to content

Commit

Permalink
Update git-sh-setup(1) to allow transparent use of git-rev-parse --pa…
Browse files Browse the repository at this point in the history
…rseopt

If you set OPTIONS_SPEC, git-sh-setups uses git-rev-parse --parseopt
automatically.

It also diverts usage to re-exec $0 with the -h option as parse-options.c
will catch that.

If you need git-rev-parse --parseopt to keep the `--` the user may have
passed to your command, set OPTIONS_KEEPDASHDASH to a non empty value
in your script.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pierre Habouzit authored and Junio C Hamano committed Nov 6, 2007
1 parent 21d4783 commit bac199b
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions git-sh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,36 @@ die() {
exit 1
}

usage() {
die "Usage: $0 $USAGE"
}
if test -n "$OPTIONS_SPEC"; then
usage() {
exec "$0" -h
}

parseopt_extra=
[ -n "$OPTIONS_KEEPDASHDASH" ] &&
parseopt_extra="$parseopt_extra --keep-dashdash"

eval `echo "$OPTIONS_SPEC" | git rev-parse --parseopt $parseopt_extra -- "$@" || echo exit $?`
else
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|--h|--he|--hel|--help)
echo "$LONG_USAGE"
exit
esac
fi

set_reflog_action() {
if [ -z "${GIT_REFLOG_ACTION:+set}" ]
Expand Down Expand Up @@ -91,21 +118,6 @@ get_author_ident_from_commit () {
LANG=C LC_ALL=C sed -ne "$pick_author_script"
}

if [ -z "$LONG_USAGE" ]
then
LONG_USAGE="Usage: $0 $USAGE"
else
LONG_USAGE="Usage: $0 $USAGE
$LONG_USAGE"
fi

case "$1" in
-h|--h|--he|--hel|--help)
echo "$LONG_USAGE"
exit
esac

# Make sure we are in a valid repository of a vintage we understand.
if [ -z "$SUBDIRECTORY_OK" ]
then
Expand Down

0 comments on commit bac199b

Please sign in to comment.