2 #include "clar_libgit2.h"
6 #include "diff_generate.h"
8 static git_repository
*repo
;
10 void test_diff_format_email__initialize(void)
12 repo
= cl_git_sandbox_init("diff_format_email");
15 void test_diff_format_email__cleanup(void)
17 cl_git_sandbox_cleanup();
20 #ifndef GIT_DEPRECATE_HARD
21 static void assert_email_match(
24 git_diff_format_email_options
*opts
)
27 git_commit
*commit
= NULL
;
28 git_diff
*diff
= NULL
;
29 git_buf buf
= GIT_BUF_INIT
;
31 git_oid_fromstr(&oid
, oidstr
);
33 cl_git_pass(git_commit_lookup(&commit
, repo
, &oid
));
35 opts
->id
= git_commit_id(commit
);
36 opts
->author
= git_commit_author(commit
);
38 opts
->summary
= git_commit_summary(commit
);
40 cl_git_pass(git_diff__commit(&diff
, repo
, commit
, NULL
));
41 cl_git_pass(git_diff_format_email(&buf
, diff
, opts
));
43 cl_assert_equal_s(expected
, buf
.ptr
);
44 git_buf_dispose(&buf
);
46 cl_git_pass(git_diff_commit_as_email(
47 &buf
, repo
, commit
, 1, 1, opts
->flags
, NULL
));
48 cl_assert_equal_s(expected
, buf
.ptr
);
51 git_commit_free(commit
);
52 git_buf_dispose(&buf
);
56 void test_diff_format_email__simple(void)
58 #ifndef GIT_DEPRECATE_HARD
59 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
61 "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
62 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
63 "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
64 "Subject: [PATCH] Modify some content\n" \
67 " file1.txt | 8 +++++---\n" \
68 " 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
70 "diff --git a/file1.txt b/file1.txt\n" \
71 "index 94aaae8..af8f41d 100644\n" \
74 "@@ -1,15 +1,17 @@\n" \
96 "libgit2 " LIBGIT2_VERSION
"\n" \
100 email
, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts
);
104 void test_diff_format_email__with_message(void)
106 #ifndef GIT_DEPRECATE_HARD
107 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
108 const char *email
= "From 627e7e12d87e07a83fad5b6bfa25e86ead4a5270 Mon Sep 17 00:00:00 2001\n" \
109 "From: Patrick Steinhardt <ps@pks.im>\n" \
110 "Date: Tue, 24 Nov 2015 13:34:39 +0100\n" \
111 "Subject: [PATCH] Modify content with message\n" \
113 "Modify content of file3.txt by appending a new line. Make this\n" \
114 "commit message somewhat longer to test behavior with newlines\n" \
115 "embedded in the message body.\n" \
117 "Also test if new paragraphs are included correctly.\n" \
119 " file3.txt | 1 +\n" \
120 " 1 file changed, 1 insertion(+)\n" \
122 "diff --git a/file3.txt b/file3.txt\n" \
123 "index 9a2d780..7309653 100644\n" \
124 "--- a/file3.txt\n" \
125 "+++ b/file3.txt\n" \
126 "@@ -3,3 +3,4 @@ file3!\n" \
132 "libgit2 " LIBGIT2_VERSION
"\n" \
135 opts
.body
= "Modify content of file3.txt by appending a new line. Make this\n" \
136 "commit message somewhat longer to test behavior with newlines\n" \
137 "embedded in the message body.\n" \
139 "Also test if new paragraphs are included correctly.";
142 email
, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270", &opts
);
147 void test_diff_format_email__multiple(void)
149 #ifndef GIT_DEPRECATE_HARD
151 git_commit
*commit
= NULL
;
152 git_diff
*diff
= NULL
;
153 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
154 git_buf buf
= GIT_BUF_INIT
;
157 "From 10808fe9c9be5a190c0ba68d1a002233fb363508 Mon Sep 17 00:00:00 2001\n" \
158 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
159 "Date: Thu, 10 Apr 2014 19:37:05 +0200\n" \
160 "Subject: [PATCH 1/2] Added file2.txt file3.txt\n" \
163 " file2.txt | 5 +++++\n" \
164 " file3.txt | 5 +++++\n" \
165 " 2 files changed, 10 insertions(+)\n" \
166 " create mode 100644 file2.txt\n" \
167 " create mode 100644 file3.txt\n" \
169 "diff --git a/file2.txt b/file2.txt\n" \
170 "new file mode 100644\n" \
171 "index 0000000..e909123\n" \
173 "+++ b/file2.txt\n" \
174 "@@ -0,0 +1,5 @@\n" \
180 "diff --git a/file3.txt b/file3.txt\n" \
181 "new file mode 100644\n" \
182 "index 0000000..9435022\n" \
184 "+++ b/file3.txt\n" \
185 "@@ -0,0 +1,5 @@\n" \
192 "libgit2 " LIBGIT2_VERSION
"\n" \
194 "From 873806f6f27e631eb0b23e4b56bea2bfac14a373 Mon Sep 17 00:00:00 2001\n" \
195 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
196 "Date: Thu, 10 Apr 2014 19:37:36 +0200\n" \
197 "Subject: [PATCH 2/2] Modified file2.txt, file3.txt\n" \
200 " file2.txt | 2 +-\n" \
201 " file3.txt | 2 +-\n" \
202 " 2 files changed, 2 insertions(+), 2 deletions(-)\n" \
204 "diff --git a/file2.txt b/file2.txt\n" \
205 "index e909123..7aff11d 100644\n" \
206 "--- a/file2.txt\n" \
207 "+++ b/file2.txt\n" \
208 "@@ -1,5 +1,5 @@\n" \
215 "diff --git a/file3.txt b/file3.txt\n" \
216 "index 9435022..9a2d780 100644\n" \
217 "--- a/file3.txt\n" \
218 "+++ b/file3.txt\n" \
219 "@@ -1,5 +1,5 @@\n" \
227 "libgit2 " LIBGIT2_VERSION
"\n" \
231 git_oid_fromstr(&oid
, "10808fe9c9be5a190c0ba68d1a002233fb363508");
232 cl_git_pass(git_commit_lookup(&commit
, repo
, &oid
));
234 opts
.id
= git_commit_id(commit
);
235 opts
.author
= git_commit_author(commit
);
236 opts
.summary
= git_commit_summary(commit
);
238 opts
.total_patches
= 2;
240 cl_git_pass(git_diff__commit(&diff
, repo
, commit
, NULL
));
241 cl_git_pass(git_diff_format_email(&buf
, diff
, &opts
));
244 git_commit_free(commit
);
248 git_oid_fromstr(&oid
, "873806f6f27e631eb0b23e4b56bea2bfac14a373");
249 cl_git_pass(git_commit_lookup(&commit
, repo
, &oid
));
251 opts
.id
= git_commit_id(commit
);
252 opts
.author
= git_commit_author(commit
);
253 opts
.summary
= git_commit_summary(commit
);
255 opts
.total_patches
= 2;
257 cl_git_pass(git_diff__commit(&diff
, repo
, commit
, NULL
));
258 cl_git_pass(git_diff_format_email(&buf
, diff
, &opts
));
260 cl_assert_equal_s(email
, buf
.ptr
);
263 git_commit_free(commit
);
264 git_buf_dispose(&buf
);
268 void test_diff_format_email__exclude_marker(void)
270 #ifndef GIT_DEPRECATE_HARD
271 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
273 "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
274 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
275 "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
276 "Subject: Modify some content\n" \
279 " file1.txt | 8 +++++---\n" \
280 " 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
282 "diff --git a/file1.txt b/file1.txt\n" \
283 "index 94aaae8..af8f41d 100644\n" \
284 "--- a/file1.txt\n" \
285 "+++ b/file1.txt\n" \
286 "@@ -1,15 +1,17 @@\n" \
308 "libgit2 " LIBGIT2_VERSION
"\n" \
311 opts
.flags
|= GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER
;
314 email
, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts
);
318 void test_diff_format_email__invalid_no(void)
320 #ifndef GIT_DEPRECATE_HARD
322 git_commit
*commit
= NULL
;
323 git_diff
*diff
= NULL
;
324 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
325 git_buf buf
= GIT_BUF_INIT
;
327 git_oid_fromstr(&oid
, "9264b96c6d104d0e07ae33d3007b6a48246c6f92");
329 cl_git_pass(git_commit_lookup(&commit
, repo
, &oid
));
331 opts
.id
= git_commit_id(commit
);
332 opts
.author
= git_commit_author(commit
);
333 opts
.summary
= git_commit_summary(commit
);
335 opts
.total_patches
= 1;
337 cl_git_pass(git_diff__commit(&diff
, repo
, commit
, NULL
));
338 cl_git_fail(git_diff_format_email(&buf
, diff
, &opts
));
339 cl_git_fail(git_diff_commit_as_email(&buf
, repo
, commit
, 2, 1, 0, NULL
));
342 git_commit_free(commit
);
343 git_buf_dispose(&buf
);
347 void test_diff_format_email__mode_change(void)
349 #ifndef GIT_DEPRECATE_HARD
350 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
352 "From 7ade76dd34bba4733cf9878079f9fd4a456a9189 Mon Sep 17 00:00:00 2001\n" \
353 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
354 "Date: Thu, 10 Apr 2014 10:05:03 +0200\n" \
355 "Subject: [PATCH] Update permissions\n" \
358 " file1.txt.renamed | 0\n" \
359 " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
360 " mode change 100644 => 100755 file1.txt.renamed\n" \
362 "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \
363 "old mode 100644\n" \
364 "new mode 100755\n" \
366 "libgit2 " LIBGIT2_VERSION
"\n" \
370 email
, "7ade76dd34bba4733cf9878079f9fd4a456a9189", &opts
);
374 void test_diff_format_email__rename_add_remove(void)
376 #ifndef GIT_DEPRECATE_HARD
377 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
379 "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \
380 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
381 "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \
382 "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \
385 " file1.txt | 17 -----------------\n" \
386 " file1.txt.renamed | 17 +++++++++++++++++\n" \
387 " 2 files changed, 17 insertions(+), 17 deletions(-)\n" \
388 " delete mode 100644 file1.txt\n" \
389 " create mode 100644 file1.txt.renamed\n" \
391 "diff --git a/file1.txt b/file1.txt\n" \
392 "deleted file mode 100644\n" \
393 "index af8f41d..0000000\n" \
394 "--- a/file1.txt\n" \
396 "@@ -1,17 +0,0 @@\n" \
414 "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \
415 "new file mode 100644\n" \
416 "index 0000000..a97157a\n" \
418 "+++ b/file1.txt.renamed\n" \
419 "@@ -0,0 +1,17 @@\n" \
425 "+file1.txt_renamed\n" \
431 "+file1.txt_renamed\n" \
438 "libgit2 " LIBGIT2_VERSION
"\n" \
442 email
, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts
);
446 void test_diff_format_email__multiline_summary(void)
448 #ifndef GIT_DEPRECATE_HARD
449 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
451 "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
452 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
453 "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
454 "Subject: [PATCH] Modify some content\n" \
457 " file1.txt | 8 +++++---\n" \
458 " 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
460 "diff --git a/file1.txt b/file1.txt\n" \
461 "index 94aaae8..af8f41d 100644\n" \
462 "--- a/file1.txt\n" \
463 "+++ b/file1.txt\n" \
464 "@@ -1,15 +1,17 @@\n" \
486 "libgit2 " LIBGIT2_VERSION
"\n" \
489 opts
.summary
= "Modify some content\nSome extra stuff here";
492 email
, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts
);
496 void test_diff_format_email__binary(void)
498 #ifndef GIT_DEPRECATE_HARD
499 git_diff_format_email_options opts
= GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
501 "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \
502 "From: Jacques Germishuys <jacquesg@striata.com>\n" \
503 "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \
504 "Subject: [PATCH] Modified binary file\n" \
507 " binary.bin | Bin 3 -> 5 bytes\n" \
508 " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
510 "diff --git a/binary.bin b/binary.bin\n" \
511 "index bd474b2..9ac35ff 100644\n" \
512 "Binary files a/binary.bin and b/binary.bin differ\n" \
514 "libgit2 " LIBGIT2_VERSION
"\n" \
517 opts
.summary
= "Modified binary file";
520 email
, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts
);