Skip to content

Commit 3b9dfde

Browse files
committed
git-gui: Assume untracked directories are Git submodules
If `git ls-files --others` returned us the name of a directory then it is because Git has decided that this directory itself contains a valid Git repository and its files shouldn't be listed as untracked for this repository. In such a case we should label the object as a Git repository and not just as a directory. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 4ed1a19 commit 3b9dfde

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/diff.tcl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,30 @@ proc show_diff {path w {lno {}}} {
8484
#
8585
if {$m eq {_O}} {
8686
set max_sz [expr {128 * 1024}]
87+
set type unknown
8788
if {[catch {
88-
if {[file type $path] == {link}} {
89+
set type [file type $path]
90+
switch -- $type {
91+
directory {
92+
set type submodule
93+
set content {}
94+
set sz 0
95+
}
96+
link {
8997
set content [file readlink $path]
9098
set sz [string length $content]
91-
} else {
99+
}
100+
file {
92101
set fd [open $path r]
93102
fconfigure $fd -eofchar {}
94103
set content [read $fd $max_sz]
95104
close $fd
96105
set sz [file size $path]
97106
}
107+
default {
108+
error "'$type' not supported"
109+
}
110+
}
98111
} err ]} {
99112
set diff_active 0
100113
unlock_index
@@ -103,7 +116,9 @@ proc show_diff {path w {lno {}}} {
103116
return
104117
}
105118
$ui_diff conf -state normal
106-
if {![catch {set type [exec file $path]}]} {
119+
if {$type eq {submodule}} {
120+
$ui_diff insert end "* Git Repository (subproject)\n" d_@
121+
} elseif {![catch {set type [exec file $path]}]} {
107122
set n [string length $path]
108123
if {[string equal -length $n $path $type]} {
109124
set type [string range $type $n end]

0 commit comments

Comments
 (0)