Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHan Young <hanyang.tony@bytedance.com>2023-07-21 06:57:58 +0300
committerJunio C Hamano <gitster@pobox.com>2023-07-21 17:32:58 +0300
commit835950bd19260426f664a9b0164c580db9f9aacb (patch)
tree4da4e0ddf111a518fb2d95cee70e89806fae6a86 /blame.c
parentcba07a324d2cda06dd7a7b35b4579f800de024aa (diff)
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>
Diffstat (limited to 'blame.c')
-rw-r--r--blame.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/blame.c b/blame.c
index d12bd9f97b..141756975b 100644
--- a/blame.c
+++ b/blame.c
@@ -2806,7 +2806,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
parent_oid = &head_oid;
}
- setup_work_tree();
+ if (!sb->contents_from)
+ setup_work_tree();
+
sb->final = fake_working_tree_commit(sb->repo,
&sb->revs->diffopt,
sb->path, sb->contents_from,