summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-02-17 17:21:40 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-02-17 17:21:40 -0800
commit69571dfe219f48614e0e0ae7e28efae0be297764 (patch)
tree74213c28659aa3dbcb9ad78a9a6bd946d0c5f6dd /builtin
parentMerge branch 'mr/bisect-in-c-4' (diff)
parentclone: respect remote unborn HEAD (diff)
downloadtgif-69571dfe219f48614e0e0ae7e28efae0be297764.tar.xz
Merge branch 'jt/clone-unborn-head'
"git clone" tries to locally check out the branch pointed at by HEAD of the remote repository after it is done, but the protocol did not convey the information necessary to do so when copying an empty repository. The protocol v2 learned how to do so. * jt/clone-unborn-head: clone: respect remote unborn HEAD connect, transport: encapsulate arg in struct ls-refs: report unborn targets of symrefs
Diffstat (limited to 'builtin')
-rw-r--r--builtin/clone.c34
-rw-r--r--builtin/fetch-pack.c3
-rw-r--r--builtin/fetch.c18
-rw-r--r--builtin/ls-remote.c9
4 files changed, 43 insertions, 21 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index e335734b4c..51e844a2de 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -979,7 +979,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
int err = 0, complete_refs_before_fetch = 1;
int submodule_progress;
- struct strvec ref_prefixes = STRVEC_INIT;
+ struct transport_ls_refs_options transport_ls_refs_options =
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
packet_trace_identity("clone");
@@ -1257,14 +1258,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport->smart_options->check_self_contained_and_connected = 1;
- strvec_push(&ref_prefixes, "HEAD");
- refspec_ref_prefixes(&remote->fetch, &ref_prefixes);
+ strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
+ refspec_ref_prefixes(&remote->fetch,
+ &transport_ls_refs_options.ref_prefixes);
if (option_branch)
- expand_ref_prefix(&ref_prefixes, option_branch);
+ expand_ref_prefix(&transport_ls_refs_options.ref_prefixes,
+ option_branch);
if (!option_no_tags)
- strvec_push(&ref_prefixes, "refs/tags/");
+ strvec_push(&transport_ls_refs_options.ref_prefixes,
+ "refs/tags/");
- refs = transport_get_remote_refs(transport, &ref_prefixes);
+ refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
if (refs) {
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
@@ -1326,8 +1330,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
remote_head = NULL;
option_no_checkout = 1;
if (!option_bare) {
- const char *branch = git_default_branch_name(0);
- char *ref = xstrfmt("refs/heads/%s", branch);
+ const char *branch;
+ char *ref;
+
+ if (transport_ls_refs_options.unborn_head_target &&
+ skip_prefix(transport_ls_refs_options.unborn_head_target,
+ "refs/heads/", &branch)) {
+ ref = transport_ls_refs_options.unborn_head_target;
+ transport_ls_refs_options.unborn_head_target = NULL;
+ create_symref("HEAD", ref, reflog_msg.buf);
+ } else {
+ branch = git_default_branch_name(0);
+ ref = xstrfmt("refs/heads/%s", branch);
+ }
install_branch_config(0, branch, remote_name, ref);
free(ref);
@@ -1380,6 +1395,7 @@ cleanup:
strbuf_release(&key);
junk_mode = JUNK_LEAVE_ALL;
- strvec_clear(&ref_prefixes);
+ strvec_clear(&transport_ls_refs_options.ref_prefixes);
+ free(transport_ls_refs_options.unborn_head_target);
return err;
}
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 58b7c1fbdc..c2d96f4c89 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -220,7 +220,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
version = discover_version(&reader);
switch (version) {
case protocol_v2:
- get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL, args.stateless_rpc);
+ get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL,
+ args.stateless_rpc);
break;
case protocol_v1:
case protocol_v0:
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 91f3d20696..0b90de87c7 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1455,7 +1455,8 @@ static int do_fetch(struct transport *transport,
int autotags = (transport->remote->fetch_tags == 1);
int retcode = 0;
const struct ref *remote_refs;
- struct strvec ref_prefixes = STRVEC_INIT;
+ struct transport_ls_refs_options transport_ls_refs_options =
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
int must_list_refs = 1;
if (tags == TAGS_DEFAULT) {
@@ -1475,7 +1476,7 @@ static int do_fetch(struct transport *transport,
if (rs->nr) {
int i;
- refspec_ref_prefixes(rs, &ref_prefixes);
+ refspec_ref_prefixes(rs, &transport_ls_refs_options.ref_prefixes);
/*
* We can avoid listing refs if all of them are exact
@@ -1489,22 +1490,25 @@ static int do_fetch(struct transport *transport,
}
}
} else if (transport->remote && transport->remote->fetch.nr)
- refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
+ refspec_ref_prefixes(&transport->remote->fetch,
+ &transport_ls_refs_options.ref_prefixes);
if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
must_list_refs = 1;
- if (ref_prefixes.nr)
- strvec_push(&ref_prefixes, "refs/tags/");
+ if (transport_ls_refs_options.ref_prefixes.nr)
+ strvec_push(&transport_ls_refs_options.ref_prefixes,
+ "refs/tags/");
}
if (must_list_refs) {
trace2_region_enter("fetch", "remote_refs", the_repository);
- remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
+ remote_refs = transport_get_remote_refs(transport,
+ &transport_ls_refs_options);
trace2_region_leave("fetch", "remote_refs", the_repository);
} else
remote_refs = NULL;
- strvec_clear(&ref_prefixes);
+ strvec_clear(&transport_ls_refs_options.ref_prefixes);
ref_map = get_ref_map(transport->remote, remote_refs, rs,
tags, &autotags);
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 092917eca2..ef604752a0 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -45,7 +45,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
int show_symref_target = 0;
const char *uploadpack = NULL;
const char **pattern = NULL;
- struct strvec ref_prefixes = STRVEC_INIT;
+ struct transport_ls_refs_options transport_options =
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
int i;
struct string_list server_options = STRING_LIST_INIT_DUP;
@@ -94,9 +95,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
}
if (flags & REF_TAGS)
- strvec_push(&ref_prefixes, "refs/tags/");
+ strvec_push(&transport_options.ref_prefixes, "refs/tags/");
if (flags & REF_HEADS)
- strvec_push(&ref_prefixes, "refs/heads/");
+ strvec_push(&transport_options.ref_prefixes, "refs/heads/");
remote = remote_get(dest);
if (!remote) {
@@ -118,7 +119,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
if (server_options.nr)
transport->server_options = &server_options;
- ref = transport_get_remote_refs(transport, &ref_prefixes);
+ ref = transport_get_remote_refs(transport, &transport_options);
if (ref) {
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
repo_set_hash_algo(the_repository, hash_algo);