]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/fetch/local.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / fetch / local.c
CommitLineData
e579e0f7
MB
1#include "clar_libgit2.h"
2#include "futils.h"
3
4static git_repository *repo;
5
6void test_fetch_local__initialize(void)
7{
8 cl_git_pass(git_repository_init(&repo, "./fetch", 0));
9}
10
11void test_fetch_local__cleanup(void)
12{
13 git_repository_free(repo);
14 repo = NULL;
15
16 cl_fixture_cleanup("./fetch");
17}
18
19void test_fetch_local__defaults(void)
20{
21 git_remote *remote;
22 git_object *obj;
23 git_oid expected_id;
24
25 cl_git_pass(git_remote_create(&remote, repo, "test",
26 cl_fixture("testrepo.git")));
27 cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
28
29 git_oid_fromstr(&expected_id, "258f0e2a959a364e40ed6603d5d44fbb24765b10");
30
31 cl_git_pass(git_revparse_single(&obj, repo, "refs/remotes/test/haacked"));
32 cl_assert_equal_oid(&expected_id, git_object_id(obj));
33
34 git_object_free(obj);
35 git_remote_free(remote);
36}
37
38void test_fetch_local__reachable_commit(void)
39{
40 git_remote *remote;
41 git_strarray refspecs;
42 git_object *obj;
43 git_oid expected_id;
44 git_str fetchhead = GIT_STR_INIT;
45 char *refspec = "+5b5b025afb0b4c913b4c338a42934a3863bf3644:refs/success";
46
47 refspecs.strings = &refspec;
48 refspecs.count = 1;
49
50 git_oid_fromstr(&expected_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
51
52 cl_git_pass(git_remote_create(&remote, repo, "test",
53 cl_fixture("testrepo.git")));
54 cl_git_pass(git_remote_fetch(remote, &refspecs, NULL, NULL));
55
56 cl_git_pass(git_revparse_single(&obj, repo, "refs/success"));
57 cl_assert_equal_oid(&expected_id, git_object_id(obj));
58
59 cl_git_pass(git_futils_readbuffer(&fetchhead, "./fetch/.git/FETCH_HEAD"));
60 cl_assert_equal_strn(fetchhead.ptr,
61 "5b5b025afb0b4c913b4c338a42934a3863bf3644\t\t'5b5b025afb0b4c913b4c338a42934a3863bf3644' of ",
62 strlen("5b5b025afb0b4c913b4c338a42934a3863bf3644\t\t'5b5b025afb0b4c913b4c338a42934a3863bf3644' of "));
63
64 git_str_dispose(&fetchhead);
65 git_object_free(obj);
66 git_remote_free(remote);
67}