|
| 1 | +#include "clar_libgit2.h" |
| 2 | +#include "git2/sys/commit.h" |
| 3 | + |
| 4 | +static git_remote *_remote; |
| 5 | +static git_repository *_repo, *_dummy; |
| 6 | + |
| 7 | +void test_network_remote_tag__initialize(void) |
| 8 | +{ |
| 9 | + cl_fixture_sandbox("testrepo.git"); |
| 10 | + git_repository_open(&_repo, "testrepo.git"); |
| 11 | + |
| 12 | + /* We need a repository to have a remote */ |
| 13 | + cl_git_pass(git_repository_init(&_dummy, "dummytag.git", true)); |
| 14 | + cl_git_pass(git_remote_create(&_remote, _dummy, "origin", cl_git_path_url("testrepo.git"))); |
| 15 | +} |
| 16 | + |
| 17 | +void test_network_remote_tag__cleanup(void) |
| 18 | +{ |
| 19 | + git_remote_free(_remote); |
| 20 | + _remote = NULL; |
| 21 | + |
| 22 | + git_repository_free(_repo); |
| 23 | + _repo = NULL; |
| 24 | + |
| 25 | + git_repository_free(_dummy); |
| 26 | + _dummy = NULL; |
| 27 | + |
| 28 | + cl_fixture_cleanup("testrepo.git"); |
| 29 | + cl_fixture_cleanup("dummytag.git"); |
| 30 | +} |
| 31 | + |
| 32 | +/* |
| 33 | + * Create one commit, one tree, one blob. |
| 34 | + * Create two tags: one for the commit, one for the blob. |
| 35 | + */ |
| 36 | +static void create_commit_with_tags(git_reference **out, git_oid *out_commit_tag_id, git_oid *out_blob_tag_id, git_repository *repo) |
| 37 | +{ |
| 38 | + git_treebuilder *treebuilder; |
| 39 | + git_oid blob_id, tree_id, commit_id; |
| 40 | + git_signature *sig; |
| 41 | + git_object *target; |
| 42 | + |
| 43 | + cl_git_pass(git_treebuilder_new(&treebuilder, repo, NULL)); |
| 44 | + |
| 45 | + cl_git_pass(git_blob_create_from_buffer(&blob_id, repo, "", 0)); |
| 46 | + cl_git_pass(git_treebuilder_insert(NULL, treebuilder, "README.md", &blob_id, 0100644)); |
| 47 | + cl_git_pass(git_treebuilder_write(&tree_id, treebuilder)); |
| 48 | + |
| 49 | + cl_git_pass(git_signature_now(&sig, "Pusher Joe", "pjoe")); |
| 50 | + cl_git_pass(git_commit_create_from_ids(&commit_id, repo, NULL, sig, sig, |
| 51 | + NULL, "Tree with tags\n", &tree_id, 0, NULL)); |
| 52 | + cl_git_pass(git_reference_create(out, repo, "refs/heads/tree-with-tags", &commit_id, true, "commit yo")); |
| 53 | + |
| 54 | + cl_git_pass(git_object_lookup(&target, repo, &commit_id, GIT_OBJECT_COMMIT)); |
| 55 | + cl_git_pass(git_tag_create_lightweight(out_commit_tag_id, repo, "tagged-commit", target, true)); |
| 56 | + git_object_free(target); |
| 57 | + |
| 58 | + cl_git_pass(git_object_lookup(&target, repo, &blob_id, GIT_OBJECT_BLOB)); |
| 59 | + cl_git_pass(git_tag_create_lightweight(out_blob_tag_id, repo, "tagged-blob", target, true)); |
| 60 | + git_object_free(target); |
| 61 | + |
| 62 | + git_treebuilder_free(treebuilder); |
| 63 | + git_signature_free(sig); |
| 64 | +} |
| 65 | + |
| 66 | +void test_network_remote_tag__push_different_tag_types(void) |
| 67 | +{ |
| 68 | + git_push_options opts = GIT_PUSH_OPTIONS_INIT; |
| 69 | + git_reference *ref; |
| 70 | + git_oid commit_tag_id, blob_tag_id; |
| 71 | + char* refspec_tree = "refs/heads/tree-with-tags"; |
| 72 | + char* refspec_tagged_commit = "refs/tags/tagged-commit"; |
| 73 | + char* refspec_tagged_blob = "refs/tags/tagged-blob"; |
| 74 | + const git_strarray refspecs_tree = { &refspec_tree, 1 }; |
| 75 | + const git_strarray refspecs_tagged_commit = { &refspec_tagged_commit, 1 }; |
| 76 | + const git_strarray refspecs_tagged_blob = { &refspec_tagged_blob, 1 }; |
| 77 | + |
| 78 | + create_commit_with_tags(&ref, &commit_tag_id, &blob_tag_id, _dummy); |
| 79 | + |
| 80 | + /* Push tree */ |
| 81 | + cl_git_pass(git_remote_push(_remote, &refspecs_tree, &opts)); |
| 82 | + git_reference_free(ref); |
| 83 | + cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/tree-with-tags")); |
| 84 | + git_reference_free(ref); |
| 85 | + |
| 86 | + /* Push tagged commit */ |
| 87 | + cl_git_pass(git_remote_push(_remote, &refspecs_tagged_commit, &opts)); |
| 88 | + cl_git_pass(git_reference_name_to_id(&commit_tag_id, _repo, "refs/tags/tagged-commit")); |
| 89 | + |
| 90 | + /* Push tagged blob */ |
| 91 | + cl_git_pass(git_remote_push(_remote, &refspecs_tagged_blob, &opts)); |
| 92 | + cl_git_pass(git_reference_name_to_id(&blob_tag_id, _repo, "refs/tags/tagged-blob")); |
| 93 | +} |
0 commit comments