# RE: [PATCH] Fix pulling into the same branch.

7 messages from 2005-08-26 to 2005-09-11. Participants: Luck, Tony, Junio C Hamano, Johannes Schindelin, Linus Torvalds.
Thread: https://gitlist.dev/t/1662

## Luck, Tony, 2005-08-26 18:13

Subject: RE: [PATCH] Fix pulling into the same branch.
Message-ID: <B8E391BBE9FE384DAA4C5C003888BE6F043BA469@scsmsx401.amr.corp.intel.com>
URL: https://gitlist.dev/e/B8E391BBE9FE384DAA4C5C003888BE6F043BA469%40scsmsx401.amr.corp.intel.com

```
>I am tempted to move this logic to "git fetch" instead, because
>it has the same issue.  Tony's "linus" branch example has been
>updated to do a "git fetch" instead of "git pull" from the
>earlier description in his howto, but if he happens to be on the
>"linus" branch, he would still have this same problem.

I don't spend much time on the linus branch (just to build an
updated cscope database, etc.).  I never want to check anything
in on that branch [sometime I should figure out how use the "hooks"
to keep me from shooting myself in the foot here].

>In the meantime, warning the user about the issue and suggesting
>how to do the fast-forwarding of the working tree himself in the
>warning message might be the safest and the most sensible thing
>to do.

Yes please ... a big fat warning with coloured flashing lights
and explosions from the sound card.

-Tony

```

## Junio C Hamano, 2005-08-27 03:31

Subject: Re: [PATCH] Fix pulling into the same branch.
Message-ID: <7vzmr43vix.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzmr43vix.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <B8E391BBE9FE384DAA4C5C003888BE6F043BA469@scsmsx401.amr.corp.intel.com>

```
"Luck, Tony" <tony.luck@intel.com> writes:

>>In the meantime, warning the user about the issue and suggesting
>>how to do the fast-forwarding of the working tree himself in the
>>warning message might be the safest and the most sensible thing
>>to do.
>
> Yes please ... a big fat warning with coloured flashing lights
> and explosions from the sound card.

Yeah, but what to do afterwards?  I can see this as an
compromise:

 * "git fetch", just like the updated "git pull", reads
   $GIT_DIR/HEAD before it starts its work, and compares it with
   $GIT_DIR/HEAD after it is done.  If the --update-head-ok flag
   is not given on the command line, and if the HEAD changed,
   then barf and exit with non-zero status after reverting
   $GIT_DIR/HEAD to its original value.  If --update-head-ok is
   given, none of the above check and revert happens.

 * "git pull" calls "git fetch" with the extra flag, and does
   its thing the current way.

So if you are calling from the command line, "git fetch linus",
when you were still on "linus" branch (which you do not normally
do but just to prevent mistakes), it would trigger the check and
your $GIT_DIR/HEAD would stay intact.  If you stayed on your own
branch, "git fetch linus" would continue to just fast forward
"linus" head without touching the working tree.

Come to think of it, it may be cleaner to simply forbid
fast-forward fetching into the current repository (whether it is
"git fetch" or "git pull").  At least in your workflow you do
not do that ever anyway.

Johannes, what do you think, as the original advocate of "push in
reverse"?

```

## Johannes Schindelin, 2005-09-11 09:56

Subject: Re: [PATCH] Fix pulling into the same branch.
Message-ID: <Pine.LNX.4.63.0509111153380.32555@wgmdd8.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0509111153380.32555%40wgmdd8.biozentrum.uni-wuerzburg.de
In-Reply-To: <7vzmr43vix.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Fri, 26 Aug 2005, Junio C Hamano wrote:

> Come to think of it, it may be cleaner to simply forbid
> fast-forward fetching into the current repository (whether it is
> "git fetch" or "git pull").  At least in your workflow you do
> not do that ever anyway.
> 
> Johannes, what do you think, as the original advocate of "push in
> reverse"?

I'm fine with it.

Although it might make more sense to check for dirty state, and 
fast-forward only for a clean state (together with a checkout of the new 
HEAD).

Ciao,
Dscho

```

## Junio C Hamano, 2005-09-11 17:36

Subject: Re: [PATCH] Fix pulling into the same branch.
Message-ID: <7vk6hntslb.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vk6hntslb.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.63.0509111153380.32555@wgmdd8.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Fri, 26 Aug 2005, Junio C Hamano wrote:
>
>> Johannes, what do you think, as the original advocate of "push in
>> reverse"?
>
> I'm fine with it.

Wow, blast from the past ;-).

> Although it might make more sense to check for dirty state, and 
> fast-forward only for a clean state (together with a checkout of the new 
> HEAD).

Yes, but the issue becomes how we can reliably tell if a
repository is naked or has an associated working tree.  I've
seen people rsync only .git subdirectory of their live working
tree to publish to a public repository, which means their pulic
repository has <project>.git/index file, so it is kind of
tricky.

```

## Linus Torvalds, 2005-09-11 17:58

Subject: Re: [PATCH] Fix pulling into the same branch.
Message-ID: <Pine.LNX.4.58.0509111054590.3242@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0509111054590.3242%40g5.osdl.org
In-Reply-To: <7vk6hntslb.fsf@assigned-by-dhcp.cox.net>

```


On Sun, 11 Sep 2005, Junio C Hamano wrote:
> 
> Yes, but the issue becomes how we can reliably tell if a
> repository is naked or has an associated working tree.

You can't "git pull" into a naked thing anyway. And

	git-read-tree -m -u <old-head> <new-head>

should always do the right thing (ie if there is dirty state that would be
updated, it will fail gracefully).

Or did I miss something?

		Linus

```

## Junio C Hamano, 2005-09-11 18:41

Subject: Re: [PATCH] Fix pulling into the same branch.
Message-ID: <7vvf17saza.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vvf17saza.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.58.0509111054590.3242@g5.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> writes:

> On Sun, 11 Sep 2005, Junio C Hamano wrote:
>> 
>> Yes, but the issue becomes how we can reliably tell if a
>> repository is naked or has an associated working tree.
>
> You can't "git pull" into a naked thing anyway. And
>
> 	git-read-tree -m -u <old-head> <new-head>
>
> should always do the right thing (ie if there is dirty state that would be
> updated, it will fail gracefully).
>
> Or did I miss something?

No, I just stated my view poorly.

You cannot do pull into a naked one, but you can still fetch
into it.  My comment Johannes was responding to was what to do
when you do 'git fetch' into the repository associated with your
working tree and your branch is fast forwarded.  We obviously
want to prevent it from happening.  However, it is OK to do so
if the fetch is happening into a naked one and I was wondering
if there is a reliable way to tell that situation and allowing
that.

```

## Johannes Schindelin, 2005-09-11 23:15

Subject: Re: [PATCH] Fix pulling into the same branch.
Message-ID: <Pine.LNX.4.63.0509120113380.10414@wgmdd8.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0509120113380.10414%40wgmdd8.biozentrum.uni-wuerzburg.de
In-Reply-To: <7vk6hntslb.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Sun, 11 Sep 2005, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On Fri, 26 Aug 2005, Junio C Hamano wrote:
> >
> >> Johannes, what do you think, as the original advocate of "push in
> >> reverse"?
> >
> > I'm fine with it.
> 
> Wow, blast from the past ;-).

Sorry, I tried to relax for two weeks. That didn't work, though (pun 
intended).

> > Although it might make more sense to check for dirty state, and 
> > fast-forward only for a clean state (together with a checkout of the new 
> > HEAD).
> 
> Yes, but the issue becomes how we can reliably tell if a
> repository is naked or has an associated working tree.  I've
> seen people rsync only .git subdirectory of their live working
> tree to publish to a public repository, which means their pulic
> repository has <project>.git/index file, so it is kind of
> tricky.

I think it is easy to discern the two states "up to date checkout" and 
"dirty checkout or no checkout at all". But then, you're right: git fetch 
should not touch the working copy.

Ciao,
Dscho

```
