Merge branch 'mm/diff-no-patch-synonym-to-s'
"git show -s" was less discoverable than it should be. * mm/diff-no-patch-synonym-to-s: Documentation/git-log.txt: capitalize section names Documentation: move description of -s, --no-patch to diff-options.txt Documentation/git-show.txt: include common diff options, like git-log.txt diff: allow --patch & cie to override -s/--no-patch diff: allow --no-patch as synonym for -s t4000-diff-format.sh: modernize style
This commit is contained in:
commit
e2ecd252b5
@ -26,6 +26,11 @@ ifndef::git-format-patch[]
|
|||||||
{git-diff? This is the default.}
|
{git-diff? This is the default.}
|
||||||
endif::git-format-patch[]
|
endif::git-format-patch[]
|
||||||
|
|
||||||
|
-s::
|
||||||
|
--no-patch::
|
||||||
|
Suppress diff output. Useful for commands like `git show` that
|
||||||
|
show the patch by default, or to cancel the effect of `--patch`.
|
||||||
|
|
||||||
-U<n>::
|
-U<n>::
|
||||||
--unified=<n>::
|
--unified=<n>::
|
||||||
Generate diffs with <n> lines of context instead of
|
Generate diffs with <n> lines of context instead of
|
||||||
|
@ -97,7 +97,7 @@ include::rev-list-options.txt[]
|
|||||||
|
|
||||||
include::pretty-formats.txt[]
|
include::pretty-formats.txt[]
|
||||||
|
|
||||||
Common diff options
|
COMMON DIFF OPTIONS
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
:git-log: 1
|
:git-log: 1
|
||||||
@ -105,7 +105,7 @@ include::diff-options.txt[]
|
|||||||
|
|
||||||
include::diff-generate-patch.txt[]
|
include::diff-generate-patch.txt[]
|
||||||
|
|
||||||
Examples
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
`git log --no-merges`::
|
`git log --no-merges`::
|
||||||
|
|
||||||
@ -161,12 +161,12 @@ Examples
|
|||||||
`git log -3`::
|
`git log -3`::
|
||||||
Limits the number of commits to show to 3.
|
Limits the number of commits to show to 3.
|
||||||
|
|
||||||
Discussion
|
DISCUSSION
|
||||||
----------
|
----------
|
||||||
|
|
||||||
include::i18n.txt[]
|
include::i18n.txt[]
|
||||||
|
|
||||||
Configuration
|
CONFIGURATION
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
See linkgit:git-config[1] for core variables and linkgit:git-diff[1]
|
See linkgit:git-config[1] for core variables and linkgit:git-diff[1]
|
||||||
|
@ -45,6 +45,15 @@ include::pretty-options.txt[]
|
|||||||
include::pretty-formats.txt[]
|
include::pretty-formats.txt[]
|
||||||
|
|
||||||
|
|
||||||
|
COMMON DIFF OPTIONS
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
:git-log: 1
|
||||||
|
include::diff-options.txt[]
|
||||||
|
|
||||||
|
include::diff-generate-patch.txt[]
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -849,7 +849,4 @@ options may be given. See linkgit:git-diff-files[1] for more options.
|
|||||||
-t::
|
-t::
|
||||||
|
|
||||||
Show the tree objects in the diff output. This implies '-r'.
|
Show the tree objects in the diff output. This implies '-r'.
|
||||||
|
|
||||||
-s::
|
|
||||||
Suppress diff output.
|
|
||||||
endif::git-rev-list[]
|
endif::git-rev-list[]
|
||||||
|
30
diff.c
30
diff.c
@ -3505,6 +3505,11 @@ static int parse_submodule_opt(struct diff_options *options, const char *value)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void enable_patch_output(int *fmt) {
|
||||||
|
*fmt &= ~DIFF_FORMAT_NO_OUTPUT;
|
||||||
|
*fmt |= DIFF_FORMAT_PATCH;
|
||||||
|
}
|
||||||
|
|
||||||
int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
||||||
{
|
{
|
||||||
const char *arg = av[0];
|
const char *arg = av[0];
|
||||||
@ -3512,15 +3517,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
int argcount;
|
int argcount;
|
||||||
|
|
||||||
/* Output format options */
|
/* Output format options */
|
||||||
if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch"))
|
if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
|
||||||
options->output_format |= DIFF_FORMAT_PATCH;
|
|| opt_arg(arg, 'U', "unified", &options->context))
|
||||||
else if (opt_arg(arg, 'U', "unified", &options->context))
|
enable_patch_output(&options->output_format);
|
||||||
options->output_format |= DIFF_FORMAT_PATCH;
|
|
||||||
else if (!strcmp(arg, "--raw"))
|
else if (!strcmp(arg, "--raw"))
|
||||||
options->output_format |= DIFF_FORMAT_RAW;
|
options->output_format |= DIFF_FORMAT_RAW;
|
||||||
else if (!strcmp(arg, "--patch-with-raw"))
|
else if (!strcmp(arg, "--patch-with-raw")) {
|
||||||
options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
|
enable_patch_output(&options->output_format);
|
||||||
else if (!strcmp(arg, "--numstat"))
|
options->output_format |= DIFF_FORMAT_RAW;
|
||||||
|
} else if (!strcmp(arg, "--numstat"))
|
||||||
options->output_format |= DIFF_FORMAT_NUMSTAT;
|
options->output_format |= DIFF_FORMAT_NUMSTAT;
|
||||||
else if (!strcmp(arg, "--shortstat"))
|
else if (!strcmp(arg, "--shortstat"))
|
||||||
options->output_format |= DIFF_FORMAT_SHORTSTAT;
|
options->output_format |= DIFF_FORMAT_SHORTSTAT;
|
||||||
@ -3542,13 +3547,14 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
options->output_format |= DIFF_FORMAT_CHECKDIFF;
|
options->output_format |= DIFF_FORMAT_CHECKDIFF;
|
||||||
else if (!strcmp(arg, "--summary"))
|
else if (!strcmp(arg, "--summary"))
|
||||||
options->output_format |= DIFF_FORMAT_SUMMARY;
|
options->output_format |= DIFF_FORMAT_SUMMARY;
|
||||||
else if (!strcmp(arg, "--patch-with-stat"))
|
else if (!strcmp(arg, "--patch-with-stat")) {
|
||||||
options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT;
|
enable_patch_output(&options->output_format);
|
||||||
else if (!strcmp(arg, "--name-only"))
|
options->output_format |= DIFF_FORMAT_DIFFSTAT;
|
||||||
|
} else if (!strcmp(arg, "--name-only"))
|
||||||
options->output_format |= DIFF_FORMAT_NAME;
|
options->output_format |= DIFF_FORMAT_NAME;
|
||||||
else if (!strcmp(arg, "--name-status"))
|
else if (!strcmp(arg, "--name-status"))
|
||||||
options->output_format |= DIFF_FORMAT_NAME_STATUS;
|
options->output_format |= DIFF_FORMAT_NAME_STATUS;
|
||||||
else if (!strcmp(arg, "-s"))
|
else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
|
||||||
options->output_format |= DIFF_FORMAT_NO_OUTPUT;
|
options->output_format |= DIFF_FORMAT_NO_OUTPUT;
|
||||||
else if (!prefixcmp(arg, "--stat"))
|
else if (!prefixcmp(arg, "--stat"))
|
||||||
/* --stat, --stat-width, --stat-name-width, or --stat-count */
|
/* --stat, --stat-width, --stat-name-width, or --stat-count */
|
||||||
@ -3621,7 +3627,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
|
|
||||||
/* flags options */
|
/* flags options */
|
||||||
else if (!strcmp(arg, "--binary")) {
|
else if (!strcmp(arg, "--binary")) {
|
||||||
options->output_format |= DIFF_FORMAT_PATCH;
|
enable_patch_output(&options->output_format);
|
||||||
DIFF_OPT_SET(options, BINARY);
|
DIFF_OPT_SET(options, BINARY);
|
||||||
}
|
}
|
||||||
else if (!strcmp(arg, "--full-index"))
|
else if (!strcmp(arg, "--full-index"))
|
||||||
|
@ -15,17 +15,17 @@ line 3'
|
|||||||
cat path0 >path1
|
cat path0 >path1
|
||||||
chmod +x path1
|
chmod +x path1
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'update-index --add two files with and without +x.' '
|
||||||
'update-index --add two files with and without +x.' \
|
git update-index --add path0 path1
|
||||||
'git update-index --add path0 path1'
|
'
|
||||||
|
|
||||||
mv path0 path0-
|
mv path0 path0-
|
||||||
sed -e 's/line/Line/' <path0- >path0
|
sed -e 's/line/Line/' <path0- >path0
|
||||||
chmod +x path0
|
chmod +x path0
|
||||||
rm -f path1
|
rm -f path1
|
||||||
test_expect_success \
|
test_expect_success 'git diff-files -p after editing work tree.' '
|
||||||
'git diff-files -p after editing work tree.' \
|
git diff-files -p >actual
|
||||||
'git diff-files -p >current'
|
'
|
||||||
|
|
||||||
# that's as far as it comes
|
# that's as far as it comes
|
||||||
if [ "$(git config --get core.filemode)" = false ]
|
if [ "$(git config --get core.filemode)" = false ]
|
||||||
@ -55,8 +55,38 @@ deleted file mode 100755
|
|||||||
-line 3
|
-line 3
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'validate git diff-files -p output.' '
|
||||||
'validate git diff-files -p output.' \
|
compare_diff_patch expected actual
|
||||||
'compare_diff_patch current expected'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git diff-files -s after editing work tree' '
|
||||||
|
git diff-files -s >actual 2>err &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
|
test_must_be_empty err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git diff-files --no-patch as synonym for -s' '
|
||||||
|
git diff-files --no-patch >actual 2>err &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
|
test_must_be_empty err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git diff-files --no-patch --patch shows the patch' '
|
||||||
|
git diff-files --no-patch --patch >actual &&
|
||||||
|
compare_diff_patch expected actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git diff-files --no-patch --patch-with-raw shows the patch and raw data' '
|
||||||
|
git diff-files --no-patch --patch-with-raw >actual &&
|
||||||
|
grep -q "^:100644 100755 .* 0000000000000000000000000000000000000000 M path0\$" actual &&
|
||||||
|
tail -n +4 actual >actual-patch &&
|
||||||
|
compare_diff_patch expected actual-patch
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git diff-files --patch --no-patch does not show the patch' '
|
||||||
|
git diff-files --patch --no-patch >actual 2>err &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
|
test_must_be_empty err
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user