Skip to content

Commit 3c7bab0

Browse files
rcoupgitster
authored andcommitted
fetch: add --refetch option
Teach fetch and transports the --refetch option to force a full fetch without negotiating common commits with the remote. Use when applying a new partial clone filter to refetch all matching objects. Signed-off-by: Robert Coup <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 869a0eb commit 3c7bab0

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

Documentation/fetch-options.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ endif::git-pull[]
163163
behavior for a remote may be specified with the remote.<name>.tagOpt
164164
setting. See linkgit:git-config[1].
165165

166+
ifndef::git-pull[]
167+
--refetch::
168+
Instead of negotiating with the server to avoid transferring commits and
169+
associated objects that are already present locally, this option fetches
170+
all objects as a fresh clone would. Use this to reapply a partial clone
171+
filter from configuration or using `--filter=` when the filter
172+
definition has changed.
173+
endif::git-pull[]
174+
166175
--refmap=<refspec>::
167176
When fetching refs listed on the command line, use the
168177
specified refspec (can be given more than once) to map the

builtin/fetch.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int prune_tags = -1; /* unspecified */
5959

6060
static int all, append, dry_run, force, keep, multiple, update_head_ok;
6161
static int write_fetch_head = 1;
62-
static int verbosity, deepen_relative, set_upstream;
62+
static int verbosity, deepen_relative, set_upstream, refetch;
6363
static int progress = -1;
6464
static int enable_auto_gc = 1;
6565
static int tags = TAGS_DEFAULT, unshallow, update_shallow, deepen;
@@ -190,6 +190,9 @@ static struct option builtin_fetch_options[] = {
190190
OPT_SET_INT_F(0, "unshallow", &unshallow,
191191
N_("convert to a complete repository"),
192192
1, PARSE_OPT_NONEG),
193+
OPT_SET_INT_F(0, "refetch", &refetch,
194+
N_("re-fetch without negotiating common commits"),
195+
1, PARSE_OPT_NONEG),
193196
{ OPTION_STRING, 0, "submodule-prefix", &submodule_prefix, N_("dir"),
194197
N_("prepend this to submodule path output"), PARSE_OPT_HIDDEN },
195198
OPT_CALLBACK_F(0, "recurse-submodules-default",
@@ -1296,6 +1299,14 @@ static int check_exist_and_connected(struct ref *ref_map)
12961299
if (deepen)
12971300
return -1;
12981301

1302+
/*
1303+
* Similarly, if we need to refetch, we always want to perform a full
1304+
* fetch ignoring existing objects.
1305+
*/
1306+
if (refetch)
1307+
return -1;
1308+
1309+
12991310
/*
13001311
* check_connected() allows objects to merely be promised, but
13011312
* we need all direct targets to exist.
@@ -1492,6 +1503,8 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
14921503
set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, "yes");
14931504
if (update_shallow)
14941505
set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
1506+
if (refetch)
1507+
set_option(transport, TRANS_OPT_REFETCH, "yes");
14951508
if (filter_options.choice) {
14961509
const char *spec =
14971510
expand_list_objects_filter_spec(&filter_options);

transport-helper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ static int fetch_refs(struct transport *transport,
715715
if (data->transport_options.update_shallow)
716716
set_helper_option(transport, "update-shallow", "true");
717717

718+
if (data->transport_options.refetch)
719+
set_helper_option(transport, "refetch", "true");
720+
718721
if (data->transport_options.filter_options.choice) {
719722
const char *spec = expand_list_objects_filter_spec(
720723
&data->transport_options.filter_options);

transport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ static int set_git_option(struct git_transport_options *opts,
243243
list_objects_filter_die_if_populated(&opts->filter_options);
244244
parse_list_objects_filter(&opts->filter_options, value);
245245
return 0;
246+
} else if (!strcmp(name, TRANS_OPT_REFETCH)) {
247+
opts->refetch = !!value;
248+
return 0;
246249
} else if (!strcmp(name, TRANS_OPT_REJECT_SHALLOW)) {
247250
opts->reject_shallow = !!value;
248251
return 0;
@@ -377,6 +380,7 @@ static int fetch_refs_via_pack(struct transport *transport,
377380
args.update_shallow = data->options.update_shallow;
378381
args.from_promisor = data->options.from_promisor;
379382
args.filter_options = data->options.filter_options;
383+
args.refetch = data->options.refetch;
380384
args.stateless_rpc = transport->stateless_rpc;
381385
args.server_options = transport->server_options;
382386
args.negotiation_tips = data->options.negotiation_tips;

transport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct git_transport_options {
1616
unsigned update_shallow : 1;
1717
unsigned reject_shallow : 1;
1818
unsigned deepen_relative : 1;
19+
unsigned refetch : 1;
1920

2021
/* see documentation of corresponding flag in fetch-pack.h */
2122
unsigned from_promisor : 1;
@@ -216,6 +217,9 @@ void transport_check_allowed(const char *type);
216217
/* Filter objects for partial clone and fetch */
217218
#define TRANS_OPT_LIST_OBJECTS_FILTER "filter"
218219

220+
/* Refetch all objects without negotiating */
221+
#define TRANS_OPT_REFETCH "refetch"
222+
219223
/* Request atomic (all-or-nothing) updates when pushing */
220224
#define TRANS_OPT_ATOMIC "atomic"
221225

0 commit comments

Comments
 (0)