From: Junio C Hamano <gitster@pobox.com>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
git@vger.kernel.org, spearce@spearce.org
Subject: Re: [PATCH v2] Fix fetch/pull when run without --update-head-ok
Date: Tue, 14 Oct 2008 15:07:08 -0700 [thread overview]
Message-ID: <7vk5ca7rw3.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.LNX.1.00.0810141258050.19665@iabervon.org> (Daniel Barkalow's message of "Tue, 14 Oct 2008 13:02:35 -0400 (EDT)")
Daniel Barkalow <barkalow@iabervon.org> writes:
> On Tue, 14 Oct 2008, Daniel Barkalow wrote:
> ...
>> That is, it uses --update-head-ok because "git pull origin master:master"
>> will work correctly, regardless of whether the local master is
>> yet-to-be-born or not.
>
> In particular, the --update-head-ok is from b10ac50f, which is what added
> the check to prohibit fetching into the current branch otherwise, back in
> August 2005. There's never been anything preventing updating the current
> branch using "pull".
What you wrote above is correct, and it is all that is necessary to make
"pull master:master" (when 'master' is the current branch) work correctly,
in normal situations. Dscho's patch is in itself is a good thing to do,
but is not necessary when the caller gives --update-head-ok.
Nor is it sufficient. Have you tested the current "git-pull" with or
without Dscho's patch applied to "git-fetch" when 'master' is an unborn
branch? "git-pull" has this piece:
curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
if test "$curr_head" != "$orig_head"
then
# The fetch involved updating the current branch.
# The working tree and the index file is still based on the
# $orig_head commit, but we are merging into $curr_head.
# First update the working tree to match $curr_head.
echo >&2 "Warning: fetch updated the current branch head."
...
fi
The above part (written by yours truly) did not care what happens when the
current branch is unborn. Back then when git-pull was originally written,
nobody was crazy enough to pull into an empty branch and expect it to
work. The code to allow that craziness (look for "initial pull" in the
same script to find a 6-line block near the end) came much later, and the
commit that added the "initial pull" support should have adjusted the
above codeblock if it really wanted to support pulling into an unborn
branch, but it forgot to do so. It also forgot to handle the case where
the originally unborn current branch was fetched into.
If we really care about is "git pull origin master:master" into an unborn
branch, I think we need the attached patch on top, and this is regardless
of Dscho's patch that tightens the check when -update-head-ok is not given.
git-pull.sh | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git c/git-pull.sh w/git-pull.sh
index 75c3610..664fe34 100755
--- c/git-pull.sh
+++ w/git-pull.sh
@@ -124,7 +124,7 @@ orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
git fetch --update-head-ok "$@" || exit 1
curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
-if test "$curr_head" != "$orig_head"
+if test -n "$orig_head" && test "$curr_head" != "$orig_head"
then
# The fetch involved updating the current branch.
@@ -172,7 +172,7 @@ esac
if test -z "$orig_head"
then
- git update-ref -m "initial pull" HEAD $merge_head "" &&
+ git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
git read-tree --reset -u HEAD || exit 1
exit
fi
next prev parent reply other threads:[~2008-10-14 22:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-11 11:38 [PATCH] fetch: refuse to fetch into the current branch in a non-bare repository Johannes Schindelin
2008-10-11 21:44 ` Junio C Hamano
2008-10-12 18:47 ` Shawn O. Pearce
2008-10-13 9:28 ` Johannes Schindelin
2008-10-12 18:52 ` Shawn O. Pearce
2008-10-12 20:37 ` Daniel Barkalow
2008-10-13 9:36 ` [PATCH v2] Fix fetch/pull when run without --update-head-ok Johannes Schindelin
2008-10-13 14:09 ` Shawn O. Pearce
2008-10-13 17:57 ` Johannes Schindelin
2008-10-13 14:23 ` Junio C Hamano
2008-10-13 17:30 ` Junio C Hamano
2008-10-13 18:12 ` Johannes Schindelin
2008-10-13 20:05 ` Daniel Barkalow
2008-10-14 9:49 ` Johannes Schindelin
2008-10-14 15:02 ` Shawn O. Pearce
2008-10-14 16:04 ` Daniel Barkalow
2008-10-14 16:15 ` Johannes Schindelin
2008-10-14 15:57 ` Daniel Barkalow
2008-10-14 16:17 ` Johannes Schindelin
2008-10-14 16:52 ` Daniel Barkalow
2008-10-14 17:02 ` Daniel Barkalow
2008-10-14 22:07 ` Junio C Hamano [this message]
2008-10-14 22:53 ` [PATCH] pull: allow "git pull origin $something:$current_branch" into an unborn branch Junio C Hamano
2008-10-13 17:08 ` [PATCH v2] Fix fetch/pull when run without --update-head-ok Daniel Barkalow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vk5ca7rw3.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).