threads / discuss / 42629

URL rewrite in local config unable to override global config rule

Subject: URL rewrite in local config unable to override global config rule

## tl;dr

6 messages between Jun 16, 2016 and Jun 18, 2016.

replies: 5people: 2as markdown or json

Saksham Saxena· Jun 16, 2016, 10:14 UTC · lore
Hello everyone

I came across an anomaly in git recently, and would like to share it here. Please suggest if this is a bug, or if my approach is wrong.

Summary : Added a new rule to the local config of a git repo by issuing ' git config --local url."https://".insteadOf git:// ', but it wasn't observed by git as it kept using "git://".

Details : I had set my global config to use "git://" instead of "https://", as I prefer working with SSH. Recently, I began writing a 'GitHub Wiki' of one of my GitHub projects, and, apparently, those Wikis are normal git repositories, and can be cloned and edited locally. However, the clone url available is served over HTTPS only, and doesn't support any other protocol. Naturally, I had to change my config to change the behavior of git while connecting to the remote. I thus proceeded to update the local config of the repo to use "https://" instead of "git://". However, my remote urls weren't updated. I manually then removed these remote urls and added new HTTPS ones. Yet, the remote urls showed "git://" protocol in them. Screenshot of the terminal window can be found here (http://i.stack.imgur.com/y7GMP.png).

I tried to add the "pushInsteadOf" rule as well, but again, it didn't take effect. This is particularly disappointing, because the local config have the highest priority, and yet it isn't effective at all. Because of the limitation of my remote, I cannot even push my changes. True, that I can dig up some dirty workarounds, but I do not understand why this behavior is seen.

I have also asked this on the popular Stack Overflow forum (http://stackoverflow.com/questions/37844460/git-remote-url-is-not-updating). If any of the moderators here do not find this issue as a bug, then they may help me out on the forum itself (if you happen to be on it) to reduce the noise on this thread.

I hope I described my problem clearly. Awaiting response.

Regards Saksham Saxena

Jeff King· Jun 16, 2016, 12:13 UTC · re: Saksham Saxena · lore

Re: URL rewrite in local config unable to override global config rule

On Thu, Jun 16, 2016 at 03:44:17PM +0530, Saksham Saxena wrote:
> Summary : Added a new rule to the local config of a git repo by
> issuing ' git config --local url."https://".insteadOf git:// ', but it
> wasn't observed by git as it kept using "git://".
Hmm. This works in a simple example for me...
> Details : I had set my global config to use "git://" instead of
> "https://", as I prefer working with SSH.

..even if I have an existing "url.git://.insteadOf=https://". But I could believe that having other config confuses things. The url-rewriting is not "last one wins", but rather that we try all of them, and the longest match wins.

Can you show us the output of "git config --list" on a repository that is having this problem, and then the command that you run and its output?

Show 5 quoted lines
> Recently, I began writing a
> 'GitHub Wiki' of one of my GitHub projects, and, apparently, those
> Wikis are normal git repositories, and can be cloned and edited
> locally. However, the clone url available is served over HTTPS only,
> and doesn't support any other protocol.

You should be able to clone, fetch, or push wiki repositories using any of the normal protocols. So:

  git@github.com:username/repo.wiki.git

should work. Likewise, git:// will work if the repository is public, but you cannot push over it.

-Peff
Saksham Saxena· Jun 17, 2016, 14:35 UTC · re: Jeff King · lore

Re: URL rewrite in local config unable to override global config rule

On Thu, Jun 16, 2016 at 5:43 PM, Jeff King <peff@peff.net> wrote:
Show 16 quoted lines
> On Thu, Jun 16, 2016 at 03:44:17PM +0530, Saksham Saxena wrote:
>
>> Summary : Added a new rule to the local config of a git repo by
>> issuing ' git config --local url."https://".insteadOf git:// ', but it
>> wasn't observed by git as it kept using "git://".
>
> Hmm. This works in a simple example for me...
>
>> Details : I had set my global config to use "git://" instead of
>> "https://", as I prefer working with SSH.
>
> ..even if I have an existing "url.git://.insteadOf=https://". But I
> could believe that having other config confuses things. The
> url-rewriting is not "last one wins", but rather that we try all of
>
> > them, and the longest match wins.
Longest? Could you elaborate please?
Show 5 quoted lines
>
> Can you show us the output of "git config --list" on a repository that
> is having this problem, and then the command that you run and its
>
> > output?

Here you go (https://gist.github.com/sakshamsaxena/a1cee9c39ddc127ae659e92d02d58f0b). The commands are run in that sequence.

Show 15 quoted lines
>
>> Recently, I began writing a
>> 'GitHub Wiki' of one of my GitHub projects, and, apparently, those
>> Wikis are normal git repositories, and can be cloned and edited
>> locally. However, the clone url available is served over HTTPS only,
>> and doesn't support any other protocol.
>
> You should be able to clone, fetch, or push wiki repositories using any
> of the normal protocols. So:
>
>   git@github.com:username/repo.wiki.git
>
> should work. Likewise, git:// will work if the repository is public, but
>
> > you cannot push over it.
True. Can't push over git:// and that's why I'm limited to https://
>
> -Peff
-- 
Regards
Saksham Saxena
Member, IEEE Delhi Section Student Network
Member, IEEE DTU Student Branch
Student, Delhi Technological University
Jeff King· Jun 17, 2016, 15:01 UTC · re: Saksham Saxena · lore

Re: URL rewrite in local config unable to override global config rule

On Fri, Jun 17, 2016 at 08:05:47PM +0530, Saksham Saxena wrote:
Show 7 quoted lines
> > ..even if I have an existing "url.git://.insteadOf=https://". But I
> > could believe that having other config confuses things. The
> > url-rewriting is not "last one wins", but rather that we try all of
> >
> > > them, and the longest match wins.
> 
> Longest? Could you elaborate please?

The one that matches the longest number of characters. So "https://example.com" is a preferred match over "https://".

I don't think that's what's going on here, though.
> Here you go (https://gist.github.com/sakshamsaxena/a1cee9c39ddc127ae659e92d02d58f0b).
> The commands are run in that sequence.
OK, so you have:
  url.git://.insteadof=https://
in your initial config, to convert https URLs to git.
Later you add:
  url.https://.insteadof=git://
to do the opposite.
The URL in your config uses http:
  remote.origin.url=https://github.com/sakshamsaxena/sails-hook-jbvcs.wiki.git
And when you push, this gets converted to "git://".

I think this is the expected behavior, due to the first insteadOf, which converts https to git. Both rules are "active", in the sense that the later one does not replace the former; together they make a list of rules to try applying.

Git doesn't recursively apply insteadOf transformations. So the "convert https to git" rule triggers, and we stop. The "convert git to https" one doesn't trigger initially (because we are already https). And if we were to apply rules recursively in this case, it would loop infinitely.

So I this is all operating as intended. And what you really want is a way to say "erase any earlier rewrite rules; I do not want them applied in this repository". There's currently not any way to do that.

For other "multi-valued configs" like this one (i.e., ones that form a list rather than overriding earlier values), we have started using the convention that assigning the empty value resets the list. But this particular config key has not learned that trick yet, so it would require a patch to git.

Show 10 quoted lines
> > You should be able to clone, fetch, or push wiki repositories using any
> > of the normal protocols. So:
> >
> >   git@github.com:username/repo.wiki.git
> >
> > should work. Likewise, git:// will work if the repository is public, but
> >
> > > you cannot push over it.
> 
> True. Can't push over git:// and that's why I'm limited to https://

You can over ssh, though (which I thought you said earlier was your preferred protocol).

-Peff
Saksham Saxena· Jun 18, 2016, 05:36 UTC · re: Jeff King · lore

Re: URL rewrite in local config unable to override global config rule

Thanks a lot Peff. This cleared a lot of things. Would it be okay if I cite some parts of this conversation on my personal blog?

On Fri, Jun 17, 2016 at 8:31 PM, Jeff King <peff@peff.net> wrote:
Show 71 quoted lines
> On Fri, Jun 17, 2016 at 08:05:47PM +0530, Saksham Saxena wrote:
>
>> > ..even if I have an existing "url.git://.insteadOf=https://". But I
>> > could believe that having other config confuses things. The
>> > url-rewriting is not "last one wins", but rather that we try all of
>> >
>> > > them, and the longest match wins.
>>
>> Longest? Could you elaborate please?
>
> The one that matches the longest number of characters. So
> "https://example.com" is a preferred match over "https://".
>
> I don't think that's what's going on here, though.
>
>> Here you go (https://gist.github.com/sakshamsaxena/a1cee9c39ddc127ae659e92d02d58f0b).
>> The commands are run in that sequence.
>
> OK, so you have:
>
>   url.git://.insteadof=https://
>
> in your initial config, to convert https URLs to git.
>
> Later you add:
>
>   url.https://.insteadof=git://
>
> to do the opposite.
>
> The URL in your config uses http:
>
>   remote.origin.url=https://github.com/sakshamsaxena/sails-hook-jbvcs.wiki.git
>
> And when you push, this gets converted to "git://".
>
> I think this is the expected behavior, due to the first insteadOf, which
> converts https to git. Both rules are "active", in the sense that the
> later one does not replace the former; together they make a list of
> rules to try applying.
>
> Git doesn't recursively apply insteadOf transformations. So the "convert
> https to git" rule triggers, and we stop. The "convert git to https" one
> doesn't trigger initially (because we are already https). And if we were
> to apply rules recursively in this case, it would loop infinitely.
>
> So I this is all operating as intended. And what you really want is a
> way to say "erase any earlier rewrite rules; I do not want them applied
> in this repository". There's currently not any way to do that.
>
> For other "multi-valued configs" like this one (i.e., ones that form a
> list rather than overriding earlier values), we have started using the
> convention that assigning the empty value resets the list. But this
> particular config key has not learned that trick yet, so it would
> require a patch to git.
>
>> > You should be able to clone, fetch, or push wiki repositories using any
>> > of the normal protocols. So:
>> >
>> >   git@github.com:username/repo.wiki.git
>> >
>> > should work. Likewise, git:// will work if the repository is public, but
>> >
>> > > you cannot push over it.
>>
>> True. Can't push over git:// and that's why I'm limited to https://
>
> You can over ssh, though (which I thought you said earlier was your
> preferred protocol).
>
> -Peff

Thanks and Regards Saksham Saxena

Jeff King· Jun 18, 2016, 13:49 UTC · re: Saksham Saxena · lore

Re: URL rewrite in local config unable to override global config rule

On Sat, Jun 18, 2016 at 11:06:41AM +0530, Saksham Saxena wrote:
> Thanks a lot Peff. This cleared a lot of things. Would it be okay if I
> cite some parts of this conversation on my personal blog?
Sure, that is fine with me.
-Peff

← back to recent threads