3

I used to be able to run gitk on bare directory on remote server.

I got a new Win10 machine, installed git from git-scm .com That gave me git and git Bash. Now when I go to the same remote server

 MINGW64 /t/git/MyProject (BARE:master)$ gitk

gitk says fatal: this operation mus be run in a work tree

I kind of understand what's going on, and yes I can do $ git log

But why did it work before?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
shlasasha
  • 165
  • 1
  • 14

2 Answers2

3

But why did it work before?

A recent change in the behavoir of git

git rev-parse --show-toplevel

broke gitk. This can be found wehn following down the original bug report.

I recommend downgrading to version 2.24.1.windows.2 which is the most recent that doesnt have it.

hefe
  • 46
  • 1
  • At my work with Windows 10, gitk works on a bare repository - sometimes. e.g. for our 75 repos on this remote server, ~40-50 work with gitk with the others reporting this message above – J-Dizzle Aug 31 '23 at 11:25
1
gitk says fatal: this operation mus be run in a work tree

With Git 2.29 (Q4 2020), "gitk" should fix this issue when run in a bare repository.

See commit a99bc27 (15 Dec 2019), and commit f177c49 (02 Nov 2019) by Роман Донченко (SpecLad).
See commit 2faa6cd (09 Apr 2020) by Johannes Sixt (j6t).
See commit 113ce12 (11 Feb 2020) by Stefan Dotterweich (stefandtw).
See commit c1a6345 (15 Oct 2019) by Eric Huber (echuber2).
See commit d4247e0 (07 Dec 2019) by Kazuhiro Kato (kkato233).
See commit b8b6095 (12 Dec 2019) by Beat Bolli (bbolli).
See commit e2b9cb1 (03 Oct 2020), and commit e272a77 (23 Jan 2020) by Junio C Hamano (gitster).
See commit 6cd8049 (03 Oct 2020) by Paul Mackerras (paulusmack).
See commit e244588 (10 Sep 2020) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 0cf28f6, 05 Oct 2020)

gitk: be prepared to be run in a bare repository

Helped-by: Eric Sunshine
Signed-off-by: Paul Mackerras

784b7e2f ("gitk: Fix "External diff" with separate work tree", 2011-04-04, Git v1.7.9-rc0) added an unconditional call to "git rev-parse --show-toplevel(man)" to set up a global variable quite early in the course of the program, so that the location of the working tree can later be known if/when the user chooses to run the external diff via the external_diff_get_one_file proc.
Before that change, the external diff code used to assume that the parent directory of ".git" directory is the top-level of the working tree.

Recent versions of git(man) however notices that "rev-parse --show-toplevel" executed in a bare repository is an error, which makes gitk stop, even before the user could attempt to run external diff.

Use the gitworktree helper introduced in 65bb0bda ("gitk: Fix the display of files when filtered by path", 2011-12-13, Git v1.7.10-rc3 -- merge), which is prepared to see failures from "rev-parse --show-toplevel" and other means it tries to find the top-level of the working tree instead to work around this issue.
The resulting value in $worktree global, when run in a bare repository, is bogus, but the code is not prepared to run external diff correctly without a working tree anyway ;-)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250