Subject: Re: Plumbing for mapping from a remote tracking ref to the remote ref?

From: Junio C Hamano <[email-masked]>
Date: Wed, 15 Jun 2022 13:18:26 -0700

Tao Klerks <[email-masked]> writes:

> Given the following configured fetch refspec for a remote:
>
> [remote "origin"]
>         url = git@someserver:somerepo.git
>         fetch = +refs/heads/*:refs/remotes/somepath/*
>
> And given a ref of the form "refs/remotes/somepath/branch_A",
>
> I'm wondering whether there is any plumbing that would be able to tell
> me what to put in a "fetch" command, to get
> "refs/remotes/somepath/branch_A" fetched - in other words, is there
> any plumbing that can use the configured fetch refspecs to map
> "refs/remotes/somepath/branch_A" to "refs/heads/branch_A" for me, so
> that I can then do "git fetch origin refs/heads/branch_A".

I am fairly certain that I never have written one myself ;-)

I wonder how the end-user experience should look like.

	$ git refmap refs/remotes/somepath/branch-A
	origin refs/heads/branch-A

	$ git refmap refs/remotes/somepath/{branch-A,branch-B}
	origin refs/heads/branch-A
	origin refs/heads/branch-B

IOW, you give name(s) of remote-tracking branches and then you get
the remote and their ref for these?

I do not oppose to such a command existing, but I do not know what
the right answer should be for a case like this:

	[remote "origin"]
		url = ... the official project repository ...
		fetch = +refs/heads/*:refs/remotes/upstream/*

	[remote "mirror"]
		url = ... a local mirror you'd use regularly ...
		fetch = +refs/heads/*:refs/remotes/upstream/*

In order to support such a "more than one can update the same" case
sensibly, the output may have to repeat the input, e.g.

	$ git refmap refs/remotes/upstream/main
	refs/remotes/upstream/main	origin refs/heads/main
	refs/remotes/upstream/main	mirror refs/heads/main

perhaps?