Subject: Re: `git fetch --refmap=<refspec>…<repository> <refspec>…​`providing NON-empty <refspec> to the --refmap ALSO causes Git to ignore the configured refspecs

From: Junio C Hamano <[email-masked]>
Date: Wed, 04 Sep 2024 07:34:52 -0700

Han Jiang <[email-masked]> writes:

> What happened instead? (Actual behavior)
>
> In `git fetch --refmap='+refs/heads/branch1:refs/remotes/server/branch1'
> server branch1 branch2`,
> `remote.server.fetch=+refs/heads/*:refs/remotes/server/*` is replaced
> by `--refmap='+refs/heads/branch1:refs/remotes/server/branch1'`,
> so these are what would be done:
> branch1 -> server/branch1

This is totally expected.

A refspec specifies "what to fetch" and "where to store locally what
we fetched" at the same time.  A refmap only specifies the "where
the stuff is stored locally" part, and what to fetch is specified
separately.  You asked branch1 and branch2 to be fetched (peek into
the .git/FETCH_HEAD file to see both objects are fetched) from the
command line arguments, and your refmap specified where to store
what you got from their refs/heads/branch1.  As the refmap does not
say anything about any other branches, they are not stored anywhere
in your local refs/ namespace.

Typically --refmap is given with a glob, but the story is the same
there.  If you fetched refs/notes/commits from that same server with
a refmap to map "refs/heads/*:refs/remotes/server/*", the notes commit
is not mapped to anywhere with the refmap, so nothing will happen to
it.