git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Try harder to find a remote when on a detached HEAD or non-tracking branch.
@ 2012-06-18 17:01 marcnarc
  2012-06-18 17:33 ` Junio C Hamano
  2012-06-18 17:53 ` Arnaud Lacombe
  0 siblings, 2 replies; 20+ messages in thread
From: marcnarc @ 2012-06-18 17:01 UTC (permalink / raw)
  To: git; +Cc: Jens Lehmann, Marc Branchaud

From: Marc Branchaud <marcnarc@xiplink.com>

get_default_remote() tries to use the checked-out branch's 'remote' config
value to figure out the remote's name.  This fails if there is no currently
checked-out branch (i.e. HEAD is detached) or if the checked-out branch
doesn't track a remote.  In these cases and the function would just fall
back to "origin".

Instead, let's use the first remote listed in the configuration, and fall
back to "origin" only if we don't find any configured remotes.

Prior to this change, git would fail to initialize a relative-path
submodule if the super-repo was on a detached HEAD and it had no remote
named "origin".

Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
---

Our build system likes to use detached HEADs, so we got tripped up when we
started using relative submodule URLs.

(I'm not sure about the portability of my change, or if I should wrap it
to 80 columns...)

 git-parse-remote.sh        |  1 +
 t/t7400-submodule-basic.sh | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 484b2e6..225ad94 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -8,6 +8,7 @@ get_default_remote () {
 	curr_branch=$(git symbolic-ref -q HEAD)
 	curr_branch="${curr_branch#refs/heads/}"
 	origin=$(git config --get "branch.$curr_branch.remote")
+	test -z "$origin" && origin=$(git config --list | grep '^remote\.' | head -1 | awk -F . '{print $2}')
 	echo ${origin:-origin}
 }
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 81827e6..8f1ff4f 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -507,6 +507,28 @@ test_expect_success 'relative path works with user@host:path' '
 	)
 '
 
+test_expect_success 'relative path works on detached HEAD and remote is not named "origin"' '
+	mkdir detachtest &&
+	(
+		cd detachtest &&
+		git init &&
+		mkdir sub &&
+		(
+			cd sub &&
+			git init &&
+			test_commit foo
+		) &&
+		git add sub &&
+		git commit -m "added sub" &&
+		git checkout HEAD@{0} &&
+		git config -f .gitmodules submodule.sub.path sub &&
+		git config -f .gitmodules submodule.sub.url ../subrepo &&
+		git remote add awkward ssh://awkward/repo &&
+		git submodule init sub &&
+		test "$(git config submodule.sub.url)" = ssh://awkward/subrepo
+	)
+'
+
 test_expect_success 'moving the superproject does not break submodules' '
 	(
 		cd addtest &&
-- 
1.7.11.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2012-06-20 17:42 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-18 17:01 [PATCH] Try harder to find a remote when on a detached HEAD or non-tracking branch marcnarc
2012-06-18 17:33 ` Junio C Hamano
2012-06-18 21:40   ` Marc Branchaud
2012-06-18 22:12     ` Junio C Hamano
2012-06-19 14:07       ` Marc Branchaud
2012-06-19 17:55         ` Junio C Hamano
2012-06-19 19:31           ` Heiko Voigt
2012-06-19 21:42             ` Marc Branchaud
2012-06-20 17:42               ` Heiko Voigt
2012-06-19 20:12           ` Jeff King
2012-06-19 20:31             ` Junio C Hamano
2012-06-19 21:43             ` Marc Branchaud
2012-06-19 21:46               ` Jeff King
2012-06-19 21:58                 ` Junio C Hamano
2012-06-19 22:00                   ` Jeff King
2012-06-19 22:26                     ` Junio C Hamano
2012-06-19 19:41         ` Jens Lehmann
2012-06-19 21:43           ` Marc Branchaud
2012-06-20  2:49             ` Phil Hord
2012-06-18 17:53 ` Arnaud Lacombe

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 NNTP newsgroup(s).