2006-06-26 20:46:52 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Various diff formatting options'
|
|
|
|
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
|
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2006-06-26 20:46:52 +00:00
|
|
|
. ./test-lib.sh
|
2021-02-12 13:29:40 +00:00
|
|
|
. "$TEST_DIRECTORY"/lib-diff.sh
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
|
|
|
|
mkdir dir &&
|
2007-07-03 15:01:06 +00:00
|
|
|
mkdir dir2 &&
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 1 2 3 >file0 &&
|
|
|
|
test_write_lines A B >dir/sub &&
|
2006-06-26 20:46:52 +00:00
|
|
|
cat file0 >file2 &&
|
|
|
|
git add file0 file2 dir/sub &&
|
|
|
|
git commit -m Initial &&
|
|
|
|
|
|
|
|
git branch initial &&
|
|
|
|
git branch side &&
|
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 4 5 6 >>file0 &&
|
|
|
|
test_write_lines C D >>dir/sub &&
|
2006-06-26 20:46:52 +00:00
|
|
|
rm -f file2 &&
|
|
|
|
git update-index --remove file0 file2 dir/sub &&
|
2006-07-14 02:51:12 +00:00
|
|
|
git commit -m "Second${LF}${LF}This is the second commit." &&
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines A B C >file1 &&
|
2006-06-26 20:46:52 +00:00
|
|
|
git add file1 &&
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines E F >>dir/sub &&
|
2006-06-26 20:46:52 +00:00
|
|
|
git update-index dir/sub &&
|
|
|
|
git commit -m Third &&
|
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
|
|
|
|
git checkout side &&
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines A B C >>file0 &&
|
|
|
|
test_write_lines 1 2 >>dir/sub &&
|
2006-06-26 20:46:52 +00:00
|
|
|
cat dir/sub >file3 &&
|
|
|
|
git add file3 &&
|
|
|
|
git update-index file0 dir/sub &&
|
|
|
|
git commit -m Side &&
|
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
|
|
|
|
git checkout master &&
|
2021-07-22 05:04:48 +00:00
|
|
|
git pull -s ours --no-rebase . side &&
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines A B C >>file0 &&
|
|
|
|
test_write_lines 1 2 >>dir/sub &&
|
2006-06-26 20:46:52 +00:00
|
|
|
git update-index file0 dir/sub &&
|
|
|
|
|
2009-02-18 06:48:06 +00:00
|
|
|
mkdir dir3 &&
|
|
|
|
cp dir/sub dir3/sub &&
|
2018-03-24 07:44:31 +00:00
|
|
|
test-tool chmtime +1 dir3/sub &&
|
2009-02-18 06:48:06 +00:00
|
|
|
|
2007-01-29 00:16:53 +00:00
|
|
|
git config log.showroot false &&
|
2006-07-11 19:01:54 +00:00
|
|
|
git commit --amend &&
|
2011-04-10 22:48:50 +00:00
|
|
|
|
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
git checkout -b rearrange initial &&
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines B A >dir/sub &&
|
2011-04-10 22:48:50 +00:00
|
|
|
git add dir/sub &&
|
|
|
|
git commit -m "Rearranged lines in dir/sub" &&
|
|
|
|
git checkout master &&
|
|
|
|
|
2017-09-27 22:51:26 +00:00
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
git checkout -b mode initial &&
|
|
|
|
git update-index --chmod=+x file0 &&
|
|
|
|
git commit -m "update mode" &&
|
|
|
|
git checkout -f master &&
|
|
|
|
|
diff-tree.c: load notes machinery when required
Since its introduction in 7249e91 (revision.c: support --notes
command-line option, 2011-03-29), combining '--notes' with any option
that causes us to format notes (e.g., '--pretty', '--format="%N"', etc)
results in a failed assertion at runtime.
$ git rev-list HEAD | git diff-tree --stdin --pretty=medium --notes
commit 8f3d9f354286745c751374f5f1fcafee6b3f3136
git: notes.c:1308: format_display_notes: Assertion `display_notes_trees' failed.
Aborted
This failure is due to diff-tree not calling 'load_display_notes' to
initialize the notes machinery.
Ordinarily, this failure isn't triggered, because it requires passing
both '--notes' and another of the above mentioned options. In the case
of '--pretty', for example, we set 'opt->verbose_header', causing
'show_log()' to eventually call 'format_display_notes()', which expects
a non-NULL 'display_note_trees'.
Without initializing the notes machinery, 'display_note_trees' remains
NULL, and thus triggers an assertion failure.
Fix this by initializing the notes machinery after parsing our options,
and harden this behavior against regression with a test in t4013. (Note
that the added ref in this test requires updating two unrelated tests
which use 'log --all', and thus need to learn about the new refs).
Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-21 00:13:15 +00:00
|
|
|
GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
|
|
|
|
GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
|
|
|
|
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
|
|
|
|
git checkout -b note initial &&
|
|
|
|
git update-index --chmod=+x file2 &&
|
|
|
|
git commit -m "update mode (file2)" &&
|
|
|
|
git notes add -m "note" &&
|
|
|
|
git checkout -f master &&
|
|
|
|
|
2019-01-24 12:35:40 +00:00
|
|
|
# Same merge as master, but with parents reversed. Hide it in a
|
|
|
|
# pseudo-ref to avoid impacting tests with --all.
|
|
|
|
commit=$(echo reverse |
|
|
|
|
git commit-tree -p master^2 -p master^1 master^{tree}) &&
|
|
|
|
git update-ref REVERSE $commit &&
|
|
|
|
|
2016-02-25 08:59:21 +00:00
|
|
|
git config diff.renames false &&
|
|
|
|
|
2006-06-26 20:46:52 +00:00
|
|
|
git show-branch
|
|
|
|
'
|
|
|
|
|
|
|
|
: <<\EOF
|
|
|
|
! [initial] Initial
|
2020-07-30 17:06:42 +00:00
|
|
|
* [master] Merge branch 'side'
|
2011-04-10 22:48:50 +00:00
|
|
|
! [rearrange] Rearranged lines in dir/sub
|
|
|
|
! [side] Side
|
|
|
|
----
|
|
|
|
+ [rearrange] Rearranged lines in dir/sub
|
2020-07-30 17:06:42 +00:00
|
|
|
- [master] Merge branch 'side'
|
2011-04-10 22:48:50 +00:00
|
|
|
* + [side] Side
|
|
|
|
* [master^] Third
|
|
|
|
* [master~2] Second
|
|
|
|
+*++ [initial] Initial
|
2006-06-26 20:46:52 +00:00
|
|
|
EOF
|
|
|
|
|
2020-02-07 00:52:40 +00:00
|
|
|
process_diffs () {
|
t4013: improve diff-post-processor logic
From 72f936b1 (t4013: make test hash independent, 2020-02-07),
we started to adjust metadata of git-diff's output in order to
ignore uninteresting metadata which is dependent of underlying hash
algorithm.
However, we forgot to special case all-zero object names, which is
special for missing objects, in consequence, we could't catch
possible future bugs where object names is all-zeros including but
not limited to:
* show intend-to-add entry
* deleted entry
* diff between index and working tree with new file
We also mistakenly munged file-modes as if they were object names
abbreviated to 6 hexadecimal digits.
In addition, in the upcoming change, we would like to test for
customizing the length of abbreviated blob objects on the index line,
which is not supported by current diff-processor logic.
Let's fix the bug for all-zero object names, and file modes.
While we're at it, support abbreviation of object names up to 16 bytes.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-21 11:51:46 +00:00
|
|
|
perl -e '
|
|
|
|
my $oid_length = length($ARGV[0]);
|
|
|
|
my $x40 = "[0-9a-f]{40}";
|
|
|
|
my $xab = "[0-9a-f]{4,16}";
|
|
|
|
my $orx = "[0-9a-f]" x $oid_length;
|
|
|
|
|
|
|
|
sub munge_oid {
|
|
|
|
my ($oid) = @_;
|
|
|
|
my $x;
|
|
|
|
|
|
|
|
return "" unless length $oid;
|
|
|
|
|
|
|
|
if ($oid =~ /^(100644|100755|120000)$/) {
|
|
|
|
return $oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oid =~ /^0*$/) {
|
|
|
|
$x = "0";
|
|
|
|
} else {
|
|
|
|
$x = "f";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($oid) == 40) {
|
|
|
|
return $x x $oid_length;
|
|
|
|
} else {
|
|
|
|
return $x x length($oid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (<STDIN>) {
|
|
|
|
s/($orx)/munge_oid($1)/ge;
|
|
|
|
s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
|
|
|
|
s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
|
|
|
|
s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
|
|
|
|
s/^($x40)($| )/munge_oid($1) . $2/e;
|
|
|
|
s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
' "$ZERO_OID" <"$1"
|
2020-02-07 00:52:40 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:22:59 +00:00
|
|
|
V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
|
2017-12-03 21:27:41 +00:00
|
|
|
while read magic cmd
|
2006-06-26 20:46:52 +00:00
|
|
|
do
|
2020-12-21 15:19:43 +00:00
|
|
|
status=success
|
2017-12-03 21:27:41 +00:00
|
|
|
case "$magic" in
|
|
|
|
'' | '#'*)
|
|
|
|
continue ;;
|
|
|
|
:*)
|
|
|
|
magic=${magic#:}
|
|
|
|
label="$magic-$cmd"
|
|
|
|
case "$magic" in
|
|
|
|
noellipses) ;;
|
2020-12-21 15:19:43 +00:00
|
|
|
failure)
|
|
|
|
status=failure
|
|
|
|
magic=
|
|
|
|
label="$cmd" ;;
|
2017-12-03 21:27:41 +00:00
|
|
|
*)
|
tests: send "bug in the test script" errors to the script's stderr
Some of the functions in our test library check that they were invoked
properly with conditions like this:
test "$#" = 2 ||
error "bug in the test script: not 2 parameters to test-expect-success"
If this particular condition is triggered, then 'error' will abort the
whole test script with a bold red error message [1] right away.
However, under certain circumstances the test script will be aborted
completely silently, namely if:
- a similar condition in a test helper function like
'test_line_count' is triggered,
- which is invoked from the test script's "main" shell [2],
- and the test script is run manually (i.e. './t1234-foo.sh' as
opposed to 'make t1234-foo.sh' or 'make test') [3]
- and without the '--verbose' option,
because the error message is printed from within 'test_eval_', where
standard output is redirected either to /dev/null or to a log file.
The only indication that something is wrong is that not all tests in
the script are executed and at the end of the test script's output
there is no "# passed all N tests" message, which are subtle and can
easily go unnoticed, as I had to experience myself.
Send these "bug in the test script" error messages directly to the
test scripts standard error and thus to the terminal, so those bugs
will be much harder to overlook. Instead of updating all ~20 such
'error' calls with a redirection, let's add a BUG() function to
'test-lib.sh', wrapping an 'error' call with the proper redirection
and also including the common prefix of those error messages, and
convert all those call sites [4] to use this new BUG() function
instead.
[1] That particular error message from 'test_expect_success' is
printed in color only when running with or without '--verbose';
with '--tee' or '--verbose-log' the error is printed without
color, but it is printed to the terminal nonetheless.
[2] If such a condition is triggered in a subshell of a test, then
'error' won't be able to abort the whole test script, but only the
subshell, which in turn causes the test to fail in the usual way,
indicating loudly and clearly that something is wrong.
[3] Well, 'error' aborts the test script the same way when run
manually or by 'make' or 'prove', but both 'make' and 'prove' pay
attention to the test script's exit status, and even a silently
aborted test script would then trigger those tools' usual
noticable error messages.
[4] Strictly speaking, not all those 'error' calls need that
redirection to send their output to the terminal, see e.g.
'test_expect_success' in the opening example, but I think it's
better to be consistent.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-11-19 13:13:26 +00:00
|
|
|
BUG "unknown magic $magic" ;;
|
2017-12-03 21:27:41 +00:00
|
|
|
esac ;;
|
|
|
|
*)
|
|
|
|
cmd="$magic $cmd" magic=
|
|
|
|
label="$cmd" ;;
|
2006-06-26 20:46:52 +00:00
|
|
|
esac
|
2017-12-03 21:27:41 +00:00
|
|
|
test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
|
2014-04-30 16:22:59 +00:00
|
|
|
pfx=$(printf "%04d" $test_count)
|
2008-08-08 09:26:28 +00:00
|
|
|
expect="$TEST_DIRECTORY/t4013/diff.$test"
|
2006-06-26 20:46:52 +00:00
|
|
|
actual="$pfx-diff.$test"
|
|
|
|
|
2020-12-21 15:19:43 +00:00
|
|
|
test_expect_$status "git $cmd # magic is ${magic:-(not used)}" '
|
2006-06-26 20:46:52 +00:00
|
|
|
{
|
2017-12-03 21:27:41 +00:00
|
|
|
echo "$ git $cmd"
|
|
|
|
case "$magic" in
|
|
|
|
"")
|
|
|
|
GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
|
|
|
|
noellipses)
|
|
|
|
git $cmd ;;
|
|
|
|
esac |
|
2006-08-13 01:04:07 +00:00
|
|
|
sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
|
2007-03-05 00:08:04 +00:00
|
|
|
-e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
|
2006-06-26 20:46:52 +00:00
|
|
|
echo "\$"
|
|
|
|
} >"$actual" &&
|
|
|
|
if test -f "$expect"
|
|
|
|
then
|
2020-02-07 00:52:40 +00:00
|
|
|
process_diffs "$actual" >actual &&
|
|
|
|
process_diffs "$expect" >expect &&
|
2012-03-13 05:05:54 +00:00
|
|
|
case $cmd in
|
|
|
|
*format-patch* | *-stat*)
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expect actual;;
|
2012-03-13 05:05:54 +00:00
|
|
|
*)
|
2020-02-07 00:52:40 +00:00
|
|
|
test_cmp expect actual;;
|
2012-03-13 05:05:54 +00:00
|
|
|
esac &&
|
2020-02-07 00:52:40 +00:00
|
|
|
rm -f "$actual" actual expect
|
2006-06-26 20:46:52 +00:00
|
|
|
else
|
|
|
|
# this is to help developing new tests.
|
|
|
|
cp "$actual" "$expect"
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
done <<\EOF
|
|
|
|
diff-tree initial
|
|
|
|
diff-tree -r initial
|
|
|
|
diff-tree -r --abbrev initial
|
|
|
|
diff-tree -r --abbrev=4 initial
|
|
|
|
diff-tree --root initial
|
|
|
|
diff-tree --root --abbrev initial
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff-tree --root --abbrev initial
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree --root -r initial
|
|
|
|
diff-tree --root -r --abbrev initial
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff-tree --root -r --abbrev initial
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree --root -r --abbrev=4 initial
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff-tree --root -r --abbrev=4 initial
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree -p initial
|
|
|
|
diff-tree --root -p initial
|
diff: index-line: respect --abbrev in object's name
A handful of Git's commands respect `--abbrev' for customizing length
of abbreviation of object names.
For diff-family, Git supports 2 different options for 2 different
purposes, `--full-index' for showing diff-patch object's name in full,
and `--abbrev' to customize the length of object names in diff-raw and
diff-tree header lines, without any options to customise the length of
object names in diff-patch format. When working with diff-patch format,
we only have two options, either full index, or default abbrev length.
Although, that behaviour is documented, it doesn't stop users from
trying to use `--abbrev' with the hope of customising diff-patch's
objects' name's abbreviation.
Let's allow the blob object names shown on the "index" line to be
abbreviated to arbitrary length given via the "--abbrev" option.
To preserve backward compatibility with old script that specify both
`--full-index' and `--abbrev', always show full object id
if `--full-index' is specified.
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-21 11:51:47 +00:00
|
|
|
diff-tree --root -p --abbrev=10 initial
|
|
|
|
diff-tree --root -p --full-index initial
|
|
|
|
diff-tree --root -p --full-index --abbrev=10 initial
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree --patch-with-stat initial
|
|
|
|
diff-tree --root --patch-with-stat initial
|
|
|
|
diff-tree --patch-with-raw initial
|
|
|
|
diff-tree --root --patch-with-raw initial
|
|
|
|
|
|
|
|
diff-tree --pretty initial
|
|
|
|
diff-tree --pretty --root initial
|
|
|
|
diff-tree --pretty -p initial
|
|
|
|
diff-tree --pretty --stat initial
|
|
|
|
diff-tree --pretty --summary initial
|
|
|
|
diff-tree --pretty --stat --summary initial
|
|
|
|
diff-tree --pretty --root -p initial
|
|
|
|
diff-tree --pretty --root --stat initial
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
|
|
|
diff-tree --pretty --root --summary initial
|
|
|
|
# improved by Timo's patch
|
|
|
|
diff-tree --pretty --root --summary -r initial
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree --pretty --root --stat --summary initial
|
|
|
|
diff-tree --pretty --patch-with-stat initial
|
|
|
|
diff-tree --pretty --root --patch-with-stat initial
|
|
|
|
diff-tree --pretty --patch-with-raw initial
|
|
|
|
diff-tree --pretty --root --patch-with-raw initial
|
|
|
|
|
|
|
|
diff-tree --pretty=oneline initial
|
|
|
|
diff-tree --pretty=oneline --root initial
|
|
|
|
diff-tree --pretty=oneline -p initial
|
|
|
|
diff-tree --pretty=oneline --root -p initial
|
|
|
|
diff-tree --pretty=oneline --patch-with-stat initial
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree --pretty=oneline --root --patch-with-stat initial
|
|
|
|
diff-tree --pretty=oneline --patch-with-raw initial
|
|
|
|
diff-tree --pretty=oneline --root --patch-with-raw initial
|
|
|
|
|
|
|
|
diff-tree --pretty side
|
|
|
|
diff-tree --pretty -p side
|
|
|
|
diff-tree --pretty --patch-with-stat side
|
|
|
|
|
2017-09-27 22:51:26 +00:00
|
|
|
diff-tree initial mode
|
|
|
|
diff-tree --stat initial mode
|
|
|
|
diff-tree --summary initial mode
|
|
|
|
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree master
|
2021-05-20 21:46:57 +00:00
|
|
|
diff-tree -m master
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree -p master
|
|
|
|
diff-tree -p -m master
|
|
|
|
diff-tree -c master
|
|
|
|
diff-tree -c --abbrev master
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff-tree -c --abbrev master
|
2006-06-26 20:46:52 +00:00
|
|
|
diff-tree --cc master
|
2006-06-27 06:29:11 +00:00
|
|
|
# stat only should show the diffstat with the first parent
|
|
|
|
diff-tree -c --stat master
|
|
|
|
diff-tree --cc --stat master
|
|
|
|
diff-tree -c --stat --summary master
|
|
|
|
diff-tree --cc --stat --summary master
|
|
|
|
# stat summary should show the diffstat and summary with the first parent
|
|
|
|
diff-tree -c --stat --summary side
|
|
|
|
diff-tree --cc --stat --summary side
|
2019-01-24 12:34:51 +00:00
|
|
|
diff-tree --cc --shortstat master
|
2019-01-24 12:35:40 +00:00
|
|
|
diff-tree --cc --summary REVERSE
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
|
|
|
diff-tree --cc --patch-with-stat master
|
|
|
|
# improved by Timo's patch
|
2006-06-27 06:29:11 +00:00
|
|
|
diff-tree --cc --patch-with-stat --summary master
|
|
|
|
# this is correct
|
|
|
|
diff-tree --cc --patch-with-stat --summary side
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
log master
|
|
|
|
log -p master
|
|
|
|
log --root master
|
|
|
|
log --root -p master
|
|
|
|
log --patch-with-stat master
|
|
|
|
log --root --patch-with-stat master
|
2006-06-27 06:29:11 +00:00
|
|
|
log --root --patch-with-stat --summary master
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
2006-06-27 06:29:11 +00:00
|
|
|
log --root -c --patch-with-stat --summary master
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
2006-06-27 06:29:11 +00:00
|
|
|
log --root --cc --patch-with-stat --summary master
|
2020-07-29 20:10:20 +00:00
|
|
|
log --no-diff-merges -p --first-parent master
|
2020-08-05 22:08:32 +00:00
|
|
|
log --diff-merges=off -p --first-parent master
|
|
|
|
log --first-parent --diff-merges=off -p master
|
2010-03-09 05:11:40 +00:00
|
|
|
log -p --first-parent master
|
2020-12-21 15:20:00 +00:00
|
|
|
log -p --diff-merges=first-parent master
|
|
|
|
log --diff-merges=first-parent master
|
2010-03-09 05:11:40 +00:00
|
|
|
log -m -p --first-parent master
|
|
|
|
log -m -p master
|
2020-12-21 15:19:45 +00:00
|
|
|
log --cc -m -p master
|
|
|
|
log -c -m -p master
|
2021-05-20 21:46:55 +00:00
|
|
|
log -m --raw master
|
2021-05-20 21:46:56 +00:00
|
|
|
log -m --stat master
|
2006-06-26 20:46:52 +00:00
|
|
|
log -SF master
|
2010-08-05 08:22:52 +00:00
|
|
|
log -S F master
|
2006-06-27 06:29:11 +00:00
|
|
|
log -SF -p master
|
2011-03-09 20:52:15 +00:00
|
|
|
log -SF master --max-count=0
|
|
|
|
log -SF master --max-count=1
|
|
|
|
log -SF master --max-count=2
|
2010-08-31 21:27:41 +00:00
|
|
|
log -GF master
|
|
|
|
log -GF -p master
|
|
|
|
log -GF -p --pickaxe-all master
|
2020-10-20 06:48:09 +00:00
|
|
|
log -IA -IB -I1 -I2 -p master
|
2009-02-19 11:13:40 +00:00
|
|
|
log --decorate --all
|
2009-08-15 14:23:12 +00:00
|
|
|
log --decorate=full --all
|
2022-08-05 17:58:40 +00:00
|
|
|
log --decorate --clear-decorations --all
|
|
|
|
log --decorate=full --clear-decorations --all
|
2006-06-26 20:46:52 +00:00
|
|
|
|
2009-02-19 11:13:41 +00:00
|
|
|
rev-list --parents HEAD
|
|
|
|
rev-list --children HEAD
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
whatchanged master
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses whatchanged master
|
2006-06-26 20:46:52 +00:00
|
|
|
whatchanged -p master
|
|
|
|
whatchanged --root master
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses whatchanged --root master
|
2006-06-26 20:46:52 +00:00
|
|
|
whatchanged --root -p master
|
|
|
|
whatchanged --patch-with-stat master
|
|
|
|
whatchanged --root --patch-with-stat master
|
|
|
|
whatchanged --root --patch-with-stat --summary master
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
2006-06-27 06:29:11 +00:00
|
|
|
whatchanged --root -c --patch-with-stat --summary master
|
2006-06-29 19:00:12 +00:00
|
|
|
# improved by Timo's patch
|
2006-06-27 06:29:11 +00:00
|
|
|
whatchanged --root --cc --patch-with-stat --summary master
|
2006-06-26 20:46:52 +00:00
|
|
|
whatchanged -SF master
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses whatchanged -SF master
|
2006-06-27 06:29:11 +00:00
|
|
|
whatchanged -SF -p master
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
log --patch-with-stat master -- dir/
|
|
|
|
whatchanged --patch-with-stat master -- dir/
|
2006-06-27 06:29:11 +00:00
|
|
|
log --patch-with-stat --summary master -- dir/
|
|
|
|
whatchanged --patch-with-stat --summary master -- dir/
|
2006-06-26 20:46:52 +00:00
|
|
|
|
|
|
|
show initial
|
|
|
|
show --root initial
|
|
|
|
show side
|
|
|
|
show master
|
2010-03-09 07:27:25 +00:00
|
|
|
show -c master
|
2010-03-09 08:22:54 +00:00
|
|
|
show -m master
|
|
|
|
show --first-parent master
|
2006-06-26 20:46:52 +00:00
|
|
|
show --stat side
|
|
|
|
show --stat --summary side
|
|
|
|
show --patch-with-stat side
|
|
|
|
show --patch-with-raw side
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses show --patch-with-raw side
|
2006-06-26 20:46:52 +00:00
|
|
|
show --patch-with-stat --summary side
|
|
|
|
|
2006-06-29 07:01:07 +00:00
|
|
|
format-patch --stdout initial..side
|
|
|
|
format-patch --stdout initial..master^
|
|
|
|
format-patch --stdout initial..master
|
2008-10-02 20:55:39 +00:00
|
|
|
format-patch --stdout --no-numbered initial..master
|
|
|
|
format-patch --stdout --numbered initial..master
|
2006-06-29 07:01:07 +00:00
|
|
|
format-patch --attach --stdout initial..side
|
2009-03-23 02:14:05 +00:00
|
|
|
format-patch --attach --stdout --suffix=.diff initial..side
|
2006-06-29 07:01:07 +00:00
|
|
|
format-patch --attach --stdout initial..master^
|
|
|
|
format-patch --attach --stdout initial..master
|
2007-03-03 23:12:06 +00:00
|
|
|
format-patch --inline --stdout initial..side
|
|
|
|
format-patch --inline --stdout initial..master^
|
2009-03-23 02:14:06 +00:00
|
|
|
format-patch --inline --stdout --numbered-files initial..master
|
2008-10-02 20:55:39 +00:00
|
|
|
format-patch --inline --stdout initial..master
|
2007-04-11 23:58:08 +00:00
|
|
|
format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
|
2007-07-02 00:48:59 +00:00
|
|
|
config format.subjectprefix DIFFERENT_PREFIX
|
|
|
|
format-patch --inline --stdout initial..master^^
|
2008-02-19 03:56:13 +00:00
|
|
|
format-patch --stdout --cover-letter -n initial..master^
|
2006-06-29 07:01:07 +00:00
|
|
|
|
2006-07-02 05:02:17 +00:00
|
|
|
diff --abbrev initial..side
|
2019-05-29 09:11:15 +00:00
|
|
|
diff -U initial..side
|
|
|
|
diff -U1 initial..side
|
2006-07-02 05:02:17 +00:00
|
|
|
diff -r initial..side
|
|
|
|
diff --stat initial..side
|
|
|
|
diff -r --stat initial..side
|
|
|
|
diff initial..side
|
|
|
|
diff --patch-with-stat initial..side
|
|
|
|
diff --patch-with-raw initial..side
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff --patch-with-raw initial..side
|
2006-07-02 05:02:17 +00:00
|
|
|
diff --patch-with-stat -r initial..side
|
|
|
|
diff --patch-with-raw -r initial..side
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff --patch-with-raw -r initial..side
|
2007-07-03 15:01:06 +00:00
|
|
|
diff --name-status dir2 dir
|
2008-05-24 05:28:56 +00:00
|
|
|
diff --no-index --name-status dir2 dir
|
2009-01-06 18:53:32 +00:00
|
|
|
diff --no-index --name-status -- dir2 dir
|
2009-02-18 06:48:06 +00:00
|
|
|
diff --no-index dir dir3
|
2008-10-11 01:56:15 +00:00
|
|
|
diff master master^ side
|
2016-08-31 23:27:20 +00:00
|
|
|
# Can't use spaces...
|
|
|
|
diff --line-prefix=abc master master^ side
|
2009-02-19 11:13:37 +00:00
|
|
|
diff --dirstat master~1 master~2
|
2011-04-10 22:48:50 +00:00
|
|
|
diff --dirstat initial rearrange
|
2011-04-10 22:48:51 +00:00
|
|
|
diff --dirstat-by-file initial rearrange
|
2019-01-24 12:36:47 +00:00
|
|
|
diff --dirstat --cc master~1 master
|
diff: handle --no-abbrev in no-index case
There are two different places where the --no-abbrev option is parsed,
and two different places where SHA-1s are abbreviated. We normally parse
--no-abbrev with setup_revisions(), but in the no-index case, "git diff"
calls diff_opt_parse() directly, and diff_opt_parse() didn't handle
--no-abbrev until now. (It did handle --abbrev, however.) We normally
abbreviate SHA-1s with find_unique_abbrev(), but commit 4f03666 ("diff:
handle sha1 abbreviations outside of repository, 2016-10-20) recently
introduced a special case when you run "git diff" outside of a
repository.
setup_revisions() does also call diff_opt_parse(), but not for --abbrev
or --no-abbrev, which it handles itself. setup_revisions() sets
rev_info->abbrev, and later copies that to diff_options->abbrev. It
handles --no-abbrev by setting abbrev to zero. (This change doesn't
touch that.)
Setting abbrev to zero was broken in the outside-of-a-repository special
case, which until now resulted in a truly zero-length SHA-1, rather than
taking zero to mean do not abbreviate. The only way to trigger this bug,
however, was by running "git diff --raw" without either the --abbrev or
--no-abbrev options, because 1) without --raw it doesn't respect abbrev
(which is bizarre, but has been that way forever), 2) we silently clamp
--abbrev=0 to MINIMUM_ABBREV, and 3) --no-abbrev wasn't handled until
now.
The outside-of-a-repository case is one of three no-index cases. The
other two are when one of the files you're comparing is outside of the
repository you're in, and the --no-index option.
Signed-off-by: Jack Bates <jack@nottheoilrig.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-12-06 16:56:14 +00:00
|
|
|
# No-index --abbrev and --no-abbrev
|
|
|
|
diff --raw initial
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff --raw initial
|
diff: handle --no-abbrev in no-index case
There are two different places where the --no-abbrev option is parsed,
and two different places where SHA-1s are abbreviated. We normally parse
--no-abbrev with setup_revisions(), but in the no-index case, "git diff"
calls diff_opt_parse() directly, and diff_opt_parse() didn't handle
--no-abbrev until now. (It did handle --abbrev, however.) We normally
abbreviate SHA-1s with find_unique_abbrev(), but commit 4f03666 ("diff:
handle sha1 abbreviations outside of repository, 2016-10-20) recently
introduced a special case when you run "git diff" outside of a
repository.
setup_revisions() does also call diff_opt_parse(), but not for --abbrev
or --no-abbrev, which it handles itself. setup_revisions() sets
rev_info->abbrev, and later copies that to diff_options->abbrev. It
handles --no-abbrev by setting abbrev to zero. (This change doesn't
touch that.)
Setting abbrev to zero was broken in the outside-of-a-repository special
case, which until now resulted in a truly zero-length SHA-1, rather than
taking zero to mean do not abbreviate. The only way to trigger this bug,
however, was by running "git diff --raw" without either the --abbrev or
--no-abbrev options, because 1) without --raw it doesn't respect abbrev
(which is bizarre, but has been that way forever), 2) we silently clamp
--abbrev=0 to MINIMUM_ABBREV, and 3) --no-abbrev wasn't handled until
now.
The outside-of-a-repository case is one of three no-index cases. The
other two are when one of the files you're comparing is outside of the
repository you're in, and the --no-index option.
Signed-off-by: Jack Bates <jack@nottheoilrig.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-12-06 16:56:14 +00:00
|
|
|
diff --raw --abbrev=4 initial
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff --raw --abbrev=4 initial
|
diff: handle --no-abbrev in no-index case
There are two different places where the --no-abbrev option is parsed,
and two different places where SHA-1s are abbreviated. We normally parse
--no-abbrev with setup_revisions(), but in the no-index case, "git diff"
calls diff_opt_parse() directly, and diff_opt_parse() didn't handle
--no-abbrev until now. (It did handle --abbrev, however.) We normally
abbreviate SHA-1s with find_unique_abbrev(), but commit 4f03666 ("diff:
handle sha1 abbreviations outside of repository, 2016-10-20) recently
introduced a special case when you run "git diff" outside of a
repository.
setup_revisions() does also call diff_opt_parse(), but not for --abbrev
or --no-abbrev, which it handles itself. setup_revisions() sets
rev_info->abbrev, and later copies that to diff_options->abbrev. It
handles --no-abbrev by setting abbrev to zero. (This change doesn't
touch that.)
Setting abbrev to zero was broken in the outside-of-a-repository special
case, which until now resulted in a truly zero-length SHA-1, rather than
taking zero to mean do not abbreviate. The only way to trigger this bug,
however, was by running "git diff --raw" without either the --abbrev or
--no-abbrev options, because 1) without --raw it doesn't respect abbrev
(which is bizarre, but has been that way forever), 2) we silently clamp
--abbrev=0 to MINIMUM_ABBREV, and 3) --no-abbrev wasn't handled until
now.
The outside-of-a-repository case is one of three no-index cases. The
other two are when one of the files you're comparing is outside of the
repository you're in, and the --no-index option.
Signed-off-by: Jack Bates <jack@nottheoilrig.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-12-06 16:56:14 +00:00
|
|
|
diff --raw --no-abbrev initial
|
|
|
|
diff --no-index --raw dir2 dir
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff --no-index --raw dir2 dir
|
diff: handle --no-abbrev in no-index case
There are two different places where the --no-abbrev option is parsed,
and two different places where SHA-1s are abbreviated. We normally parse
--no-abbrev with setup_revisions(), but in the no-index case, "git diff"
calls diff_opt_parse() directly, and diff_opt_parse() didn't handle
--no-abbrev until now. (It did handle --abbrev, however.) We normally
abbreviate SHA-1s with find_unique_abbrev(), but commit 4f03666 ("diff:
handle sha1 abbreviations outside of repository, 2016-10-20) recently
introduced a special case when you run "git diff" outside of a
repository.
setup_revisions() does also call diff_opt_parse(), but not for --abbrev
or --no-abbrev, which it handles itself. setup_revisions() sets
rev_info->abbrev, and later copies that to diff_options->abbrev. It
handles --no-abbrev by setting abbrev to zero. (This change doesn't
touch that.)
Setting abbrev to zero was broken in the outside-of-a-repository special
case, which until now resulted in a truly zero-length SHA-1, rather than
taking zero to mean do not abbreviate. The only way to trigger this bug,
however, was by running "git diff --raw" without either the --abbrev or
--no-abbrev options, because 1) without --raw it doesn't respect abbrev
(which is bizarre, but has been that way forever), 2) we silently clamp
--abbrev=0 to MINIMUM_ABBREV, and 3) --no-abbrev wasn't handled until
now.
The outside-of-a-repository case is one of three no-index cases. The
other two are when one of the files you're comparing is outside of the
repository you're in, and the --no-index option.
Signed-off-by: Jack Bates <jack@nottheoilrig.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-12-06 16:56:14 +00:00
|
|
|
diff --no-index --raw --abbrev=4 dir2 dir
|
2017-12-03 21:27:43 +00:00
|
|
|
:noellipses diff --no-index --raw --abbrev=4 dir2 dir
|
diff: handle --no-abbrev in no-index case
There are two different places where the --no-abbrev option is parsed,
and two different places where SHA-1s are abbreviated. We normally parse
--no-abbrev with setup_revisions(), but in the no-index case, "git diff"
calls diff_opt_parse() directly, and diff_opt_parse() didn't handle
--no-abbrev until now. (It did handle --abbrev, however.) We normally
abbreviate SHA-1s with find_unique_abbrev(), but commit 4f03666 ("diff:
handle sha1 abbreviations outside of repository, 2016-10-20) recently
introduced a special case when you run "git diff" outside of a
repository.
setup_revisions() does also call diff_opt_parse(), but not for --abbrev
or --no-abbrev, which it handles itself. setup_revisions() sets
rev_info->abbrev, and later copies that to diff_options->abbrev. It
handles --no-abbrev by setting abbrev to zero. (This change doesn't
touch that.)
Setting abbrev to zero was broken in the outside-of-a-repository special
case, which until now resulted in a truly zero-length SHA-1, rather than
taking zero to mean do not abbreviate. The only way to trigger this bug,
however, was by running "git diff --raw" without either the --abbrev or
--no-abbrev options, because 1) without --raw it doesn't respect abbrev
(which is bizarre, but has been that way forever), 2) we silently clamp
--abbrev=0 to MINIMUM_ABBREV, and 3) --no-abbrev wasn't handled until
now.
The outside-of-a-repository case is one of three no-index cases. The
other two are when one of the files you're comparing is outside of the
repository you're in, and the --no-index option.
Signed-off-by: Jack Bates <jack@nottheoilrig.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-12-06 16:56:14 +00:00
|
|
|
diff --no-index --raw --no-abbrev dir2 dir
|
2018-02-24 14:09:59 +00:00
|
|
|
|
|
|
|
diff-tree --pretty --root --stat --compact-summary initial
|
|
|
|
diff-tree --pretty -R --root --stat --compact-summary initial
|
diff-tree.c: load notes machinery when required
Since its introduction in 7249e91 (revision.c: support --notes
command-line option, 2011-03-29), combining '--notes' with any option
that causes us to format notes (e.g., '--pretty', '--format="%N"', etc)
results in a failed assertion at runtime.
$ git rev-list HEAD | git diff-tree --stdin --pretty=medium --notes
commit 8f3d9f354286745c751374f5f1fcafee6b3f3136
git: notes.c:1308: format_display_notes: Assertion `display_notes_trees' failed.
Aborted
This failure is due to diff-tree not calling 'load_display_notes' to
initialize the notes machinery.
Ordinarily, this failure isn't triggered, because it requires passing
both '--notes' and another of the above mentioned options. In the case
of '--pretty', for example, we set 'opt->verbose_header', causing
'show_log()' to eventually call 'format_display_notes()', which expects
a non-NULL 'display_note_trees'.
Without initializing the notes machinery, 'display_note_trees' remains
NULL, and thus triggers an assertion failure.
Fix this by initializing the notes machinery after parsing our options,
and harden this behavior against regression with a test in t4013. (Note
that the added ref in this test requires updating two unrelated tests
which use 'log --all', and thus need to learn about the new refs).
Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-21 00:13:15 +00:00
|
|
|
diff-tree --pretty note
|
|
|
|
diff-tree --pretty --notes note
|
|
|
|
diff-tree --format=%N note
|
2018-02-24 14:09:59 +00:00
|
|
|
diff-tree --stat --compact-summary initial mode
|
|
|
|
diff-tree -R --stat --compact-summary initial mode
|
2006-06-26 20:46:52 +00:00
|
|
|
EOF
|
|
|
|
|
Revert 'diff-merges: let "-m" imply "-p"'
This reverts commit f5bfcc823ba242a46e20fb6f71c9fbf7ebb222fe, which
made "git log -m" imply "--patch" by default. The logic was that
"-m", which makes diff generation for merges perform a diff against
each parent, has no use unless I am viewing the diff, so we could save
the user some typing by turning on display of the resulting diff
automatically. That wasn't expected to adversely affect scripts
because scripts would either be using a command like "git diff-tree"
that already emits diffs by default or would be combining -m with a
diff generation option such as --name-status. By saving typing for
interactive use without adversely affecting scripts in the wild, it
would be a pure improvement.
The problem is that although diff generation options are only relevant
for the displayed diff, a script author can imagine them affecting
path limiting. For example, I might run
git log -w --format=%H -- README
hoping to list commits that edited README, excluding whitespace-only
changes. In fact, a whitespace-only change is not TREESAME so the use
of -w here has no effect (since we don't apply these diff generation
flags to the diff_options struct rev_info::pruning used for this
purpose), but the documentation suggests that it should work
Suppose you specified foo as the <paths>. We shall call
commits that modify foo !TREESAME, and the rest TREESAME. (In
a diff filtered for foo, they look different and equal,
respectively.)
and a script author who has not tested whitespace-only changes
wouldn't notice.
Similarly, a script author could include
git log -m --first-parent --format=%H -- README
to filter the first-parent history for commits that modified README.
The -m is a no-op but it reflects the script author's intent. For
example, until 1e20a407fe2 (stash list: stop passing "-m" to "git
log", 2021-05-21), "git stash list" did this.
As a result, we can't safely change "-m" to imply "-p" without fear of
breaking such scripts. Restore the previous behavior.
Noticed because Rust's src/bootstrap/bootstrap.py made use of this
same construct: https://github.com/rust-lang/rust/pull/87513. That
script has been updated to omit the unnecessary "-m" option, but we
can expect other scripts in the wild to have similar expectations.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-06 01:45:23 +00:00
|
|
|
test_expect_success 'log -m matches pure log' '
|
|
|
|
git log master >result &&
|
2021-05-20 21:46:54 +00:00
|
|
|
process_diffs result >expected &&
|
|
|
|
git log -m >result &&
|
|
|
|
process_diffs result >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2021-04-13 11:41:14 +00:00
|
|
|
test_expect_success 'log --diff-merges=on matches --diff-merges=separate' '
|
|
|
|
git log -p --diff-merges=separate master >result &&
|
|
|
|
process_diffs result >expected &&
|
|
|
|
git log -p --diff-merges=on master >result &&
|
|
|
|
process_diffs result >actual &&
|
2021-04-13 11:41:17 +00:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'deny wrong log.diffMerges config' '
|
|
|
|
test_config log.diffMerges wrong-value &&
|
|
|
|
test_expect_code 128 git log
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git config log.diffMerges first-parent' '
|
|
|
|
git log -p --diff-merges=first-parent master >result &&
|
|
|
|
process_diffs result >expected &&
|
|
|
|
test_config log.diffMerges first-parent &&
|
|
|
|
git log -p --diff-merges=on master >result &&
|
|
|
|
process_diffs result >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git config log.diffMerges first-parent vs -m' '
|
|
|
|
git log -p --diff-merges=first-parent master >result &&
|
|
|
|
process_diffs result >expected &&
|
|
|
|
test_config log.diffMerges first-parent &&
|
|
|
|
git log -p -m master >result &&
|
|
|
|
process_diffs result >actual &&
|
2021-04-13 11:41:14 +00:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2021-05-20 21:46:58 +00:00
|
|
|
# -m in "git diff-index" means "match missing", that differs
|
|
|
|
# from its meaning in "git diff". Let's check it in diff-index.
|
|
|
|
# The line in the output for removed file should disappear when
|
|
|
|
# we provide -m in diff-index.
|
|
|
|
test_expect_success 'git diff-index -m' '
|
|
|
|
rm -f file1 &&
|
|
|
|
git diff-index HEAD >without-m &&
|
|
|
|
lines_count=$(wc -l <without-m) &&
|
|
|
|
git diff-index -m HEAD >with-m &&
|
|
|
|
git restore file1 &&
|
|
|
|
test_line_count = $((lines_count - 1)) with-m
|
|
|
|
'
|
|
|
|
|
2010-08-05 08:22:52 +00:00
|
|
|
test_expect_success 'log -S requires an argument' '
|
|
|
|
test_must_fail git log -S
|
|
|
|
'
|
|
|
|
|
2011-02-03 06:23:34 +00:00
|
|
|
test_expect_success 'diff --cached on unborn branch' '
|
|
|
|
echo ref: refs/heads/unborn >.git/HEAD &&
|
|
|
|
git diff --cached >result &&
|
2020-02-07 00:52:40 +00:00
|
|
|
process_diffs result >actual &&
|
|
|
|
process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
|
|
|
|
test_cmp expected actual
|
2011-02-03 06:23:34 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff --cached -- file on unborn branch' '
|
|
|
|
git diff --cached -- file0 >result &&
|
2020-02-07 00:52:40 +00:00
|
|
|
process_diffs result >actual &&
|
|
|
|
process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
|
|
|
|
test_cmp expected actual
|
2011-02-03 06:23:34 +00:00
|
|
|
'
|
2016-08-31 23:27:20 +00:00
|
|
|
test_expect_success 'diff --line-prefix with spaces' '
|
|
|
|
git diff --line-prefix="| | | " --cached -- file0 >result &&
|
2020-02-07 00:52:40 +00:00
|
|
|
process_diffs result >actual &&
|
|
|
|
process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
|
|
|
|
test_cmp expected actual
|
2016-08-31 23:27:20 +00:00
|
|
|
'
|
2011-02-03 06:23:34 +00:00
|
|
|
|
2014-07-28 18:01:57 +00:00
|
|
|
test_expect_success 'diff-tree --stdin with log formatting' '
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
Side
|
|
|
|
Third
|
|
|
|
Second
|
|
|
|
EOF
|
|
|
|
git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2.36 gitk/diff-tree --stdin regression fix
This only surfaced as a regression after 2.36 release, but the
breakage was already there with us for at least a year.
The diff_free() call is to be used after we completely finished with
a diffopt structure. After "git diff A B" finishes producing
output, calling it before process exit is fine. But there are
commands that prepares diff_options struct once, compares two sets
of paths, releases resources that were used to do the comparison,
then reuses the same diff_option struct to go on to compare the next
two sets of paths, like "git log -p".
After "git log -p" finishes showing a single commit, calling it
before it goes on to the next commit is NOT fine. There is a
mechanism, the .no_free member in diff_options struct, to help "git
log" to avoid calling diff_free() after showing each commit and
instead call it just one. When the mechanism was introduced in
e900d494 (diff: add an API for deferred freeing, 2021-02-11),
however, we forgot to do the same to "diff-tree --stdin", which *is*
a moral equivalent to "git log".
During 2.36 release cycle, we started clearing the pathspec in
diff_free(), so programs like gitk that runs
git diff-tree --stdin -- <pathspec>
downstream of a pipe, processing one commit after another, started
showing irrelevant comparison outside the given <pathspec> from the
second commit. The same commit, by forgetting to teach the .no_free
mechanism, broke "diff-tree --stdin -I<regexp>" and nobody noticed
it for over a year, presumably because it is so seldom used an
option.
But <pathspec> is a different story. The breakage was very
prominently visible and was reported immediately after 2.36 was
released.
Fix this breakage by mimicking how "git log" utilizes the .no_free
member so that "diff-tree --stdin" behaves more similarly to "log".
Protect the fix with a few new tests.
Reported-by: Matthias Aßhauer <mha1993@live.de>
Helped-by: René Scharfe <l.s.r@web.de>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-04-26 16:11:44 +00:00
|
|
|
test_expect_success 'diff-tree --stdin with pathspec' '
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
Third
|
|
|
|
|
|
|
|
dir/sub
|
|
|
|
Second
|
|
|
|
|
|
|
|
dir/sub
|
|
|
|
EOF
|
|
|
|
git rev-list master^ |
|
|
|
|
git diff-tree -r --stdin --name-only --format=%s dir >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2.36 show regression fix
This only surfaced as a regression after 2.36 release, but the
breakage was already there with us for at least a year.
e900d494 (diff: add an API for deferred freeing, 2021-02-11)
introduced a mechanism to delay freeing resources held in
diff_options struct that need to be kept as long as the struct will
be reused to compute diff. "git log -p" was taught to utilize the
mechanism but it was done with an incorrect assumption that the
underlying helper function, cmd_log_walk(), is called only once,
and it is OK to do the freeing at the end of it.
Alas, for "git show A B", the function is called once for each
commit given, so it is not OK to free the resources until we finish
calling it for all the commits given from the command line.
During 2.36 release cycle, we started clearing the <pathspec> as
part of this freeing, which made the bug a lot more visible.
Fix this breakage by tweaking how cmd_log_walk() frees the resources
at the end and using a variant of it that does not immediately free
the resources to show each commit object from the command line in
"git show".
Protect the fix with a few new tests.
Reported-by: Daniel Li <dan@danielyli.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-04-30 05:29:51 +00:00
|
|
|
test_expect_success 'show A B ... -- <pathspec>' '
|
|
|
|
# side touches dir/sub, file0, and file3
|
|
|
|
# master^ touches dir/sub, and file1
|
|
|
|
# master^^ touches dir/sub, file0, and file2
|
|
|
|
git show --name-only --format="<%s>" side master^ master^^ -- dir >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<Side>
|
|
|
|
|
|
|
|
dir/sub
|
|
|
|
<Third>
|
|
|
|
|
|
|
|
dir/sub
|
|
|
|
<Second>
|
|
|
|
|
|
|
|
dir/sub
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-10-20 06:48:09 +00:00
|
|
|
test_expect_success 'diff -I<regex>: setup' '
|
|
|
|
git checkout master &&
|
|
|
|
test_seq 50 >file0 &&
|
|
|
|
git commit -m "Set up -I<regex> test file" file0 &&
|
|
|
|
test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 &&
|
|
|
|
echo >>file0
|
|
|
|
'
|
|
|
|
test_expect_success 'diff -I<regex>' '
|
|
|
|
git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
diff --git a/file0 b/file0
|
|
|
|
--- a/file0
|
|
|
|
+++ b/file0
|
|
|
|
@@ -34,7 +31,6 @@
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
|
-37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
EOF
|
|
|
|
compare_diff_patch expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff -I<regex> --stat' '
|
|
|
|
git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
file0 | 1 -
|
|
|
|
1 file changed, 1 deletion(-)
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff -I<regex>: detect malformed regex' '
|
|
|
|
test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error &&
|
|
|
|
test_i18ngrep "invalid regex given to -I: " error
|
|
|
|
'
|
|
|
|
|
2006-06-26 20:46:52 +00:00
|
|
|
test_done
|