]> git.ipfire.org Git - thirdparty/git.git/commit - blame.c
blame: allow --contents to work with bare repo
authorHan Young <hanyang.tony@bytedance.com>
Fri, 21 Jul 2023 03:57:58 +0000 (11:57 +0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Jul 2023 14:32:58 +0000 (07:32 -0700)
commit835950bd19260426f664a9b0164c580db9f9aacb
tree4da4e0ddf111a518fb2d95cee70e89806fae6a86
parentcba07a324d2cda06dd7a7b35b4579f800de024aa
blame: allow --contents to work with bare repo

The --contents option can be used with git blame to blame the file
as if it had the contents from the specified file. Since 1a3119ed
(blame: allow --contents to work with non-HEAD commit, 2023-03-24),
the --contents option can work with non-HEAD commit. However, if you
try to use --contents in a bare repository, you get the following
error:

    fatal: this operation must be run in a work tree

This is because before trying to generate a fake working tree
commit, we always call setup_work_tree(). But in a bare repo,
working tree is not available. The call to setup_work_tree is used
to prepare the reading of the blamed file in the working tree, which
isn't necessary if we are reading the contents from the specific
file instead of the file in the working tree.

Add a check in setup_scoreboard to skip setup_work_tree if we are
reading from the file specified in --contents.

This enables us to use --contents in a bare repo. This is a nice
addition on top of 1a3119ed, having a working tree to use --contents
is optional.

Add test for the --contents option with bare repo to the
annotate-tests.sh test script.

Signed-off-by: Han Young <hanyang.tony@bytedance.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
blame.c
t/annotate-tests.sh