Skip to content

Commit

Permalink
builtin/show: do not prune by pathspec
Browse files Browse the repository at this point in the history
By design, "git show commit -- path" is not "git show commit:path", and
there is no reason to change that. But "git show commit -- path" simply
returns nothing at all "most of the time" because it prunes by pathspec
even though it does not walk commits. This is pretty useless.

So, turn off commit pruning (but keep diff limiting of course) so that
"git show commit -- path" shows the commit message and the diff that the
commit introduces to path (filtered by path); only the diff will be
empty "most of the time".

As an intended side effect, users mistaking "git show commit -- path"
for "git show commit:path" are automatically reminded that they asked
git to show a commit, not a blob.

In case the user has specified "--do-walk", assume they want the old
behaviour (prune by default).

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
  • Loading branch information
Michael J Gruber authored and mjg committed Apr 18, 2024
1 parent 701ccde commit 664a0fe
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ int cmd_show(int argc, const char **argv, const char *prefix)
opt.def = "HEAD";
opt.tweak = show_setup_revisions_tweak;
cmd_log_init(argc, argv, prefix, &rev, &opt);
if (rev.no_walk)
rev.prune = 0;

if (!rev.no_walk)
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
Expand Down

0 comments on commit 664a0fe

Please sign in to comment.