threads / patch / 15949

patchgit-fetch should not strip off ".git" extension

Subject: [PATCH] git-fetch should not strip off ".git" extension

## tl;dr

13 messages between Oct 18, 2008 and Oct 22, 2008. Diffs are folded; open one to read it.

replies: 12people: 4as markdown or json

Leo Razoumov· Oct 18, 2008, 11:59 UTC · lore

When source git repository has extension ".git" like in "MyRepo.git" "git fetch" will drop ".git" extension and refer to it as "MyRepo".

Example:
sh$ git fetch -v ../MyRepo.git master
From ../MyRepo
 * branch            master     -> FETCH_HEAD

sh$ cat .git/FETCH_HEAD 6eb10bd105f2ef7f64c595100c0a850c5b3cfeb9 branch 'master' of ../MyRepo

Please, note that "git fetch" writes "../MyRepo" instead of "../MyRepo.git"

My workflow makes it convenient to have two distinct repositories (1) "MyRepo" => where I work daily (WIP) (2) "MyRepo.git" => --bare repository accessible to others. "MyRepo" pushes ready changes to "MyRepo.git" Dropping ".git" extension causes confusion between these two quite similarly named repositories.

This problem can be easily solved by the patch below that removes the code that strips off ".git" extension.

--Leo--
----8<-------------------
 builtin-fetch--tool.c |    2 --
 builtin-fetch.c       |    2 --
 2 files changed, 0 insertions(+), 4 deletions(-)
Show changes to 2 files +0 −4

builtin-fetch--tool.c, builtin-fetch.c

diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index 7460ab7..5d0b95f 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -160,8 +160,6 @@ static int append_fetch_head(FILE *fp,
 	for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
 		;
 	remote_len = i + 1;
-	if (4 < i && !strncmp(".git", remote + i - 3, 4))
-		remote_len = i - 3;

 	note_len = 0;
 	if (*what) {
diff --git a/builtin-fetch.c b/builtin-fetch.c
index ee93d3a..28123a5 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -348,8 +348,6 @@ static int store_updated_refs(const char *url,
const char *remote_name,
 		for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
 			;
 		url_len = i + 1;
-		if (4 < i && !strncmp(".git", url + i - 3, 4))
-			url_len = i - 3;

 		note_len = 0;
 		if (*what) {
Andreas Ericsson· Oct 20, 2008, 10:36 UTC · re: Leo Razoumov · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

Leo Razoumov wrote:
Show 57 quoted lines
> When source git repository has extension ".git" like in "MyRepo.git"
> "git fetch" will drop ".git" extension and refer to it as "MyRepo".
> 
> Example:
> 
> sh$ git fetch -v ../MyRepo.git master
> From ../MyRepo
>  * branch            master     -> FETCH_HEAD
> 
> sh$ cat .git/FETCH_HEAD
> 6eb10bd105f2ef7f64c595100c0a850c5b3cfeb9           branch 'master' of ../MyRepo
> 
> Please, note that "git fetch" writes "../MyRepo" instead of "../MyRepo.git"
> 
> My workflow makes it convenient to have two distinct repositories
> (1) "MyRepo"      => where I work daily (WIP)
> (2) "MyRepo.git" => --bare repository accessible to others. "MyRepo"
> pushes ready changes to "MyRepo.git"
> Dropping ".git" extension causes confusion between these two quite
> similarly named repositories.
> 
> This problem can be easily solved by the patch below that removes the
> code that strips off ".git" extension.
> 
> --Leo--
> 
> ----8<-------------------
> 
>  builtin-fetch--tool.c |    2 --
>  builtin-fetch.c       |    2 --
>  2 files changed, 0 insertions(+), 4 deletions(-)
> 
> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
> index 7460ab7..5d0b95f 100644
> --- a/builtin-fetch--tool.c
> +++ b/builtin-fetch--tool.c
> @@ -160,8 +160,6 @@ static int append_fetch_head(FILE *fp,
>  	for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
>  		;
>  	remote_len = i + 1;
> -	if (4 < i && !strncmp(".git", remote + i - 3, 4))
> -		remote_len = i - 3;
> 
>  	note_len = 0;
>  	if (*what) {
> diff --git a/builtin-fetch.c b/builtin-fetch.c
> index ee93d3a..28123a5 100644
> --- a/builtin-fetch.c
> +++ b/builtin-fetch.c
> @@ -348,8 +348,6 @@ static int store_updated_refs(const char *url,
> const char *remote_name,
>  		for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
>  			;
>  		url_len = i + 1;
> -		if (4 < i && !strncmp(".git", url + i - 3, 4))
> -			url_len = i - 3;
> 
Will this still play nicely with
   git clone foo.git
?
Otherwise, please also fix the fallout from this patch.
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Leo Razoumov· Oct 20, 2008, 15:08 UTC · re: Andreas Ericsson · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

On 10/20/08, Andreas Ericsson <ae@op5.se> wrote:
Show 10 quoted lines
> [..snip..]]
>  Will this still play nicely with
>
>   git clone foo.git
>
>  ?
>
>  Otherwise, please also fix the fallout from this patch.
>
>  --

Andreas, thanks for the comment. I have been testing this patch for over two weeks already and so far encountered no problems. I routinely perform "git clone foo.git" and it works correctly creating new repo "foo" and properly populating it.

--Leo--
Junio C Hamano· Oct 20, 2008, 18:37 UTC · re: Andreas Ericsson · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

Andreas Ericsson <ae@op5.se> writes:
Show 37 quoted lines
>>...
>>
>>  builtin-fetch--tool.c |    2 --
>>  builtin-fetch.c       |    2 --
>>  2 files changed, 0 insertions(+), 4 deletions(-)
>>
>> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
>> index 7460ab7..5d0b95f 100644
>> --- a/builtin-fetch--tool.c
>> +++ b/builtin-fetch--tool.c
>> @@ -160,8 +160,6 @@ static int append_fetch_head(FILE *fp,
>>  	for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
>>  		;
>>  	remote_len = i + 1;
>> -	if (4 < i && !strncmp(".git", remote + i - 3, 4))
>> -		remote_len = i - 3;
>>
>>  	note_len = 0;
>>  	if (*what) {
>> diff --git a/builtin-fetch.c b/builtin-fetch.c
>> index ee93d3a..28123a5 100644
>> --- a/builtin-fetch.c
>> +++ b/builtin-fetch.c
>> @@ -348,8 +348,6 @@ static int store_updated_refs(const char *url,
>> const char *remote_name,
>>  		for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
>>  			;
>>  		url_len = i + 1;
>> -		if (4 < i && !strncmp(".git", url + i - 3, 4))
>> -			url_len = i - 3;
>>
> 
> Will this still play nicely with
>
>   git clone foo.git
>
> ?
I think it would.

As far as I can tell, the only thing the patch changes is to disable the long established "repository name clean-up" feature in the autogenerated merge messages (iow, input to "fmt-merge-msg").

Leo Razoumov· Oct 21, 2008, 10:23 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

On 10/20/08, Junio C Hamano <gitster@pobox.com> wrote:
Show 47 quoted lines
> Andreas Ericsson <ae@op5.se> writes:
>
>  >>...
>
> >>
>  >>  builtin-fetch--tool.c |    2 --
>  >>  builtin-fetch.c       |    2 --
>  >>  2 files changed, 0 insertions(+), 4 deletions(-)
>  >>
>  >> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
>  >> index 7460ab7..5d0b95f 100644
>  >> --- a/builtin-fetch--tool.c
>  >> +++ b/builtin-fetch--tool.c
>  >> @@ -160,8 +160,6 @@ static int append_fetch_head(FILE *fp,
>  >>      for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
>  >>              ;
>  >>      remote_len = i + 1;
>  >> -    if (4 < i && !strncmp(".git", remote + i - 3, 4))
>  >> -            remote_len = i - 3;
>  >>
>  >>      note_len = 0;
>  >>      if (*what) {
>  >> diff --git a/builtin-fetch.c b/builtin-fetch.c
>  >> index ee93d3a..28123a5 100644
>  >> --- a/builtin-fetch.c
>  >> +++ b/builtin-fetch.c
>  >> @@ -348,8 +348,6 @@ static int store_updated_refs(const char *url,
>  >> const char *remote_name,
>  >>              for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
>  >>                      ;
>  >>              url_len = i + 1;
>  >> -            if (4 < i && !strncmp(".git", url + i - 3, 4))
>  >> -                    url_len = i - 3;
>  >>
>  >
>  > Will this still play nicely with
>  >
>  >   git clone foo.git
>  >
>  > ?
>
>
> I think it would.
>
>  As far as I can tell, the only thing the patch changes is to disable the
>  long established "repository name clean-up" feature in the autogenerated
>  merge messages (iow, input to "fmt-merge-msg").

Even though the old behavior is "long established", it introduces unnecessary ambiguity. If I have two repos

(1) Foo #private repo where I do my daily work (2) Foo.git #exported public repo

the current behavior makes git messages confuse the repos.
--Leo--
Junio C Hamano· Oct 21, 2008, 16:56 UTC · re: Leo Razoumov · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

"Leo Razoumov" <slonik.az@gmail.com> writes:
> Even though the old behavior is "long established", it introduces
> unnecessary ambiguity. If I have two repos
> ...

Of course. Now you know why people don't name such a pair of repositories like that ;-).

Alex Riesen· Oct 21, 2008, 22:06 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

2008/10/21 Junio C Hamano <gitster@pobox.com>:
Show 8 quoted lines
> "Leo Razoumov" <slonik.az@gmail.com> writes:
>
>> Even though the old behavior is "long established", it introduces
>> unnecessary ambiguity. If I have two repos
>> ...
>
> Of course.  Now you know why people don't name such a pair of repositories
> like that ;-).
FWIW, I support Leo on that. The "established" behavior is stupid.
Junio C Hamano· Oct 21, 2008, 22:36 UTC · re: Alex Riesen · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

"Alex Riesen" <raa.lkml@gmail.com> writes:
Show 11 quoted lines
> 2008/10/21 Junio C Hamano <gitster@pobox.com>:
>> "Leo Razoumov" <slonik.az@gmail.com> writes:
>>
>>> Even though the old behavior is "long established", it introduces
>>> unnecessary ambiguity. If I have two repos
>>> ...
>>
>> Of course.  Now you know why people don't name such a pair of repositories
>> like that ;-).
>
> FWIW, I support Leo on that. The "established" behavior is stupid.

I am not inclined to respond to such an emotional argument. On the other hand, it is fair to say that the existing behaviour is established, because it is backed by a long history, which you can objectively verify.

If you think about it deeper, you will realize that it is not even clear if it is "stupid".

More importantly, the behaviour is consistent with the way how "git fetch" and "git clone" DWIMs the repository name by suffixing .git when the input lacks it. And this DWIMmery comes from the expectations that:

 (1) people name their repository project.git; and
 (2) people like using and seeing short names (iow, "clone
     git://$somewhere/project" is preferred over "clone
     git://$somewhere/project.git");

If a repository whose real location is git://$somewhere/project.git is cloned/fetched as git://$somewhere/project by people, recording the merge source using the shorter name used by people to fetch from it is more consistent. The patch breaks this consistency [*1*].

What is clear is that you would confuse yourself if you have two repositories A and A.git next to each other, and that is primarily because it breaks the above expectation.

git core-level rarely imposes such policies, but what Porcelains do is a different matter.

Hence the suggestion: don't do it.
[Footnote]

*1* It would be a different matter if the patch at the same time removed the fetch/clone DWIMmery. At least such a patch would be internally self consistent.

Alex Riesen· Oct 21, 2008, 22:43 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

2008/10/22 Junio C Hamano <gitster@pobox.com>:
Show 7 quoted lines
> "Alex Riesen" <raa.lkml@gmail.com> writes:
>>
>> FWIW, I support Leo on that. The "established" behavior is stupid.
>
> I am not inclined to respond to such an emotional argument.  On the other
> hand, it is fair to say that the existing behaviour is established,
> because it is backed by a long history, which you can objectively verify.
I found it illogical (well, stupid) and inconvinient
> *1* It would be a different matter if the patch at the same time removed
> the fetch/clone DWIMmery.  At least such a patch would be internally self
> consistent.
Good idea.
Andreas Ericsson· Oct 22, 2008, 07:55 UTC · re: Alex Riesen · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

Alex Riesen wrote:
Show 14 quoted lines
> 2008/10/22 Junio C Hamano <gitster@pobox.com>:
>> "Alex Riesen" <raa.lkml@gmail.com> writes:
>>> FWIW, I support Leo on that. The "established" behavior is stupid.
>> I am not inclined to respond to such an emotional argument.  On the other
>> hand, it is fair to say that the existing behaviour is established,
>> because it is backed by a long history, which you can objectively verify.
> 
> I found it illogical (well, stupid) and inconvinient
> 
>> *1* It would be a different matter if the patch at the same time removed
>> the fetch/clone DWIMmery.  At least such a patch would be internally self
>> consistent.
> 
> Good idea.

No. Bad idea. That would not only break people's fetch configurations if they've done clone on repos without passing .git, but also mean users would have to remember if a particular server names their bare repos "project.git".

If you remove *all* DWIMmery from fetch/clone, you'd also break people's expectations when they're fetching from each other, as they'd have to pass "git://devpeer/project/.git" instead of just "git://devpeer/project", which is what *looks* sane.

A good idea would be to always report the name the user used. 'git clone' already does that, recording the non-DWIMmed URL in the remotes config.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Junio C Hamano· Oct 21, 2008, 23:35 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

Junio C Hamano <gitster@pobox.com> writes:
Show 20 quoted lines
> More importantly, the behaviour is consistent with the way how "git fetch"
> and "git clone" DWIMs the repository name by suffixing .git when the input
> lacks it.  And this DWIMmery comes from the expectations that:
>
>  (1) people name their repository project.git; and
>
>  (2) people like using and seeing short names (iow, "clone
>      git://$somewhere/project" is preferred over "clone
>      git://$somewhere/project.git");
>
> If a repository whose real location is git://$somewhere/project.git is
> cloned/fetched as git://$somewhere/project by people, recording the merge
> source using the shorter name used by people to fetch from it is more
> consistent.  The patch breaks this consistency [*1*].
> ...
> [Footnote]
>
> *1* It would be a different matter if the patch at the same time removed
> the fetch/clone DWIMmery.  At least such a patch would be internally self
> consistent.

Actually, after looking at what the involved codepaths do, I am inclined to change my mind. Somehow I thought the transport.c infrastructure DWIMs and uses the result of DWIMmery throughout the program (iow, at the point in the codepath the patch touches, we cannot tell what the user originally asked for), which is not the case at all. That changes everything.

The current behaviour is Ok if you match your behaviour to the original expectations, but:

 * if you clone from "git://$somewhere/project" originally, your
   remote.origin.url will not end with ".git";
 * or equivalently, if your remote.origin.url does not end with ".git".

and when you fetch in such a repository with or without the patch, the results are the same. URL without trailing ".git".

So the change in the behaviour is only when you originally explicitly asked to clone "git://$somewhere/project.git". With the change, that wish is preserved. Without the change, ".git" is unconditionally dropped.

The situation is the same if you explicitly ask to fetch from a URL that ends with ".git" (or "/.git"). With the change, the explicit ".git" is preserved; without it, it is dropped.

So I now think the patch (if it were massaged into an applicable shape with proper log message and sign-off) is an improvement.

Alex, thanks for sanity checking ;-)
Leo Razoumov· Oct 22, 2008, 11:35 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

On 10/21/08, Junio C Hamano <gitster@pobox.com> wrote:
Show 52 quoted lines
> "Alex Riesen" <raa.lkml@gmail.com> writes:
>
>  > 2008/10/21 Junio C Hamano <gitster@pobox.com>:
>  >> "Leo Razoumov" <slonik.az@gmail.com> writes:
>  >>
>  >>> Even though the old behavior is "long established", it introduces
>  >>> unnecessary ambiguity. If I have two repos
>  >>> ...
>  >>
>  >> Of course.  Now you know why people don't name such a pair of repositories
>  >> like that ;-).
>  >
>  > FWIW, I support Leo on that. The "established" behavior is stupid.
>
>
> I am not inclined to respond to such an emotional argument.  On the other
>  hand, it is fair to say that the existing behaviour is established,
>  because it is backed by a long history, which you can objectively verify.
>
>  If you think about it deeper, you will realize that it is not even clear
>  if it is "stupid".
>
>  More importantly, the behaviour is consistent with the way how "git fetch"
>  and "git clone" DWIMs the repository name by suffixing .git when the input
>  lacks it.  And this DWIMmery comes from the expectations that:
>
>   (1) people name their repository project.git; and
>
>   (2) people like using and seeing short names (iow, "clone
>      git://$somewhere/project" is preferred over "clone
>      git://$somewhere/project.git");
>
>  If a repository whose real location is git://$somewhere/project.git is
>  cloned/fetched as git://$somewhere/project by people, recording the merge
>  source using the shorter name used by people to fetch from it is more
>  consistent.  The patch breaks this consistency [*1*].
>
>  What is clear is that you would confuse yourself if you have two
>  repositories A and A.git next to each other, and that is primarily because
>  it breaks the above expectation.
>
>  git core-level rarely imposes such policies, but what Porcelains do is a
>  different matter.
>
>  Hence the suggestion: don't do it.
>
>  [Footnote]
>
>  *1* It would be a different matter if the patch at the same time removed
>  the fetch/clone DWIMmery.  At least such a patch would be internally self
>  consistent.
>

I think this discussion went in the direction of "correct" versus "convent". I, personally, will choose correct over convenient any time. Different people use git for different projects and their expectations differ in this regard. In my case after I do "git clone Foo.git" I get "Foo" repo side-by-side with "Foo.git" and the ambiguity becomes apparent.

Regarding your footnote *1*. I agree with your suggestions and I can improve the patch in the following way:

(1) Fetch/clone messages/comments will refer to the source/destination repos by their complete names without stripping off any parts (2) Searching for a source repo, clone/fetch will first try an exact match and if it fails it will remove/add ".git" suffix and

Leo Razoumov· Oct 22, 2008, 11:50 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-fetch should not strip off ".git" extension

My apologies!! I hit send button by mistake before message was complete. Please, see below a completed version. --Leo--

On 10/21/08, Junio C Hamano <gitster@pobox.com> wrote:
Show 52 quoted lines
> "Alex Riesen" <raa.lkml@gmail.com> writes:
>
>  > 2008/10/21 Junio C Hamano <gitster@pobox.com>:
>  >> "Leo Razoumov" <slonik.az@gmail.com> writes:
>  >>
>  >>> Even though the old behavior is "long established", it introduces
>  >>> unnecessary ambiguity. If I have two repos
>  >>> ...
>  >>
>  >> Of course.  Now you know why people don't name such a pair of repositories
>  >> like that ;-).
>  >
>  > FWIW, I support Leo on that. The "established" behavior is stupid.
>
>
> I am not inclined to respond to such an emotional argument.  On the other
>  hand, it is fair to say that the existing behaviour is established,
>  because it is backed by a long history, which you can objectively verify.
>
>  If you think about it deeper, you will realize that it is not even clear
>  if it is "stupid".
>
>  More importantly, the behaviour is consistent with the way how "git fetch"
>  and "git clone" DWIMs the repository name by suffixing .git when the input
>  lacks it.  And this DWIMmery comes from the expectations that:
>
>   (1) people name their repository project.git; and
>
>   (2) people like using and seeing short names (iow, "clone
>      git://$somewhere/project" is preferred over "clone
>      git://$somewhere/project.git");
>
>  If a repository whose real location is git://$somewhere/project.git is
>  cloned/fetched as git://$somewhere/project by people, recording the merge
>  source using the shorter name used by people to fetch from it is more
>  consistent.  The patch breaks this consistency [*1*].
>
>  What is clear is that you would confuse yourself if you have two
>  repositories A and A.git next to each other, and that is primarily because
>  it breaks the above expectation.
>
>  git core-level rarely imposes such policies, but what Porcelains do is a
>  different matter.
>
>  Hence the suggestion: don't do it.
>
>  [Footnote]
>
>  *1* It would be a different matter if the patch at the same time removed
>  the fetch/clone DWIMmery.  At least such a patch would be internally self
>  consistent.
>

I think this discussion went in the direction of "correct" versus "convent". I, personally, will choose correct over convenient any time. Different people use git for different projects and their expectations differ in this regard. In my case after I do "git clone Foo.git" I get "Foo" repo side-by-side with "Foo.git" and the ambiguity becomes apparent.

Regarding your footnote *1*. I agree with your suggestions and I can improve the patch in the following way:

(P1) Fetch/clone messages/records will refer to the source/destination repos by their complete names without stripping off any parts of the name.

(P2) Searching for a source repo, clone/fetch will first try an exact match and if it fails it will remove/add ".git" suffix as needed and retry.

Item (P2) will provide the convenience, while item (P1) still guarantees correctness.

Please, let me know if such approach is more satisfactory.
--Leo--

← back to recent threads