Thread (6 messages) flat view 6 messages, 4 authors, 2016-06-15

Re: [RFC/PATCH] Re: git submodule -b ... of current HEAD fails

From: Jens Lehmann <hidden>
Date: 2016-06-15 22:50:09

Possibly related (same subject, not in this thread)

Am 01.12.2010 19:50, schrieb Jonathan Nieder:
	git submodule add -b $branch $repository

fails when HEAD already points to $branch in $repository.

Reported-by: Klaus Ethgen <redacted>
Signed-off-by: Jonathan Nieder <redacted>
---
Hi Klaus,

Klaus Ethgen wrote at <http://bugs.debian.org/605600>:
quoted
Strange problem, if I create a submodule of an other repository giving
the currently used HEAD branch I get the error: »fatal: git checkout:
branch myimbabranch already exists« while when giving other branch
work well.
Interesting.  The problem is in cmd_add of git-submodule.sh; this
patch demonstrates a quick fix.  Jens, any idea why git submodule
is not using "clone --branch" directly?
Nope, these lines date back to the time before I got involved in the
submodule business ... Seems like this "git checkout" was added in
March 2008 by Mark Levedahl (CCed), maybe he can shed some light on
that.

But to me your change looks good, so feel free to add:
Acked-by: Jens Lehmann <redacted>

quoted hunk ↗ jump to hunk
diff --git a/git-submodule.sh b/git-submodule.sh
index 33bc41f..6242d7f 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -241,7 +241,7 @@ cmd_add()
 			# ash fails to wordsplit ${branch:+-b "$branch"...}
 			case "$branch" in
 			'') git checkout -f -q ;;
-			?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
+			?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
 			esac
 		) || die "Unable to checkout submodule '$path'"
 	fi
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help