# URL substitution and config file precedence

5 messages from 2010-08-02 to 2010-08-02. Participants: martin f krafft, Ævar Arnfjörð Bjarmason, Jonathan Nieder.
Thread: https://gitlist.dev/t/24603

## martin f krafft, 2010-08-02 15:37

Subject: URL substitution and config file precedence
Message-ID: <20100802153720.GA28481@fishbowl.rw.madduck.net>
URL: https://gitlist.dev/e/20100802153720.GA28481%40fishbowl.rw.madduck.net

```
Dear Gits,

I expect .git/config to tae precedence over ~/.gitconfig, which in
turn gets favoured over /etc/gitconfig. This works fine, except for
the url.….insteadOf settings.

Have a look at the following:

  % grep madduck: .git/config
    url = madduck:pub/puppet/modules/git

  % grep -B1 nsteadOf /etc/gitconfig ~/.gitconfig
  /etc/gitconfig-[url "git://git.madduck.net/madduck/"]
  /etc/gitconfig: insteadOf = madduck:
  --
  /home/madduck/.gitconfig-[url "ssh://git.madduck.net/madduck/"]
  /home/madduck/.gitconfig:       insteadOf = madduck:
  /home/madduck/.gitconfig:       pushInsteadOf = git://git.madduck.net/madduck/

  % git push -v
  Pushing to git://git.madduck.net/madduck/pub/puppet/modules/git
  fatal: The remote end hung up unexpectedly

There seem to be two problems:

  1. the value from /etc/gitconfig seems to be preferred over the
     one from ~/.gitconfig. I think this is due to the fact that the
     syntax for URL substitution is a bit whack and the two keys
     different, so the merge is actually a union-merge, and then the
     result is probably just the first match (git:// sorts before
     ssh://).

  2. URL substitution is not recursive, or else the git:// URL would
     eventually be replaced with the ssh:// URL.

I can address both issues by adding a "pushInsteadOf = madduck:" to
~/.gitconfig, but …

… that only addresses pushing. I don't see a way to fix fetching,
where the pushInsteadOf trick does not work.

Any ideas how to work around it?

Why was the syntax chosen backwards in this way? Why not have

  [urlsubst "madduck:"]
      replaceWith = ssh://git.madduck.net/madduck/

or even better:

  [url_regsubst]
      somefreelychosenname = s|madduck:|ssh://git.madduck.net/madduck/|

Thoughts?

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"stab it and steer"
                                                             -- sailor
 
spamtraps: madduck.bogus@madduck.net

```

## Ævar Arnfjörð Bjarmason, 2010-08-02 16:05

Subject: Re: URL substitution and config file precedence
Message-ID: <AANLkTikdyNjcgZpY=BPjkieacDXHPvp0he77VJZCMLpw@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikdyNjcgZpY%3DBPjkieacDXHPvp0he77VJZCMLpw%40mail.gmail.com
In-Reply-To: <20100802153720.GA28481@fishbowl.rw.madduck.net>

```
On Mon, Aug 2, 2010 at 15:37, martin f krafft <madduck@madduck.net> wrote:
> Dear Gits,
>
> I expect .git/config to tae precedence over ~/.gitconfig, which in
> turn gets favoured over /etc/gitconfig. This works fine, except for
> the url.….insteadOf settings.
>
> Have a look at the following:
>
>  % grep madduck: .git/config
>    url = madduck:pub/puppet/modules/git
>
>  % grep -B1 nsteadOf /etc/gitconfig ~/.gitconfig
>  /etc/gitconfig-[url "git://git.madduck.net/madduck/"]
>  /etc/gitconfig: insteadOf = madduck:
>  --
>  /home/madduck/.gitconfig-[url "ssh://git.madduck.net/madduck/"]
>  /home/madduck/.gitconfig:       insteadOf = madduck:
>  /home/madduck/.gitconfig:       pushInsteadOf = git://git.madduck.net/madduck/
>
>  % git push -v
>  Pushing to git://git.madduck.net/madduck/pub/puppet/modules/git
>  fatal: The remote end hung up unexpectedly
>
> There seem to be two problems:
>
>  1. the value from /etc/gitconfig seems to be preferred over the
>     one from ~/.gitconfig. I think this is due to the fact that the
>     syntax for URL substitution is a bit whack and the two keys
>     different, so the merge is actually a union-merge, and then the
>     result is probably just the first match (git:// sorts before
>     ssh://).

Right, the git-config backend just merges on a key-value basis. It isn't smart.

> Why was the syntax chosen backwards in this way? Why not have
>
>  [urlsubst "madduck:"]
>      replaceWith = ssh://git.madduck.net/madduck/
>
> or even better:
>
>  [url_regsubst]
>      somefreelychosenname = s|madduck:|ssh://git.madduck.net/madduck/|

I don't know, but it usually helps if you add the person who added the
feature to the CC-list.

```

## martin f krafft, 2010-08-02 17:38

Subject: Re: URL substitution and config file precedence
Message-ID: <20100802173853.GB5325@fishbowl.rw.madduck.net>
URL: https://gitlist.dev/e/20100802173853.GB5325%40fishbowl.rw.madduck.net
In-Reply-To: <AANLkTikdyNjcgZpY=BPjkieacDXHPvp0he77VJZCMLpw@mail.gmail.com>

```
also sprach Ævar Arnfjörð Bjarmason <avarab@gmail.com> [2010.08.02.1805 +0200]:
> I don't know, but it usually helps if you add the person who added
> the feature to the CC-list.

Yeah, I didn't check. Does anyone happen to know who that was,
saving me the excursion into the history? I don't have Git cloned on
this laptop and I am on a really bad link. :(

Thanks,

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"da haben wir es also: eine kirchliche ordnung mit priesterschaft,
 theologie, kultus, sakrament;
 kurz, alles das, was jesus von nazareth bekämpft hatte..."
                                                 - friedrich nietzsche
 
spamtraps: madduck.bogus@madduck.net

```

## Ævar Arnfjörð Bjarmason, 2010-08-02 17:46

Subject: Re: URL substitution and config file precedence
Message-ID: <AANLkTimf+T9_W4oMjj+vujr+oDXwEuNO4OyjO+oRtV05@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimf%2BT9_W4oMjj%2Bvujr%2BoDXwEuNO4OyjO%2BoRtV05%40mail.gmail.com
In-Reply-To: <20100802173853.GB5325@fishbowl.rw.madduck.net>

```
On Mon, Aug 2, 2010 at 17:38, martin f krafft <madduck@madduck.net> wrote:
> also sprach Ævar Arnfjörð Bjarmason <avarab@gmail.com> [2010.08.02.1805 +0200]:
>> I don't know, but it usually helps if you add the person who added
>> the feature to the CC-list.
>
> Yeah, I didn't check. Does anyone happen to know who that was,
> saving me the excursion into the history? I don't have Git cloned on
> this laptop and I am on a really bad link. :(

Daniel Barkalow added it back in 2008. Adding him to the CC list.

```

## Jonathan Nieder, 2010-08-02 20:57

Subject: Re: URL substitution and config file precedence
Message-ID: <20100802205748.GA2890@burratino>
URL: https://gitlist.dev/e/20100802205748.GA2890%40burratino
In-Reply-To: <20100802153720.GA28481@fishbowl.rw.madduck.net>

```
martin f krafft wrote:

>   % grep madduck: .git/config
>     url = madduck:pub/puppet/modules/git
> 
>   % grep -B1 nsteadOf /etc/gitconfig ~/.gitconfig
>   /etc/gitconfig-[url "git://git.madduck.net/madduck/"]
>   /etc/gitconfig: insteadOf = madduck:
>   --
>   /home/madduck/.gitconfig-[url "ssh://git.madduck.net/madduck/"]
>   /home/madduck/.gitconfig:       insteadOf = madduck:
>   /home/madduck/.gitconfig:       pushInsteadOf = git://git.madduck.net/madduck/
> 
>   % git push -v
>   Pushing to git://git.madduck.net/madduck/pub/puppet/modules/git
>   fatal: The remote end hung up unexpectedly
> 
> There seem to be two problems:
> 
>   1. the value from /etc/gitconfig seems to be preferred over the
>      one from ~/.gitconfig. I think this is due to the fact that the
>      syntax for URL substitution is a bit whack and the two keys
>      different, so the merge is actually a union-merge, and then the
>      result is probably just the first match (git:// sorts before
>      ssh://).

Almost.  I do not think there is any sorting involved.

It instead seems to be an unintended consequence of the "first match
wins" rule from v1.5.5-rc0~142^2 (url rewriting: take longest and
first match, 2008-02-24).  If we were starting over, I think it would
make more sense to make the _last_ match win, which would be closer to
how git configuration works in general.

> Why was the syntax chosen backwards in this way? Why not have
> 
>   [urlsubst "madduck:"]
>       replaceWith = ssh://git.madduck.net/madduck/

I wasn’t there, so I can’t complain.
http://thread.gmane.org/gmane.comp.version-control.git/74535/focus=74594

I think you’re right, that

	[fakeurl "madduck:"]
		url = git://git.madduck.net/madduck/
		pushurl = ssh://git.madduck.net/madduck/

or similar would be more convenient to work with than

	[url "ssh://git.madduck.net/madduck/"]
		pushinsteadof = madduck:
	[url "git://git.madduck.net/madduck/"]
		insteadof = madduck:

Jonathan

```
