Merge branch 'bf/fetch-set-head-fix'
Fetching into a bare repository incorrectly assumed it always used a mirror layout when deciding to update remote-tracking HEAD, which has been corrected. * bf/fetch-set-head-fix: fetch set_head: fix non-mirror remotes in bare repositories fetch set_head: refactor to use remote directly
This commit is contained in:
@ -1617,13 +1617,13 @@ static void report_set_head(const char *remote, const char *head_name,
|
|||||||
strbuf_release(&buf_prefix);
|
strbuf_release(&buf_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_head(const struct ref *remote_refs, int follow_remote_head,
|
static int set_head(const struct ref *remote_refs, struct remote *remote)
|
||||||
const char *no_warn_branch)
|
|
||||||
{
|
{
|
||||||
int result = 0, create_only, is_bare, was_detached;
|
int result = 0, create_only, baremirror, was_detached;
|
||||||
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
|
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
|
||||||
b_local_head = STRBUF_INIT;
|
b_local_head = STRBUF_INIT;
|
||||||
const char *remote = gtransport->remote->name;
|
int follow_remote_head = remote->follow_remote_head;
|
||||||
|
const char *no_warn_branch = remote->no_warn_branch;
|
||||||
char *head_name = NULL;
|
char *head_name = NULL;
|
||||||
struct ref *ref, *matches;
|
struct ref *ref, *matches;
|
||||||
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
|
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
|
||||||
@ -1655,17 +1655,17 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,
|
|||||||
|
|
||||||
if (!head_name)
|
if (!head_name)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
is_bare = is_bare_repository();
|
baremirror = is_bare_repository() && remote->mirror;
|
||||||
create_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !is_bare;
|
create_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !baremirror;
|
||||||
if (is_bare) {
|
if (baremirror) {
|
||||||
strbuf_addstr(&b_head, "HEAD");
|
strbuf_addstr(&b_head, "HEAD");
|
||||||
strbuf_addf(&b_remote_head, "refs/heads/%s", head_name);
|
strbuf_addf(&b_remote_head, "refs/heads/%s", head_name);
|
||||||
} else {
|
} else {
|
||||||
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote);
|
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote->name);
|
||||||
strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote, head_name);
|
strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote->name, head_name);
|
||||||
}
|
}
|
||||||
/* make sure it's valid */
|
/* make sure it's valid */
|
||||||
if (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) {
|
if (!baremirror && !refs_ref_exists(refs, b_remote_head.buf)) {
|
||||||
result = 1;
|
result = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1678,7 +1678,7 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,
|
|||||||
if (verbosity >= 0 &&
|
if (verbosity >= 0 &&
|
||||||
follow_remote_head == FOLLOW_REMOTE_WARN &&
|
follow_remote_head == FOLLOW_REMOTE_WARN &&
|
||||||
(!no_warn_branch || strcmp(no_warn_branch, head_name)))
|
(!no_warn_branch || strcmp(no_warn_branch, head_name)))
|
||||||
report_set_head(remote, head_name, &b_local_head, was_detached);
|
report_set_head(remote->name, head_name, &b_local_head, was_detached);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(head_name);
|
free(head_name);
|
||||||
@ -1924,8 +1924,7 @@ static int do_fetch(struct transport *transport,
|
|||||||
"you need to specify exactly one branch with the --set-upstream option"));
|
"you need to specify exactly one branch with the --set-upstream option"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (set_head(remote_refs, transport->remote->follow_remote_head,
|
if (set_head(remote_refs, transport->remote))
|
||||||
transport->remote->no_warn_branch))
|
|
||||||
;
|
;
|
||||||
/*
|
/*
|
||||||
* Way too many cases where this can go wrong
|
* Way too many cases where this can go wrong
|
||||||
|
@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'non-mirror fetch does not interfere with mirror' '
|
||||||
|
test_when_finished rm -rf headnotmain &&
|
||||||
|
(
|
||||||
|
git init --bare -b notmain headnotmain &&
|
||||||
|
cd headnotmain &&
|
||||||
|
git remote add -f other ../two &&
|
||||||
|
test "$(git symbolic-ref HEAD)" = "refs/heads/notmain"
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'add --mirror=fetch' '
|
test_expect_success 'add --mirror=fetch' '
|
||||||
mkdir mirror-fetch &&
|
mkdir mirror-fetch &&
|
||||||
git init -b main mirror-fetch/parent &&
|
git init -b main mirror-fetch/parent &&
|
||||||
|
@ -81,6 +81,23 @@ test_expect_success "fetch test remote HEAD" '
|
|||||||
branch=$(git rev-parse refs/remotes/origin/main) &&
|
branch=$(git rev-parse refs/remotes/origin/main) &&
|
||||||
test "z$head" = "z$branch"'
|
test "z$head" = "z$branch"'
|
||||||
|
|
||||||
|
test_expect_success "fetch test remote HEAD in bare repository" '
|
||||||
|
test_when_finished rm -rf barerepo &&
|
||||||
|
(
|
||||||
|
cd "$D" &&
|
||||||
|
git init --bare barerepo &&
|
||||||
|
cd barerepo &&
|
||||||
|
git remote add upstream ../two &&
|
||||||
|
git fetch upstream &&
|
||||||
|
git rev-parse --verify refs/remotes/upstream/HEAD &&
|
||||||
|
git rev-parse --verify refs/remotes/upstream/main &&
|
||||||
|
head=$(git rev-parse refs/remotes/upstream/HEAD) &&
|
||||||
|
branch=$(git rev-parse refs/remotes/upstream/main) &&
|
||||||
|
test "z$head" = "z$branch"
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
|
||||||
test_expect_success "fetch test remote HEAD change" '
|
test_expect_success "fetch test remote HEAD change" '
|
||||||
cd "$D" &&
|
cd "$D" &&
|
||||||
cd two &&
|
cd two &&
|
||||||
|
Reference in New Issue
Block a user