121
122
set _appname {Git Gui}
123
set _gitdir {}
124
+set _gitworktree {}
125
set _gitexec {}
126
set _githtmldir {}
127
set _reponame {}
1101
error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1102
exit 1
1103
}
1104
+# _gitdir exists, so try loading the config
1105
+load_config 0
1106
+apply_config
1107
+# try to set work tree from environment, falling back to core.worktree
1108
+if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1109
+ set _gitworktree [get_config core.worktree]
1110
+}
1111
if {$_prefix ne {}} {
1104
- regsub -all {[^/]+/} $_prefix ../ cdup
1112
+ if {$_gitworktree eq {}} {
1113
+ regsub -all {[^/]+/} $_prefix ../ cdup
1114
+ } else {
1115
+ set cdup $_gitworktree
1116
+ }
1117
if {[catch {cd $cdup} err]} {
1118
catch {wm withdraw .}
1119
error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1120
exit 1
1121
}
1122
+ set _gitworktree [pwd]
1123
unset cdup
1124
} elseif {![is_enabled bare]} {
1125
if {[lindex [file split $_gitdir] end] ne {.git}} {
1127
error_popup [strcat [mc "Cannot use funny .git directory:"] "\n\n$_gitdir"]
1128
exit 1
1129
}
1117
- if {[catch {cd [file dirname $_gitdir]} err]} {
1130
+ if {$_gitworktree eq {}} {
1131
+ set _gitworktree [file dirname $_gitdir]
1132
+ }
1133
+ if {[catch {cd $_gitworktree} err]} {
1134
catch {wm withdraw .}
1119
- error_popup [strcat [mc "No working directory"] " [file dirname $_gitdir]:\n\n$err"]
1135
+ error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1136
exit 1
1137
}
1138
+ set _gitworktree [pwd]
1139
}
1140
set _reponame [file split [file normalize $_gitdir]]
1141
if {[lindex $_reponame end] eq {.git}} {
1952
1953
proc do_gitk {revs {is_submodule false}} {
1954
global current_diff_path file_states current_diff_side ui_index
1955
+ global _gitworktree
1956
1957
# -- Always start gitk through whatever we were loaded with. This
1958
# lets us bypass using shell process on Windows systems.
1973
set pwd [pwd]
1974
1975
if {!$is_submodule} {
1958
- cd [file dirname [gitdir]]
1959
- set env(GIT_DIR) [file tail [gitdir]]
1976
+ if {$_gitworktree ne {}} {
1977
+ cd $_gitworktree
1978
+ }
1979
+ set env(GIT_DIR) [file normalize [gitdir]]
1980
} else {
1981
cd $current_diff_path
1982
if {$revs eq {--}} {
2052
}
2053
2054
proc do_explore {} {
2055
+ global _gitworktree
2056
set explorer {}
2057
if {[is_Cygwin] || [is_Windows]} {
2058
set explorer "explorer.exe"
2062
# freedesktop.org-conforming system is our best shot
2063
set explorer "xdg-open"
2064
}
2044
- eval exec $explorer [list [file nativename [file dirname [gitdir]]]] &
2065
+ eval exec $explorer $_gitworktree &
2066
}
2067
2068
set is_quitting 0
2426
##
2427
## ui construction
2428
2408
-load_config 0
2409
-apply_config
2429
set ui_comm {}
2430
2431
# -- Menu Bar
3511
set file_lists($ui_index) [list]
3512
set file_lists($ui_workdir) [list]
3513
3495
-wm title . "[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"
3514
+wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3515
focus -force $ui_comm
3516
3517
# -- Warn the user about environmental problems. Cygwin's Tcl