git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Ben Jackson <ben@ben.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Ben Jackson <ben@ben.com>
Subject: [PATCH v2] Work around ash "alternate value" expansion bug
Date: Sat, 18 Apr 2009 20:42:07 -0700	[thread overview]
Message-ID: <1240112527-79979-1-git-send-email-ben@ben.com> (raw)
In-Reply-To: <1240044459-57227-1-git-send-email-ben@ben.com>

Ash (used as /bin/sh on many distros) has a shell expansion bug
for the form ${var:+word word}.  The result is a single argument
"word word".  Work around by using ${var:+word} ${var:+word} or
equivalent.

Signed-off-by: Ben Jackson <ben@ben.com>
---

See http://thread.gmane.org/gmane.comp.version-control.git/116816 for
the original notes which describe the problem in more detail.

This version uses a different workaround suggested by Junio for
git-submodule which is less likely to be "cleaned up" back to the
original problem.  Since new the change is more complex I beefed
up the new test slightly to ensure we are getting into the right case.

 git-am.sh                  |    2 +-
 git-submodule.sh           |   11 +++++++++--
 t/t7400-submodule-basic.sh |   10 ++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index bfc50c9..e539c60 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -570,7 +570,7 @@ do
 			GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
 			export GIT_COMMITTER_DATE
 		fi &&
-		git commit-tree $tree ${parent:+-p $parent} <"$dotest/final-commit"
+		git commit-tree $tree ${parent:+-p} $parent <"$dotest/final-commit"
 	) &&
 	git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
 	stop_here $this
diff --git a/git-submodule.sh b/git-submodule.sh
index 7c2e060..8e234a4 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -204,8 +204,15 @@ cmd_add()
 	else
 
 		module_clone "$path" "$realrepo" || exit
-		(unset GIT_DIR; cd "$path" && git checkout -f -q ${branch:+-b "$branch" "origin/$branch"}) ||
-		die "Unable to checkout submodule '$path'"
+		(
+			unset GIT_DIR
+			cd "$path" &&
+			# ash fails to wordsplit ${branch:+-b "$branch"...}
+			case "$branch" in
+			'') git checkout -f -q ;;
+			?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
+			esac
+		) || die "Unable to checkout submodule '$path'"
 	fi
 
 	git add "$path" ||
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index af690ec..0f2ccc6 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -64,6 +64,16 @@ test_expect_success 'submodule add' '
 	)
 '
 
+test_expect_success 'submodule add --branch' '
+	(
+		cd addtest &&
+		git submodule add -b initial "$submodurl" submod-branch &&
+		git submodule init &&
+		cd submod-branch &&
+		git branch | grep initial
+	)
+'
+
 test_expect_success 'submodule add with ./ in path' '
 	(
 		cd addtest &&
-- 
1.6.0.1

  parent reply	other threads:[~2009-04-19  3:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-18  8:47 [PATCH] Work around ash "alternate value" expansion bug Ben Jackson
2009-04-18 18:30 ` Junio C Hamano
2009-04-19  3:42 ` Ben Jackson [this message]
2009-04-19  4:38   ` [PATCH v2] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1240112527-79979-1-git-send-email-ben@ben.com \
    --to=ben@ben.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).