static void assert_email_match( const char *expected, const char *oidstr, git_diff_format_email_options *opts) { git_oid oid; git_commit *commit = NULL; git_diff *diff = NULL; git_buf buf = GIT_BUF_INIT; git_oid_fromstr(&oid, oidstr); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); opts->id = git_commit_id(commit); opts->author = git_commit_author(commit); if (!opts->summary) opts->summary = git_commit_summary(commit); cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_diff_format_email(&buf, diff, opts)); cl_assert_equal_s(expected, git_buf_cstr(&buf)); git_buf_clear(&buf); cl_git_pass(git_diff_commit_as_email( &buf, repo, commit, 1, 1, opts->flags, NULL)); cl_assert_equal_s(expected, git_buf_cstr(&buf)); git_diff_free(diff); git_commit_free(commit); git_buf_free(&buf); }
void test_diff_format_email__invalid_no(void) { git_oid oid; git_commit *commit = NULL; git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; git_buf buf = GIT_BUF_INIT; git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); opts.id = git_commit_id(commit); opts.author = git_commit_author(commit); opts.summary = git_commit_summary(commit); opts.patch_no = 2; opts.total_patches = 1; cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_fail(git_diff_format_email(&buf, diff, &opts)); cl_git_fail(git_diff_commit_as_email(&buf, repo, commit, 2, 1, 0, NULL)); cl_git_fail(git_diff_commit_as_email(&buf, repo, commit, 0, 0, 0, NULL)); git_diff_free(diff); git_commit_free(commit); git_buf_free(&buf); }
static void diff_stats_from_commit_oid( git_diff_stats **stats, const char *oidstr, bool rename) { git_oid oid; git_commit *commit; git_diff *diff; git_oid_fromstr(&oid, oidstr); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); cl_git_pass(git_diff__commit(&diff, _repo, commit, NULL)); if (rename) cl_git_pass(git_diff_find_similar(diff, NULL)); cl_git_pass(git_diff_get_stats(stats, diff)); git_diff_free(diff); git_commit_free(commit); }
void test_diff_format_email__multiple(void) { git_oid oid; git_commit *commit = NULL; git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; git_buf buf = GIT_BUF_INIT; const char *email = "From 10808fe9c9be5a190c0ba68d1a002233fb363508 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <*****@*****.**>\n" \ "Date: Thu, 10 Apr 2014 19:37:05 +0200\n" \ "Subject: [PATCH 1/2] Added file2.txt file3.txt\n" \ "\n" \ "---\n" \ " file2.txt | 5 +++++\n" \ " file3.txt | 5 +++++\n" \ " 2 files changed, 10 insertions(+), 0 deletions(-)\n" \ " create mode 100644 file2.txt\n" \ " create mode 100644 file3.txt\n" \ "\n" \ "diff --git a/file2.txt b/file2.txt\n" \ "new file mode 100644\n" \ "index 0000000..e909123\n" \ "--- /dev/null\n" \ "+++ b/file2.txt\n" \ "@@ -0,0 +1,5 @@\n" \ "+file2\n" \ "+file2\n" \ "+file2\n" \ "+file2\n" \ "+file2\n" \ "diff --git a/file3.txt b/file3.txt\n" \ "new file mode 100644\n" \ "index 0000000..9435022\n" \ "--- /dev/null\n" \ "+++ b/file3.txt\n" \ "@@ -0,0 +1,5 @@\n" \ "+file3\n" \ "+file3\n" \ "+file3\n" \ "+file3\n" \ "+file3\n" \ "--\n" \ "libgit2 " LIBGIT2_VERSION "\n" \ "\n" \ "From 873806f6f27e631eb0b23e4b56bea2bfac14a373 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <*****@*****.**>\n" \ "Date: Thu, 10 Apr 2014 19:37:36 +0200\n" \ "Subject: [PATCH 2/2] Modified file2.txt, file3.txt\n" \ "\n" \ "---\n" \ " file2.txt | 2 +-\n" \ " file3.txt | 2 +-\n" \ " 2 files changed, 2 insertions(+), 2 deletions(-)\n" \ "\n" \ "diff --git a/file2.txt b/file2.txt\n" \ "index e909123..7aff11d 100644\n" \ "--- a/file2.txt\n" \ "+++ b/file2.txt\n" \ "@@ -1,5 +1,5 @@\n" \ " file2\n" \ " file2\n" \ " file2\n" \ "-file2\n" \ "+file2!\n" \ " file2\n" \ "diff --git a/file3.txt b/file3.txt\n" \ "index 9435022..9a2d780 100644\n" \ "--- a/file3.txt\n" \ "+++ b/file3.txt\n" \ "@@ -1,5 +1,5 @@\n" \ " file3\n" \ "-file3\n" \ "+file3!\n" \ " file3\n" \ " file3\n" \ " file3\n" \ "--\n" \ "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; git_oid_fromstr(&oid, "10808fe9c9be5a190c0ba68d1a002233fb363508"); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); opts.id = git_commit_id(commit); opts.author = git_commit_author(commit); opts.summary = git_commit_summary(commit); opts.patch_no = 1; opts.total_patches = 2; cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_diff_format_email(&buf, diff, &opts)); git_diff_free(diff); git_commit_free(commit); diff = NULL; commit = NULL; git_oid_fromstr(&oid, "873806f6f27e631eb0b23e4b56bea2bfac14a373"); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); opts.id = git_commit_id(commit); opts.author = git_commit_author(commit); opts.summary = git_commit_summary(commit); opts.patch_no = 2; opts.total_patches = 2; cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_diff_format_email(&buf, diff, &opts)); cl_assert_equal_s(email, git_buf_cstr(&buf)); git_diff_free(diff); git_commit_free(commit); git_buf_free(&buf); }