@@ -27,7 +27,7 @@ SYNOPSIS
[--[no-]encode-email-headers]
[--no-notes | --notes[=<ref>]]
[--interdiff=<previous>]
- [--range-diff=<previous> [--creation-factor=<percent>]]
+ [--range-diff=<previous> [--creation-factor=<percent>] [--left-only]]
[--filename-max-length=<n>]
[--progress]
[<common diff options>]
@@ -301,6 +301,23 @@ material (this may change in the future).
creation/deletion cost fudge factor. See linkgit:git-range-diff[1])
for details.
+--left-only:
+ Used with `--range-diff`, only emit output related to the first range.
+ This option only can be used in this situation: The first iteration `t1`
+ based on the upstream commit `b1`, the second iteration `t2` based on the
+ upstream commit `b2`, `b2` inherited from the `b1`, then If the user want
+ output the range-diff between this two iterations (t1 and t2) in cover-letter,
+ and just use `b1` as the same base for `--range-diff`, but they don't want the
+ upstream range `b1..b2` included on the right side of the range-diff output.
+ By using `git format-patch --range-diff=b1..t1 b1..t2 --cover-letter --left-only`,
+ all content on the right side will be removed, leaving only the range
+ `b1..t1` on the left side.
++
+Note that this `--left-only` is just a lazy way to let user use same base
+and avoid outputting upstream commits in cover-letter, and the side effect
+is that `b2..t2` on the right side will not be outputted.
+
+
--notes[=<ref>]::
--no-notes::
Append the notes (see linkgit:git-notes[1]) for the commit
@@ -1153,7 +1153,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
struct commit *origin,
int nr, struct commit **list,
const char *branch_name,
- int quiet)
+ int quiet, int left_only)
{
const char *committer;
struct shortlog log;
@@ -1228,7 +1228,8 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
.creation_factor = rev->creation_factor,
.dual_color = 1,
.diffopt = &opts,
- .other_arg = &other_arg
+ .other_arg = &other_arg,
+ .left_only = left_only
};
diff_setup(&opts);
@@ -1732,6 +1733,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
struct strbuf rdiff2 = STRBUF_INIT;
struct strbuf rdiff_title = STRBUF_INIT;
int creation_factor = -1;
+ int left_only = 0;
const struct option builtin_format_patch_options[] = {
OPT_CALLBACK_F('n', "numbered", &numbered, NULL,
@@ -1814,6 +1816,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
parse_opt_object_name),
OPT_STRING(0, "range-diff", &rdiff_prev, N_("refspec"),
N_("show changes against <refspec> in cover letter or single patch")),
+ OPT_BOOL(0, "left-only", &left_only,
+ N_("only emit output related to the first range")),
OPT_INTEGER(0, "creation-factor", &creation_factor,
N_("percentage by which creation is weighted")),
OPT_END()
@@ -2083,10 +2087,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
_("Interdiff against v%d:"));
}
+ if (!rdiff_prev) {
+ if (creation_factor >= 0)
+ die(_("--creation-factor requires --range-diff"));
+ if (left_only)
+ die(_("--left-only requires --range-diff"));
+ }
+
if (creation_factor < 0)
creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
- else if (!rdiff_prev)
- die(_("--creation-factor requires --range-diff"));
if (rdiff_prev) {
if (!cover_letter && total != 1)
@@ -2134,7 +2143,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (thread)
gen_message_id(&rev, "cover");
make_cover_letter(&rev, !!output_directory,
- origin, nr, list, branch_name, quiet);
+ origin, nr, list, branch_name, quiet,
+ left_only);
print_bases(&bases, rev.diffopt.file);
print_signature(rev.diffopt.file);
total++;
@@ -748,4 +748,31 @@ test_expect_success '--left-only/--right-only' '
test_cmp expect actual
'
+test_expect_success 'format-patch --range-diff --left-only' '
+ rm -fr repo &&
+ git init repo &&
+ cd repo &&
+ git branch -M main &&
+ echo "base" >base &&
+ git add base &&
+ git commit -m "base" &&
+ git checkout -b my-feature &&
+ echo "feature" >feature &&
+ git add feature &&
+ git commit -m "feature" &&
+ base="$(git rev-parse main)" &&
+ old="$(git rev-parse my-feature)" &&
+ git checkout main &&
+ echo "other" >>base &&
+ git add base &&
+ git commit -m "new" &&
+ git checkout my-feature &&
+ git rebase $base --onto main &&
+ tip="$(git rev-parse my-feature)" &&
+ git format-patch --range-diff $base..$old $base..$tip --cover-letter &&
+ grep "> 1: .* new$" 0000-cover-letter.patch &&
+ git format-patch --range-diff $base..$old $base..$tip --left-only --cover-letter &&
+ ! grep "> 1: .* feature$" 0000-cover-letter.patch
+'
+
test_done