mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
fetch: test when HEAD points to nonexistent branch
When HEAD points to a nonexistent or invalid branch - for example, to `refs/heads/` - the fetch should be permitted to continue, but we should not use it when creating the `for merge` option in the FETCH_HEAD file. (This emulates git's behavior.)
This commit is contained in:
@@ -319,6 +319,16 @@ static int assert_master_for_merge(const char *ref, const char *url, const git_o
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int assert_none_for_merge(const char *ref, const char *url, const git_oid *id, unsigned int is_merge, void *data)
|
||||
{
|
||||
GIT_UNUSED(ref);
|
||||
GIT_UNUSED(url);
|
||||
GIT_UNUSED(id);
|
||||
GIT_UNUSED(data);
|
||||
|
||||
return is_merge ? -1 : 0;
|
||||
}
|
||||
|
||||
void test_fetchhead_nonetwork__unborn_with_upstream(void)
|
||||
{
|
||||
git_repository *repo;
|
||||
@@ -366,6 +376,25 @@ void test_fetchhead_nonetwork__fetch_into_repo_with_symrefs(void)
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
void test_fetchhead_nonetwork__fetch_into_repo_with_invalid_head(void)
|
||||
{
|
||||
git_remote *remote;
|
||||
char *strings[] = { "refs/heads/*:refs/remotes/origin/*" };
|
||||
git_strarray refspecs = { strings, 1 };
|
||||
|
||||
cl_set_cleanup(&cleanup_repository, "./test1");
|
||||
cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
|
||||
|
||||
/* HEAD pointing to nonexistent branch */
|
||||
cl_git_rewritefile("./test1/.git/HEAD", "ref: refs/heads/\n");
|
||||
|
||||
cl_git_pass(git_remote_create_anonymous(&remote, g_repo, cl_fixture("testrepo.git")));
|
||||
cl_git_pass(git_remote_fetch(remote, &refspecs, NULL, NULL));
|
||||
cl_git_pass(git_repository_fetchhead_foreach(g_repo, assert_none_for_merge, NULL));
|
||||
|
||||
git_remote_free(remote);
|
||||
}
|
||||
|
||||
void test_fetchhead_nonetwork__quote_in_branch_name(void)
|
||||
{
|
||||
cl_set_cleanup(&cleanup_repository, "./test1");
|
||||
|
||||
Reference in New Issue
Block a user