Skip to content

Commit 74cb884

Browse files
Martin von Zweigbergkpaulusmack
authored andcommitted
gitk: Show modified files with separate work tree
"git rev-parse --is-inside-work-tree" is currently used to determine whether to show modified files in gitk (the red and green fake commits). This does not work if the current directory is not inside the work tree, as can be the case e.g. if GIT_WORK_TREE is set. Instead, check if the repository is not bare and that we are not inside the .git directory. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 86e847b commit 74cb884

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

gitk

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ exec wish "$0" -- "$@"
99

1010
package require Tk
1111

12+
proc hasworktree {} {
13+
return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
14+
[exec git rev-parse --is-inside-git-dir] == "false"}]
15+
}
16+
1217
# A simple scheduler for compute-intensive stuff.
1318
# The aim is to make sure that event handlers for GUI actions can
1419
# run at least every 50-100 ms. Unfortunately fileevent handlers are
@@ -459,11 +464,11 @@ proc updatecommits {} {
459464
global viewactive viewcomplete tclencoding
460465
global startmsecs showneartags showlocalchanges
461466
global mainheadid viewmainheadid viewmainheadid_orig pending_select
462-
global isworktree
467+
global hasworktree
463468
global varcid vposids vnegids vflags vrevs
464469
global show_notes
465470

466-
set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
471+
set hasworktree [hasworktree]
467472
rereadrefs
468473
set view $curview
469474
if {$mainheadid ne $viewmainheadid_orig($view)} {
@@ -5024,9 +5029,9 @@ proc dohidelocalchanges {} {
50245029
# spawn off a process to do git diff-index --cached HEAD
50255030
proc dodiffindex {} {
50265031
global lserial showlocalchanges vfilelimit curview
5027-
global isworktree
5032+
global hasworktree
50285033

5029-
if {!$showlocalchanges || !$isworktree} return
5034+
if {!$showlocalchanges || !$hasworktree} return
50305035
incr lserial
50315036
set cmd "|git diff-index --cached HEAD"
50325037
if {$vfilelimit($curview) ne {}} {
@@ -11633,9 +11638,9 @@ set stopped 0
1163311638
set stuffsaved 0
1163411639
set patchnum 0
1163511640
set lserial 0
11636-
set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
11641+
set hasworktree [hasworktree]
1163711642
set cdup {}
11638-
if {$isworktree} {
11643+
if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
1163911644
set cdup [exec git rev-parse --show-cdup]
1164011645
}
1164111646
set worktree [exec git rev-parse --show-toplevel]

0 commit comments

Comments
 (0)