git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Try harder to find a remote when on a detached HEAD or non-tracking branch.

From
Arnaud Lacombe <lacombar@gmail.com>
Date
Jun 18, 2012, 17:53 UTC
Message-ID
<CACqU3MXgb1f7MU0m-yCp48UZrnfqBztBToZoibAFraYvT+TpEg@mail.gmail.com>
In-Reply-To
<1340038866-24552-1-git-send-email-marcnarc@xiplink.com>
Hi,
On Mon, Jun 18, 2012 at 1:01 PM,  <marcnarc@xiplink.com> wrote:
Show 15 quoted lines
> 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".
>

Marc, could you explain the problem you were trying to solve ? You are only giving hints about the change made, not the reason behind it.

Thanks,
 - Arnaud
Show 65 quoted lines
> 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
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Phil Hord
Message 20 of 20 in “Try harder to find a remote when on a detached HEAD or non-tracking branch.”
  1. Try harder to find a remote when on a detached HEAD or non-tracking branch.marcnarc@xiplink.com, Jun 18, 2012
  2. Junio C HamanoJun 18, 2012
  3. Marc BranchaudJun 18, 2012
  4. Junio C HamanoJun 18, 2012
  5. Marc BranchaudJun 19, 2012
  6. Junio C HamanoJun 19, 2012
  7. Heiko VoigtJun 19, 2012
  8. Marc BranchaudJun 19, 2012
  9. Heiko VoigtJun 20, 2012
  10. Jeff KingJun 19, 2012
  11. Junio C HamanoJun 19, 2012
  12. Marc BranchaudJun 19, 2012
  13. Jeff KingJun 19, 2012
  14. Junio C HamanoJun 19, 2012
  15. Jeff KingJun 19, 2012
  16. Junio C HamanoJun 19, 2012
  17. Jens LehmannJun 19, 2012
  18. Marc BranchaudJun 19, 2012
  19. Phil HordJun 20, 2012
  20. Arnaud LacombeJun 18, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.