如何“推卸责任”在远程端存储库上?

发布于 2024-10-02 08:33:52 字数 233 浏览 3 评论 0 原文

在我的服务器上,我托管我的个人 git 远程项目(使用 gitosis),并且我构建了一个 Web 界面来浏览存储库(类似于 Github)。

在远程端,您不允许做很多事情,因为缺少工作树,这是正确的:顺便说一句,对于存储库资源管理器,只需很少的命令我就可以做几乎所有事情。

除了gitblame

我无法找出如何在远程端存储库中归咎于没有工作树的文件。你有什么想法吗?

on my server I host my personal git remote-side projects (with gitosis), and I have built a web interface to browse the repositories (something like Github).

On the remote-side, you are not allowed to do a lot of stuff, because a working tree is missing, and this is correct: btw, for a repository explorer, with few commands I can do almost everything.

Except for git blame.

I'm not able to find out how to blame a file without a working tree, within the remote-side repository. Got you some ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音盲 2024-10-09 08:33:52

即使在裸存储库中,以下内容也应该有效:

git blame <rev> -- <path>

例如

git blame master -- README.txt

The following should work even in bare repositories:

git blame <rev> -- <path>

E.g.

git blame master -- README.txt
ゃ懵逼小萝莉 2024-10-09 08:33:52

我找不到 git 文档谈论 -- 选项的地方,顺便说一句,这很有效

实际上,这是必要的,因为“git Blame”准备采取
古代奇怪的参数顺序“blame ”除了
通常的“责备[] ”。

这意味着,Git 2.17(2018 年第 2 季度)将解释裸存储库中的“git Blame HEAD COPYING”无法运行,而“git Blame HEAD -- COPYING”运行很好。

但从 2.17 开始,您将不再需要“--”。

请参阅 提交 0c668f5(2018 年 2 月 5 日),作者:Junio C Hamano (gitster)
(由 Junio C Hamano -- gitster -- 合并于 提交 0c668f5,2018 年 2 月 7 日)

blame:加强命令行解析器

除了
通常的“blame [] ”至少有两个否定
后果:

  • 为了区分这两个命令,它会检查最后一个命令是否
    line 参数命名工作树中的路径,使用
    file_exists()
    然而,“blame ”是一个请求
    解释存储在 的内容中的每一行
    修订版 并且不需要有工作树版本
    文件的。使用 file_exists() 进行检查是完全错误的。

  • 为了强制错误的 file_exists() 检查工作,代码
    在此之前调用 setup_work_tree() ,因为它的路径
    相对于项目树的顶层。
    然而,“blame ”即使在裸存储库中也必须可用,
    并且没有理由让 setup_work_tree() 抱怨
    并死于“此操作必须在工作树中运行”。



要更正前者,请切换到检查最后一个标记是否是
修订(如果是这样,则使用“blame ”解析参数
规则)。

通过删除 setup_work_tree() 来纠正后者并
file_exists() 检查——调用此函数的唯一情况
是当我们运行“blame ”时(即没有启动修订版并且
要求将工作树文件归咎于 ,挖掘
HEAD 修订版),但在 setup_scoreboard() 中有一个调用
在调用 fake_working_tree_commit() 之前。

简而言之,从 Git 2.17 开始,这将在裸存储库中工作:

git blame master -- README.txt

而使用 Git 2.22,错误消息“此操作必须在工作树中运行”应该消失!

非裸存储库中的“gitblame --path”开始从工作树进行指责,并且裸存储库中的相同命令会出错,因为根据定义没有工作树。
该命令已被教导从 HEAD 处的提交开始指责,
哪个更有用。

请参阅 提交 a544fb0(2019 年 4 月 7 日),作者:SZEDER Gábor (szeder)
(由 Junio C Hamano -- gitster -- 合并于 提交 d8620d3,2019 年 4 月 25 日)

blame:当没有给出开始提交时,默认为裸存储库中的 HEAD

当在未指定要开始的提交的情况下调用“gitblame”时
指责从,它从工作树中给定文件的状态开始。
但是,当在没有开始提交的裸存储库中调用时,
那么就没有工作树状态可以开始,并且它会随着
以下错误消息:

$ git rev-parse --is-bare-repository
  真的
$ git Blame 文件.c
  致命:此操作必须在工作树中运行

这是误导性的,因为它暗示“gitblame”不起作用
完全在裸存储库中,但事实上,当
它被赋予了一个开始的提交。

当然,我们可以改进错误消息,但我们只是默认在裸存储库中使用 HEAD,因为这很可能是用户想要的(如果他们想从其他提交开始,那么他们就会有首先指定这一点)。

'git annotate' 只是 'gitblame' 的一个薄包装,所以在
同样的情况它打印了相同的误导性错误消息,并且这个
补丁也修复了它。


注意:如果您使用 gitweb 查看“指责”,如 Jakub Narębski推荐,gitweb中有一个相当老的错误,其中 javascript 操作模式下的增量指责输出从未起作用。
Git 2.24(2019 年第 4 季度)已修复此问题。

请参阅 提交 52bd3e4(2019 年 10 月 27 日),作者:罗伯特·卢伯达 (roblub)
(由 Junio C Hamano -- gitster -- 合并于 提交 0d6799e,2019 年 10 月 30 日)

gitweb:在javascript中正确存储以前的版本- 动作模式

签署人:Jonathan Nieder
签字人:罗伯特·卢贝尔达
确认者:Jakub Narębski

如果没有此更改,设置

$feature{'javascript-actions'}{'default'} = [2];

gitweb.conf中破坏了gitweb的指责页面:单击页面第二列中显示的行号没有任何效果

为了进行比较,在禁用 javascript-actions 的情况下,单击行号会加载该行的先前版本。

地址https://bugs.debian.org/741883


使用 Git 2.42(2023 年第 3 季度),“git Blame --contents=文件"(man) 已被教导如何在裸存储库中工作。

请参阅 提交 835950b(2023 年 7 月 21 日),作者:Han Young (eseedo)
(由 Junio C Hamano -- gitster -- 合并于 提交 f4a7c24,2023 年 8 月 4 日)

责备:允许--内容与裸存储库一起使用

签字人:韩永

--contents 选项可以与 git Blame( man) 责备该文件,就好像它具有指定文件中的内容一样。
由于 1a3119e ("blame: 允许 - -contents 处理非 HEAD 提交”,2023-03-24,Git v2.41.0-rc0 -- 合并列在第7批中) ,--contents 选项可以与非 HEAD 提交一起使用。
但是,如果您尝试在裸存储库中使用 --contents ,则会收到以下错误:

致命:此操作必须在工作树中运行

这是因为在尝试生成虚假工作树提交之前,我们总是调用 setup_work_tree()
但在裸仓库中,工作树不可用。
对setup_work_tree的调用用于准备读取工作树中的受责备文件,如果我们从特定文件而不是工作树中的文件读取内容,则不需要这样做。

setup_scoreboard 中添加一个检查,以便在我们从 --contents 中指定的文件读取时跳过 setup_work_tree

这使我们能够在裸存储库中使用 --contents
这是对 1a3119e 的一个很好的补充,有一个可以使用的工作树--contents 是可选的。

将带有裸存储库的 --contents 选项的测试添加到 annotate-tests.sh 测试脚本中。

I'm not able to find where the git docs talk about -- option, by the way this works greatly

Actually, this is necessary because "git blame" is prepared to take an
ancient odd argument order "blame <path> <rev>" in addition to the
usual "blame [<rev>] <path>".

That means, as Git 2.17 (Q2 2018) will explain "git blame HEAD COPYING" in a bare repository failed to run, while "git blame HEAD -- COPYING" run just fine.

But from 2.17 on, you won't need '--' anymore.

See commit 0c668f5 (05 Feb 2018) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 0c668f5, 07 Feb 2018)

blame: tighten command line parser

An ancient odd argument order "blame <path> <rev>" in addition to the
usual "blame [<rev>] <path>" has at least two negative
ramifications:

  • In order to tell these two apart, it checks if the last command
    line argument names a path in the working tree, using
    file_exists().
    However, "blame <rev> <path>" is a request to
    explain each and every line in the contents of <path> stored in
    revision <rev> and does not need to have a working tree version
    of the file. A check with file_exists() is simply wrong.

  • To coerce that mistaken file_exists() check to work, the code
    calls setup_work_tree() before doing so, because the path it has
    is relative to the top-level of the project tree.
    However, "blame <rev> <path>" MUST be usable even in a bare repository,
    and there is no reason for letting setup_work_tree() complain
    and die with "This operation must be run in a work tree".

To correct the former, switch to check if the last token is a
revision (and if so, parse arguments using "blame <path> <rev>"
rule).

Correct the latter by getting rid of setup_work_tree() and
file_exists() check--the only case the call to this function matters
is when we are running "blame <path>" (i.e. no starting revision and
asking to blame the working tree file at <path>, digging through the
HEAD revision), but there is a call in setup_scoreboard() just
before it calls fake_working_tree_commit().

So in short, starting Git 2.17, this will work in a bare repo:

git blame master -- README.txt

And with Git 2.22, the error message "This operation must be run in a work tree" should disappear!

"git blame -- path" in a non-bare repository starts blaming from the working tree, and the same command in a bare repository errors out because there is no working tree by definition.
The command has been taught to instead start blaming from the commit at HEAD,
which is more useful.

See commit a544fb0 (07 Apr 2019) by SZEDER Gábor (szeder).
(Merged by Junio C Hamano -- gitster -- in commit d8620d3, 25 Apr 2019)

blame: default to HEAD in a bare repo when no start commit is given

When 'git blame' is invoked without specifying the commit to start
blaming from, it starts from the given file's state in the work tree.
However, when invoked in a bare repository without a start commit,
then there is no work tree state to start from, and it dies with the
following error message:

$ git rev-parse --is-bare-repository
  true
$ git blame file.c
  fatal: this operation must be run in a work tree

This is misleading, because it implies that 'git blame' doesn't work
in bare repositories at all, but it does, in fact, work just fine when
it is given a commit to start from.

We could improve the error message, of course, but let's just default to HEAD in a bare repository instead, as most likely that is what the user wanted anyway (if they wanted to start from an other commit, then they would have specified that in the first place).

'git annotate' is just a thin wrapper around 'git blame', so in the
same situation it printed the same misleading error message, and this
patch fixes it, too.


Note: if you are using gitweb to see the "blames", as recommended by Jakub Narębski, there is a rather old bug in gitweb, where the incremental blame output in javascript actions mode never worked.
This is fixed with Git 2.24 (Q4 2019).

See commit 52bd3e4 (27 Oct 2019) by Robert Luberda (roblub).
(Merged by Junio C Hamano -- gitster -- in commit 0d6799e, 30 Oct 2019)

gitweb: correctly store previous rev in javascript-actions mode

Signed-off-by: Jonathan Nieder
Signed-off-by: Robert Luberda
Acked-by: Jakub Narębski

Without this change, the setting

$feature{'javascript-actions'}{'default'} = [2];

in gitweb.conf breaks gitweb's blame page: clicking on line numbers displayed in the second column on the page has no effect.

For comparison, with javascript-actions disabled, clicking on line numbers loads the previous version of the line.

Addresses https://bugs.debian.org/741883.


With Git 2.42 (Q3 2023), "git blame --contents=file"(man) has been taught to work in a bare repository.

See commit 835950b (21 Jul 2023) by Han Young (eseedo).
(Merged by Junio C Hamano -- gitster -- in commit f4a7c24, 04 Aug 2023)

blame: allow --contents to work with bare repo

Signed-off-by: Han Young

The --contents option can be used with git blame(man) to blame the file as if it had the contents from the specified file.
Since 1a3119e ("blame: allow --contents to work with non-HEAD commit", 2023-03-24, Git v2.41.0-rc0 -- merge listed in batch #7), 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 1a3119e, 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文