From ac650054415876576e31735375126ec47e280c0c Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 30 Nov 2017 03:50:57 -0800 Subject: [PATCH] tg.sh/pre-commit.sh: do not rely on word-splitting inside braces This ought to result in three arguments to echo: word=go echo ${word:+and "$word"} Just as though it was written like so: echo and go Some older shell implementations end up behaving like this: echo "and go" That breaks numerous things and can easily be avoided by moving the splitting whitespace outside of the braces like so: echo ${word:+and} ${word:+"$word"} Signed-off-by: Kyle J. McKay --- hooks/pre-commit.sh | 2 +- tg.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh index 8629c26..2b2e78b 100644 --- a/hooks/pre-commit.sh +++ b/hooks/pre-commit.sh @@ -204,7 +204,7 @@ elif [ -n "$changedeps" ]; then else files=".topmsg" fi -newcommit="$(git commit-tree -m "tg: $mode $files" ${headrev:+-p $headrev} "$newtree")" +newcommit="$(git commit-tree -m "tg: $mode $files" ${headrev:+-p} ${headrev:+"$headrev"} "$newtree")" git update-ref -m "tg: sequester $files changes into their own preliminary commit" HEAD "$newcommit" warn "sequestered $files changes into their own preliminary commit" info "run the same \`git commit\` command again to commit the remaining changes" >&2 diff --git a/tg.sh b/tg.sh index c740291..83f0e1b 100644 --- a/tg.sh +++ b/tg.sh @@ -1672,8 +1672,8 @@ do_status() if [ -n "$upref" ]; then uprefpart=" ... ${upref#$abbrev/remotes/}" mbase="$(git merge-base HEAD "$upref")" || : - ahead="$(git rev-list --count HEAD ${mbase:+--not $mbase})" || ahead=0 - behind="$(git rev-list --count "$upref" ${mbase:+--not $mbase})" || behind=0 + ahead="$(git rev-list --count HEAD ${mbase:+--not} $mbase)" || ahead=0 + behind="$(git rev-list --count "$upref" ${mbase:+--not} $mbase)" || behind=0 [ "$ahead$behind" = "00" ] || uprefpart="$uprefpart [" [ "$ahead" = "0" ] || uprefpart="${uprefpart}ahead $ahead" [ "$ahead" = "0" ] || [ "$behind" = "0" ] || uprefpart="$uprefpart, " -- 2.11.4.GIT