summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-01-07 12:22:08 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2021-01-07 14:00:25 +0000
commitc41871e542dce9cfb1b5cf1814e17c65c7e04ce4 (patch)
tree4ac53c11761106a15e0874eb45d2770a103d38fb
parentc31032a3cf449b77c1ca2a966ec3ca31f2f1fb00 (diff)
downloadlibgit2-c41871e542dce9cfb1b5cf1814e17c65c7e04ce4.tar.gz
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.)
-rw-r--r--tests/fetchhead/nonetwork.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 6cea6d166..02e7ecfdb 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -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");