Ejemplo n.º 1
0
void test_object_tag_read__parse(void)
{
   // read and parse a tag from the repository
   git_tag *tag1, *tag2;
   git_commit *commit;
   git_oid id1, id2, id_commit;

   git_oid_fromstr(&id1, tag1_id);
   git_oid_fromstr(&id2, tag2_id);
   git_oid_fromstr(&id_commit, tagged_commit);

   cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));

   cl_assert_equal_s(git_tag_name(tag1), "test");
   cl_assert(git_tag_type(tag1) == GIT_OBJ_TAG);

   cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
   cl_assert(tag2 != NULL);

   cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);

   cl_git_pass(git_tag_target((git_object **)&commit, tag2));
   cl_assert(commit != NULL);

   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);

   git_tag_free(tag1);
   git_tag_free(tag2);
   git_commit_free(commit);
}
Ejemplo n.º 2
0
void test_object_tag_read__parse_without_message(void)
{
   // read and parse a tag without a message field
   git_repository *short_tag_repo;
   git_tag *short_tag;
   git_commit *commit;
   git_oid id, id_commit;

   // TODO: This is a little messy
   cl_git_pass(git_repository_open(&short_tag_repo, cl_fixture("short_tag.git")));

   git_oid_fromstr(&id, short_tag_id);
   git_oid_fromstr(&id_commit, short_tagged_commit);

   cl_git_pass(git_tag_lookup(&short_tag, short_tag_repo, &id));
   cl_assert(short_tag != NULL);

   cl_assert_equal_s(git_tag_name(short_tag), "no_description");
   cl_assert(git_oid_cmp(&id, git_tag_id(short_tag)) == 0);
   cl_assert(short_tag->message == NULL);

   cl_git_pass(git_tag_target((git_object **)&commit, short_tag));
   cl_assert(commit != NULL);

   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);

   git_tag_free(short_tag);
   git_commit_free(commit);
   git_repository_free(short_tag_repo);
}
Ejemplo n.º 3
0
void test_object_tag_read__parse_without_tagger(void)
{
   // read and parse a tag without a tagger field
   git_repository *bad_tag_repo;
   git_tag *bad_tag;
   git_commit *commit;
   git_oid id, id_commit;

   // TODO: This is a little messy
   cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));

   git_oid_fromstr(&id, bad_tag_id);
   git_oid_fromstr(&id_commit, badly_tagged_commit);

   cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
   cl_assert(bad_tag != NULL);

   cl_assert_equal_s(git_tag_name(bad_tag), "e90810b");
   cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
   cl_assert(bad_tag->tagger == NULL);

   cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
   cl_assert(commit != NULL);

   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);

   git_tag_free(bad_tag);
   git_commit_free(commit);
   git_repository_free(bad_tag_repo);
}
Ejemplo n.º 4
0
Archivo: git.c Proyecto: ileitch/meanie
static int mne_git_get_tag_tree(git_tree **tag_tree, git_reference **tag_ref, const char *ref_name) {
  int err = git_reference_lookup(tag_ref, repo, ref_name);
  mne_check_error("git_reference_lookup()", err, __FILE__, __LINE__);

  const git_oid *tag_oid = git_reference_oid(*tag_ref);
  assert(tag_oid != NULL);

  git_tag *tag;
  err = git_tag_lookup(&tag, repo, tag_oid);
  const git_oid *tag_commit_oid;

  if (err == GIT_ENOTFOUND) {
    /* Not a tag, must be a commit. */
    tag_commit_oid = tag_oid;
  } else {
    err = mne_git_get_tag_commit_oid(&tag_commit_oid, tag);
    git_tag_free(tag);
    if (err != GIT_OK)
      return err;
  }

  git_commit *tag_commit;
  err = git_commit_lookup(&tag_commit, repo, tag_commit_oid);
  mne_check_error("git_commit_lookup()", err, __FILE__, __LINE__);

  err = git_commit_tree(tag_tree, tag_commit);
  mne_check_error("git_commit_tree()", err, __FILE__, __LINE__);

  git_commit_free(tag_commit);

  return MNE_GIT_OK;
}
Ejemplo n.º 5
0
void MainWindow::on_pushButtonLoadRev_clicked()
{
    if (ui->listRevisions->currentRow() >= 0)
    {
        QString tag_name_str = "refs/tags/"+ui->listRevisions->currentItem()->text();
        const char* tag_name = tag_name_str.toStdString().c_str();
        git_reference *ref;
        if (git_reference_lookup(&ref, repo, tag_name) >= 0)
        {
            git_tag *tag;
            git_reference_peel((git_object**)&tag, ref, GIT_OBJ_TAG);

            qDebug() << "selected tag message = " << git_tag_message(tag);
            git_tag_free(tag);
            git_reference_free(ref);
        }
    }
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
0
/**
 * Create tag targeting HEAD commit in repository.
 *
 * @param repo S4 class git_repository
 * @param name Name for the tag.
 * @param message The tag message.
 * @param tagger The tagger (author) of the tag
 * @return S4 object of class git_tag
 */
SEXP git2r_tag_create(SEXP repo, SEXP name, SEXP message, SEXP tagger)
{
    SEXP result = R_NilValue;
    int err;
    git_oid oid;
    git_repository *repository = NULL;
    git_signature *sig_tagger = NULL;
    git_tag *tag = NULL;
    git_object *target = NULL;

    if (git2r_arg_check_string(name))
        git2r_error(__func__, NULL, "'name'", git2r_err_string_arg);
    if (git2r_arg_check_string(message))
        git2r_error(__func__, NULL, "'message'", git2r_err_string_arg);
    if (git2r_arg_check_signature(tagger))
        git2r_error(__func__, NULL, "'tagger'", git2r_err_signature_arg);

    repository = git2r_repository_open(repo);
    if (!repository)
        git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL);

    err = git2r_signature_from_arg(&sig_tagger, tagger);
    if (err)
        goto cleanup;

    err = git_revparse_single(&target, repository, "HEAD^{commit}");
    if (err)
        goto cleanup;

    err = git_tag_create(
        &oid,
        repository,
        CHAR(STRING_ELT(name, 0)),
        target,
        sig_tagger,
        CHAR(STRING_ELT(message, 0)),
        0);
    if (err)
        goto cleanup;

    err = git_tag_lookup(&tag, repository, &oid);
    if (err)
        goto cleanup;

    PROTECT(result = NEW_OBJECT(MAKE_CLASS("git_tag")));
    git2r_tag_init(tag, repo, result);

cleanup:
    if (tag)
        git_tag_free(tag);

    if (sig_tagger)
        git_signature_free(sig_tagger);

    if (target)
        git_object_free(target);

    if (repository)
        git_repository_free(repository);

    if (R_NilValue != result)
        UNPROTECT(1);

    if (err)
        git2r_error(__func__, giterr_last(), NULL, NULL);

    return result;
}