Merge branch 'dl/range-diff-with-notes'

"git range-diff" learned to take the "--notes=<ref>" and the
"--no-notes" options to control the commit notes included in the
log message that gets compared.

* dl/range-diff-with-notes:
  format-patch: pass notes configuration to range-diff
  range-diff: pass through --notes to `git log`
  range-diff: output `## Notes ##` header
  t3206: range-diff compares logs with commit notes
  t3206: s/expected/expect/
  t3206: disable parameter substitution in heredoc
  t3206: remove spaces after redirect operators
  pretty-options.txt: --notes accepts a ref instead of treeish
  rev-list-options.txt: remove reference to --show-notes
  argv-array: add space after `while`
This commit is contained in:
Junio C Hamano 2019-12-05 12:52:44 -08:00
Родитель 9502b616f1 5b583e6a09
Коммит f3c7bfdde2
10 изменённых файлов: 291 добавлений и 50 удалений

Просмотреть файл

@ -57,6 +57,10 @@ to revert to color all lines according to the outer diff markers
See the ``Algorithm`` section below for an explanation why this is See the ``Algorithm`` section below for an explanation why this is
needed. needed.
--[no-]notes[=<ref>]::
This flag is passed to the `git log` program
(see linkgit:git-log[1]) that generates the patches.
<range1> <range2>:: <range1> <range2>::
Compare the commits specified by the two ranges, where Compare the commits specified by the two ranges, where
`<range1>` is considered an older version of `<range2>`. `<range1>` is considered an older version of `<range2>`.
@ -75,7 +79,7 @@ to revert to color all lines according to the outer diff markers
linkgit:git-diff[1]), most notably the `--color=[<when>]` and linkgit:git-diff[1]), most notably the `--color=[<when>]` and
`--no-color` options. These options are used when generating the "diff `--no-color` options. These options are used when generating the "diff
between patches", i.e. to compare the author, commit message and diff of between patches", i.e. to compare the author, commit message and diff of
corresponding old/new commits. There is currently no means to tweak the corresponding old/new commits. There is currently no means to tweak most of the
diff options passed to `git log` when generating those patches. diff options passed to `git log` when generating those patches.
OUTPUT STABILITY OUTPUT STABILITY

Просмотреть файл

@ -57,7 +57,7 @@ message by 4 spaces (i.e. 'medium', which is the default, 'full',
and 'fuller'). and 'fuller').
ifndef::git-rev-list[] ifndef::git-rev-list[]
--notes[=<treeish>]:: --notes[=<ref>]::
Show the notes (see linkgit:git-notes[1]) that annotate the Show the notes (see linkgit:git-notes[1]) that annotate the
commit, when showing the commit log message. This is the default commit, when showing the commit log message. This is the default
for `git log`, `git show` and `git whatchanged` commands when for `git log`, `git show` and `git whatchanged` commands when
@ -68,8 +68,8 @@ By default, the notes shown are from the notes refs listed in the
`core.notesRef` and `notes.displayRef` variables (or corresponding `core.notesRef` and `notes.displayRef` variables (or corresponding
environment overrides). See linkgit:git-config[1] for more details. environment overrides). See linkgit:git-config[1] for more details.
+ +
With an optional '<treeish>' argument, use the treeish to find the notes With an optional '<ref>' argument, use the ref to find the notes
to display. The treeish can specify the full refname when it begins to display. The ref can specify the full refname when it begins
with `refs/notes/`; when it begins with `notes/`, `refs/` and otherwise with `refs/notes/`; when it begins with `notes/`, `refs/` and otherwise
`refs/notes/` is prefixed to form a full name of the ref. `refs/notes/` is prefixed to form a full name of the ref.
+ +
@ -85,7 +85,7 @@ being displayed. Examples: "--notes=foo" will show only notes from
"--notes --notes=foo --no-notes --notes=bar" will only show notes "--notes --notes=foo --no-notes --notes=bar" will only show notes
from "refs/notes/bar". from "refs/notes/bar".
--show-notes[=<treeish>]:: --show-notes[=<ref>]::
--[no-]standard-notes:: --[no-]standard-notes::
These options are deprecated. Use the above --notes/--no-notes These options are deprecated. Use the above --notes/--no-notes
options instead. options instead.

Просмотреть файл

@ -58,7 +58,7 @@ endif::git-rev-list[]
`--all-match`). `--all-match`).
ifndef::git-rev-list[] ifndef::git-rev-list[]
+ +
When `--show-notes` is in effect, the message from the notes is When `--notes` is in effect, the message from the notes is
matched as if it were part of the log message. matched as if it were part of the log message.
endif::git-rev-list[] endif::git-rev-list[]

Просмотреть файл

@ -46,7 +46,7 @@ void argv_array_pushl(struct argv_array *array, ...)
const char *arg; const char *arg;
va_start(ap, array); va_start(ap, array);
while((arg = va_arg(ap, const char *))) while ((arg = va_arg(ap, const char *)))
argv_array_push(array, arg); argv_array_push(array, arg);
va_end(ap); va_end(ap);
} }

Просмотреть файл

@ -1111,6 +1111,25 @@ do_pp:
strbuf_release(&subject_sb); strbuf_release(&subject_sb);
} }
static int get_notes_refs(struct string_list_item *item, void *arg)
{
argv_array_pushf(arg, "--notes=%s", item->string);
return 0;
}
static void get_notes_args(struct argv_array *arg, struct rev_info *rev)
{
if (!rev->show_notes) {
argv_array_push(arg, "--no-notes");
} else if (rev->notes_opt.use_default_notes > 0 ||
(rev->notes_opt.use_default_notes == -1 &&
!rev->notes_opt.extra_notes_refs.nr)) {
argv_array_push(arg, "--notes");
} else {
for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
}
}
static void make_cover_letter(struct rev_info *rev, int use_stdout, static void make_cover_letter(struct rev_info *rev, int use_stdout,
struct commit *origin, struct commit *origin,
int nr, struct commit **list, int nr, struct commit **list,
@ -1183,13 +1202,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
* can be added later if deemed desirable. * can be added later if deemed desirable.
*/ */
struct diff_options opts; struct diff_options opts;
struct argv_array other_arg = ARGV_ARRAY_INIT;
diff_setup(&opts); diff_setup(&opts);
opts.file = rev->diffopt.file; opts.file = rev->diffopt.file;
opts.use_color = rev->diffopt.use_color; opts.use_color = rev->diffopt.use_color;
diff_setup_done(&opts); diff_setup_done(&opts);
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title); fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
get_notes_args(&other_arg, rev);
show_range_diff(rev->rdiff1, rev->rdiff2, show_range_diff(rev->rdiff1, rev->rdiff2,
rev->creation_factor, 1, &opts); rev->creation_factor, 1, &opts, &other_arg);
argv_array_clear(&other_arg);
} }
} }

Просмотреть файл

@ -15,12 +15,16 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
{ {
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
struct diff_options diffopt = { NULL }; struct diff_options diffopt = { NULL };
struct argv_array other_arg = ARGV_ARRAY_INIT;
int simple_color = -1; int simple_color = -1;
struct option range_diff_options[] = { struct option range_diff_options[] = {
OPT_INTEGER(0, "creation-factor", &creation_factor, OPT_INTEGER(0, "creation-factor", &creation_factor,
N_("Percentage by which creation is weighted")), N_("Percentage by which creation is weighted")),
OPT_BOOL(0, "no-dual-color", &simple_color, OPT_BOOL(0, "no-dual-color", &simple_color,
N_("use simple diff colors")), N_("use simple diff colors")),
OPT_PASSTHRU_ARGV(0, "notes", &other_arg,
N_("notes"), N_("passed to 'git log'"),
PARSE_OPT_OPTARG),
OPT_END() OPT_END()
}; };
struct option *options; struct option *options;
@ -78,7 +82,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
FREE_AND_NULL(options); FREE_AND_NULL(options);
res = show_range_diff(range1.buf, range2.buf, creation_factor, res = show_range_diff(range1.buf, range2.buf, creation_factor,
simple_color < 1, &diffopt); simple_color < 1, &diffopt, &other_arg);
strbuf_release(&range1); strbuf_release(&range1);
strbuf_release(&range2); strbuf_release(&range2);

Просмотреть файл

@ -770,7 +770,7 @@ void show_log(struct rev_info *opt)
opts.use_color = opt->diffopt.use_color; opts.use_color = opt->diffopt.use_color;
diff_setup_done(&opts); diff_setup_done(&opts);
show_range_diff(opt->rdiff1, opt->rdiff2, show_range_diff(opt->rdiff1, opt->rdiff2,
opt->creation_factor, 1, &opts); opt->creation_factor, 1, &opts, NULL);
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff)); memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
} }

Просмотреть файл

@ -40,7 +40,8 @@ static size_t find_end_of_line(char *buffer, unsigned long size)
* Reads the patches into a string list, with the `util` field being populated * Reads the patches into a string list, with the `util` field being populated
* as struct object_id (will need to be free()d). * as struct object_id (will need to be free()d).
*/ */
static int read_patches(const char *range, struct string_list *list) static int read_patches(const char *range, struct string_list *list,
struct argv_array *other_arg)
{ {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
@ -61,8 +62,11 @@ static int read_patches(const char *range, struct string_list *list)
"--output-indicator-new=>", "--output-indicator-new=>",
"--output-indicator-old=<", "--output-indicator-old=<",
"--output-indicator-context=#", "--output-indicator-context=#",
"--no-abbrev-commit", range, "--no-abbrev-commit",
NULL); NULL);
if (other_arg)
argv_array_pushv(&cp.args, other_arg->argv);
argv_array_push(&cp.args, range);
cp.out = -1; cp.out = -1;
cp.no_stdin = 1; cp.no_stdin = 1;
cp.git_cmd = 1; cp.git_cmd = 1;
@ -144,6 +148,12 @@ static int read_patches(const char *range, struct string_list *list)
strbuf_addstr(&buf, line); strbuf_addstr(&buf, line);
strbuf_addstr(&buf, "\n\n"); strbuf_addstr(&buf, "\n\n");
strbuf_addstr(&buf, " ## Commit message ##\n"); strbuf_addstr(&buf, " ## Commit message ##\n");
} else if (starts_with(line, "Notes") &&
line[strlen(line) - 1] == ':') {
strbuf_addstr(&buf, "\n\n");
/* strip the trailing colon */
strbuf_addf(&buf, " ## %.*s ##\n",
(int)(strlen(line) - 1), line);
} else if (starts_with(line, " ")) { } else if (starts_with(line, " ")) {
p = line + len - 2; p = line + len - 2;
while (isspace(*p) && p >= line) while (isspace(*p) && p >= line)
@ -496,16 +506,17 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
int show_range_diff(const char *range1, const char *range2, int show_range_diff(const char *range1, const char *range2,
int creation_factor, int dual_color, int creation_factor, int dual_color,
struct diff_options *diffopt) struct diff_options *diffopt,
struct argv_array *other_arg)
{ {
int res = 0; int res = 0;
struct string_list branch1 = STRING_LIST_INIT_DUP; struct string_list branch1 = STRING_LIST_INIT_DUP;
struct string_list branch2 = STRING_LIST_INIT_DUP; struct string_list branch2 = STRING_LIST_INIT_DUP;
if (read_patches(range1, &branch1)) if (read_patches(range1, &branch1, other_arg))
res = error(_("could not parse log for '%s'"), range1); res = error(_("could not parse log for '%s'"), range1);
if (!res && read_patches(range2, &branch2)) if (!res && read_patches(range2, &branch2, other_arg))
res = error(_("could not parse log for '%s'"), range2); res = error(_("could not parse log for '%s'"), range2);
if (!res) { if (!res) {

Просмотреть файл

@ -2,6 +2,7 @@
#define RANGE_DIFF_H #define RANGE_DIFF_H
#include "diff.h" #include "diff.h"
#include "argv-array.h"
#define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60 #define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60
@ -12,6 +13,7 @@
*/ */
int show_range_diff(const char *range1, const char *range2, int show_range_diff(const char *range1, const char *range2,
int creation_factor, int dual_color, int creation_factor, int dual_color,
struct diff_options *diffopt); struct diff_options *diffopt,
struct argv_array *other_arg);
#endif #endif

Просмотреть файл

@ -8,8 +8,8 @@ test_description='range-diff tests'
# harm than good. We need some real history. # harm than good. We need some real history.
test_expect_success 'setup' ' test_expect_success 'setup' '
git fast-import < "$TEST_DIRECTORY"/t3206/history.export && git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
test_oid_cache <<-EOF test_oid_cache <<-\EOF
# topic # topic
t1 sha1:4de457d t1 sha1:4de457d
t2 sha1:fccce22 t2 sha1:fccce22
@ -121,88 +121,88 @@ test_expect_success 'setup' '
test_expect_success 'simple A..B A..C (unmodified)' ' test_expect_success 'simple A..B A..C (unmodified)' '
git range-diff --no-color master..topic master..unmodified \ git range-diff --no-color master..topic master..unmodified \
>actual && >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/ 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'simple B...C (unmodified)' ' test_expect_success 'simple B...C (unmodified)' '
git range-diff --no-color topic...unmodified >actual && git range-diff --no-color topic...unmodified >actual &&
# same "expected" as above # same "expect" as above
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'simple A B C (unmodified)' ' test_expect_success 'simple A B C (unmodified)' '
git range-diff --no-color master topic unmodified >actual && git range-diff --no-color master topic unmodified >actual &&
# same "expected" as above # same "expect" as above
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'trivial reordering' ' test_expect_success 'trivial reordering' '
git range-diff --no-color master topic reordered >actual && git range-diff --no-color master topic reordered >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/ 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/ 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/ 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'removed a commit' ' test_expect_success 'removed a commit' '
git range-diff --no-color master topic removed >actual && git range-diff --no-color master topic removed >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
2: $(test_oid t2) < -: $(test_oid __) s/4/A/ 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/ 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/ 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'added a commit' ' test_expect_success 'added a commit' '
git range-diff --no-color master topic added >actual && git range-diff --no-color master topic added >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/ 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
-: $(test_oid __) > 3: $(test_oid a3) s/6/A/ -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/ 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/ 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'new base, A B C' ' test_expect_success 'new base, A B C' '
git range-diff --no-color master topic rebased >actual && git range-diff --no-color master topic rebased >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/ 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/ 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/ 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'new base, B...C' ' test_expect_success 'new base, B...C' '
# this syntax includes the commits from master! # this syntax includes the commits from master!
git range-diff --no-color topic...rebased >actual && git range-diff --no-color topic...rebased >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
-: $(test_oid __) > 1: $(test_oid b5) unrelated -: $(test_oid __) > 1: $(test_oid b5) unrelated
1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/ 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/ 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/ 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/ 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'changed commit' ' test_expect_success 'changed commit' '
git range-diff --no-color topic...changed >actual && git range-diff --no-color topic...changed >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
@ -226,23 +226,23 @@ test_expect_success 'changed commit' '
+B +B
13 13
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'changed commit with --no-patch diff option' ' test_expect_success 'changed commit with --no-patch diff option' '
git range-diff --no-color --no-patch topic...changed >actual && git range-diff --no-color --no-patch topic...changed >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'changed commit with --stat diff option' ' test_expect_success 'changed commit with --stat diff option' '
git range-diff --no-color --stat topic...changed >actual && git range-diff --no-color --stat topic...changed >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
a => b | 0 a => b | 0
1 file changed, 0 insertions(+), 0 deletions(-) 1 file changed, 0 insertions(+), 0 deletions(-)
@ -256,12 +256,12 @@ test_expect_success 'changed commit with --stat diff option' '
a => b | 0 a => b | 0
1 file changed, 0 insertions(+), 0 deletions(-) 1 file changed, 0 insertions(+), 0 deletions(-)
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'changed commit with sm config' ' test_expect_success 'changed commit with sm config' '
git range-diff --no-color --submodule=log topic...changed >actual && git range-diff --no-color --submodule=log topic...changed >actual &&
cat >expected <<-EOF && cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
@ -285,12 +285,12 @@ test_expect_success 'changed commit with sm config' '
+B +B
13 13
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'renamed file' ' test_expect_success 'renamed file' '
git range-diff --no-color --submodule=log topic...renamed-file >actual && git range-diff --no-color --submodule=log topic...renamed-file >actual &&
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/ 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
@@ Metadata @@ Metadata
@ -330,12 +330,12 @@ test_expect_success 'renamed file' '
Z 10 Z 10
Z B Z B
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'file with mode only change' ' test_expect_success 'file with mode only change' '
git range-diff --no-color --submodule=log topic...mode-only-change >actual && git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expect <<-EOF &&
1: fccce22 ! 1: 4d39cb3 s/4/A/ 1: fccce22 ! 1: 4d39cb3 s/4/A/
@@ Metadata @@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch> ZAuthor: Thomas Rast <trast@inf.ethz.ch>
@ -370,12 +370,12 @@ test_expect_success 'file with mode only change' '
+ ## other-file (mode change 100644 => 100755) ## + ## other-file (mode change 100644 => 100755) ##
3: a63e992 = 3: 4c1e0f5 s/12/B/ 3: a63e992 = 3: 4c1e0f5 s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'file added and later removed' ' test_expect_success 'file added and later removed' '
git range-diff --no-color --submodule=log topic...added-removed >actual && git range-diff --no-color --submodule=log topic...added-removed >actual &&
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/ 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
@@ Metadata @@ Metadata
@ -411,7 +411,7 @@ test_expect_success 'file added and later removed' '
+ ## new-file (deleted) ## + ## new-file (deleted) ##
4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/ 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'no commits on one side' ' test_expect_success 'no commits on one side' '
@ -421,7 +421,7 @@ test_expect_success 'no commits on one side' '
test_expect_success 'changed message' ' test_expect_success 'changed message' '
git range-diff --no-color topic...changed-message >actual && git range-diff --no-color topic...changed-message >actual &&
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/ 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/ 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
@@ Metadata @@ Metadata
@ -436,7 +436,7 @@ test_expect_success 'changed message' '
3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/ 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/ 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
EOF EOF
test_cmp expected actual test_cmp expect actual
' '
test_expect_success 'dual-coloring' ' test_expect_success 'dual-coloring' '
@ -505,4 +505,202 @@ test_expect_success 'range-diff overrides diff.noprefix internally' '
git -c diff.noprefix=true range-diff HEAD^... git -c diff.noprefix=true range-diff HEAD^...
' '
test_expect_success 'range-diff compares notes by default' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
test_when_finished git notes remove topic unmodified &&
git range-diff --no-color master..topic master..unmodified \
>actual &&
sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
@@ Commit message
Z
Z
Z ## Notes ##
- topic note
+ unmodified note
Z
Z ## file ##
Z@@ file: A
EOF
test_cmp expect actual
'
test_expect_success 'range-diff with --no-notes' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
test_when_finished git notes remove topic unmodified &&
git range-diff --no-color --no-notes master..topic master..unmodified \
>actual &&
cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
EOF
test_cmp expect actual
'
test_expect_success 'range-diff with multiple --notes' '
git notes --ref=note1 add -m "topic note1" topic &&
git notes --ref=note1 add -m "unmodified note1" unmodified &&
test_when_finished git notes --ref=note1 remove topic unmodified &&
git notes --ref=note2 add -m "topic note2" topic &&
git notes --ref=note2 add -m "unmodified note2" unmodified &&
test_when_finished git notes --ref=note2 remove topic unmodified &&
git range-diff --no-color --notes=note1 --notes=note2 master..topic master..unmodified \
>actual &&
sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
@@ Commit message
Z
Z
Z ## Notes (note1) ##
- topic note1
+ unmodified note1
Z
Z
Z ## Notes (note2) ##
- topic note2
+ unmodified note2
Z
Z ## file ##
Z@@ file: A
EOF
test_cmp expect actual
'
test_expect_success 'format-patch --range-diff does not compare notes by default' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
test_when_finished git notes remove topic unmodified &&
git format-patch --cover-letter --range-diff=$prev \
master..unmodified >actual &&
test_when_finished "rm 000?-*" &&
test_line_count = 5 actual &&
test_i18ngrep "^Range-diff:$" 0000-* &&
grep "= 1: .* s/5/A" 0000-* &&
grep "= 2: .* s/4/A" 0000-* &&
grep "= 3: .* s/11/B" 0000-* &&
grep "= 4: .* s/12/B" 0000-* &&
! grep "Notes" 0000-* &&
! grep "note" 0000-*
'
test_expect_success 'format-patch --range-diff with --no-notes' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
test_when_finished git notes remove topic unmodified &&
git format-patch --no-notes --cover-letter --range-diff=$prev \
master..unmodified >actual &&
test_when_finished "rm 000?-*" &&
test_line_count = 5 actual &&
test_i18ngrep "^Range-diff:$" 0000-* &&
grep "= 1: .* s/5/A" 0000-* &&
grep "= 2: .* s/4/A" 0000-* &&
grep "= 3: .* s/11/B" 0000-* &&
grep "= 4: .* s/12/B" 0000-* &&
! grep "Notes" 0000-* &&
! grep "note" 0000-*
'
test_expect_success 'format-patch --range-diff with --notes' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
test_when_finished git notes remove topic unmodified &&
git format-patch --notes --cover-letter --range-diff=$prev \
master..unmodified >actual &&
test_when_finished "rm 000?-*" &&
test_line_count = 5 actual &&
test_i18ngrep "^Range-diff:$" 0000-* &&
grep "= 1: .* s/5/A" 0000-* &&
grep "= 2: .* s/4/A" 0000-* &&
grep "= 3: .* s/11/B" 0000-* &&
grep "! 4: .* s/12/B" 0000-* &&
sed s/Z/\ /g >expect <<-EOF &&
@@ Commit message
Z
Z
Z ## Notes ##
- topic note
+ unmodified note
Z
Z ## file ##
Z@@ file: A
EOF
sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
test_cmp expect actual
'
test_expect_success 'format-patch --range-diff with --notes' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
test_when_finished git notes remove topic unmodified &&
test_config format.notes true &&
git format-patch --cover-letter --range-diff=$prev \
master..unmodified >actual &&
test_when_finished "rm 000?-*" &&
test_line_count = 5 actual &&
test_i18ngrep "^Range-diff:$" 0000-* &&
grep "= 1: .* s/5/A" 0000-* &&
grep "= 2: .* s/4/A" 0000-* &&
grep "= 3: .* s/11/B" 0000-* &&
grep "! 4: .* s/12/B" 0000-* &&
sed s/Z/\ /g >expect <<-EOF &&
@@ Commit message
Z
Z
Z ## Notes ##
- topic note
+ unmodified note
Z
Z ## file ##
Z@@ file: A
EOF
sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
test_cmp expect actual
'
test_expect_success 'format-patch --range-diff with multiple notes' '
git notes --ref=note1 add -m "topic note1" topic &&
git notes --ref=note1 add -m "unmodified note1" unmodified &&
test_when_finished git notes --ref=note1 remove topic unmodified &&
git notes --ref=note2 add -m "topic note2" topic &&
git notes --ref=note2 add -m "unmodified note2" unmodified &&
test_when_finished git notes --ref=note2 remove topic unmodified &&
git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
master..unmodified >actual &&
test_when_finished "rm 000?-*" &&
test_line_count = 5 actual &&
test_i18ngrep "^Range-diff:$" 0000-* &&
grep "= 1: .* s/5/A" 0000-* &&
grep "= 2: .* s/4/A" 0000-* &&
grep "= 3: .* s/11/B" 0000-* &&
grep "! 4: .* s/12/B" 0000-* &&
sed s/Z/\ /g >expect <<-EOF &&
@@ Commit message
Z
Z
Z ## Notes (note1) ##
- topic note1
+ unmodified note1
Z
Z
Z ## Notes (note2) ##
- topic note2
+ unmodified note2
Z
Z ## file ##
Z@@ file: A
EOF
sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
test_cmp expect actual
'
test_done test_done