format-patch: Don't go over merge commits
If the topmost three commits in a branch were merge commits, 'git format-patch -3' used to output nothing. Since Git can't prepare patches out of merge commits anyway, don't go over them in the first place. 'git format-patch -3' now prepares three patches from the topmost three commits without counting merge commits. Also add a corresponding test in t4014-format-patch and update documentation. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ramkumar Ramachandra committed
Aug 28, 2010 at 01:58 UTC
2c642ed8668745271a714f0a672dbfcd6b0a6fa8
3 files changed
+18
-7
Documentation/git-format-patch.txt
+1
-1
@@ -73,7 +73,7 @@ OPTIONS
73
include::diff-options.txt[]
74
75
-<n>::
76
- Limits the number of patches to prepare.
76
+ Prepare patches from the topmost <n> commits.
77
78
-o <dir>::
79
--output-directory <dir>::
builtin/log.c
+1
-6
@@ -1012,8 +1012,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1012
rev.commit_format = CMIT_FMT_EMAIL;
1013
rev.verbose_header = 1;
1014
rev.diff = 1;
1015
- rev.combine_merges = 0;
1016
- rev.ignore_merges = 1;
1015
+ rev.no_merges = 1;
1016
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
1017
rev.subject_prefix = fmt_patch_subject_prefix;
1018
memset(&s_r_opt, 0, sizeof(s_r_opt));
@@ -1184,10 +1183,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1183
continue;
1184
}
1185
1187
- /* ignore merges */
1188
- if (commit->parents && commit->parents->next)
1189
- continue;
1190
-
1186
if (ignore_if_in_upstream &&
1187
has_commit_patch_id(commit, &ids))
1188
continue;
t/t4014-format-patch.sh
+16
@@ -56,6 +56,22 @@ test_expect_success "format-patch --ignore-if-in-upstream" '
56
57
'
58
59
+test_expect_success "format-patch doesn't consider merge commits" '
60
+
61
+ git checkout -b slave master &&
62
+ echo "Another line" >>file &&
63
+ test_tick &&
64
+ git commit -am "Slave change #1" &&
65
+ echo "Yet another line" >>file &&
66
+ test_tick &&
67
+ git commit -am "Slave change #2" &&
68
+ git checkout -b merger master &&
69
+ test_tick &&
70
+ git merge --no-ff slave &&
71
+ cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` &&
72
+ test $cnt = 3
73
+'
74
+
75
test_expect_success "format-patch result applies" '
76
77
git checkout -b rebuild-0 master &&