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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Mon, Jun 18, 2012 at 1:01 PM,  <marcnarc@xxxxxxxxxxx> wrote:
> From: Marc Branchaud <marcnarc@xxxxxxxxxxx>
>
> 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

> Signed-off-by: Marc Branchaud <marcnarc@xxxxxxxxxxx>
> ---
>
> 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@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]