Thread View: linux.kernel.git
2 messages
2 total messages
Started by "Harald Nordgren via GitGitGadge...
Sun, 22 Nov 2026 11:57
[PATCH v15 2/7] fetch: let --refmap apply to configured refspecs
Author: "Harald Nordgren via GitGitGadge...
Date: Sun, 22 Nov 2026 11:57
Date: Sun, 22 Nov 2026 11:57
104 lines
14664 bytes
14664 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>
"git fetch --refmap=<map> <remote>" without refspecs on the command
line dies with "--refmap option is only meaningful with command-line
refspec(s)". So there is no way to fetch what remote.<name>.fetch
normally fetches and store it somewhere else for one invocation.
Let the option apply there as well. The configured refspecs still
decide what is fetched, and the refs are stored through <map> instead
of at the destinations configured in remote.<name>.fetch. The command
line overrides the configuration, the same way refspecs given on the
command line override remote.<name>.fetch.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
Documentation/fetch-options.adoc | 8 ++++++--
builtin/fetch.c | 15 +++++++++++++--
t/t5510-fetch.sh | 9 +++++++--
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/Documentation/fetch-options.adoc b/Documentation/fetch-options.adoc
index 327169cee7..27f2ac6dc7 100644
--- a/Documentation/fetch-options.adoc
+++ b/Documentation/fetch-options.adoc
@@ -239,8 +239,12 @@ endif::git-pull[]
specified refspec (can be given more than once) to map the
refs to remote-tracking branches, instead of the values of
`remote.<name>.fetch` configuration variables for the remote
- repository. A ref fetched with a destination of its own
- (`<src>:<dst>`) is stored only there and is not mapped.
+ repository. A refspec on the command line with a destination
+ of its own (`<src>:<dst>`) is stored only there and is not
+ mapped. Without refspecs on the command line, the
+ `remote.<name>.fetch` values still decide what is fetched, and
+ the refs are stored through the specified refspec instead of
+ at the destinations configured there.
Providing an empty _<refspec>_ to the
`--refmap` option causes Git to ignore the configured
refspecs and rely entirely on the refspecs supplied as
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 0ee252e353..ccff0075c9 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -291,6 +291,14 @@ static void map_refs_without_dst(const struct ref *ref_map,
free_refs(unmapped);
}
+static void drop_destinations(struct ref *ref_map)
+{
+ for (struct ref *rm = ref_map; rm; rm = rm->next) {
+ free_one_ref(rm->peer_ref);
+ rm->peer_ref = NULL;
+ }
+}
+
static void create_fetch_oidset(struct ref **head, struct oidset *out)
{
struct ref *rm = *head;
@@ -585,8 +593,6 @@ static struct ref *get_ref_map(struct remote *remote,
for (i = 0; i < remote->fetch.nr; i++)
get_fetch_map(ref_map, &remote->fetch.items[i],
&oref_tail, 1);
- } else if (refmap.nr) {
- die("--refmap option is only meaningful with command-line refspec(s)");
} else {
/* Use the defaults */
struct branch *branch = branch_get(NULL);
@@ -621,6 +627,11 @@ static struct ref *get_ref_map(struct remote *remote,
ref_map->fetch_head_status = FETCH_HEAD_MERGE;
tail = &ref_map->next;
}
+
+ if (refmap.nr) {
+ drop_destinations(ref_map);
+ map_refs_without_dst(ref_map, &refmap, &oref_tail);
+ }
}
if (tags == TAGS_SET) {
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 4b40ec965a..412a5401a8 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -906,10 +906,15 @@ test_expect_success 'explicit pull should update tracking' '
)
'
-test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
+test_expect_success '--refmap without command-line refspec replaces where remote.*.fetch stores' '
(
cd three &&
- test_must_fail git fetch --refmap="*:refs/remotes/none/*"
+ git update-ref refs/remotes/origin/main base-origin-main &&
+ o=$(git rev-parse --verify refs/remotes/origin/main) &&
+ git fetch --refmap="refs/heads/*:refs/remotes/none/*" origin &&
+ n=$(git rev-parse --verify refs/remotes/origin/main) &&
+ test "$o" = "$n" &&
+ git rev-parse --verify refs/remotes/none/main
)
'
--
gitgitgadget
Re: [PATCH v15 2/7] fetch: let --refmap apply to configured refspecs
Author: Junio C Hamano
Date: Tue, 24 Nov 2026 15:04
Date: Tue, 24 Nov 2026 15:04
58 lines
15058 bytes
15058 bytes
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> @@ -585,8 +593,6 @@ static struct ref *get_ref_map(struct remote *remote,
> for (i = 0; i < remote->fetch.nr; i++)
> get_fetch_map(ref_map, &remote->fetch.items[i],
> &oref_tail, 1);
> - } else if (refmap.nr) {
> - die("--refmap option is only meaningful with command-line refspec(s)");
> } else {
> /* Use the defaults */
> struct branch *branch = branch_get(NULL);
With no configured remote.<name>.fetch,
$ git fetch --refmap=... <URL>
would no longer error out due to this removal. Instead, it would fetch
HEAD into FETCH_HEAD while silently ignoring the given refmap.
I am not sure if we still want to reject --refmap when neither rs->nr
nor remote->fetch.nr (nor fetchUpstreams later) gives it anything to
map, or if allowing it is harmless.
> @@ -621,6 +627,11 @@ static struct ref *get_ref_map(struct remote *remote,
> ref_map->fetch_head_status = FETCH_HEAD_MERGE;
> tail = &ref_map->next;
> }
> +
> + if (refmap.nr) {
> + drop_destinations(ref_map);
> + map_refs_without_dst(ref_map, &refmap, &oref_tail);
> + }
> }
This is a bit hard to read without context, but doesn't this break
automatic tag following? Earlier in the loop over remote->fetch,
*autotags is set to 1 whenever remote->fetch.items[i].dst is non-empty.
If a user passes --refmap="" from the command line to decline storage of
remote-tracking branches, drop_destinations() clears all '.peer_ref'
pointers here, yet *autotags has already been computed and stays 1, so
tag auto-following still runs.
Conversely, if '.fetch' has destinationless "just store in FETCH_HEAD"
entries and --refmap supplies destinations, *autotags stays 0.
In addition, in do_fetch(), when rs->nr is 0, prune_refs() is given
&transport->remote->fetch and not &refmap. So
$ git fetch --prune --refmap="refs/heads/*:refs/remotes/none/*" origin
would still prune based on remote.origin.fetch, which would most likely
be set to store in refs/remotes/origin/, and the refs/remotes/none/
hierarchy would not be pruned. I am not sure if this is actually a good
thing.
Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads