Merge branch 'jk/clone-detached'
* jk/clone-detached: clone: always fetch remote HEAD make copy_ref globally available consider only branches in guess_remote_head t: add tests for cloning remotes with detached HEAD
This commit is contained in:
commit
8ab19bc5de
@ -345,8 +345,9 @@ static void remove_junk_on_signal(int signo)
|
|||||||
static struct ref *wanted_peer_refs(const struct ref *refs,
|
static struct ref *wanted_peer_refs(const struct ref *refs,
|
||||||
struct refspec *refspec)
|
struct refspec *refspec)
|
||||||
{
|
{
|
||||||
struct ref *local_refs = NULL;
|
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
|
||||||
struct ref **tail = &local_refs;
|
struct ref *local_refs = head;
|
||||||
|
struct ref **tail = head ? &head->next : &local_refs;
|
||||||
|
|
||||||
get_fetch_map(refs, refspec, &tail, 0);
|
get_fetch_map(refs, refspec, &tail, 0);
|
||||||
if (!option_mirror)
|
if (!option_mirror)
|
||||||
@ -359,8 +360,11 @@ static void write_remote_refs(const struct ref *local_refs)
|
|||||||
{
|
{
|
||||||
const struct ref *r;
|
const struct ref *r;
|
||||||
|
|
||||||
for (r = local_refs; r; r = r->next)
|
for (r = local_refs; r; r = r->next) {
|
||||||
|
if (!r->peer_ref)
|
||||||
|
continue;
|
||||||
add_extra_ref(r->peer_ref->name, r->old_sha1, 0);
|
add_extra_ref(r->peer_ref->name, r->old_sha1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
pack_refs(PACK_REFS_ALL);
|
pack_refs(PACK_REFS_ALL);
|
||||||
clear_extra_refs();
|
clear_extra_refs();
|
||||||
|
6
remote.c
6
remote.c
@ -896,7 +896,7 @@ struct ref *alloc_ref(const char *name)
|
|||||||
return alloc_ref_with_prefix("", 0, name);
|
return alloc_ref_with_prefix("", 0, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref *copy_ref(const struct ref *ref)
|
struct ref *copy_ref(const struct ref *ref)
|
||||||
{
|
{
|
||||||
struct ref *cpy;
|
struct ref *cpy;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -1667,7 +1667,9 @@ struct ref *guess_remote_head(const struct ref *head,
|
|||||||
|
|
||||||
/* Look for another ref that points there */
|
/* Look for another ref that points there */
|
||||||
for (r = refs; r; r = r->next) {
|
for (r = refs; r; r = r->next) {
|
||||||
if (r != head && !hashcmp(r->old_sha1, head->old_sha1)) {
|
if (r != head &&
|
||||||
|
!prefixcmp(r->name, "refs/heads/") &&
|
||||||
|
!hashcmp(r->old_sha1, head->old_sha1)) {
|
||||||
*tail = copy_ref(r);
|
*tail = copy_ref(r);
|
||||||
tail = &((*tail)->next);
|
tail = &((*tail)->next);
|
||||||
if (!all)
|
if (!all)
|
||||||
|
2
remote.h
2
remote.h
@ -70,7 +70,7 @@ struct refspec {
|
|||||||
extern const struct refspec *tag_refspec;
|
extern const struct refspec *tag_refspec;
|
||||||
|
|
||||||
struct ref *alloc_ref(const char *name);
|
struct ref *alloc_ref(const char *name);
|
||||||
|
struct ref *copy_ref(const struct ref *ref);
|
||||||
struct ref *copy_ref_list(const struct ref *ref);
|
struct ref *copy_ref_list(const struct ref *ref);
|
||||||
|
|
||||||
int check_ref_type(const struct ref *ref, int flags);
|
int check_ref_type(const struct ref *ref, int flags);
|
||||||
|
76
t/t5707-clone-detached.sh
Executable file
76
t/t5707-clone-detached.sh
Executable file
@ -0,0 +1,76 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='test cloning a repository with detached HEAD'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
head_is_detached() {
|
||||||
|
git --git-dir=$1/.git rev-parse --verify HEAD &&
|
||||||
|
test_must_fail git --git-dir=$1/.git symbolic-ref HEAD
|
||||||
|
}
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
echo one >file &&
|
||||||
|
git add file &&
|
||||||
|
git commit -m one &&
|
||||||
|
echo two >file &&
|
||||||
|
git commit -a -m two &&
|
||||||
|
git tag two &&
|
||||||
|
echo three >file &&
|
||||||
|
git commit -a -m three
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone repo (detached HEAD points to branch)' '
|
||||||
|
git checkout master^0 &&
|
||||||
|
git clone "file://$PWD" detached-branch
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD matches' '
|
||||||
|
echo three >expect &&
|
||||||
|
git --git-dir=detached-branch/.git log -1 --format=%s >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
test_expect_failure 'cloned HEAD is detached' '
|
||||||
|
head_is_detached detached-branch
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone repo (detached HEAD points to tag)' '
|
||||||
|
git checkout two^0 &&
|
||||||
|
git clone "file://$PWD" detached-tag
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD matches' '
|
||||||
|
echo two >expect &&
|
||||||
|
git --git-dir=detached-tag/.git log -1 --format=%s >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD is detached' '
|
||||||
|
head_is_detached detached-tag
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone repo (detached HEAD points to history)' '
|
||||||
|
git checkout two^ &&
|
||||||
|
git clone "file://$PWD" detached-history
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD matches' '
|
||||||
|
echo one >expect &&
|
||||||
|
git --git-dir=detached-history/.git log -1 --format=%s >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD is detached' '
|
||||||
|
head_is_detached detached-history
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone repo (orphan detached HEAD)' '
|
||||||
|
git checkout master^0 &&
|
||||||
|
echo four >file &&
|
||||||
|
git commit -a -m four &&
|
||||||
|
git clone "file://$PWD" detached-orphan
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD matches' '
|
||||||
|
echo four >expect &&
|
||||||
|
git --git-dir=detached-orphan/.git log -1 --format=%s >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
test_expect_success 'cloned HEAD is detached' '
|
||||||
|
head_is_detached detached-orphan
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user