Skip to content

Commit c80d25d

Browse files
committed
git-gui: Correct 'git gui blame' in a subdirectory
David Kastrup pointed out that the following sequence was not working as we had intended: $ cd lib $ git gui blame console.tcl fatal: cannot stat path lib/console.tcl: No such file or directory The problem here was we disabled the chdir to the root of the working tree when we are running with a "bare allowed" feature such as blame or browser, but we still kept the prefix we found via `git rev-parse --show-prefix`. This caused us to try and look for the file "console.tcl" within the subdirectory but also include the subdirectory's own path from the root of the working tree. This is unlikely to succeed, unless the user just happened to have a "lib/lib/console.tcl" file in the repository, in which case we would produce the wrong result. In the case of a bare repository we shouldn't get back a value from `rev-parse --show-prefix`, so really $_prefix should only be set to the non-empty string if we are in a working tree and we are in a subdirectory of that working tree. If this is true we really want to always be at the top level of the working tree, as all paths are accessed as though they were relative to the top of the working tree. Converting $_prefix to a ../ sequence is a fairly simple approach to moving up the requisite levels. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 9c9f5fa commit c80d25d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

git-gui.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,15 @@ if {![file isdirectory $_gitdir]} {
703703
error_popup "Git directory not found:\n\n$_gitdir"
704704
exit 1
705705
}
706-
if {![is_enabled bare]} {
706+
if {$_prefix ne {}} {
707+
regsub -all {[^/]+/} $_prefix ../ cdup
708+
if {[catch {cd $cdup} err]} {
709+
catch {wm withdraw .}
710+
error_popup "Cannot move to top of working directory:\n\n$err"
711+
exit 1
712+
}
713+
unset cdup
714+
} elseif {![is_enabled bare]} {
707715
if {[lindex [file split $_gitdir] end] ne {.git}} {
708716
catch {wm withdraw .}
709717
error_popup "Cannot use funny .git directory:\n\n$_gitdir"

0 commit comments

Comments
 (0)