Beispiel #1
0
/**
 * ggit_tag_get_target_oid:
 * @tag: a #GgitTag.
 *
 * Gets the target #GgitOId of @tag.
 *
 * Returns: (transfer full): the target #GgitOId of the tag.
 */
GgitOId *
ggit_tag_get_target_oid (GgitTag *tag)
{
	const git_oid *oid;
	git_tag *t;

	g_return_val_if_fail (GGIT_IS_TAG (tag), NULL);

	t = (git_tag *)GGIT_OBJECT (tag)->priv->obj;
	oid = git_tag_target_oid (t);

	return _ggit_oid_new ((git_oid *)oid);
}
Beispiel #2
0
void test_object_tag_write__basic(void)
{
   // write a tag to the repository and read it again
	git_tag *tag;
	git_oid target_id, tag_id;
	git_signature *tagger;
	const git_signature *tagger1;
	git_reference *ref_tag;
	git_object *target;

	git_oid_fromstr(&target_id, tagged_commit);
	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));

	/* create signature */
	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));

	cl_git_pass(
		git_tag_create(&tag_id, g_repo,
		  "the-tag", target, tagger, tagger_message, 0)
	);

	git_object_free(target);
	git_signature_free(tagger);

	cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id));
	cl_assert(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0);

	/* Check attributes were set correctly */
	tagger1 = git_tag_tagger(tag);
	cl_assert(tagger1 != NULL);
	cl_assert_equal_s(tagger1->name, tagger_name);
	cl_assert_equal_s(tagger1->email, tagger_email);
	cl_assert(tagger1->when.time == 123456789);
	cl_assert(tagger1->when.offset == 60);

	cl_assert_equal_s(git_tag_message(tag), tagger_message);

	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag"));
	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
	cl_git_pass(git_reference_delete(ref_tag));

	git_tag_free(tag);
}
Beispiel #3
0
	tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60);
	must_be_true(tagger != NULL);

	must_pass(git_tag_create(
		&tag_id, /* out id */
		repo,
		"the-tag",
		&target_id,
		GIT_OBJ_COMMIT,
		tagger,
		TAGGER_MESSAGE));

	git_signature_free((git_signature *)tagger);

	must_pass(git_tag_lookup(&tag, repo, &tag_id));
	must_be_true(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0);

	/* Check attributes were set correctly */
	tagger = git_tag_tagger(tag);
	must_be_true(tagger != NULL);
	must_be_true(strcmp(tagger->name, TAGGER_NAME) == 0);
	must_be_true(strcmp(tagger->email, TAGGER_EMAIL) == 0);
	must_be_true(tagger->when.time == 123456789);
	must_be_true(tagger->when.offset == 60);

	must_be_true(strcmp(git_tag_message(tag), TAGGER_MESSAGE) == 0);

	must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/the-tag"));
	must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
	must_pass(git_reference_delete(ref_tag));
Beispiel #4
0
static int add_ref(const char *name, git_repository *repo, git_vector *vec)
{
	const char peeled[] = "^{}";
	git_remote_head *head;
	git_reference *ref;
	git_object *obj = NULL;
	int error = GIT_SUCCESS, peel_len, ret;

	head = git__malloc(sizeof(git_remote_head));
	if (head == NULL)
		return GIT_ENOMEM;

	head->name = git__strdup(name);
	if (head->name == NULL) {
		error = GIT_ENOMEM;
		goto out;
	}

	error = git_reference_lookup(&ref, repo, name);
	if (error < GIT_SUCCESS)
		goto out;

	error = git_reference_resolve(&ref, ref);
	if (error < GIT_SUCCESS)
		goto out;

	git_oid_cpy(&head->oid, git_reference_oid(ref));

	error = git_vector_insert(vec, head);
	if (error < GIT_SUCCESS)
		goto out;

	/* If it's not a tag, we don't need to try to peel it */
	if (git__prefixcmp(name, GIT_REFS_TAGS_DIR))
		goto out;

	error = git_object_lookup(&obj, repo, &head->oid, GIT_OBJ_ANY);
	if (error < GIT_SUCCESS) {
		git__rethrow(error, "Failed to lookup object");
	}

	/* If it's not an annotated tag, just get out */
	if (git_object_type(obj) != GIT_OBJ_TAG)
		goto out;

	/* And if it's a tag, peel it, and add it to the list */
	head = git__malloc(sizeof(git_remote_head));
	peel_len = strlen(name) + STRLEN(peeled);
	head->name = git__malloc(peel_len + 1);
	ret = snprintf(head->name, peel_len + 1, "%s%s", name, peeled);
	if (ret >= peel_len + 1) {
		error = git__throw(GIT_ERROR, "The string is magically to long");
	}

	git_oid_cpy(&head->oid, git_tag_target_oid((git_tag *) obj));

	error = git_vector_insert(vec, head);
	if (error < GIT_SUCCESS)
		goto out;

 out:
	git_object_close(obj);
	if (error < GIT_SUCCESS) {
		free(head->name);
		free(head);
	}
	return error;
}