]>
git.proxmox.com Git - libgit2.git/blob - tests/network/remote/push.c
1 #include "clar_libgit2.h"
2 #include "git2/sys/commit.h"
4 static git_remote
*_remote
;
5 static git_repository
*_repo
, *_dummy
;
7 void test_network_remote_push__initialize(void)
9 cl_fixture_sandbox("testrepo.git");
10 git_repository_open(&_repo
, "testrepo.git");
12 /* We need a repository to have a remote */
13 cl_git_pass(git_repository_init(&_dummy
, "dummy.git", true));
14 cl_git_pass(git_remote_create(&_remote
, _dummy
, "origin", cl_git_path_url("testrepo.git")));
17 void test_network_remote_push__cleanup(void)
19 git_remote_free(_remote
);
22 git_repository_free(_repo
);
25 git_repository_free(_dummy
);
28 cl_fixture_cleanup("testrepo.git");
29 cl_fixture_cleanup("dummy.git");
32 int negotiation_cb(const git_push_update
**updates
, size_t len
, void *payload
)
34 const git_push_update
*expected
= payload
;
36 cl_assert_equal_i(1, len
);
37 cl_assert_equal_s(expected
->src_refname
, updates
[0]->src_refname
);
38 cl_assert_equal_s(expected
->dst_refname
, updates
[0]->dst_refname
);
39 cl_assert_equal_oid(&expected
->src
, &updates
[0]->src
);
40 cl_assert_equal_oid(&expected
->dst
, &updates
[0]->dst
);
45 void test_network_remote_push__delete_notification(void)
47 git_push_options opts
= GIT_PUSH_OPTIONS_INIT
;
49 git_push_update expected
;
50 char *refspec
= ":refs/heads/master";
51 const git_strarray refspecs
= {
56 cl_git_pass(git_reference_lookup(&ref
, _repo
, "refs/heads/master"));
58 expected
.src_refname
= "";
59 expected
.dst_refname
= "refs/heads/master";
60 memset(&expected
.dst
, 0, sizeof(git_oid
));
61 git_oid_cpy(&expected
.src
, git_reference_target(ref
));
63 opts
.callbacks
.push_negotiation
= negotiation_cb
;
64 opts
.callbacks
.payload
= &expected
;
65 cl_git_pass(git_remote_push(_remote
, &refspecs
, &opts
));
67 git_reference_free(ref
);
68 cl_git_fail_with(GIT_ENOTFOUND
, git_reference_lookup(&ref
, _repo
, "refs/heads/master"));
72 void create_dummy_commit(git_reference
**out
, git_repository
*repo
)
75 git_oid tree_id
, commit_id
;
78 cl_git_pass(git_repository_index(&index
, repo
));
79 cl_git_pass(git_index_write_tree(&tree_id
, index
));
80 git_index_free(index
);
82 cl_git_pass(git_signature_now(&sig
, "Pusher Joe", "pjoe"));
83 cl_git_pass(git_commit_create_from_ids(&commit_id
, repo
, NULL
, sig
, sig
,
84 NULL
, "Empty tree\n", &tree_id
, 0, NULL
));
85 cl_git_pass(git_reference_create(out
, repo
, "refs/heads/empty-tree", &commit_id
, true, "commit yo"));
86 git_signature_free(sig
);
89 void test_network_remote_push__create_notification(void)
91 git_push_options opts
= GIT_PUSH_OPTIONS_INIT
;
93 git_push_update expected
;
94 char *refspec
= "refs/heads/empty-tree";
95 const git_strarray refspecs
= {
100 create_dummy_commit(&ref
, _dummy
);
102 expected
.src_refname
= "refs/heads/empty-tree";
103 expected
.dst_refname
= "refs/heads/empty-tree";
104 git_oid_cpy(&expected
.dst
, git_reference_target(ref
));
105 memset(&expected
.src
, 0, sizeof(git_oid
));
107 opts
.callbacks
.push_negotiation
= negotiation_cb
;
108 opts
.callbacks
.payload
= &expected
;
109 cl_git_pass(git_remote_push(_remote
, &refspecs
, &opts
));
111 git_reference_free(ref
);
112 cl_git_pass(git_reference_lookup(&ref
, _repo
, "refs/heads/empty-tree"));
113 git_reference_free(ref
);