Skip to content

Commit

Permalink
Install the default "master" branch configuration after cloning a void
Browse files Browse the repository at this point in the history
After "cloning from an empty repository", we have a configuration to
describe the remote's URL and the default ref mappings, but we lack the
branch configuration for the default branch we create on our end,
"master".

It is likely that the empty repository we cloned from will point the
default "master" branch with its HEAD, so prepare the local configuration
to match.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Feb 13, 2009
1 parent 1a526d4 commit 5cd12b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
23 changes: 18 additions & 5 deletions builtin-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ static struct ref *write_remote_refs(const struct ref *refs,
return local_refs;
}

static void install_branch_config(const char *local,
const char *origin,
const char *remote)
{
struct strbuf key = STRBUF_INIT;
strbuf_addf(&key, "branch.%s.remote", local);
git_config_set(key.buf, origin);
strbuf_reset(&key);
strbuf_addf(&key, "branch.%s.merge", local);
git_config_set(key.buf, remote);
strbuf_release(&key);
}

int cmd_clone(int argc, const char **argv, const char *prefix)
{
int use_local_hardlinks = 1;
Expand Down Expand Up @@ -539,6 +552,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
head_points_at = NULL;
remote_head = NULL;
option_no_checkout = 1;
if (!option_bare)
install_branch_config("master", option_origin,
"refs/heads/master");
}

if (head_points_at) {
Expand Down Expand Up @@ -567,11 +583,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
head_points_at->peer_ref->name,
reflog_msg.buf);

strbuf_addf(&key, "branch.%s.remote", head);
git_config_set(key.buf, option_origin);
strbuf_reset(&key);
strbuf_addf(&key, "branch.%s.merge", head);
git_config_set(key.buf, head_points_at->name);
install_branch_config(head, option_origin,
head_points_at->name);
}
} else if (remote_head) {
/* Source had detached HEAD pointing somewhere. */
Expand Down
15 changes: 15 additions & 0 deletions t/t5601-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,19 @@ test_expect_success 'clone to an existing path' '
test_must_fail git clone src target-5
'

test_expect_success 'clone a void' '
mkdir src-0 &&
(
cd src-0 && git init
) &&
git clone src-0 target-6 &&
(
cd src-0 && test_commit A
) &&
git clone src-0 target-7 &&
# There is no reason to insist they are bit-for-bit
# identical, but this test should suffice for now.
test_cmp target-6/.git/config target-7/.git/config
'

test_done

0 comments on commit 5cd12b8

Please sign in to comment.