Skip to content

Commit b206724

Browse files
committed
clone: add failing test for a mirror-clone with clone_into
Show a failure to perform a mirror-clone from a repository, both local and remote.
1 parent 7851e59 commit b206724

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

tests/network/fetchlocal.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,29 @@ void test_network_fetchlocal__partial(void)
8686
git_strarray_free(&refnames);
8787
git_remote_free(origin);
8888
}
89+
90+
void test_network_fetchlocal__clone_into_mirror(void)
91+
{
92+
git_buf path = GIT_BUF_INIT;
93+
git_repository *repo;
94+
git_remote *remote;
95+
git_reference *head;
96+
97+
cl_git_pass(git_repository_init(&repo, "./foo.git", true));
98+
cl_git_pass(git_remote_create(&remote, repo, "origin", cl_git_fixture_url("testrepo.git")));
99+
100+
git_remote_clear_refspecs(remote);
101+
cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*"));
102+
103+
cl_git_pass(git_clone_into(repo, remote, NULL, NULL, NULL));
104+
105+
cl_git_pass(git_reference_lookup(&head, repo, "HEAD"));
106+
cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
107+
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
108+
109+
git_remote_free(remote);
110+
git_reference_free(head);
111+
git_repository_free(repo);
112+
git_buf_free(&path);
113+
cl_fixture_cleanup("./foo.git");
114+
}

tests/online/clone.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ void test_online_clone__clone_into(void)
164164
git_buf_free(&path);
165165
}
166166

167+
void test_online_clone__clone_mirror(void)
168+
{
169+
git_buf path = GIT_BUF_INIT;
170+
git_remote *remote;
171+
git_reference *head;
172+
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
173+
174+
bool fetch_progress_cb_was_called = false;
175+
176+
cl_git_pass(git_repository_init(&g_repo, "./foo.git", true));
177+
cl_git_pass(git_remote_create(&remote, g_repo, "origin", LIVE_REPO_URL));
178+
179+
callbacks.transfer_progress = &fetch_progress;
180+
callbacks.payload = &fetch_progress_cb_was_called;
181+
git_remote_set_callbacks(remote, &callbacks);
182+
183+
git_remote_clear_refspecs(remote);
184+
cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*"));
185+
186+
cl_git_pass(git_clone_into(g_repo, remote, NULL, NULL, NULL));
187+
188+
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
189+
cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
190+
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
191+
192+
cl_assert_equal_i(true, fetch_progress_cb_was_called);
193+
194+
git_remote_free(remote);
195+
git_reference_free(head);
196+
git_buf_free(&path);
197+
cl_fixture_cleanup("./foo.git");
198+
}
199+
167200
static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *payload)
168201
{
169202
int *callcount = (int*)payload;

0 commit comments

Comments
 (0)