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); }
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); }
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); }
emacs_value egit_tag_id(emacs_env *env, emacs_value _tag) { EGIT_ASSERT_TAG(_tag); git_tag *tag = EGIT_EXTRACT(_tag); const git_oid *oid = git_tag_id(tag); const char *oid_s = git_oid_tostr_s(oid); return EM_STRING(oid_s); }
/** * Init slots in S4 class git_tag * * @param source a tag * @param repo S4 class git_repository that contains the tag * @param dest S4 class git_tag to initialize * @return void */ void git2r_tag_init(git_tag *source, SEXP repo, SEXP dest) { const git_signature *tagger; const git_oid *oid; char sha[GIT_OID_HEXSZ + 1]; char target[GIT_OID_HEXSZ + 1]; oid = git_tag_id(source); git_oid_tostr(sha, sizeof(sha), oid); SET_SLOT(dest, Rf_install("sha"), mkString(sha)); SET_SLOT(dest, Rf_install("message"), mkString(git_tag_message(source))); SET_SLOT(dest, Rf_install("name"), mkString(git_tag_name(source))); tagger = git_tag_tagger(source); if (tagger) git2r_signature_init(tagger, GET_SLOT(dest, Rf_install("tagger"))); oid = git_tag_target_id(source); git_oid_tostr(target, sizeof(target), oid);; SET_SLOT(dest, Rf_install("target"), mkString(target)); SET_SLOT(dest, Rf_install("repo"), repo); }
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); git_oid_mkstr(&id1, tag1_id); git_oid_mkstr(&id2, tag2_id); git_oid_mkstr(&id_commit, tagged_commit); must_pass(git_tag_lookup(&tag1, repo, &id1)); must_be_true(strcmp(git_tag_name(tag1), "test") == 0); must_be_true(git_tag_type(tag1) == GIT_OBJ_TAG); must_pass(git_tag_target((git_object **)&tag2, tag1)); must_be_true(tag2 != NULL); must_be_true(git_oid_cmp(&id2, git_tag_id(tag2)) == 0); must_pass(git_tag_target((git_object **)&commit, tag2)); must_be_true(commit != NULL); must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0); git_tag_close(tag1); git_tag_close(tag2); git_commit_close(commit); git_repository_free(repo); END_TEST BEGIN_TEST(read1, "list all tag names from the repository") git_repository *repo; git_strarray tag_list;
static gboolean git_evtag_builtin_verify (struct EvTag *self, int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; int r; gboolean verified = FALSE; GOptionContext *optcontext; git_oid tag_oid; git_object *obj = NULL; char *long_tagname = NULL; git_tag *tag; const char *tagname; const char *message; git_oid specified_oid; const char *nl; guint64 elapsed_ns; const char *expected_checksum; char commit_oid_hexstr[GIT_OID_HEXSZ+1]; char tag_oid_hexstr[GIT_OID_HEXSZ+1]; char *git_verify_tag_argv[] = {"git", "verify-tag", NULL, NULL }; optcontext = g_option_context_new ("TAGNAME - Verify a signed tag"); if (!option_context_parse (optcontext, verify_options, &argc, &argv, cancellable, error)) goto out; if (argc < 2) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "A TAGNAME argument is required"); goto out; } else if (argc > 2) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Too many arguments"); goto out; } tagname = argv[1]; long_tagname = g_strconcat ("refs/tags/", tagname, NULL); r = git_reference_name_to_id (&tag_oid, self->top_repo, long_tagname); if (!handle_libgit_ret (r, error)) goto out; r = git_tag_lookup (&tag, self->top_repo, &tag_oid); if (!handle_libgit_ret (r, error)) goto out; r = git_tag_target (&obj, tag); if (!handle_libgit_ret (r, error)) goto out; specified_oid = *git_object_id (obj); git_oid_fmt (commit_oid_hexstr, &specified_oid); commit_oid_hexstr[sizeof(commit_oid_hexstr)-1] = '\0'; if (!validate_at_head (self, &specified_oid, error)) goto out; message = git_tag_message (tag); if (!git_oid_tostr (tag_oid_hexstr, sizeof (tag_oid_hexstr), git_tag_id (tag))) g_assert_not_reached (); if (!opt_no_signature) { git_verify_tag_argv[2] = tag_oid_hexstr; if (!spawn_sync_require_success (git_verify_tag_argv, G_SPAWN_SEARCH_PATH, error)) goto out; } if (!checksum_commit_recurse (self, &specified_oid, &elapsed_ns, cancellable, error)) goto out; expected_checksum = g_checksum_get_string (self->checksum); while (TRUE) { nl = strchr (message, '\n'); if (g_str_has_prefix (message, EVTAG_SHA512)) { char *line; if (nl) line = g_strndup (message, nl - message); else line = g_strdup (message); g_strchomp (line); if (!verify_line (expected_checksum, line, commit_oid_hexstr, error)) goto out; { char *stats = get_stats (self); g_print ("%s\n", stats); g_free (stats); } g_print ("Successfully verified: %s\n", line); verified = TRUE; break; } if (!nl) break; message = nl + 1; } if (!verified) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to find %s in tag message", EVTAG_SHA512); goto out; } ret = TRUE; out: return ret; }