# recent change in git.git/master broke my repos

18 messages from 2007-10-25 to 2007-10-27. Participants: Randal L. Schwartz, Karl Hasselström, Jeff King, Nicolas Pitre, Daniel Barkalow, Andreas Ericsson, Junio C Hamano.
Thread: https://gitlist.dev/t/10461

## Randal L. Schwartz, 2007-10-25 14:32

Subject: recent change in git.git/master broke my repos
Message-ID: <86oden6z97.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86oden6z97.fsf%40blue.stonehenge.com

```

I have echo "ref: refs/remotes/origin/master" >.git/refs/heads/upstream
so that my daily update script can go:

   git-fetch
   if [ repo is on master, and is not dirty ];
      git-merge upstream
   fi

Yesterday that worked.

Today I get a rash of:

  fatal: Couldn't find remote ref refs/remotes/origin/master

from my git-fetch.

Is git-fetch broken, or am I?  And if it's me, how do I do what I
want instead?

And when are we gonna get "fast forward only" for git-merge?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

```

## Karl Hasselström, 2007-10-25 15:01

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <20071025150107.GB31196@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20071025150107.GB31196%40diana.vm.bytemark.co.uk
In-Reply-To: <86oden6z97.fsf@blue.stonehenge.com>

```
On 2007-10-25 07:32:36 -0700, Randal L. Schwartz wrote:

> And when are we gonna get "fast forward only" for git-merge?

I'd like that too. For cases when I know I don't have to do a merge,
and want git to yell at me if I'm mistaken. For example, in a
repository that tracks an upstream so I can build the latest version,
but where I don't normally do any development.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```

## Jeff King, 2007-10-25 15:51

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <20071025155142.GB19655@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20071025155142.GB19655%40coredump.intra.peff.net
In-Reply-To: <86oden6z97.fsf@blue.stonehenge.com>

```
On Thu, Oct 25, 2007 at 07:32:36AM -0700, Randal L. Schwartz wrote:

> I have echo "ref: refs/remotes/origin/master" >.git/refs/heads/upstream
> so that my daily update script can go:
> 
>    git-fetch
>    if [ repo is on master, and is not dirty ];
>       git-merge upstream
>    fi
> 
> Yesterday that worked.
> 
> Today I get a rash of:
> 
>   fatal: Couldn't find remote ref refs/remotes/origin/master
> 
> from my git-fetch.

Works fine here (meaning I can examine 'upstream' as I would any other
branch, and it points to the same place as origin/master).

Why is git-fetch touching your upstream branch at all? Do you have
something in your .git/config instructing it to do so? Or do you mean
that the 'git-merge upstream' command is failing? Can you 'git-show
upstream'? If not, can you 'git-show origin/master'?

-Peff

```

## Randal L. Schwartz, 2007-10-25 15:55

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <86fxzz6vfh.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86fxzz6vfh.fsf%40blue.stonehenge.com
In-Reply-To: <20071025155142.GB19655@coredump.intra.peff.net>

```
>>>>> "Jeff" == Jeff King <peff@peff.net> writes:

Jeff> Why is git-fetch touching your upstream branch at all? Do you have
Jeff> something in your .git/config instructing it to do so? Or do you mean
Jeff> that the 'git-merge upstream' command is failing? Can you 'git-show
Jeff> upstream'? If not, can you 'git-show origin/master'?

It's probably due to this:

[remote "origin"]
        url = [obscured]
        fetch = +refs/heads/*:refs/remotes/origin/*

fetch wants to sync my heads with the origin heads.  But yes, it's
definitely the fetch that fails under today's version, and not
under yesterday's version.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

```

## Jeff King, 2007-10-25 15:57

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <20071025155712.GA21446@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20071025155712.GA21446%40coredump.intra.peff.net
In-Reply-To: <86fxzz6vfh.fsf@blue.stonehenge.com>

```
On Thu, Oct 25, 2007 at 08:55:14AM -0700, Randal L. Schwartz wrote:

> It's probably due to this:
> 
> [remote "origin"]
>         url = [obscured]
>         fetch = +refs/heads/*:refs/remotes/origin/*
> 
> fetch wants to sync my heads with the origin heads.  But yes, it's
> definitely the fetch that fails under today's version, and not
> under yesterday's version.

So that should take the remote's refs/heads/* and put them in your
refs/remotes/origin/*. I don't see how that would have anything to do
with your 'refs/heads/upstream' branch.

-Peff

```

## Randal L. Schwartz, 2007-10-25 15:58

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <86bqan6v9f.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86bqan6v9f.fsf%40blue.stonehenge.com
In-Reply-To: <20071025155712.GA21446@coredump.intra.peff.net>

```
>>>>> "Jeff" == Jeff King <peff@peff.net> writes:

Jeff> On Thu, Oct 25, 2007 at 08:55:14AM -0700, Randal L. Schwartz wrote:
>> It's probably due to this:
>> 
>> [remote "origin"]
>> url = [obscured]
>> fetch = +refs/heads/*:refs/remotes/origin/*
>> 
>> fetch wants to sync my heads with the origin heads.  But yes, it's
>> definitely the fetch that fails under today's version, and not
>> under yesterday's version.

Jeff> So that should take the remote's refs/heads/* and put them in your
Jeff> refs/remotes/origin/*. I don't see how that would have anything to do
Jeff> with your 'refs/heads/upstream' branch.

Agreed, but that's the place where fetch might look at refs/heads/upstream,
and the behavior is definitely different between yesterday and today.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

```

## Jeff King, 2007-10-25 16:01

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <20071025160159.GA21505@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20071025160159.GA21505%40coredump.intra.peff.net
In-Reply-To: <86bqan6v9f.fsf@blue.stonehenge.com>

```
On Thu, Oct 25, 2007 at 08:58:52AM -0700, Randal L. Schwartz wrote:

> Jeff> So that should take the remote's refs/heads/* and put them in your
> Jeff> refs/remotes/origin/*. I don't see how that would have anything to do
> Jeff> with your 'refs/heads/upstream' branch.
> 
> Agreed, but that's the place where fetch might look at refs/heads/upstream,
> and the behavior is definitely different between yesterday and today.

Fair enough. How about my other questions. Can you 'git-show upstream'?
Can you 'git-show origin/master'?

-Peff

```

## Randal L. Schwartz, 2007-10-25 16:06

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <867ilb6uwr.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/867ilb6uwr.fsf%40blue.stonehenge.com
In-Reply-To: <20071025160159.GA21505@coredump.intra.peff.net>

```
>>>>> "Jeff" == Jeff King <peff@peff.net> writes:

Jeff> On Thu, Oct 25, 2007 at 08:58:52AM -0700, Randal L. Schwartz wrote:
Jeff> So that should take the remote's refs/heads/* and put them in your
Jeff> refs/remotes/origin/*. I don't see how that would have anything to do
Jeff> with your 'refs/heads/upstream' branch.
>> 
>> Agreed, but that's the place where fetch might look at refs/heads/upstream,
>> and the behavior is definitely different between yesterday and today.

Jeff> Fair enough. How about my other questions. Can you 'git-show upstream'?
Jeff> Can you 'git-show origin/master'?

yes, and they show the same thing.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

```

## Jeff King, 2007-10-25 16:56

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <20071025165633.GA24143@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20071025165633.GA24143%40coredump.intra.peff.net
In-Reply-To: <86oden6z97.fsf@blue.stonehenge.com>

```
On Thu, Oct 25, 2007 at 07:32:36AM -0700, Randal L. Schwartz wrote:

> I have echo "ref: refs/remotes/origin/master" >.git/refs/heads/upstream
> so that my daily update script can go:
> 
>    git-fetch
>    if [ repo is on master, and is not dirty ];
>       git-merge upstream
>    fi
> 
> Yesterday that worked.
> 
> Today I get a rash of:
> 
>   fatal: Couldn't find remote ref refs/remotes/origin/master
> 
> from my git-fetch.

Randal and I discussed this a bit on IRC, and it turns out not to be
related to the 'upstream' symref. Instead, he had a broken
branch.master.merge config that pointed to "refs/remotes/origin/master"
(which you can see from his script above doesn't actually get used).

So presumably the old git-fetch didn't care that the contents of
branch.*.master didn't exist (it's just that nothing got marked for
merging), but the one just merged from the db/fetch-pack topic does.

Is this behavior change intentional?

-Peff

```

## Nicolas Pitre, 2007-10-25 17:46

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <alpine.LFD.0.9999.0710251344220.22100@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.0.9999.0710251344220.22100%40xanadu.home
In-Reply-To: <20071025150107.GB31196@diana.vm.bytemark.co.uk>

```
On Thu, 25 Oct 2007, Karl Hasselström wrote:

> On 2007-10-25 07:32:36 -0700, Randal L. Schwartz wrote:
> 
> > And when are we gonna get "fast forward only" for git-merge?
> 
> I'd like that too. For cases when I know I don't have to do a merge,
> and want git to yell at me if I'm mistaken. For example, in a
> repository that tracks an upstream so I can build the latest version,
> but where I don't normally do any development.

Isn't that called a remote branch that gets updated with "git fetch' ?
You can even trick Git into not using the refs/remotes/ namespace for 
them if you wish.


Nicolas

```

## Daniel Barkalow, 2007-10-25 18:05

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <Pine.LNX.4.64.0710251351330.7345@iabervon.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0710251351330.7345%40iabervon.org
In-Reply-To: <20071025165633.GA24143@coredump.intra.peff.net>

```
On Thu, 25 Oct 2007, Jeff King wrote:

> On Thu, Oct 25, 2007 at 07:32:36AM -0700, Randal L. Schwartz wrote:
> 
> > I have echo "ref: refs/remotes/origin/master" >.git/refs/heads/upstream
> > so that my daily update script can go:
> > 
> >    git-fetch
> >    if [ repo is on master, and is not dirty ];
> >       git-merge upstream
> >    fi
> > 
> > Yesterday that worked.
> > 
> > Today I get a rash of:
> > 
> >   fatal: Couldn't find remote ref refs/remotes/origin/master
> > 
> > from my git-fetch.
> 
> Randal and I discussed this a bit on IRC, and it turns out not to be
> related to the 'upstream' symref. Instead, he had a broken
> branch.master.merge config that pointed to "refs/remotes/origin/master"
> (which you can see from his script above doesn't actually get used).
> 
> So presumably the old git-fetch didn't care that the contents of
> branch.*.master didn't exist (it's just that nothing got marked for
> merging), but the one just merged from the db/fetch-pack topic does.
> 
> Is this behavior change intentional?

It's not exactly intentional; it's just that nobody seems to have tested 
this particular misconfiguration. It should probably report an error 
(since the configuration is, in fact, broken and potentially misleading), 
but it probably shouldn't be fatal and certainly shouldn't be so 
uninformative.

I guess it's a new feature that you can use a branch.*.merge line to 
select a ref that otherwise wouldn't be fetched at all, cause it to be 
fetched, and have it marked for merging; previously, such a config line 
would just be ignored, as it didn't exactly match anything. It's a side 
effect that something that doesn't exist (by that name on the remote side) 
is now an issue.

	-Daniel
*This .sig left intentionally blank*

```

## Randal L. Schwartz, 2007-10-25 18:29

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <863avz6oa8.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/863avz6oa8.fsf%40blue.stonehenge.com
In-Reply-To: <alpine.LFD.0.9999.0710251344220.22100@xanadu.home>

```
>>>>> "Nicolas" == Nicolas Pitre <nico@cam.org> writes:

Nicolas> Isn't that called a remote branch that gets updated with "git fetch' ?
Nicolas> You can even trick Git into not using the refs/remotes/ namespace for 
Nicolas> them if you wish.

No.  I have a local master, and I want to be able to blindly say
"git-merge" on that master when doing so is only a fast forward.


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

```

## Andreas Ericsson, 2007-10-25 20:23

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <4720FB4E.3030300@op5.se>
URL: https://gitlist.dev/e/4720FB4E.3030300%40op5.se
In-Reply-To: <alpine.LFD.0.9999.0710251344220.22100@xanadu.home>

```
Nicolas Pitre wrote:
> On Thu, 25 Oct 2007, Karl Hasselström wrote:
> 
>> On 2007-10-25 07:32:36 -0700, Randal L. Schwartz wrote:
>>
>>> And when are we gonna get "fast forward only" for git-merge?
>> I'd like that too. For cases when I know I don't have to do a merge,
>> and want git to yell at me if I'm mistaken. For example, in a
>> repository that tracks an upstream so I can build the latest version,
>> but where I don't normally do any development.
> 
> Isn't that called a remote branch that gets updated with "git fetch' ?
> You can even trick Git into not using the refs/remotes/ namespace for 
> them if you wish.
> 

You'd lose the ability to do "git diff origin/master" while disconnected
though. It's quite valuable.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

```

## Nicolas Pitre, 2007-10-25 20:38

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <alpine.LFD.0.9999.0710251637240.22100@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.0.9999.0710251637240.22100%40xanadu.home
In-Reply-To: <4720FB4E.3030300@op5.se>

```
On Thu, 25 Oct 2007, Andreas Ericsson wrote:

> Nicolas Pitre wrote:
> > Isn't that called a remote branch that gets updated with "git fetch' ?
> > You can even trick Git into not using the refs/remotes/ namespace for them
> > if you wish.
> > 
> 
> You'd lose the ability to do "git diff origin/master" while disconnected
> though. It's quite valuable.

I don't see how you'd lose anything.


Nicolas

```

## Andreas Ericsson, 2007-10-25 20:42

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <4720FF98.5080905@op5.se>
URL: https://gitlist.dev/e/4720FF98.5080905%40op5.se
In-Reply-To: <alpine.LFD.0.9999.0710251637240.22100@xanadu.home>

```
Nicolas Pitre wrote:
> On Thu, 25 Oct 2007, Andreas Ericsson wrote:
> 
>> Nicolas Pitre wrote:
>>> Isn't that called a remote branch that gets updated with "git fetch' ?
>>> You can even trick Git into not using the refs/remotes/ namespace for them
>>> if you wish.
>>>
>> You'd lose the ability to do "git diff origin/master" while disconnected
>> though. It's quite valuable.
> 
> I don't see how you'd lose anything.
> 

Sorry, I thought you were talking about a config along the lines of:
fetch = refs/heads/*:refs/heads/*

What other trick are you talking about?

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

```

## Karl Hasselström, 2007-10-26 07:39

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <20071026073955.GB11286@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20071026073955.GB11286%40diana.vm.bytemark.co.uk
In-Reply-To: <alpine.LFD.0.9999.0710251344220.22100@xanadu.home>

```
On 2007-10-25 13:46:04 -0400, Nicolas Pitre wrote:

> On Thu, 25 Oct 2007, Karl Hasselström wrote:
>
> > On 2007-10-25 07:32:36 -0700, Randal L. Schwartz wrote:
> >
> > > And when are we gonna get "fast forward only" for git-merge?
> >
> > I'd like that too. For cases when I know I don't have to do a
> > merge, and want git to yell at me if I'm mistaken. For example, in
> > a repository that tracks an upstream so I can build the latest
> > version, but where I don't normally do any development.
>
> Isn't that called a remote branch that gets updated with "git
> fetch'?

Sure, I could use a detached HEAD instead of a local branch. However,
that'll still not warn me that merging in another branch won't be a
fast-forward.

> You can even trick Git into not using the refs/remotes/ namespace
> for them if you wish.

I'm not sure what'll happen if git fetch tries to update a branch that
I've made local changes to, but I don't imagine it's anything
productive. If not forced it'll fail, and if forced it'll lose my
local commits. The former might actually be sort of what I want (git
complains when I have local commits), but I'm rather fond of the
refs/remotes/ stuff, so this solution sounds like a hack to me. What I
really want is an "extra careful" merge that is guaranteed to do
nothing but a fast-forward if it succeeds.

As is, it's a two-line shell script, though, so it isn't that
important.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```

## Junio C Hamano, 2007-10-27 06:09

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <7vejfhulzn.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vejfhulzn.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <Pine.LNX.4.64.0710251351330.7345@iabervon.org>

```
Daniel Barkalow <barkalow@iabervon.org> writes:

> On Thu, 25 Oct 2007, Jeff King wrote:
>
>> On Thu, Oct 25, 2007 at 07:32:36AM -0700, Randal L. Schwartz wrote:
>> 
>> > I have echo "ref: refs/remotes/origin/master" >.git/refs/heads/upstream
>> > so that my daily update script can go:
>> > 
>> >    git-fetch
>> >    if [ repo is on master, and is not dirty ];
>> >       git-merge upstream
>> >    fi
>> > 
>> > Yesterday that worked.
>> > 
>> > Today I get a rash of:
>> > 
>> >   fatal: Couldn't find remote ref refs/remotes/origin/master
>> > 
>> > from my git-fetch.
>> 
>> Randal and I discussed this a bit on IRC, and it turns out not to be
>> related to the 'upstream' symref. Instead, he had a broken
>> branch.master.merge config that pointed to "refs/remotes/origin/master"
>> (which you can see from his script above doesn't actually get used).
>> 
>> So presumably the old git-fetch didn't care that the contents of
>> branch.*.master didn't exist (it's just that nothing got marked for
>> merging), but the one just merged from the db/fetch-pack topic does.
>> 
>> Is this behavior change intentional?
>
> It's not exactly intentional; it's just that nobody seems to have tested 
> this particular misconfiguration. It should probably report an error 
> (since the configuration is, in fact, broken and potentially misleading), 
> but it probably shouldn't be fatal and certainly shouldn't be so 
> uninformative.

How would we proceed from here, then?

If you had "branch.master.merge = refs/heads/foobar", kept
running happily, and suddenly the remote stopped carrying that
foobar branch, you would get a configuration that uses
nonexistent remote branch name, so this is not purely a
configuration error on the fetcher's side.

Older git used to enumerate remote tracking branches explicitly,
and one of the remote.origin.fetch entries would have said
"refs/heads/foobar:refs/remotes/origin/foobar", and that would
have made git-fetch fail with the error, complaining that such a
branch does not exist.

You are suggesting that git-fetch should not fail if
remote.origin.fetch is refs/heads/*:refs/remotes/origin/*
wildcard, and I think I can agree with that; "git pull" however
should notice and and exit with an error.

Perhaps something like this?

-- >8 --
[PATCH] git-fetch: do not fail when remote branch disappears

When the branch named with branch.$name.merge is not covered by
the fetch configuration for the remote repository named with
branch.$name.remote, we automatically add that branch to the set
of branches to be fetched.  However, if the remote repository
does not have that branch (e.g. it used to exist, but got
removed), this is not a reason to fail the git-fetch itself.

The situation however will be noticed if git-fetch was called by
git-pull, as the resulting FETCH_HEAD would not have any entry
that is marked for merging.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 builtin-fetch.c |   24 ++++++++++++++++--------
 remote.c        |   22 +++++++++++++---------
 remote.h        |    5 ++++-
 3 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/builtin-fetch.c b/builtin-fetch.c
index b9d2b0c..003ed76 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -48,15 +48,21 @@ static void add_merge_config(struct ref **head,
 		if (rm)
 			continue;
 
-		/* Not fetched to a tracking branch?  We need to fetch
+		/*
+		 * Not fetched to a tracking branch?  We need to fetch
 		 * it anyway to allow this branch's "branch.$name.merge"
-		 * to be honored by git-pull.
+		 * to be honored by git-pull, but we do not have to
+		 * fail if branch.$name.merge is misconfigured to point
+		 * at a nonexisting branch.  If we were indeed called by
+		 * git-pull, it will notice the misconfiguration because
+		 * there is no entry in the resulting FETCH_HEAD marked
+		 * for merging.
 		 */
 		refspec.src = branch->merge[i]->src;
 		refspec.dst = NULL;
 		refspec.pattern = 0;
 		refspec.force = 0;
-		get_fetch_map(remote_refs, &refspec, tail);
+		get_fetch_map(remote_refs, &refspec, tail, 1);
 		for (rm = *old_tail; rm; rm = rm->next)
 			rm->merge = 1;
 	}
@@ -75,7 +81,7 @@ static struct ref *get_ref_map(struct transport *transport,
 
 	if (ref_count || tags) {
 		for (i = 0; i < ref_count; i++) {
-			get_fetch_map(remote_refs, &refs[i], &tail);
+			get_fetch_map(remote_refs, &refs[i], &tail, 0);
 			if (refs[i].dst && refs[i].dst[0])
 				*autotags = 1;
 		}
@@ -88,7 +94,7 @@ static struct ref *get_ref_map(struct transport *transport,
 			refspec.dst = "refs/tags/";
 			refspec.pattern = 1;
 			refspec.force = 0;
-			get_fetch_map(remote_refs, &refspec, &tail);
+			get_fetch_map(remote_refs, &refspec, &tail, 0);
 		}
 	} else {
 		/* Use the defaults */
@@ -97,7 +103,7 @@ static struct ref *get_ref_map(struct transport *transport,
 		int has_merge = branch_has_merge_config(branch);
 		if (remote && (remote->fetch_refspec_nr || has_merge)) {
 			for (i = 0; i < remote->fetch_refspec_nr; i++) {
-				get_fetch_map(remote_refs, &remote->fetch[i], &tail);
+				get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0);
 				if (remote->fetch[i].dst &&
 				    remote->fetch[i].dst[0])
 					*autotags = 1;
@@ -110,11 +116,13 @@ static struct ref *get_ref_map(struct transport *transport,
 			 * as given in branch.<name>.remote, we add the
 			 * ref given in branch.<name>.merge, too.
 			 */
-			if (has_merge && !strcmp(branch->remote_name,
-						remote->name))
+			if (has_merge &&
+			    !strcmp(branch->remote_name, remote->name))
 				add_merge_config(&ref_map, remote_refs, branch, &tail);
 		} else {
 			ref_map = get_remote_ref(remote_refs, "HEAD");
+			if (!ref_map)
+				die("Couldn't find remote ref HEAD");
 			ref_map->merge = 1;
 		}
 	}
diff --git a/remote.c b/remote.c
index 170015a..bec2ba1 100644
--- a/remote.c
+++ b/remote.c
@@ -857,7 +857,7 @@ struct ref *get_remote_ref(struct ref *remote_refs, const char *name)
 	struct ref *ref = find_ref_by_name_abbrev(remote_refs, name);
 
 	if (!ref)
-		die("Couldn't find remote ref %s\n", name);
+		return NULL;
 
 	return copy_ref(ref);
 }
@@ -889,20 +889,24 @@ static struct ref *get_local_ref(const char *name)
 
 int get_fetch_map(struct ref *remote_refs,
 		  const struct refspec *refspec,
-		  struct ref ***tail)
+		  struct ref ***tail,
+		  int missing_ok)
 {
 	struct ref *ref_map, *rm;
 
 	if (refspec->pattern) {
 		ref_map = get_expanded_map(remote_refs, refspec);
 	} else {
-		ref_map = get_remote_ref(remote_refs,
-					 refspec->src[0] ?
-					 refspec->src : "HEAD");
-
-		ref_map->peer_ref = get_local_ref(refspec->dst);
-		if (ref_map->peer_ref && refspec->force)
-			ref_map->peer_ref->force = 1;
+		const char *name = refspec->src[0] ? refspec->src : "HEAD";
+
+		ref_map = get_remote_ref(remote_refs, name);
+		if (!missing_ok && !ref_map)
+			die("Couldn't find remote ref %s", name);
+		if (ref_map) {
+			ref_map->peer_ref = get_local_ref(refspec->dst);
+			if (ref_map->peer_ref && refspec->force)
+				ref_map->peer_ref->force = 1;
+		}
 	}
 
 	for (rm = ref_map; rm; rm = rm->next) {
diff --git a/remote.h b/remote.h
index c62636d..878b4ec 100644
--- a/remote.h
+++ b/remote.h
@@ -67,9 +67,12 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
  * *tail is the pointer to the tail pointer of the list of results
  * beforehand, and will be set to the tail pointer of the list of
  * results afterward.
+ *
+ * missing_ok is usually false, but when we are adding branch.$name.merge
+ * it is Ok if the branch is not at the remote anymore.
  */
 int get_fetch_map(struct ref *remote_refs, const struct refspec *refspec,
-		  struct ref ***tail);
+		  struct ref ***tail, int missing_ok);
 
 struct ref *get_remote_ref(struct ref *remote_refs, const char *name);
 

```

## Daniel Barkalow, 2007-10-27 20:06

Subject: Re: recent change in git.git/master broke my repos
Message-ID: <Pine.LNX.4.64.0710271600440.7345@iabervon.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0710271600440.7345%40iabervon.org
In-Reply-To: <7vejfhulzn.fsf@gitster.siamese.dyndns.org>

```
On Fri, 26 Oct 2007, Junio C Hamano wrote:

> Daniel Barkalow <barkalow@iabervon.org> writes:
> 
> > On Thu, 25 Oct 2007, Jeff King wrote:
> >
> >> On Thu, Oct 25, 2007 at 07:32:36AM -0700, Randal L. Schwartz wrote:
> >> 
> >> > I have echo "ref: refs/remotes/origin/master" >.git/refs/heads/upstream
> >> > so that my daily update script can go:
> >> > 
> >> >    git-fetch
> >> >    if [ repo is on master, and is not dirty ];
> >> >       git-merge upstream
> >> >    fi
> >> > 
> >> > Yesterday that worked.
> >> > 
> >> > Today I get a rash of:
> >> > 
> >> >   fatal: Couldn't find remote ref refs/remotes/origin/master
> >> > 
> >> > from my git-fetch.
> >> 
> >> Randal and I discussed this a bit on IRC, and it turns out not to be
> >> related to the 'upstream' symref. Instead, he had a broken
> >> branch.master.merge config that pointed to "refs/remotes/origin/master"
> >> (which you can see from his script above doesn't actually get used).
> >> 
> >> So presumably the old git-fetch didn't care that the contents of
> >> branch.*.master didn't exist (it's just that nothing got marked for
> >> merging), but the one just merged from the db/fetch-pack topic does.
> >> 
> >> Is this behavior change intentional?
> >
> > It's not exactly intentional; it's just that nobody seems to have tested 
> > this particular misconfiguration. It should probably report an error 
> > (since the configuration is, in fact, broken and potentially misleading), 
> > but it probably shouldn't be fatal and certainly shouldn't be so 
> > uninformative.
> 
> How would we proceed from here, then?
> 
> If you had "branch.master.merge = refs/heads/foobar", kept
> running happily, and suddenly the remote stopped carrying that
> foobar branch, you would get a configuration that uses
> nonexistent remote branch name, so this is not purely a
> configuration error on the fetcher's side.

True, although I'd consider that a matter of configuration rot rather than 
it being an okay configuration; the user probably still needs to figure 
out what happened to it and what to use instead. Maybe we want to output a 
message to stderr (although higher than the die() used to be, so that we 
can report the reason that it was looking for the missing remote ref).

> Older git used to enumerate remote tracking branches explicitly,
> and one of the remote.origin.fetch entries would have said
> "refs/heads/foobar:refs/remotes/origin/foobar", and that would
> have made git-fetch fail with the error, complaining that such a
> branch does not exist.
> 
> You are suggesting that git-fetch should not fail if
> remote.origin.fetch is refs/heads/*:refs/remotes/origin/*
> wildcard, and I think I can agree with that; "git pull" however
> should notice and and exit with an error.
> 
> Perhaps something like this?

That looks like what I was going to write when I got to it (although I 
would have had the flag inverted, which is less git style, I guess).

Acked-By: Daniel Barkalow <barkalow@iabervon.org>

	-Daniel
*This .sig left intentionally blank*

```
