Skip to content

Commit c332f44

Browse files
Martin von Zweigbergkpaulusmack
authored andcommitted
gitk: Fix file highlight when run in subdirectory
The "highlight this only" and "highlight this too" commands in gitk add the path relative to $GIT_WORK_TREE to the "Find" input box. When the search (using git-diff-tree) is run, the paths are used unmodified, except for some shell escaping. Since the search is run from gitk's working directory, no commits matching the paths will be found if gitk was started in a subdirectory. Make the paths passed to git-diff-tree relative to gitk's working directory instead of being relative to $GIT_WORK_TREE. If, however, gitk is run outside of the working directory (e.g. with $GIT_WORK_TREE set), we still need to use the path relative to $GIT_WORK_TREE. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent bb3e86a commit c332f44

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

gitk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4527,12 +4527,17 @@ proc makepatterns {l} {
45274527

45284528
proc do_file_hl {serial} {
45294529
global highlight_files filehighlight highlight_paths gdttype fhl_list
4530+
global cdup
45304531

45314532
if {$gdttype eq [mc "touching paths:"]} {
45324533
if {[catch {set paths [shellsplit $highlight_files]}]} return
45334534
set highlight_paths [makepatterns $paths]
45344535
highlight_filelist
4535-
set gdtargs [concat -- $paths]
4536+
set relative_paths {}
4537+
foreach path $paths {
4538+
lappend relative_paths [file join $cdup $path]
4539+
}
4540+
set gdtargs [concat -- $relative_paths]
45364541
} elseif {$gdttype eq [mc "adding/removing string:"]} {
45374542
set gdtargs [list "-S$highlight_files"]
45384543
} else {
@@ -11641,6 +11646,10 @@ set stuffsaved 0
1164111646
set patchnum 0
1164211647
set lserial 0
1164311648
set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
11649+
set cdup {}
11650+
if {$isworktree} {
11651+
set cdup [exec git rev-parse --show-cdup]
11652+
}
1164411653
setcoords
1164511654
makewindow
1164611655
catch {

0 commit comments

Comments
 (0)