From bac199b7b17cd12286a7d5393f4789574c2e1dc4 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 4 Nov 2007 11:30:54 +0100 Subject: Update git-sh-setup(1) to allow transparent use of git-rev-parse --parseopt 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 Signed-off-by: Junio C Hamano --- git-sh-setup.sh | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'git-sh-setup.sh') diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 86d7d4c4e7..e1cf885983 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -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}" ] @@ -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 -- cgit v1.3-5-g9baa From cbea86fd149f5d4aabdff06f87bc766d414b160e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 7 Nov 2007 23:04:38 -0800 Subject: git-sh-setup: fix parseopt `eval` string underquoting The 'automagic parseopt' support corrupted non option parameters that had IFS characters in them. The worst case is when it had a non option parameter like this: $1=" * some string" Signed-off-by: Junio C Hamano --- git-sh-setup.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'git-sh-setup.sh') diff --git a/git-sh-setup.sh b/git-sh-setup.sh index e1cf885983..f1c4839a9f 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -21,11 +21,12 @@ if test -n "$OPTIONS_SPEC"; then 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 $?` + [ -n "$OPTIONS_KEEPDASHDASH" ] && parseopt_extra="--keep-dashdash" + parsed=$( + echo "$OPTIONS_SPEC" | + git rev-parse --parseopt $parseopt_extra -- "$@" + ) && + eval "$parsed" || exit else usage() { die "Usage: $0 $USAGE" -- cgit v1.3-5-g9baa From e817e3e8579742312534f20c0946cd3c562cfa7c Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 8 Nov 2007 10:32:11 +0100 Subject: sh-setup: don't let eval output to be shell-expanded. The previous patch missed the same construct in git-clone. Signed-off-by: Pierre Habouzit --- git-clone.sh | 2 +- git-sh-setup.sh | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'git-sh-setup.sh') diff --git a/git-clone.sh b/git-clone.sh index f216f03a77..24ad179bbd 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -36,7 +36,7 @@ usage() { exec "$0" -h } -eval `echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?` +eval "$(echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" get_repo_base() { ( diff --git a/git-sh-setup.sh b/git-sh-setup.sh index f1c4839a9f..5aa62dda15 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -21,12 +21,15 @@ if test -n "$OPTIONS_SPEC"; then exec "$0" -h } - [ -n "$OPTIONS_KEEPDASHDASH" ] && parseopt_extra="--keep-dashdash" - parsed=$( + parseopt_extra= + [ -n "$OPTIONS_KEEPDASHDASH" ] && + parseopt_extra="--keep-dashdash" + + eval "$( echo "$OPTIONS_SPEC" | - git rev-parse --parseopt $parseopt_extra -- "$@" - ) && - eval "$parsed" || exit + git rev-parse --parseopt $parseopt_extra -- "$@" || + echo exit $? + )" else usage() { die "Usage: $0 $USAGE" -- cgit v1.3-5-g9baa