git gui: set GIT_ASKPASS=git-gui--askpass if not set yet
[git/dscho.git] / git-gui / git-gui.sh
blob0ac2d37f224a31b7fe2f4a7b2a2a5f13a5db0c23
1 #!/bin/sh
2 # Tcl ignores the next line -*- tcl -*- \
3 if test "z$*" = zversion \
4 || test "z$*" = z--version; \
5 then \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
7 exit; \
8 fi; \
9 argv0=$0; \
10 exec wish "$argv0" -- "$@"
12 set appvers {@@GITGUI_VERSION@@}
13 set copyright [string map [list (c) \u00a9] {
14 Copyright (c) 2006-2010 Shawn Pearce, et. al.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}]
30 ######################################################################
32 ## Tcl/Tk sanity check
34 if {[catch {package require Tcl 8.4} err]
35 || [catch {package require Tk 8.4} err]
36 } {
37 catch {wm withdraw .}
38 tk_messageBox \
39 -icon error \
40 -type ok \
41 -title "git-gui: fatal error" \
42 -message $err
43 exit 1
46 catch {rename send {}} ; # What an evil concept...
48 ######################################################################
50 ## locate our library
52 set oguilib {@@GITGUI_LIBDIR@@}
53 set oguirel {@@GITGUI_RELATIVE@@}
54 if {$oguirel eq {1}} {
55 set oguilib [file dirname [file normalize $argv0]]
56 if {[file tail $oguilib] eq {git-core}} {
57 set oguilib [file dirname $oguilib]
59 set oguilib [file dirname $oguilib]
60 set oguilib [file join $oguilib share git-gui lib]
61 set oguimsg [file join $oguilib msgs]
62 } elseif {[string match @@* $oguirel]} {
63 set oguilib [file join [file dirname [file normalize $argv0]] lib]
64 set oguimsg [file join [file dirname [file normalize $argv0]] po]
65 } else {
66 set oguimsg [file join $oguilib msgs]
68 unset oguirel
70 ######################################################################
72 ## enable verbose loading?
74 if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
75 unset _verbose
76 rename auto_load real__auto_load
77 proc auto_load {name args} {
78 puts stderr "auto_load $name"
79 return [uplevel 1 real__auto_load $name $args]
81 rename source real__source
82 proc source {name} {
83 puts stderr "source $name"
84 uplevel 1 real__source $name
86 if {[tk windowingsystem] eq "win32"} { console show }
89 ######################################################################
91 ## Internationalization (i18n) through msgcat and gettext. See
92 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
94 package require msgcat
96 proc _mc_trim {fmt} {
97 set cmk [string first @@ $fmt]
98 if {$cmk > 0} {
99 return [string range $fmt 0 [expr {$cmk - 1}]]
101 return $fmt
104 proc mc {en_fmt args} {
105 set fmt [_mc_trim [::msgcat::mc $en_fmt]]
106 if {[catch {set msg [eval [list format $fmt] $args]} err]} {
107 set msg [eval [list format [_mc_trim $en_fmt]] $args]
109 return $msg
112 proc strcat {args} {
113 return [join $args {}]
116 ::msgcat::mcload $oguimsg
117 unset oguimsg
119 ######################################################################
121 ## read only globals
123 set _appname {Git Gui}
124 set _gitdir {}
125 set _gitworktree {}
126 set _isbare {}
127 set _gitexec {}
128 set _githtmldir {}
129 set _reponame {}
130 set _iscygwin {}
131 set _search_path {}
132 set _shellpath {@@SHELL_PATH@@}
134 set _trace [lsearch -exact $argv --trace]
135 if {$_trace >= 0} {
136 set argv [lreplace $argv $_trace $_trace]
137 set _trace 1
138 } else {
139 set _trace 0
142 proc shellpath {} {
143 global _shellpath env
144 if {[string match @@* $_shellpath]} {
145 if {[info exists env(SHELL)]} {
146 return $env(SHELL)
147 } else {
148 return /bin/sh
151 return $_shellpath
154 proc appname {} {
155 global _appname
156 return $_appname
159 proc gitdir {args} {
160 global _gitdir
161 if {$args eq {}} {
162 return $_gitdir
164 return [eval [list file join $_gitdir] $args]
167 proc gitexec {args} {
168 global _gitexec
169 if {$_gitexec eq {}} {
170 if {[catch {set _gitexec [git --exec-path]} err]} {
171 error "Git not installed?\n\n$err"
173 if {[is_Cygwin]} {
174 set _gitexec [exec cygpath \
175 --windows \
176 --absolute \
177 $_gitexec]
178 } else {
179 set _gitexec [file normalize $_gitexec]
182 if {$args eq {}} {
183 return $_gitexec
185 return [eval [list file join $_gitexec] $args]
188 proc githtmldir {args} {
189 global _githtmldir
190 if {$_githtmldir eq {}} {
191 if {[catch {set _githtmldir [git --html-path]}]} {
192 # Git not installed or option not yet supported
193 return {}
195 if {[is_Cygwin]} {
196 set _githtmldir [exec cygpath \
197 --windows \
198 --absolute \
199 $_githtmldir]
200 } else {
201 set _githtmldir [file normalize $_githtmldir]
204 if {$args eq {}} {
205 return $_githtmldir
207 return [eval [list file join $_githtmldir] $args]
210 proc reponame {} {
211 return $::_reponame
214 proc is_MacOSX {} {
215 if {[tk windowingsystem] eq {aqua}} {
216 return 1
218 return 0
221 proc is_Windows {} {
222 if {$::tcl_platform(platform) eq {windows}} {
223 return 1
225 return 0
228 proc is_Cygwin {} {
229 global _iscygwin
230 if {$_iscygwin eq {}} {
231 if {$::tcl_platform(platform) eq {windows}} {
232 if {[catch {set p [exec cygpath --windir]} err]} {
233 set _iscygwin 0
234 } else {
235 set _iscygwin 1
237 } else {
238 set _iscygwin 0
241 return $_iscygwin
244 proc is_enabled {option} {
245 global enabled_options
246 if {[catch {set on $enabled_options($option)}]} {return 0}
247 return $on
250 proc enable_option {option} {
251 global enabled_options
252 set enabled_options($option) 1
255 proc disable_option {option} {
256 global enabled_options
257 set enabled_options($option) 0
260 ######################################################################
262 ## config
264 proc is_many_config {name} {
265 switch -glob -- $name {
266 gui.recentrepo -
267 remote.*.fetch -
268 remote.*.push
269 {return 1}
271 {return 0}
275 proc is_config_true {name} {
276 global repo_config
277 if {[catch {set v $repo_config($name)}]} {
278 return 0
279 } elseif {$v eq {true} || $v eq {1} || $v eq {yes}} {
280 return 1
281 } else {
282 return 0
286 proc is_config_false {name} {
287 global repo_config
288 if {[catch {set v $repo_config($name)}]} {
289 return 0
290 } elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
291 return 1
292 } else {
293 return 0
297 proc get_config {name} {
298 global repo_config
299 if {[catch {set v $repo_config($name)}]} {
300 return {}
301 } else {
302 return $v
306 proc is_bare {} {
307 global _isbare
308 global _gitdir
309 global _gitworktree
311 if {$_isbare eq {}} {
312 if {[catch {
313 set _bare [git rev-parse --is-bare-repository]
314 switch -- $_bare {
315 true { set _isbare 1 }
316 false { set _isbare 0}
317 default { throw }
319 }]} {
320 if {[is_config_true core.bare]
321 || ($_gitworktree eq {}
322 && [lindex [file split $_gitdir] end] ne {.git})} {
323 set _isbare 1
324 } else {
325 set _isbare 0
329 return $_isbare
332 ######################################################################
334 ## handy utils
336 proc _trace_exec {cmd} {
337 if {!$::_trace} return
338 set d {}
339 foreach v $cmd {
340 if {$d ne {}} {
341 append d { }
343 if {[regexp {[ \t\r\n'"$?*]} $v]} {
344 set v [sq $v]
346 append d $v
348 puts stderr $d
351 #'" fix poor old emacs font-lock mode
353 proc _git_cmd {name} {
354 global _git_cmd_path
356 if {[catch {set v $_git_cmd_path($name)}]} {
357 switch -- $name {
358 version -
359 --version -
360 --exec-path { return [list $::_git $name] }
363 set p [gitexec git-$name$::_search_exe]
364 if {[file exists $p]} {
365 set v [list $p]
366 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
367 # Try to determine what sort of magic will make
368 # git-$name go and do its thing, because native
369 # Tcl on Windows doesn't know it.
371 set p [gitexec git-$name]
372 set f [open $p r]
373 set s [gets $f]
374 close $f
376 switch -glob -- [lindex $s 0] {
377 #!*sh { set i sh }
378 #!*perl { set i perl }
379 #!*python { set i python }
380 default { error "git-$name is not supported: $s" }
383 upvar #0 _$i interp
384 if {![info exists interp]} {
385 set interp [_which $i]
387 if {$interp eq {}} {
388 error "git-$name requires $i (not in PATH)"
390 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
391 } else {
392 # Assume it is builtin to git somehow and we
393 # aren't actually able to see a file for it.
395 set v [list $::_git $name]
397 set _git_cmd_path($name) $v
399 return $v
402 proc _which {what args} {
403 global env _search_exe _search_path
405 if {$_search_path eq {}} {
406 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
407 set _search_path [split [exec cygpath \
408 --windows \
409 --path \
410 --absolute \
411 $env(PATH)] {;}]
412 set _search_exe .exe
413 } elseif {[is_Windows]} {
414 set gitguidir [file dirname [info script]]
415 regsub -all ";" $gitguidir "\\;" gitguidir
416 set env(PATH) "$gitguidir;$env(PATH)"
417 set _search_path [split $env(PATH) {;}]
418 set _search_exe .exe
419 } else {
420 set _search_path [split $env(PATH) :]
421 set _search_exe {}
425 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
426 set suffix {}
427 } else {
428 set suffix $_search_exe
431 foreach p $_search_path {
432 set p [file join $p $what$suffix]
433 if {[file exists $p]} {
434 return [file normalize $p]
437 return {}
440 proc _lappend_nice {cmd_var} {
441 global _nice
442 upvar $cmd_var cmd
444 if {![info exists _nice]} {
445 set _nice [_which nice]
446 if {[catch {exec $_nice git version}]} {
447 set _nice {}
448 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
449 set _nice {}
452 if {$_nice ne {}} {
453 lappend cmd $_nice
457 proc git {args} {
458 set opt [list]
460 while {1} {
461 switch -- [lindex $args 0] {
462 --nice {
463 _lappend_nice opt
466 default {
467 break
472 set args [lrange $args 1 end]
475 set cmdp [_git_cmd [lindex $args 0]]
476 set args [lrange $args 1 end]
478 _trace_exec [concat $opt $cmdp $args]
479 set result [eval exec $opt $cmdp $args]
480 if {$::_trace} {
481 puts stderr "< $result"
483 return $result
486 proc _open_stdout_stderr {cmd} {
487 _trace_exec $cmd
488 if {[catch {
489 set fd [open [concat [list | ] $cmd] r]
490 } err]} {
491 if { [lindex $cmd end] eq {2>@1}
492 && $err eq {can not find channel named "1"}
494 # Older versions of Tcl 8.4 don't have this 2>@1 IO
495 # redirect operator. Fallback to |& cat for those.
496 # The command was not actually started, so its safe
497 # to try to start it a second time.
499 set fd [open [concat \
500 [list | ] \
501 [lrange $cmd 0 end-1] \
502 [list |& cat] \
503 ] r]
504 } else {
505 error $err
508 fconfigure $fd -eofchar {}
509 return $fd
512 proc git_read {args} {
513 set opt [list]
515 while {1} {
516 switch -- [lindex $args 0] {
517 --nice {
518 _lappend_nice opt
521 --stderr {
522 lappend args 2>@1
525 default {
526 break
531 set args [lrange $args 1 end]
534 set cmdp [_git_cmd [lindex $args 0]]
535 set args [lrange $args 1 end]
537 return [_open_stdout_stderr [concat $opt $cmdp $args]]
540 proc git_write {args} {
541 set opt [list]
543 while {1} {
544 switch -- [lindex $args 0] {
545 --nice {
546 _lappend_nice opt
549 default {
550 break
555 set args [lrange $args 1 end]
558 set cmdp [_git_cmd [lindex $args 0]]
559 set args [lrange $args 1 end]
561 _trace_exec [concat $opt $cmdp $args]
562 return [open [concat [list | ] $opt $cmdp $args] w]
565 proc githook_read {hook_name args} {
566 set pchook [gitdir hooks $hook_name]
567 lappend args 2>@1
569 # On Windows [file executable] might lie so we need to ask
570 # the shell if the hook is executable. Yes that's annoying.
572 if {[is_Windows]} {
573 upvar #0 _sh interp
574 if {![info exists interp]} {
575 set interp [_which sh]
577 if {$interp eq {}} {
578 error "hook execution requires sh (not in PATH)"
581 set scr {if test -x "$1";then exec "$@";fi}
582 set sh_c [list $interp -c $scr $interp $pchook]
583 return [_open_stdout_stderr [concat $sh_c $args]]
586 if {[file executable $pchook]} {
587 return [_open_stdout_stderr [concat [list $pchook] $args]]
590 return {}
593 proc kill_file_process {fd} {
594 set process [pid $fd]
596 catch {
597 if {[is_Windows]} {
598 # Use a Cygwin-specific flag to allow killing
599 # native Windows processes
600 exec kill -f $process
601 } else {
602 exec kill $process
607 proc gitattr {path attr default} {
608 if {[catch {set r [git check-attr $attr -- $path]}]} {
609 set r unspecified
610 } else {
611 set r [join [lrange [split $r :] 2 end] :]
612 regsub {^ } $r {} r
614 if {$r eq {unspecified}} {
615 return $default
617 return $r
620 proc sq {value} {
621 regsub -all ' $value "'\\''" value
622 return "'$value'"
625 proc load_current_branch {} {
626 global current_branch is_detached
628 set fd [open [gitdir HEAD] r]
629 if {[gets $fd ref] < 1} {
630 set ref {}
632 close $fd
634 set pfx {ref: refs/heads/}
635 set len [string length $pfx]
636 if {[string equal -length $len $pfx $ref]} {
637 # We're on a branch. It might not exist. But
638 # HEAD looks good enough to be a branch.
640 set current_branch [string range $ref $len end]
641 set is_detached 0
642 } else {
643 # Assume this is a detached head.
645 set current_branch HEAD
646 set is_detached 1
650 auto_load tk_optionMenu
651 rename tk_optionMenu real__tkOptionMenu
652 proc tk_optionMenu {w varName args} {
653 set m [eval real__tkOptionMenu $w $varName $args]
654 $m configure -font font_ui
655 $w configure -font font_ui
656 return $m
659 proc rmsel_tag {text} {
660 $text tag conf sel \
661 -background [$text cget -background] \
662 -foreground [$text cget -foreground] \
663 -borderwidth 0
664 $text tag conf in_sel -background lightgray
665 bind $text <Motion> break
666 return $text
669 wm withdraw .
670 set root_exists 0
671 bind . <Visibility> {
672 bind . <Visibility> {}
673 set root_exists 1
676 if {[is_Windows]} {
677 wm iconbitmap . -default $oguilib/git-gui.ico
678 set ::tk::AlwaysShowSelection 1
679 bind . <Control-F2> {console show}
681 # Spoof an X11 display for SSH
682 if {![info exists env(DISPLAY)]} {
683 set env(DISPLAY) :9999
685 } else {
686 catch {
687 image create photo gitlogo -width 16 -height 16
689 gitlogo put #33CC33 -to 7 0 9 2
690 gitlogo put #33CC33 -to 4 2 12 4
691 gitlogo put #33CC33 -to 7 4 9 6
692 gitlogo put #CC3333 -to 4 6 12 8
693 gitlogo put gray26 -to 4 9 6 10
694 gitlogo put gray26 -to 3 10 6 12
695 gitlogo put gray26 -to 8 9 13 11
696 gitlogo put gray26 -to 8 11 10 12
697 gitlogo put gray26 -to 11 11 13 14
698 gitlogo put gray26 -to 3 12 5 14
699 gitlogo put gray26 -to 5 13
700 gitlogo put gray26 -to 10 13
701 gitlogo put gray26 -to 4 14 12 15
702 gitlogo put gray26 -to 5 15 11 16
703 gitlogo redither
705 wm iconphoto . -default gitlogo
709 ######################################################################
711 ## config defaults
713 set cursor_ptr arrow
714 font create font_ui
715 if {[lsearch -exact [font names] TkDefaultFont] != -1} {
716 eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
717 eval [linsert [font actual TkFixedFont] 0 font create font_diff]
718 } else {
719 font create font_diff -family Courier -size 10
720 catch {
721 label .dummy
722 eval font configure font_ui [font actual [.dummy cget -font]]
723 destroy .dummy
727 font create font_uiitalic
728 font create font_uibold
729 font create font_diffbold
730 font create font_diffitalic
732 foreach class {Button Checkbutton Entry Label
733 Labelframe Listbox Message
734 Radiobutton Spinbox Text} {
735 option add *$class.font font_ui
737 if {![is_MacOSX]} {
738 option add *Menu.font font_ui
739 option add *Entry.borderWidth 1 startupFile
740 option add *Entry.relief sunken startupFile
741 option add *RadioButton.anchor w startupFile
743 unset class
745 if {[is_Windows] || [is_MacOSX]} {
746 option add *Menu.tearOff 0
749 if {[is_MacOSX]} {
750 set M1B M1
751 set M1T Cmd
752 } else {
753 set M1B Control
754 set M1T Ctrl
757 proc bind_button3 {w cmd} {
758 bind $w <Any-Button-3> $cmd
759 if {[is_MacOSX]} {
760 # Mac OS X sends Button-2 on right click through three-button mouse,
761 # or through trackpad right-clicking (two-finger touch + click).
762 bind $w <Any-Button-2> $cmd
763 bind $w <Control-Button-1> $cmd
767 proc apply_config {} {
768 global repo_config font_descs
770 foreach option $font_descs {
771 set name [lindex $option 0]
772 set font [lindex $option 1]
773 if {[catch {
774 set need_weight 1
775 foreach {cn cv} $repo_config(gui.$name) {
776 if {$cn eq {-weight}} {
777 set need_weight 0
779 font configure $font $cn $cv
781 if {$need_weight} {
782 font configure $font -weight normal
784 } err]} {
785 error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
787 foreach {cn cv} [font configure $font] {
788 font configure ${font}bold $cn $cv
789 font configure ${font}italic $cn $cv
791 font configure ${font}bold -weight bold
792 font configure ${font}italic -slant italic
795 global use_ttk NS
796 set use_ttk 0
797 set NS {}
798 if {$repo_config(gui.usettk)} {
799 set use_ttk [package vsatisfies [package provide Tk] 8.5]
800 if {$use_ttk} {
801 set NS ttk
802 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
803 pave_toplevel .
808 set default_config(branch.autosetupmerge) true
809 set default_config(merge.tool) {}
810 set default_config(mergetool.keepbackup) true
811 set default_config(merge.diffstat) true
812 set default_config(merge.summary) false
813 set default_config(merge.verbosity) 2
814 set default_config(user.name) {}
815 set default_config(user.email) {}
817 set default_config(gui.encoding) [encoding system]
818 set default_config(gui.matchtrackingbranch) false
819 set default_config(gui.textconv) true
820 set default_config(gui.pruneduringfetch) false
821 set default_config(gui.trustmtime) false
822 set default_config(gui.fastcopyblame) false
823 set default_config(gui.copyblamethreshold) 40
824 set default_config(gui.blamehistoryctx) 7
825 set default_config(gui.diffcontext) 5
826 set default_config(gui.commitmsgwidth) 75
827 set default_config(gui.newbranchtemplate) {}
828 set default_config(gui.spellingdictionary) {}
829 set default_config(gui.fontui) [font configure font_ui]
830 set default_config(gui.fontdiff) [font configure font_diff]
831 # TODO: this option should be added to the git-config documentation
832 set default_config(gui.maxfilesdisplayed) 5000
833 set default_config(gui.usettk) 1
834 set font_descs {
835 {fontui font_ui {mc "Main Font"}}
836 {fontdiff font_diff {mc "Diff/Console Font"}}
839 ######################################################################
841 ## find git
843 set _git [_which git]
844 if {$_git eq {}} {
845 catch {wm withdraw .}
846 tk_messageBox \
847 -icon error \
848 -type ok \
849 -title [mc "git-gui: fatal error"] \
850 -message [mc "Cannot find git in PATH."]
851 exit 1
854 ######################################################################
856 ## version check
858 if {[catch {set _git_version [git --version]} err]} {
859 catch {wm withdraw .}
860 tk_messageBox \
861 -icon error \
862 -type ok \
863 -title [mc "git-gui: fatal error"] \
864 -message "Cannot determine Git version:
866 $err
868 [appname] requires Git 1.5.0 or later."
869 exit 1
871 if {![regsub {^git version } $_git_version {} _git_version]} {
872 catch {wm withdraw .}
873 tk_messageBox \
874 -icon error \
875 -type ok \
876 -title [mc "git-gui: fatal error"] \
877 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
878 exit 1
881 proc get_trimmed_version {s} {
882 set r {}
883 foreach x [split $s -._] {
884 if {[string is integer -strict $x]} {
885 lappend r $x
886 } else {
887 break
890 return [join $r .]
892 set _real_git_version $_git_version
893 set _git_version [get_trimmed_version $_git_version]
895 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
896 catch {wm withdraw .}
897 if {[tk_messageBox \
898 -icon warning \
899 -type yesno \
900 -default no \
901 -title "[appname]: warning" \
902 -message [mc "Git version cannot be determined.
904 %s claims it is version '%s'.
906 %s requires at least Git 1.5.0 or later.
908 Assume '%s' is version 1.5.0?
909 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
910 set _git_version 1.5.0
911 } else {
912 exit 1
915 unset _real_git_version
917 proc git-version {args} {
918 global _git_version
920 switch [llength $args] {
922 return $_git_version
926 set op [lindex $args 0]
927 set vr [lindex $args 1]
928 set cm [package vcompare $_git_version $vr]
929 return [expr $cm $op 0]
933 set type [lindex $args 0]
934 set name [lindex $args 1]
935 set parm [lindex $args 2]
936 set body [lindex $args 3]
938 if {($type ne {proc} && $type ne {method})} {
939 error "Invalid arguments to git-version"
941 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
942 error "Last arm of $type $name must be default"
945 foreach {op vr cb} [lrange $body 0 end-2] {
946 if {[git-version $op $vr]} {
947 return [uplevel [list $type $name $parm $cb]]
951 return [uplevel [list $type $name $parm [lindex $body end]]]
954 default {
955 error "git-version >= x"
961 if {[git-version < 1.5]} {
962 catch {wm withdraw .}
963 tk_messageBox \
964 -icon error \
965 -type ok \
966 -title [mc "git-gui: fatal error"] \
967 -message "[appname] requires Git 1.5.0 or later.
969 You are using [git-version]:
971 [git --version]"
972 exit 1
975 ######################################################################
977 ## configure our library
979 set idx [file join $oguilib tclIndex]
980 if {[catch {set fd [open $idx r]} err]} {
981 catch {wm withdraw .}
982 tk_messageBox \
983 -icon error \
984 -type ok \
985 -title [mc "git-gui: fatal error"] \
986 -message $err
987 exit 1
989 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
990 set idx [list]
991 while {[gets $fd n] >= 0} {
992 if {$n ne {} && ![string match #* $n]} {
993 lappend idx $n
996 } else {
997 set idx {}
999 close $fd
1001 if {$idx ne {}} {
1002 set loaded [list]
1003 foreach p $idx {
1004 if {[lsearch -exact $loaded $p] >= 0} continue
1005 source [file join $oguilib $p]
1006 lappend loaded $p
1008 unset loaded p
1009 } else {
1010 set auto_path [concat [list $oguilib] $auto_path]
1012 unset -nocomplain idx fd
1014 ######################################################################
1016 ## config file parsing
1018 git-version proc _parse_config {arr_name args} {
1019 >= 1.5.3 {
1020 upvar $arr_name arr
1021 array unset arr
1022 set buf {}
1023 catch {
1024 set fd_rc [eval \
1025 [list git_read config] \
1026 $args \
1027 [list --null --list]]
1028 fconfigure $fd_rc -translation binary
1029 set buf [read $fd_rc]
1030 close $fd_rc
1032 foreach line [split $buf "\0"] {
1033 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1034 if {[is_many_config $name]} {
1035 lappend arr($name) $value
1036 } else {
1037 set arr($name) $value
1042 default {
1043 upvar $arr_name arr
1044 array unset arr
1045 catch {
1046 set fd_rc [eval [list git_read config --list] $args]
1047 while {[gets $fd_rc line] >= 0} {
1048 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1049 if {[is_many_config $name]} {
1050 lappend arr($name) $value
1051 } else {
1052 set arr($name) $value
1056 close $fd_rc
1061 proc load_config {include_global} {
1062 global repo_config global_config system_config default_config
1064 if {$include_global} {
1065 _parse_config system_config --system
1066 _parse_config global_config --global
1068 _parse_config repo_config
1070 foreach name [array names default_config] {
1071 if {[catch {set v $system_config($name)}]} {
1072 set system_config($name) $default_config($name)
1075 foreach name [array names system_config] {
1076 if {[catch {set v $global_config($name)}]} {
1077 set global_config($name) $system_config($name)
1079 if {[catch {set v $repo_config($name)}]} {
1080 set repo_config($name) $system_config($name)
1085 ######################################################################
1087 ## feature option selection
1089 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1090 unset _junk
1091 } else {
1092 set subcommand gui
1094 if {$subcommand eq {gui.sh}} {
1095 set subcommand gui
1097 if {$subcommand eq {gui} && [llength $argv] > 0} {
1098 set subcommand [lindex $argv 0]
1099 set argv [lrange $argv 1 end]
1102 enable_option multicommit
1103 enable_option branch
1104 enable_option transport
1105 disable_option bare
1107 switch -- $subcommand {
1108 browser -
1109 blame {
1110 enable_option bare
1112 disable_option multicommit
1113 disable_option branch
1114 disable_option transport
1116 citool {
1117 enable_option singlecommit
1118 enable_option retcode
1120 disable_option multicommit
1121 disable_option branch
1122 disable_option transport
1124 while {[llength $argv] > 0} {
1125 set a [lindex $argv 0]
1126 switch -- $a {
1127 --amend {
1128 enable_option initialamend
1130 --nocommit {
1131 enable_option nocommit
1132 enable_option nocommitmsg
1134 --commitmsg {
1135 disable_option nocommitmsg
1137 default {
1138 break
1142 set argv [lrange $argv 1 end]
1147 ######################################################################
1149 ## execution environment
1151 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1153 # Suggest our implementation of askpass, if none is set
1154 if {![info exists env(SSH_ASKPASS)]} {
1155 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1157 if {![info exists env(GIT_ASKPASS)]} {
1158 set env(GIT_ASKPASS) [gitexec git-gui--askpass]
1160 if {![info exists env(GIT_ASK_YESNO)]} {
1161 set env(GIT_ASK_YESNO) [gitexec git-gui--askyesno]
1164 ######################################################################
1166 ## repository setup
1168 set picked 0
1169 if {[catch {
1170 set _gitdir $env(GIT_DIR)
1171 set _prefix {}
1173 && [catch {
1174 # beware that from the .git dir this sets _gitdir to .
1175 # and _prefix to the empty string
1176 set _gitdir [git rev-parse --git-dir]
1177 set _prefix [git rev-parse --show-prefix]
1178 } err]} {
1179 load_config 1
1180 apply_config
1181 choose_repository::pick
1182 set picked 1
1185 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1186 # run from the .git dir itself) lest the routines to find the worktree
1187 # get confused
1188 if {$_gitdir eq "."} {
1189 set _gitdir [pwd]
1192 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1193 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1195 if {![file isdirectory $_gitdir]} {
1196 catch {wm withdraw .}
1197 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1198 exit 1
1200 # _gitdir exists, so try loading the config
1201 load_config 0
1202 apply_config
1204 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1205 if {[package vsatisfies $_git_version 1.7.0]} {
1206 set _gitworktree [git rev-parse --show-toplevel]
1207 } else {
1208 # try to set work tree from environment, core.worktree or use
1209 # cdup to obtain a relative path to the top of the worktree. If
1210 # run from the top, the ./ prefix ensures normalize expands pwd.
1211 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1212 set _gitworktree [get_config core.worktree]
1213 if {$_gitworktree eq ""} {
1214 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1219 if {$_prefix ne {}} {
1220 if {$_gitworktree eq {}} {
1221 regsub -all {[^/]+/} $_prefix ../ cdup
1222 } else {
1223 set cdup $_gitworktree
1225 if {[catch {cd $cdup} err]} {
1226 catch {wm withdraw .}
1227 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1228 exit 1
1230 set _gitworktree [pwd]
1231 unset cdup
1232 } elseif {![is_enabled bare]} {
1233 if {[is_bare]} {
1234 catch {wm withdraw .}
1235 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1236 exit 1
1238 if {$_gitworktree eq {}} {
1239 set _gitworktree [file dirname $_gitdir]
1241 if {[catch {cd $_gitworktree} err]} {
1242 catch {wm withdraw .}
1243 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1244 exit 1
1246 set _gitworktree [pwd]
1248 set _reponame [file split [file normalize $_gitdir]]
1249 if {[lindex $_reponame end] eq {.git}} {
1250 set _reponame [lindex $_reponame end-1]
1251 } else {
1252 set _reponame [lindex $_reponame end]
1255 ######################################################################
1257 ## global init
1259 set current_diff_path {}
1260 set current_diff_side {}
1261 set diff_actions [list]
1263 set HEAD {}
1264 set PARENT {}
1265 set MERGE_HEAD [list]
1266 set commit_type {}
1267 set empty_tree {}
1268 set current_branch {}
1269 set is_detached 0
1270 set current_diff_path {}
1271 set is_3way_diff 0
1272 set is_submodule_diff 0
1273 set is_conflict_diff 0
1274 set selected_commit_type new
1275 set diff_empty_count 0
1277 set nullid "0000000000000000000000000000000000000000"
1278 set nullid2 "0000000000000000000000000000000000000001"
1280 ######################################################################
1282 ## task management
1284 set rescan_active 0
1285 set diff_active 0
1286 set last_clicked {}
1288 set disable_on_lock [list]
1289 set index_lock_type none
1291 proc lock_index {type} {
1292 global index_lock_type disable_on_lock
1294 if {$index_lock_type eq {none}} {
1295 set index_lock_type $type
1296 foreach w $disable_on_lock {
1297 uplevel #0 $w disabled
1299 return 1
1300 } elseif {$index_lock_type eq "begin-$type"} {
1301 set index_lock_type $type
1302 return 1
1304 return 0
1307 proc unlock_index {} {
1308 global index_lock_type disable_on_lock
1310 set index_lock_type none
1311 foreach w $disable_on_lock {
1312 uplevel #0 $w normal
1316 ######################################################################
1318 ## status
1320 proc repository_state {ctvar hdvar mhvar} {
1321 global current_branch
1322 upvar $ctvar ct $hdvar hd $mhvar mh
1324 set mh [list]
1326 load_current_branch
1327 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1328 set hd {}
1329 set ct initial
1330 return
1333 set merge_head [gitdir MERGE_HEAD]
1334 if {[file exists $merge_head]} {
1335 set ct merge
1336 set fd_mh [open $merge_head r]
1337 while {[gets $fd_mh line] >= 0} {
1338 lappend mh $line
1340 close $fd_mh
1341 return
1344 set ct normal
1347 proc PARENT {} {
1348 global PARENT empty_tree
1350 set p [lindex $PARENT 0]
1351 if {$p ne {}} {
1352 return $p
1354 if {$empty_tree eq {}} {
1355 set empty_tree [git mktree << {}]
1357 return $empty_tree
1360 proc force_amend {} {
1361 global selected_commit_type
1362 global HEAD PARENT MERGE_HEAD commit_type
1364 repository_state newType newHEAD newMERGE_HEAD
1365 set HEAD $newHEAD
1366 set PARENT $newHEAD
1367 set MERGE_HEAD $newMERGE_HEAD
1368 set commit_type $newType
1370 set selected_commit_type amend
1371 do_select_commit_type
1374 proc rescan {after {honor_trustmtime 1}} {
1375 global HEAD PARENT MERGE_HEAD commit_type
1376 global ui_index ui_workdir ui_comm
1377 global rescan_active file_states
1378 global repo_config
1380 if {$rescan_active > 0 || ![lock_index read]} return
1382 repository_state newType newHEAD newMERGE_HEAD
1383 if {[string match amend* $commit_type]
1384 && $newType eq {normal}
1385 && $newHEAD eq $HEAD} {
1386 } else {
1387 set HEAD $newHEAD
1388 set PARENT $newHEAD
1389 set MERGE_HEAD $newMERGE_HEAD
1390 set commit_type $newType
1393 array unset file_states
1395 if {!$::GITGUI_BCK_exists &&
1396 (![$ui_comm edit modified]
1397 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1398 if {[string match amend* $commit_type]} {
1399 } elseif {[load_message GITGUI_MSG]} {
1400 } elseif {[run_prepare_commit_msg_hook]} {
1401 } elseif {[load_message MERGE_MSG]} {
1402 } elseif {[load_message SQUASH_MSG]} {
1404 $ui_comm edit reset
1405 $ui_comm edit modified false
1408 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1409 rescan_stage2 {} $after
1410 } else {
1411 set rescan_active 1
1412 ui_status [mc "Refreshing file status..."]
1413 set fd_rf [git_read update-index \
1414 -q \
1415 --unmerged \
1416 --ignore-missing \
1417 --refresh \
1419 fconfigure $fd_rf -blocking 0 -translation binary
1420 fileevent $fd_rf readable \
1421 [list rescan_stage2 $fd_rf $after]
1425 if {[is_Cygwin]} {
1426 set is_git_info_exclude {}
1427 proc have_info_exclude {} {
1428 global is_git_info_exclude
1430 if {$is_git_info_exclude eq {}} {
1431 if {[catch {exec test -f [gitdir info exclude]}]} {
1432 set is_git_info_exclude 0
1433 } else {
1434 set is_git_info_exclude 1
1437 return $is_git_info_exclude
1439 } else {
1440 proc have_info_exclude {} {
1441 return [file readable [gitdir info exclude]]
1445 proc rescan_stage2 {fd after} {
1446 global rescan_active buf_rdi buf_rdf buf_rlo
1448 if {$fd ne {}} {
1449 read $fd
1450 if {![eof $fd]} return
1451 close $fd
1454 set ls_others [list --exclude-per-directory=.gitignore]
1455 if {[have_info_exclude]} {
1456 lappend ls_others "--exclude-from=[gitdir info exclude]"
1458 set user_exclude [get_config core.excludesfile]
1459 if {$user_exclude ne {} && [file readable $user_exclude]} {
1460 lappend ls_others "--exclude-from=$user_exclude"
1463 set buf_rdi {}
1464 set buf_rdf {}
1465 set buf_rlo {}
1467 set rescan_active 3
1468 ui_status [mc "Scanning for modified files ..."]
1469 set fd_di [git_read diff-index --cached -z [PARENT]]
1470 set fd_df [git_read diff-files -z]
1471 set fd_lo [eval git_read ls-files --others -z $ls_others]
1473 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1474 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1475 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1476 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1477 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1478 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1481 proc load_message {file} {
1482 global ui_comm
1484 set f [gitdir $file]
1485 if {[file isfile $f]} {
1486 if {[catch {set fd [open $f r]}]} {
1487 return 0
1489 fconfigure $fd -eofchar {}
1490 set content [string trim [read $fd]]
1491 close $fd
1492 regsub -all -line {[ \r\t]+$} $content {} content
1493 $ui_comm delete 0.0 end
1494 $ui_comm insert end $content
1495 return 1
1497 return 0
1500 proc run_prepare_commit_msg_hook {} {
1501 global pch_error
1503 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1504 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1505 # empty file but existant file.
1507 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1509 if {[file isfile [gitdir MERGE_MSG]]} {
1510 set pcm_source "merge"
1511 set fd_mm [open [gitdir MERGE_MSG] r]
1512 puts -nonewline $fd_pcm [read $fd_mm]
1513 close $fd_mm
1514 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1515 set pcm_source "squash"
1516 set fd_sm [open [gitdir SQUASH_MSG] r]
1517 puts -nonewline $fd_pcm [read $fd_sm]
1518 close $fd_sm
1519 } else {
1520 set pcm_source ""
1523 close $fd_pcm
1525 set fd_ph [githook_read prepare-commit-msg \
1526 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1527 if {$fd_ph eq {}} {
1528 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1529 return 0;
1532 ui_status [mc "Calling prepare-commit-msg hook..."]
1533 set pch_error {}
1535 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1536 fileevent $fd_ph readable \
1537 [list prepare_commit_msg_hook_wait $fd_ph]
1539 return 1;
1542 proc prepare_commit_msg_hook_wait {fd_ph} {
1543 global pch_error
1545 append pch_error [read $fd_ph]
1546 fconfigure $fd_ph -blocking 1
1547 if {[eof $fd_ph]} {
1548 if {[catch {close $fd_ph}]} {
1549 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1550 hook_failed_popup prepare-commit-msg $pch_error
1551 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1552 exit 1
1553 } else {
1554 load_message PREPARE_COMMIT_MSG
1556 set pch_error {}
1557 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1558 return
1560 fconfigure $fd_ph -blocking 0
1561 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1564 proc read_diff_index {fd after} {
1565 global buf_rdi
1567 append buf_rdi [read $fd]
1568 set c 0
1569 set n [string length $buf_rdi]
1570 while {$c < $n} {
1571 set z1 [string first "\0" $buf_rdi $c]
1572 if {$z1 == -1} break
1573 incr z1
1574 set z2 [string first "\0" $buf_rdi $z1]
1575 if {$z2 == -1} break
1577 incr c
1578 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1579 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1580 merge_state \
1581 [encoding convertfrom $p] \
1582 [lindex $i 4]? \
1583 [list [lindex $i 0] [lindex $i 2]] \
1584 [list]
1585 set c $z2
1586 incr c
1588 if {$c < $n} {
1589 set buf_rdi [string range $buf_rdi $c end]
1590 } else {
1591 set buf_rdi {}
1594 rescan_done $fd buf_rdi $after
1597 proc read_diff_files {fd after} {
1598 global buf_rdf
1600 append buf_rdf [read $fd]
1601 set c 0
1602 set n [string length $buf_rdf]
1603 while {$c < $n} {
1604 set z1 [string first "\0" $buf_rdf $c]
1605 if {$z1 == -1} break
1606 incr z1
1607 set z2 [string first "\0" $buf_rdf $z1]
1608 if {$z2 == -1} break
1610 incr c
1611 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1612 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1613 merge_state \
1614 [encoding convertfrom $p] \
1615 ?[lindex $i 4] \
1616 [list] \
1617 [list [lindex $i 0] [lindex $i 2]]
1618 set c $z2
1619 incr c
1621 if {$c < $n} {
1622 set buf_rdf [string range $buf_rdf $c end]
1623 } else {
1624 set buf_rdf {}
1627 rescan_done $fd buf_rdf $after
1630 proc read_ls_others {fd after} {
1631 global buf_rlo
1633 append buf_rlo [read $fd]
1634 set pck [split $buf_rlo "\0"]
1635 set buf_rlo [lindex $pck end]
1636 foreach p [lrange $pck 0 end-1] {
1637 set p [encoding convertfrom $p]
1638 if {[string index $p end] eq {/}} {
1639 set p [string range $p 0 end-1]
1641 merge_state $p ?O
1643 rescan_done $fd buf_rlo $after
1646 proc rescan_done {fd buf after} {
1647 global rescan_active current_diff_path
1648 global file_states repo_config
1649 upvar $buf to_clear
1651 if {![eof $fd]} return
1652 set to_clear {}
1653 close $fd
1654 if {[incr rescan_active -1] > 0} return
1656 prune_selection
1657 unlock_index
1658 display_all_files
1659 if {$current_diff_path ne {}} { reshow_diff $after }
1660 if {$current_diff_path eq {}} { select_first_diff $after }
1663 proc prune_selection {} {
1664 global file_states selected_paths
1666 foreach path [array names selected_paths] {
1667 if {[catch {set still_here $file_states($path)}]} {
1668 unset selected_paths($path)
1673 ######################################################################
1675 ## ui helpers
1677 proc mapicon {w state path} {
1678 global all_icons
1680 if {[catch {set r $all_icons($state$w)}]} {
1681 puts "error: no icon for $w state={$state} $path"
1682 return file_plain
1684 return $r
1687 proc mapdesc {state path} {
1688 global all_descs
1690 if {[catch {set r $all_descs($state)}]} {
1691 puts "error: no desc for state={$state} $path"
1692 return $state
1694 return $r
1697 proc ui_status {msg} {
1698 global main_status
1699 if {[info exists main_status]} {
1700 $main_status show $msg
1704 proc ui_ready {{test {}}} {
1705 global main_status
1706 if {[info exists main_status]} {
1707 $main_status show [mc "Ready."] $test
1711 proc escape_path {path} {
1712 regsub -all {\\} $path "\\\\" path
1713 regsub -all "\n" $path "\\n" path
1714 return $path
1717 proc short_path {path} {
1718 return [escape_path [lindex [file split $path] end]]
1721 set next_icon_id 0
1722 set null_sha1 [string repeat 0 40]
1724 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1725 global file_states next_icon_id null_sha1
1727 set s0 [string index $new_state 0]
1728 set s1 [string index $new_state 1]
1730 if {[catch {set info $file_states($path)}]} {
1731 set state __
1732 set icon n[incr next_icon_id]
1733 } else {
1734 set state [lindex $info 0]
1735 set icon [lindex $info 1]
1736 if {$head_info eq {}} {set head_info [lindex $info 2]}
1737 if {$index_info eq {}} {set index_info [lindex $info 3]}
1740 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1741 elseif {$s0 eq {_}} {set s0 _}
1743 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1744 elseif {$s1 eq {_}} {set s1 _}
1746 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1747 set head_info [list 0 $null_sha1]
1748 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1749 && $head_info eq {}} {
1750 set head_info $index_info
1751 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1752 set index_info $head_info
1753 set head_info {}
1756 set file_states($path) [list $s0$s1 $icon \
1757 $head_info $index_info \
1759 return $state
1762 proc display_file_helper {w path icon_name old_m new_m} {
1763 global file_lists
1765 if {$new_m eq {_}} {
1766 set lno [lsearch -sorted -exact $file_lists($w) $path]
1767 if {$lno >= 0} {
1768 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1769 incr lno
1770 $w conf -state normal
1771 $w delete $lno.0 [expr {$lno + 1}].0
1772 $w conf -state disabled
1774 } elseif {$old_m eq {_} && $new_m ne {_}} {
1775 lappend file_lists($w) $path
1776 set file_lists($w) [lsort -unique $file_lists($w)]
1777 set lno [lsearch -sorted -exact $file_lists($w) $path]
1778 incr lno
1779 $w conf -state normal
1780 $w image create $lno.0 \
1781 -align center -padx 5 -pady 1 \
1782 -name $icon_name \
1783 -image [mapicon $w $new_m $path]
1784 $w insert $lno.1 "[escape_path $path]\n"
1785 $w conf -state disabled
1786 } elseif {$old_m ne $new_m} {
1787 $w conf -state normal
1788 $w image conf $icon_name -image [mapicon $w $new_m $path]
1789 $w conf -state disabled
1793 proc display_file {path state} {
1794 global file_states selected_paths
1795 global ui_index ui_workdir
1797 set old_m [merge_state $path $state]
1798 set s $file_states($path)
1799 set new_m [lindex $s 0]
1800 set icon_name [lindex $s 1]
1802 set o [string index $old_m 0]
1803 set n [string index $new_m 0]
1804 if {$o eq {U}} {
1805 set o _
1807 if {$n eq {U}} {
1808 set n _
1810 display_file_helper $ui_index $path $icon_name $o $n
1812 if {[string index $old_m 0] eq {U}} {
1813 set o U
1814 } else {
1815 set o [string index $old_m 1]
1817 if {[string index $new_m 0] eq {U}} {
1818 set n U
1819 } else {
1820 set n [string index $new_m 1]
1822 display_file_helper $ui_workdir $path $icon_name $o $n
1824 if {$new_m eq {__}} {
1825 unset file_states($path)
1826 catch {unset selected_paths($path)}
1830 proc display_all_files_helper {w path icon_name m} {
1831 global file_lists
1833 lappend file_lists($w) $path
1834 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1835 $w image create end \
1836 -align center -padx 5 -pady 1 \
1837 -name $icon_name \
1838 -image [mapicon $w $m $path]
1839 $w insert end "[escape_path $path]\n"
1842 set files_warning 0
1843 proc display_all_files {} {
1844 global ui_index ui_workdir
1845 global file_states file_lists
1846 global last_clicked
1847 global files_warning
1849 $ui_index conf -state normal
1850 $ui_workdir conf -state normal
1852 $ui_index delete 0.0 end
1853 $ui_workdir delete 0.0 end
1854 set last_clicked {}
1856 set file_lists($ui_index) [list]
1857 set file_lists($ui_workdir) [list]
1859 set to_display [lsort [array names file_states]]
1860 set display_limit [get_config gui.maxfilesdisplayed]
1861 if {[llength $to_display] > $display_limit} {
1862 if {!$files_warning} {
1863 # do not repeatedly warn:
1864 set files_warning 1
1865 info_popup [mc "Displaying only %s of %s files." \
1866 $display_limit [llength $to_display]]
1868 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1870 foreach path $to_display {
1871 set s $file_states($path)
1872 set m [lindex $s 0]
1873 set icon_name [lindex $s 1]
1875 set s [string index $m 0]
1876 if {$s ne {U} && $s ne {_}} {
1877 display_all_files_helper $ui_index $path \
1878 $icon_name $s
1881 if {[string index $m 0] eq {U}} {
1882 set s U
1883 } else {
1884 set s [string index $m 1]
1886 if {$s ne {_}} {
1887 display_all_files_helper $ui_workdir $path \
1888 $icon_name $s
1892 $ui_index conf -state disabled
1893 $ui_workdir conf -state disabled
1896 ######################################################################
1898 ## icons
1900 set filemask {
1901 #define mask_width 14
1902 #define mask_height 15
1903 static unsigned char mask_bits[] = {
1904 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1905 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1906 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1909 image create bitmap file_plain -background white -foreground black -data {
1910 #define plain_width 14
1911 #define plain_height 15
1912 static unsigned char plain_bits[] = {
1913 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1914 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1915 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1916 } -maskdata $filemask
1918 image create bitmap file_mod -background white -foreground blue -data {
1919 #define mod_width 14
1920 #define mod_height 15
1921 static unsigned char mod_bits[] = {
1922 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1923 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1924 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1925 } -maskdata $filemask
1927 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1928 #define file_fulltick_width 14
1929 #define file_fulltick_height 15
1930 static unsigned char file_fulltick_bits[] = {
1931 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1932 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1933 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1934 } -maskdata $filemask
1936 image create bitmap file_question -background white -foreground black -data {
1937 #define file_question_width 14
1938 #define file_question_height 15
1939 static unsigned char file_question_bits[] = {
1940 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1941 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1942 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1943 } -maskdata $filemask
1945 image create bitmap file_removed -background white -foreground red -data {
1946 #define file_removed_width 14
1947 #define file_removed_height 15
1948 static unsigned char file_removed_bits[] = {
1949 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1950 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1951 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1952 } -maskdata $filemask
1954 image create bitmap file_merge -background white -foreground blue -data {
1955 #define file_merge_width 14
1956 #define file_merge_height 15
1957 static unsigned char file_merge_bits[] = {
1958 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1959 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1960 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1961 } -maskdata $filemask
1963 image create bitmap file_statechange -background white -foreground green -data {
1964 #define file_merge_width 14
1965 #define file_merge_height 15
1966 static unsigned char file_statechange_bits[] = {
1967 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
1968 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
1969 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1970 } -maskdata $filemask
1972 set ui_index .vpane.files.index.list
1973 set ui_workdir .vpane.files.workdir.list
1975 set all_icons(_$ui_index) file_plain
1976 set all_icons(A$ui_index) file_plain
1977 set all_icons(M$ui_index) file_fulltick
1978 set all_icons(D$ui_index) file_removed
1979 set all_icons(U$ui_index) file_merge
1980 set all_icons(T$ui_index) file_statechange
1982 set all_icons(_$ui_workdir) file_plain
1983 set all_icons(M$ui_workdir) file_mod
1984 set all_icons(D$ui_workdir) file_question
1985 set all_icons(U$ui_workdir) file_merge
1986 set all_icons(O$ui_workdir) file_plain
1987 set all_icons(T$ui_workdir) file_statechange
1989 set max_status_desc 0
1990 foreach i {
1991 {__ {mc "Unmodified"}}
1993 {_M {mc "Modified, not staged"}}
1994 {M_ {mc "Staged for commit"}}
1995 {MM {mc "Portions staged for commit"}}
1996 {MD {mc "Staged for commit, missing"}}
1998 {_T {mc "File type changed, not staged"}}
1999 {T_ {mc "File type changed, staged"}}
2001 {_O {mc "Untracked, not staged"}}
2002 {A_ {mc "Staged for commit"}}
2003 {AM {mc "Portions staged for commit"}}
2004 {AD {mc "Staged for commit, missing"}}
2006 {_D {mc "Missing"}}
2007 {D_ {mc "Staged for removal"}}
2008 {DO {mc "Staged for removal, still present"}}
2010 {_U {mc "Requires merge resolution"}}
2011 {U_ {mc "Requires merge resolution"}}
2012 {UU {mc "Requires merge resolution"}}
2013 {UM {mc "Requires merge resolution"}}
2014 {UD {mc "Requires merge resolution"}}
2015 {UT {mc "Requires merge resolution"}}
2017 set text [eval [lindex $i 1]]
2018 if {$max_status_desc < [string length $text]} {
2019 set max_status_desc [string length $text]
2021 set all_descs([lindex $i 0]) $text
2023 unset i
2025 ######################################################################
2027 ## util
2029 proc scrollbar2many {list mode args} {
2030 foreach w $list {eval $w $mode $args}
2033 proc many2scrollbar {list mode sb top bottom} {
2034 $sb set $top $bottom
2035 foreach w $list {$w $mode moveto $top}
2038 proc incr_font_size {font {amt 1}} {
2039 set sz [font configure $font -size]
2040 incr sz $amt
2041 font configure $font -size $sz
2042 font configure ${font}bold -size $sz
2043 font configure ${font}italic -size $sz
2046 ######################################################################
2048 ## ui commands
2050 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2052 proc do_gitk {revs {is_submodule false}} {
2053 global current_diff_path file_states current_diff_side ui_index
2054 global _gitworktree
2056 # -- Always start gitk through whatever we were loaded with. This
2057 # lets us bypass using shell process on Windows systems.
2059 set exe [_which gitk -script]
2060 set cmd [list [info nameofexecutable] $exe]
2061 if {$exe eq {}} {
2062 error_popup [mc "Couldn't find gitk in PATH"]
2063 } else {
2064 global env
2066 if {[info exists env(GIT_DIR)]} {
2067 set old_GIT_DIR $env(GIT_DIR)
2068 } else {
2069 set old_GIT_DIR {}
2072 set pwd [pwd]
2074 if {!$is_submodule} {
2075 if {![is_bare]} {
2076 cd $_gitworktree
2078 set env(GIT_DIR) [file normalize [gitdir]]
2079 } else {
2080 cd $current_diff_path
2081 if {$revs eq {--}} {
2082 set s $file_states($current_diff_path)
2083 set old_sha1 {}
2084 set new_sha1 {}
2085 switch -glob -- [lindex $s 0] {
2086 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2087 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2088 MM {
2089 if {$current_diff_side eq $ui_index} {
2090 set old_sha1 [lindex [lindex $s 2] 1]
2091 set new_sha1 [lindex [lindex $s 3] 1]
2092 } else {
2093 set old_sha1 [lindex [lindex $s 3] 1]
2097 set revs $old_sha1...$new_sha1
2099 if {[info exists env(GIT_DIR)]} {
2100 unset env(GIT_DIR)
2103 eval exec $cmd $revs "--" "--" &
2105 if {$old_GIT_DIR ne {}} {
2106 set env(GIT_DIR) $old_GIT_DIR
2108 cd $pwd
2110 ui_status $::starting_gitk_msg
2111 after 10000 {
2112 ui_ready $starting_gitk_msg
2117 proc do_git_gui {} {
2118 global current_diff_path
2120 # -- Always start git gui through whatever we were loaded with. This
2121 # lets us bypass using shell process on Windows systems.
2123 set exe [list [_which git]]
2124 if {$exe eq {}} {
2125 error_popup [mc "Couldn't find git gui in PATH"]
2126 } else {
2127 global env
2129 if {[info exists env(GIT_DIR)]} {
2130 set old_GIT_DIR $env(GIT_DIR)
2131 unset env(GIT_DIR)
2132 } else {
2133 set old_GIT_DIR {}
2136 set pwd [pwd]
2137 cd $current_diff_path
2139 eval exec $exe gui &
2141 if {$old_GIT_DIR ne {}} {
2142 set env(GIT_DIR) $old_GIT_DIR
2144 cd $pwd
2146 ui_status $::starting_gitk_msg
2147 after 10000 {
2148 ui_ready $starting_gitk_msg
2153 proc do_explore {} {
2154 global _gitworktree
2155 set explorer {}
2156 if {[is_Cygwin] || [is_Windows]} {
2157 set explorer "explorer.exe"
2158 } elseif {[is_MacOSX]} {
2159 set explorer "open"
2160 } else {
2161 # freedesktop.org-conforming system is our best shot
2162 set explorer "xdg-open"
2164 eval exec $explorer [list [file nativename $_gitworktree]] &
2167 set is_quitting 0
2168 set ret_code 1
2170 proc terminate_me {win} {
2171 global ret_code
2172 if {$win ne {.}} return
2173 exit $ret_code
2176 proc do_quit {{rc {1}}} {
2177 global ui_comm is_quitting repo_config commit_type
2178 global GITGUI_BCK_exists GITGUI_BCK_i
2179 global ui_comm_spell
2180 global ret_code use_ttk
2182 if {$is_quitting} return
2183 set is_quitting 1
2185 if {[winfo exists $ui_comm]} {
2186 # -- Stash our current commit buffer.
2188 set save [gitdir GITGUI_MSG]
2189 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2190 file rename -force [gitdir GITGUI_BCK] $save
2191 set GITGUI_BCK_exists 0
2192 } else {
2193 set msg [string trim [$ui_comm get 0.0 end]]
2194 regsub -all -line {[ \r\t]+$} $msg {} msg
2195 if {(![string match amend* $commit_type]
2196 || [$ui_comm edit modified])
2197 && $msg ne {}} {
2198 catch {
2199 set fd [open $save w]
2200 puts -nonewline $fd $msg
2201 close $fd
2203 } else {
2204 catch {file delete $save}
2208 # -- Cancel our spellchecker if its running.
2210 if {[info exists ui_comm_spell]} {
2211 $ui_comm_spell stop
2214 # -- Remove our editor backup, its not needed.
2216 after cancel $GITGUI_BCK_i
2217 if {$GITGUI_BCK_exists} {
2218 catch {file delete [gitdir GITGUI_BCK]}
2221 # -- Stash our current window geometry into this repository.
2223 set cfg_wmstate [wm state .]
2224 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2225 set rc_wmstate {}
2227 if {$cfg_wmstate ne $rc_wmstate} {
2228 catch {git config gui.wmstate $cfg_wmstate}
2230 if {$cfg_wmstate eq {zoomed}} {
2231 # on Windows wm geometry will lie about window
2232 # position (but not size) when window is zoomed
2233 # restore the window before querying wm geometry
2234 wm state . normal
2236 set cfg_geometry [list]
2237 lappend cfg_geometry [wm geometry .]
2238 if {$use_ttk} {
2239 lappend cfg_geometry [.vpane sashpos 0]
2240 lappend cfg_geometry [.vpane.files sashpos 0]
2241 } else {
2242 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2243 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2245 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2246 set rc_geometry {}
2248 if {$cfg_geometry ne $rc_geometry} {
2249 catch {git config gui.geometry $cfg_geometry}
2253 set ret_code $rc
2255 # Briefly enable send again, working around Tk bug
2256 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2257 tk appname [appname]
2259 destroy .
2262 proc do_rescan {} {
2263 rescan ui_ready
2266 proc ui_do_rescan {} {
2267 rescan {force_first_diff ui_ready}
2270 proc do_commit {} {
2271 commit_tree
2274 proc next_diff {{after {}}} {
2275 global next_diff_p next_diff_w next_diff_i
2276 show_diff $next_diff_p $next_diff_w {} {} $after
2279 proc find_anchor_pos {lst name} {
2280 set lid [lsearch -sorted -exact $lst $name]
2282 if {$lid == -1} {
2283 set lid 0
2284 foreach lname $lst {
2285 if {$lname >= $name} break
2286 incr lid
2290 return $lid
2293 proc find_file_from {flist idx delta path mmask} {
2294 global file_states
2296 set len [llength $flist]
2297 while {$idx >= 0 && $idx < $len} {
2298 set name [lindex $flist $idx]
2300 if {$name ne $path && [info exists file_states($name)]} {
2301 set state [lindex $file_states($name) 0]
2303 if {$mmask eq {} || [regexp $mmask $state]} {
2304 return $idx
2308 incr idx $delta
2311 return {}
2314 proc find_next_diff {w path {lno {}} {mmask {}}} {
2315 global next_diff_p next_diff_w next_diff_i
2316 global file_lists ui_index ui_workdir
2318 set flist $file_lists($w)
2319 if {$lno eq {}} {
2320 set lno [find_anchor_pos $flist $path]
2321 } else {
2322 incr lno -1
2325 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2326 if {$w eq $ui_index} {
2327 set mmask "^$mmask"
2328 } else {
2329 set mmask "$mmask\$"
2333 set idx [find_file_from $flist $lno 1 $path $mmask]
2334 if {$idx eq {}} {
2335 incr lno -1
2336 set idx [find_file_from $flist $lno -1 $path $mmask]
2339 if {$idx ne {}} {
2340 set next_diff_w $w
2341 set next_diff_p [lindex $flist $idx]
2342 set next_diff_i [expr {$idx+1}]
2343 return 1
2344 } else {
2345 return 0
2349 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2350 global current_diff_path
2352 if {$path ne $current_diff_path} {
2353 return {}
2354 } elseif {[find_next_diff $w $path $lno $mmask]} {
2355 return {next_diff;}
2356 } else {
2357 return {reshow_diff;}
2361 proc select_first_diff {after} {
2362 global ui_workdir
2364 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2365 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2366 next_diff $after
2367 } else {
2368 uplevel #0 $after
2372 proc force_first_diff {after} {
2373 global ui_workdir current_diff_path file_states
2375 if {[info exists file_states($current_diff_path)]} {
2376 set state [lindex $file_states($current_diff_path) 0]
2377 } else {
2378 set state {OO}
2381 set reselect 0
2382 if {[string first {U} $state] >= 0} {
2383 # Already a conflict, do nothing
2384 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2385 set reselect 1
2386 } elseif {[string index $state 1] ne {O}} {
2387 # Already a diff & no conflicts, do nothing
2388 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2389 set reselect 1
2392 if {$reselect} {
2393 next_diff $after
2394 } else {
2395 uplevel #0 $after
2399 proc toggle_or_diff {w x y} {
2400 global file_states file_lists current_diff_path ui_index ui_workdir
2401 global last_clicked selected_paths
2403 set pos [split [$w index @$x,$y] .]
2404 set lno [lindex $pos 0]
2405 set col [lindex $pos 1]
2406 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2407 if {$path eq {}} {
2408 set last_clicked {}
2409 return
2412 set last_clicked [list $w $lno]
2413 array unset selected_paths
2414 $ui_index tag remove in_sel 0.0 end
2415 $ui_workdir tag remove in_sel 0.0 end
2417 # Determine the state of the file
2418 if {[info exists file_states($path)]} {
2419 set state [lindex $file_states($path) 0]
2420 } else {
2421 set state {__}
2424 # Restage the file, or simply show the diff
2425 if {$col == 0 && $y > 1} {
2426 # Conflicts need special handling
2427 if {[string first {U} $state] >= 0} {
2428 # $w must always be $ui_workdir, but...
2429 if {$w ne $ui_workdir} { set lno {} }
2430 merge_stage_workdir $path $lno
2431 return
2434 if {[string index $state 1] eq {O}} {
2435 set mmask {}
2436 } else {
2437 set mmask {[^O]}
2440 set after [next_diff_after_action $w $path $lno $mmask]
2442 if {$w eq $ui_index} {
2443 update_indexinfo \
2444 "Unstaging [short_path $path] from commit" \
2445 [list $path] \
2446 [concat $after [list ui_ready]]
2447 } elseif {$w eq $ui_workdir} {
2448 update_index \
2449 "Adding [short_path $path]" \
2450 [list $path] \
2451 [concat $after [list ui_ready]]
2453 } else {
2454 show_diff $path $w $lno
2458 proc add_one_to_selection {w x y} {
2459 global file_lists last_clicked selected_paths
2461 set lno [lindex [split [$w index @$x,$y] .] 0]
2462 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2463 if {$path eq {}} {
2464 set last_clicked {}
2465 return
2468 if {$last_clicked ne {}
2469 && [lindex $last_clicked 0] ne $w} {
2470 array unset selected_paths
2471 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2474 set last_clicked [list $w $lno]
2475 if {[catch {set in_sel $selected_paths($path)}]} {
2476 set in_sel 0
2478 if {$in_sel} {
2479 unset selected_paths($path)
2480 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2481 } else {
2482 set selected_paths($path) 1
2483 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2487 proc add_range_to_selection {w x y} {
2488 global file_lists last_clicked selected_paths
2490 if {[lindex $last_clicked 0] ne $w} {
2491 toggle_or_diff $w $x $y
2492 return
2495 set lno [lindex [split [$w index @$x,$y] .] 0]
2496 set lc [lindex $last_clicked 1]
2497 if {$lc < $lno} {
2498 set begin $lc
2499 set end $lno
2500 } else {
2501 set begin $lno
2502 set end $lc
2505 foreach path [lrange $file_lists($w) \
2506 [expr {$begin - 1}] \
2507 [expr {$end - 1}]] {
2508 set selected_paths($path) 1
2510 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2513 proc show_more_context {} {
2514 global repo_config
2515 if {$repo_config(gui.diffcontext) < 99} {
2516 incr repo_config(gui.diffcontext)
2517 reshow_diff
2521 proc show_less_context {} {
2522 global repo_config
2523 if {$repo_config(gui.diffcontext) > 1} {
2524 incr repo_config(gui.diffcontext) -1
2525 reshow_diff
2529 ######################################################################
2531 ## ui construction
2533 set ui_comm {}
2535 # -- Menu Bar
2537 menu .mbar -tearoff 0
2538 if {[is_MacOSX]} {
2539 # -- Apple Menu (Mac OS X only)
2541 .mbar add cascade -label Apple -menu .mbar.apple
2542 menu .mbar.apple
2544 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2545 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2546 if {[is_enabled branch]} {
2547 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2549 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2550 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2552 if {[is_enabled transport]} {
2553 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2554 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2556 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2557 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2560 # -- Repository Menu
2562 menu .mbar.repository
2564 if {![is_bare]} {
2565 .mbar.repository add command \
2566 -label [mc "Explore Working Copy"] \
2567 -command {do_explore}
2568 .mbar.repository add separator
2571 .mbar.repository add command \
2572 -label [mc "Browse Current Branch's Files"] \
2573 -command {browser::new $current_branch}
2574 set ui_browse_current [.mbar.repository index last]
2575 .mbar.repository add command \
2576 -label [mc "Browse Branch Files..."] \
2577 -command browser_open::dialog
2578 .mbar.repository add separator
2580 .mbar.repository add command \
2581 -label [mc "Visualize Current Branch's History"] \
2582 -command {do_gitk $current_branch}
2583 set ui_visualize_current [.mbar.repository index last]
2584 .mbar.repository add command \
2585 -label [mc "Visualize All Branch History"] \
2586 -command {do_gitk --all}
2587 .mbar.repository add separator
2589 proc current_branch_write {args} {
2590 global current_branch
2591 .mbar.repository entryconf $::ui_browse_current \
2592 -label [mc "Browse %s's Files" $current_branch]
2593 .mbar.repository entryconf $::ui_visualize_current \
2594 -label [mc "Visualize %s's History" $current_branch]
2596 trace add variable current_branch write current_branch_write
2598 if {[is_enabled multicommit]} {
2599 .mbar.repository add command -label [mc "Database Statistics"] \
2600 -command do_stats
2602 .mbar.repository add command -label [mc "Compress Database"] \
2603 -command do_gc
2605 .mbar.repository add command -label [mc "Verify Database"] \
2606 -command do_fsck_objects
2608 .mbar.repository add separator
2610 if {[is_Cygwin]} {
2611 .mbar.repository add command \
2612 -label [mc "Create Desktop Icon"] \
2613 -command do_cygwin_shortcut
2614 } elseif {[is_Windows]} {
2615 .mbar.repository add command \
2616 -label [mc "Create Desktop Icon"] \
2617 -command do_windows_shortcut
2618 } elseif {[is_MacOSX]} {
2619 .mbar.repository add command \
2620 -label [mc "Create Desktop Icon"] \
2621 -command do_macosx_app
2625 if {[is_MacOSX]} {
2626 proc ::tk::mac::Quit {args} { do_quit }
2627 } else {
2628 .mbar.repository add command -label [mc Quit] \
2629 -command do_quit \
2630 -accelerator $M1T-Q
2633 # -- Edit Menu
2635 menu .mbar.edit
2636 .mbar.edit add command -label [mc Undo] \
2637 -command {catch {[focus] edit undo}} \
2638 -accelerator $M1T-Z
2639 .mbar.edit add command -label [mc Redo] \
2640 -command {catch {[focus] edit redo}} \
2641 -accelerator $M1T-Y
2642 .mbar.edit add separator
2643 .mbar.edit add command -label [mc Cut] \
2644 -command {catch {tk_textCut [focus]}} \
2645 -accelerator $M1T-X
2646 .mbar.edit add command -label [mc Copy] \
2647 -command {catch {tk_textCopy [focus]}} \
2648 -accelerator $M1T-C
2649 .mbar.edit add command -label [mc Paste] \
2650 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2651 -accelerator $M1T-V
2652 .mbar.edit add command -label [mc Delete] \
2653 -command {catch {[focus] delete sel.first sel.last}} \
2654 -accelerator Del
2655 .mbar.edit add separator
2656 .mbar.edit add command -label [mc "Select All"] \
2657 -command {catch {[focus] tag add sel 0.0 end}} \
2658 -accelerator $M1T-A
2660 # -- Branch Menu
2662 if {[is_enabled branch]} {
2663 menu .mbar.branch
2665 .mbar.branch add command -label [mc "Create..."] \
2666 -command branch_create::dialog \
2667 -accelerator $M1T-N
2668 lappend disable_on_lock [list .mbar.branch entryconf \
2669 [.mbar.branch index last] -state]
2671 .mbar.branch add command -label [mc "Checkout..."] \
2672 -command branch_checkout::dialog \
2673 -accelerator $M1T-O
2674 lappend disable_on_lock [list .mbar.branch entryconf \
2675 [.mbar.branch index last] -state]
2677 .mbar.branch add command -label [mc "Rename..."] \
2678 -command branch_rename::dialog
2679 lappend disable_on_lock [list .mbar.branch entryconf \
2680 [.mbar.branch index last] -state]
2682 .mbar.branch add command -label [mc "Delete..."] \
2683 -command branch_delete::dialog
2684 lappend disable_on_lock [list .mbar.branch entryconf \
2685 [.mbar.branch index last] -state]
2687 .mbar.branch add command -label [mc "Reset..."] \
2688 -command merge::reset_hard
2689 lappend disable_on_lock [list .mbar.branch entryconf \
2690 [.mbar.branch index last] -state]
2693 # -- Commit Menu
2695 proc commit_btn_caption {} {
2696 if {[is_enabled nocommit]} {
2697 return [mc "Done"]
2698 } else {
2699 return [mc Commit@@verb]
2703 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2704 menu .mbar.commit
2706 if {![is_enabled nocommit]} {
2707 .mbar.commit add radiobutton \
2708 -label [mc "New Commit"] \
2709 -command do_select_commit_type \
2710 -variable selected_commit_type \
2711 -value new
2712 lappend disable_on_lock \
2713 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2715 .mbar.commit add radiobutton \
2716 -label [mc "Amend Last Commit"] \
2717 -command do_select_commit_type \
2718 -variable selected_commit_type \
2719 -value amend
2720 lappend disable_on_lock \
2721 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2723 .mbar.commit add separator
2726 .mbar.commit add command -label [mc Rescan] \
2727 -command ui_do_rescan \
2728 -accelerator F5
2729 lappend disable_on_lock \
2730 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2732 .mbar.commit add command -label [mc "Stage To Commit"] \
2733 -command do_add_selection \
2734 -accelerator $M1T-T
2735 lappend disable_on_lock \
2736 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2738 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2739 -command do_add_all \
2740 -accelerator $M1T-I
2741 lappend disable_on_lock \
2742 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2744 .mbar.commit add command -label [mc "Unstage From Commit"] \
2745 -command do_unstage_selection \
2746 -accelerator $M1T-U
2747 lappend disable_on_lock \
2748 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2750 .mbar.commit add command -label [mc "Revert Changes"] \
2751 -command do_revert_selection \
2752 -accelerator $M1T-J
2753 lappend disable_on_lock \
2754 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2756 .mbar.commit add separator
2758 .mbar.commit add command -label [mc "Show Less Context"] \
2759 -command show_less_context \
2760 -accelerator $M1T-\-
2762 .mbar.commit add command -label [mc "Show More Context"] \
2763 -command show_more_context \
2764 -accelerator $M1T-=
2766 .mbar.commit add separator
2768 if {![is_enabled nocommitmsg]} {
2769 .mbar.commit add command -label [mc "Sign Off"] \
2770 -command do_signoff \
2771 -accelerator $M1T-S
2774 .mbar.commit add command -label [commit_btn_caption] \
2775 -command do_commit \
2776 -accelerator $M1T-Return
2777 lappend disable_on_lock \
2778 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2781 # -- Merge Menu
2783 if {[is_enabled branch]} {
2784 menu .mbar.merge
2785 .mbar.merge add command -label [mc "Local Merge..."] \
2786 -command merge::dialog \
2787 -accelerator $M1T-M
2788 lappend disable_on_lock \
2789 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2790 .mbar.merge add command -label [mc "Abort Merge..."] \
2791 -command merge::reset_hard
2792 lappend disable_on_lock \
2793 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2796 # -- Transport Menu
2798 if {[is_enabled transport]} {
2799 menu .mbar.remote
2801 .mbar.remote add command \
2802 -label [mc "Add..."] \
2803 -command remote_add::dialog \
2804 -accelerator $M1T-A
2805 .mbar.remote add command \
2806 -label [mc "Push..."] \
2807 -command do_push_anywhere \
2808 -accelerator $M1T-P
2809 .mbar.remote add command \
2810 -label [mc "Delete Branch..."] \
2811 -command remote_branch_delete::dialog
2814 if {[is_MacOSX]} {
2815 proc ::tk::mac::ShowPreferences {} {do_options}
2816 } else {
2817 # -- Edit Menu
2819 .mbar.edit add separator
2820 .mbar.edit add command -label [mc "Options..."] \
2821 -command do_options
2824 # -- Tools Menu
2826 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2827 set tools_menubar .mbar.tools
2828 menu $tools_menubar
2829 $tools_menubar add separator
2830 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2831 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2832 set tools_tailcnt 3
2833 if {[array names repo_config guitool.*.cmd] ne {}} {
2834 tools_populate_all
2838 # -- Help Menu
2840 .mbar add cascade -label [mc Help] -menu .mbar.help
2841 menu .mbar.help
2843 if {[is_MacOSX]} {
2844 .mbar.apple add command -label [mc "About %s" [appname]] \
2845 -command do_about
2846 .mbar.apple add separator
2847 } else {
2848 .mbar.help add command -label [mc "About %s" [appname]] \
2849 -command do_about
2851 . configure -menu .mbar
2853 set doc_path [githtmldir]
2854 if {$doc_path ne {}} {
2855 set doc_path [file join $doc_path index.html]
2857 if {[is_Cygwin]} {
2858 set doc_path [exec cygpath --mixed $doc_path]
2862 if {[file isfile $doc_path]} {
2863 set doc_url "file:$doc_path"
2864 } else {
2865 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2868 proc start_browser {url} {
2869 git "web--browse" $url
2872 .mbar.help add command -label [mc "Online Documentation"] \
2873 -command [list start_browser $doc_url]
2875 .mbar.help add command -label [mc "Show SSH Key"] \
2876 -command do_ssh_key
2878 unset doc_path doc_url
2880 # -- Standard bindings
2882 wm protocol . WM_DELETE_WINDOW do_quit
2883 bind all <$M1B-Key-q> do_quit
2884 bind all <$M1B-Key-Q> do_quit
2885 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2886 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2888 set subcommand_args {}
2889 proc usage {} {
2890 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2891 if {[tk windowingsystem] eq "win32"} {
2892 wm withdraw .
2893 tk_messageBox -icon info -message $s \
2894 -title [mc "Usage"]
2895 } else {
2896 puts stderr $s
2898 exit 1
2901 proc normalize_relpath {path} {
2902 set elements {}
2903 foreach item [file split $path] {
2904 if {$item eq {.}} continue
2905 if {$item eq {..} && [llength $elements] > 0
2906 && [lindex $elements end] ne {..}} {
2907 set elements [lrange $elements 0 end-1]
2908 continue
2910 lappend elements $item
2912 return [eval file join $elements]
2915 # -- Not a normal commit type invocation? Do that instead!
2917 switch -- $subcommand {
2918 browser -
2919 blame {
2920 if {$subcommand eq "blame"} {
2921 set subcommand_args {[--line=<num>] rev? path}
2922 } else {
2923 set subcommand_args {rev? path}
2925 if {$argv eq {}} usage
2926 set head {}
2927 set path {}
2928 set jump_spec {}
2929 set is_path 0
2930 foreach a $argv {
2931 if {$is_path || [file exists $_prefix$a]} {
2932 if {$path ne {}} usage
2933 set path [normalize_relpath $_prefix$a]
2934 break
2935 } elseif {$a eq {--}} {
2936 if {$path ne {}} {
2937 if {$head ne {}} usage
2938 set head $path
2939 set path {}
2941 set is_path 1
2942 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2943 if {$jump_spec ne {} || $head ne {}} usage
2944 set jump_spec [list $lnum]
2945 } elseif {$head eq {}} {
2946 if {$head ne {}} usage
2947 set head $a
2948 set is_path 1
2949 } else {
2950 usage
2953 unset is_path
2955 if {$head ne {} && $path eq {}} {
2956 set path [normalize_relpath $_prefix$head]
2957 set head {}
2960 if {$head eq {}} {
2961 load_current_branch
2962 } else {
2963 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2964 if {[catch {
2965 set head [git rev-parse --verify $head]
2966 } err]} {
2967 if {[tk windowingsystem] eq "win32"} {
2968 tk_messageBox -icon error -title [mc Error] -message $err
2969 } else {
2970 puts stderr $err
2972 exit 1
2975 set current_branch $head
2978 wm deiconify .
2979 switch -- $subcommand {
2980 browser {
2981 if {$jump_spec ne {}} usage
2982 if {$head eq {}} {
2983 if {$path ne {} && [file isdirectory $path]} {
2984 set head $current_branch
2985 } else {
2986 set head $path
2987 set path {}
2990 browser::new $head $path
2992 blame {
2993 if {$head eq {} && ![file exists $path]} {
2994 catch {wm withdraw .}
2995 tk_messageBox \
2996 -icon error \
2997 -type ok \
2998 -title [mc "git-gui: fatal error"] \
2999 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
3000 exit 1
3002 blame::new $head $path $jump_spec
3005 return
3007 citool -
3008 gui {
3009 if {[llength $argv] != 0} {
3010 usage
3012 # fall through to setup UI for commits
3014 default {
3015 set err "usage: $argv0 \[{blame|browser|citool}\]"
3016 if {[tk windowingsystem] eq "win32"} {
3017 wm withdraw .
3018 tk_messageBox -icon error -message $err \
3019 -title [mc "Usage"]
3020 } else {
3021 puts stderr $err
3023 exit 1
3027 # -- Branch Control
3029 ${NS}::frame .branch
3030 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3031 ${NS}::label .branch.l1 \
3032 -text [mc "Current Branch:"] \
3033 -anchor w \
3034 -justify left
3035 ${NS}::label .branch.cb \
3036 -textvariable current_branch \
3037 -anchor w \
3038 -justify left
3039 pack .branch.l1 -side left
3040 pack .branch.cb -side left -fill x
3041 pack .branch -side top -fill x
3043 # -- Main Window Layout
3045 ${NS}::panedwindow .vpane -orient horizontal
3046 ${NS}::panedwindow .vpane.files -orient vertical
3047 if {$use_ttk} {
3048 .vpane add .vpane.files
3049 } else {
3050 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3052 pack .vpane -anchor n -side top -fill both -expand 1
3054 # -- Index File List
3056 ${NS}::frame .vpane.files.index -height 100 -width 200
3057 tlabel .vpane.files.index.title \
3058 -text [mc "Staged Changes (Will Commit)"] \
3059 -background lightgreen -foreground black
3060 text $ui_index -background white -foreground black \
3061 -borderwidth 0 \
3062 -width 20 -height 10 \
3063 -wrap none \
3064 -cursor $cursor_ptr \
3065 -xscrollcommand {.vpane.files.index.sx set} \
3066 -yscrollcommand {.vpane.files.index.sy set} \
3067 -state disabled
3068 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3069 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3070 pack .vpane.files.index.title -side top -fill x
3071 pack .vpane.files.index.sx -side bottom -fill x
3072 pack .vpane.files.index.sy -side right -fill y
3073 pack $ui_index -side left -fill both -expand 1
3075 # -- Working Directory File List
3077 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3078 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3079 -background lightsalmon -foreground black
3080 text $ui_workdir -background white -foreground black \
3081 -borderwidth 0 \
3082 -width 20 -height 10 \
3083 -wrap none \
3084 -cursor $cursor_ptr \
3085 -xscrollcommand {.vpane.files.workdir.sx set} \
3086 -yscrollcommand {.vpane.files.workdir.sy set} \
3087 -state disabled
3088 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3089 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3090 pack .vpane.files.workdir.title -side top -fill x
3091 pack .vpane.files.workdir.sx -side bottom -fill x
3092 pack .vpane.files.workdir.sy -side right -fill y
3093 pack $ui_workdir -side left -fill both -expand 1
3095 .vpane.files add .vpane.files.workdir
3096 .vpane.files add .vpane.files.index
3097 if {!$use_ttk} {
3098 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3099 .vpane.files paneconfigure .vpane.files.index -sticky news
3102 foreach i [list $ui_index $ui_workdir] {
3103 rmsel_tag $i
3104 $i tag conf in_diff -background [$i tag cget in_sel -background]
3106 unset i
3108 # -- Diff and Commit Area
3110 ${NS}::frame .vpane.lower -height 300 -width 400
3111 ${NS}::frame .vpane.lower.commarea
3112 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3113 pack .vpane.lower.diff -fill both -expand 1
3114 pack .vpane.lower.commarea -side bottom -fill x
3115 .vpane add .vpane.lower
3116 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3118 # -- Commit Area Buttons
3120 ${NS}::frame .vpane.lower.commarea.buttons
3121 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3122 -anchor w \
3123 -justify left
3124 pack .vpane.lower.commarea.buttons.l -side top -fill x
3125 pack .vpane.lower.commarea.buttons -side left -fill y
3127 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3128 -command ui_do_rescan
3129 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3130 lappend disable_on_lock \
3131 {.vpane.lower.commarea.buttons.rescan conf -state}
3133 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3134 -command do_add_all
3135 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3136 lappend disable_on_lock \
3137 {.vpane.lower.commarea.buttons.incall conf -state}
3139 if {![is_enabled nocommitmsg]} {
3140 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3141 -command do_signoff
3142 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3145 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3146 -command do_commit
3147 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3148 lappend disable_on_lock \
3149 {.vpane.lower.commarea.buttons.commit conf -state}
3151 if {![is_enabled nocommit]} {
3152 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3153 -command do_push_anywhere
3154 pack .vpane.lower.commarea.buttons.push -side top -fill x
3157 # -- Commit Message Buffer
3159 ${NS}::frame .vpane.lower.commarea.buffer
3160 ${NS}::frame .vpane.lower.commarea.buffer.header
3161 set ui_comm .vpane.lower.commarea.buffer.t
3162 set ui_coml .vpane.lower.commarea.buffer.header.l
3164 if {![is_enabled nocommit]} {
3165 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3166 -text [mc "New Commit"] \
3167 -command do_select_commit_type \
3168 -variable selected_commit_type \
3169 -value new
3170 lappend disable_on_lock \
3171 [list .vpane.lower.commarea.buffer.header.new conf -state]
3172 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3173 -text [mc "Amend Last Commit"] \
3174 -command do_select_commit_type \
3175 -variable selected_commit_type \
3176 -value amend
3177 lappend disable_on_lock \
3178 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3181 ${NS}::label $ui_coml \
3182 -anchor w \
3183 -justify left
3184 proc trace_commit_type {varname args} {
3185 global ui_coml commit_type
3186 switch -glob -- $commit_type {
3187 initial {set txt [mc "Initial Commit Message:"]}
3188 amend {set txt [mc "Amended Commit Message:"]}
3189 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3190 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3191 merge {set txt [mc "Merge Commit Message:"]}
3192 * {set txt [mc "Commit Message:"]}
3194 $ui_coml conf -text $txt
3196 trace add variable commit_type write trace_commit_type
3197 pack $ui_coml -side left -fill x
3199 if {![is_enabled nocommit]} {
3200 pack .vpane.lower.commarea.buffer.header.amend -side right
3201 pack .vpane.lower.commarea.buffer.header.new -side right
3204 text $ui_comm -background white -foreground black \
3205 -borderwidth 1 \
3206 -undo true \
3207 -maxundo 20 \
3208 -autoseparators true \
3209 -relief sunken \
3210 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3211 -font font_diff \
3212 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3213 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3214 -command [list $ui_comm yview]
3215 pack .vpane.lower.commarea.buffer.header -side top -fill x
3216 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3217 pack $ui_comm -side left -fill y
3218 pack .vpane.lower.commarea.buffer -side left -fill y
3220 # -- Commit Message Buffer Context Menu
3222 set ctxm .vpane.lower.commarea.buffer.ctxm
3223 menu $ctxm -tearoff 0
3224 $ctxm add command \
3225 -label [mc Cut] \
3226 -command {tk_textCut $ui_comm}
3227 $ctxm add command \
3228 -label [mc Copy] \
3229 -command {tk_textCopy $ui_comm}
3230 $ctxm add command \
3231 -label [mc Paste] \
3232 -command {tk_textPaste $ui_comm}
3233 $ctxm add command \
3234 -label [mc Delete] \
3235 -command {catch {$ui_comm delete sel.first sel.last}}
3236 $ctxm add separator
3237 $ctxm add command \
3238 -label [mc "Select All"] \
3239 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3240 $ctxm add command \
3241 -label [mc "Copy All"] \
3242 -command {
3243 $ui_comm tag add sel 0.0 end
3244 tk_textCopy $ui_comm
3245 $ui_comm tag remove sel 0.0 end
3247 $ctxm add separator
3248 $ctxm add command \
3249 -label [mc "Sign Off"] \
3250 -command do_signoff
3251 set ui_comm_ctxm $ctxm
3253 # -- Diff Header
3255 proc trace_current_diff_path {varname args} {
3256 global current_diff_path diff_actions file_states
3257 if {$current_diff_path eq {}} {
3258 set s {}
3259 set f {}
3260 set p {}
3261 set o disabled
3262 } else {
3263 set p $current_diff_path
3264 set s [mapdesc [lindex $file_states($p) 0] $p]
3265 set f [mc "File:"]
3266 set p [escape_path $p]
3267 set o normal
3270 .vpane.lower.diff.header.status configure -text $s
3271 .vpane.lower.diff.header.file configure -text $f
3272 .vpane.lower.diff.header.path configure -text $p
3273 foreach w $diff_actions {
3274 uplevel #0 $w $o
3277 trace add variable current_diff_path write trace_current_diff_path
3279 gold_frame .vpane.lower.diff.header
3280 tlabel .vpane.lower.diff.header.status \
3281 -background gold \
3282 -foreground black \
3283 -width $max_status_desc \
3284 -anchor w \
3285 -justify left
3286 tlabel .vpane.lower.diff.header.file \
3287 -background gold \
3288 -foreground black \
3289 -anchor w \
3290 -justify left
3291 tlabel .vpane.lower.diff.header.path \
3292 -background gold \
3293 -foreground black \
3294 -anchor w \
3295 -justify left
3296 pack .vpane.lower.diff.header.status -side left
3297 pack .vpane.lower.diff.header.file -side left
3298 pack .vpane.lower.diff.header.path -fill x
3299 set ctxm .vpane.lower.diff.header.ctxm
3300 menu $ctxm -tearoff 0
3301 $ctxm add command \
3302 -label [mc Copy] \
3303 -command {
3304 clipboard clear
3305 clipboard append \
3306 -format STRING \
3307 -type STRING \
3308 -- $current_diff_path
3310 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3311 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3313 # -- Diff Body
3315 ${NS}::frame .vpane.lower.diff.body
3316 set ui_diff .vpane.lower.diff.body.t
3317 text $ui_diff -background white -foreground black \
3318 -borderwidth 0 \
3319 -width 80 -height 5 -wrap none \
3320 -font font_diff \
3321 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3322 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3323 -state disabled
3324 catch {$ui_diff configure -tabstyle wordprocessor}
3325 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3326 -command [list $ui_diff xview]
3327 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3328 -command [list $ui_diff yview]
3329 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3330 pack .vpane.lower.diff.body.sby -side right -fill y
3331 pack $ui_diff -side left -fill both -expand 1
3332 pack .vpane.lower.diff.header -side top -fill x
3333 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3335 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3336 $ui_diff tag configure clr4$n -background $c
3337 $ui_diff tag configure clri4$n -foreground $c
3338 $ui_diff tag configure clr3$n -foreground $c
3339 $ui_diff tag configure clri3$n -background $c
3341 $ui_diff tag configure clr1 -font font_diffbold
3343 $ui_diff tag conf d_cr -elide true
3344 $ui_diff tag conf d_@ -font font_diffbold
3345 $ui_diff tag conf d_+ -foreground {#00a000}
3346 $ui_diff tag conf d_- -foreground red
3348 $ui_diff tag conf d_++ -foreground {#00a000}
3349 $ui_diff tag conf d_-- -foreground red
3350 $ui_diff tag conf d_+s \
3351 -foreground {#00a000} \
3352 -background {#e2effa}
3353 $ui_diff tag conf d_-s \
3354 -foreground red \
3355 -background {#e2effa}
3356 $ui_diff tag conf d_s+ \
3357 -foreground {#00a000} \
3358 -background ivory1
3359 $ui_diff tag conf d_s- \
3360 -foreground red \
3361 -background ivory1
3363 $ui_diff tag conf d<<<<<<< \
3364 -foreground orange \
3365 -font font_diffbold
3366 $ui_diff tag conf d======= \
3367 -foreground orange \
3368 -font font_diffbold
3369 $ui_diff tag conf d>>>>>>> \
3370 -foreground orange \
3371 -font font_diffbold
3373 $ui_diff tag raise sel
3375 # -- Diff Body Context Menu
3378 proc create_common_diff_popup {ctxm} {
3379 $ctxm add command \
3380 -label [mc Refresh] \
3381 -command reshow_diff
3382 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3383 $ctxm add command \
3384 -label [mc Copy] \
3385 -command {tk_textCopy $ui_diff}
3386 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3387 $ctxm add command \
3388 -label [mc "Select All"] \
3389 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3390 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3391 $ctxm add command \
3392 -label [mc "Copy All"] \
3393 -command {
3394 $ui_diff tag add sel 0.0 end
3395 tk_textCopy $ui_diff
3396 $ui_diff tag remove sel 0.0 end
3398 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3399 $ctxm add separator
3400 $ctxm add command \
3401 -label [mc "Decrease Font Size"] \
3402 -command {incr_font_size font_diff -1}
3403 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3404 $ctxm add command \
3405 -label [mc "Increase Font Size"] \
3406 -command {incr_font_size font_diff 1}
3407 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3408 $ctxm add separator
3409 set emenu $ctxm.enc
3410 menu $emenu
3411 build_encoding_menu $emenu [list force_diff_encoding]
3412 $ctxm add cascade \
3413 -label [mc "Encoding"] \
3414 -menu $emenu
3415 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3416 $ctxm add separator
3417 $ctxm add command -label [mc "Options..."] \
3418 -command do_options
3421 set ctxm .vpane.lower.diff.body.ctxm
3422 menu $ctxm -tearoff 0
3423 $ctxm add command \
3424 -label [mc "Apply/Reverse Hunk"] \
3425 -command {apply_hunk $cursorX $cursorY}
3426 set ui_diff_applyhunk [$ctxm index last]
3427 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3428 $ctxm add command \
3429 -label [mc "Apply/Reverse Line"] \
3430 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3431 set ui_diff_applyline [$ctxm index last]
3432 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3433 $ctxm add separator
3434 $ctxm add command \
3435 -label [mc "Show Less Context"] \
3436 -command show_less_context
3437 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3438 $ctxm add command \
3439 -label [mc "Show More Context"] \
3440 -command show_more_context
3441 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3442 $ctxm add separator
3443 create_common_diff_popup $ctxm
3445 set ctxmmg .vpane.lower.diff.body.ctxmmg
3446 menu $ctxmmg -tearoff 0
3447 $ctxmmg add command \
3448 -label [mc "Run Merge Tool"] \
3449 -command {merge_resolve_tool}
3450 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3451 $ctxmmg add separator
3452 $ctxmmg add command \
3453 -label [mc "Use Remote Version"] \
3454 -command {merge_resolve_one 3}
3455 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3456 $ctxmmg add command \
3457 -label [mc "Use Local Version"] \
3458 -command {merge_resolve_one 2}
3459 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3460 $ctxmmg add command \
3461 -label [mc "Revert To Base"] \
3462 -command {merge_resolve_one 1}
3463 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3464 $ctxmmg add separator
3465 $ctxmmg add command \
3466 -label [mc "Show Less Context"] \
3467 -command show_less_context
3468 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3469 $ctxmmg add command \
3470 -label [mc "Show More Context"] \
3471 -command show_more_context
3472 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3473 $ctxmmg add separator
3474 create_common_diff_popup $ctxmmg
3476 set ctxmsm .vpane.lower.diff.body.ctxmsm
3477 menu $ctxmsm -tearoff 0
3478 $ctxmsm add command \
3479 -label [mc "Visualize These Changes In The Submodule"] \
3480 -command {do_gitk -- true}
3481 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3482 $ctxmsm add command \
3483 -label [mc "Visualize Current Branch History In The Submodule"] \
3484 -command {do_gitk {} true}
3485 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3486 $ctxmsm add command \
3487 -label [mc "Visualize All Branch History In The Submodule"] \
3488 -command {do_gitk --all true}
3489 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3490 $ctxmsm add separator
3491 $ctxmsm add command \
3492 -label [mc "Start git gui In The Submodule"] \
3493 -command {do_git_gui}
3494 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3495 $ctxmsm add separator
3496 create_common_diff_popup $ctxmsm
3498 proc has_textconv {path} {
3499 if {[is_config_false gui.textconv]} {
3500 return 0
3502 set filter [gitattr $path diff set]
3503 set textconv [get_config [join [list diff $filter textconv] .]]
3504 if {$filter ne {set} && $textconv ne {}} {
3505 return 1
3506 } else {
3507 return 0
3511 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3512 global current_diff_path file_states
3513 set ::cursorX $x
3514 set ::cursorY $y
3515 if {[info exists file_states($current_diff_path)]} {
3516 set state [lindex $file_states($current_diff_path) 0]
3517 } else {
3518 set state {__}
3520 if {[string first {U} $state] >= 0} {
3521 tk_popup $ctxmmg $X $Y
3522 } elseif {$::is_submodule_diff} {
3523 tk_popup $ctxmsm $X $Y
3524 } else {
3525 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3526 if {$::ui_index eq $::current_diff_side} {
3527 set l [mc "Unstage Hunk From Commit"]
3528 if {$has_range} {
3529 set t [mc "Unstage Lines From Commit"]
3530 } else {
3531 set t [mc "Unstage Line From Commit"]
3533 } else {
3534 set l [mc "Stage Hunk For Commit"]
3535 if {$has_range} {
3536 set t [mc "Stage Lines For Commit"]
3537 } else {
3538 set t [mc "Stage Line For Commit"]
3541 if {$::is_3way_diff
3542 || $current_diff_path eq {}
3543 || {__} eq $state
3544 || {_O} eq $state
3545 || {_T} eq $state
3546 || {T_} eq $state
3547 || [has_textconv $current_diff_path]} {
3548 set s disabled
3549 } else {
3550 set s normal
3552 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3553 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3554 tk_popup $ctxm $X $Y
3557 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3559 # -- Status Bar
3561 set main_status [::status_bar::new .status]
3562 pack .status -anchor w -side bottom -fill x
3563 $main_status show [mc "Initializing..."]
3565 # -- Load geometry
3567 proc on_ttk_pane_mapped {w pane pos} {
3568 bind $w <Map> {}
3569 after 0 [list after idle [list $w sashpos $pane $pos]]
3571 proc on_tk_pane_mapped {w pane x y} {
3572 bind $w <Map> {}
3573 after 0 [list after idle [list $w sash place $pane $x $y]]
3575 proc on_application_mapped {} {
3576 global repo_config use_ttk
3577 bind . <Map> {}
3578 set gm $repo_config(gui.geometry)
3579 if {$use_ttk} {
3580 bind .vpane <Map> \
3581 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3582 bind .vpane.files <Map> \
3583 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3584 } else {
3585 bind .vpane <Map> \
3586 [list on_tk_pane_mapped %W 0 \
3587 [lindex $gm 1] \
3588 [lindex [.vpane sash coord 0] 1]]
3589 bind .vpane.files <Map> \
3590 [list on_tk_pane_mapped %W 0 \
3591 [lindex [.vpane.files sash coord 0] 0] \
3592 [lindex $gm 2]]
3594 wm geometry . [lindex $gm 0]
3596 if {[info exists repo_config(gui.geometry)]} {
3597 bind . <Map> [list on_application_mapped]
3598 wm geometry . [lindex $repo_config(gui.geometry) 0]
3601 # -- Load window state
3603 if {[info exists repo_config(gui.wmstate)]} {
3604 catch {wm state . $repo_config(gui.wmstate)}
3607 # -- Key Bindings
3609 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3610 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3611 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3612 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3613 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3614 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3615 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3616 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3617 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3618 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3619 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3620 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3621 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3622 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3623 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3624 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3625 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3626 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3627 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3628 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3629 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3630 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3632 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3633 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3634 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3635 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3636 bind $ui_diff <$M1B-Key-v> {break}
3637 bind $ui_diff <$M1B-Key-V> {break}
3638 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3639 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3640 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3641 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3642 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3643 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3644 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3645 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3646 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3647 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3648 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3649 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3650 bind $ui_diff <Button-1> {focus %W}
3652 if {[is_enabled branch]} {
3653 bind . <$M1B-Key-n> branch_create::dialog
3654 bind . <$M1B-Key-N> branch_create::dialog
3655 bind . <$M1B-Key-o> branch_checkout::dialog
3656 bind . <$M1B-Key-O> branch_checkout::dialog
3657 bind . <$M1B-Key-m> merge::dialog
3658 bind . <$M1B-Key-M> merge::dialog
3660 if {[is_enabled transport]} {
3661 bind . <$M1B-Key-p> do_push_anywhere
3662 bind . <$M1B-Key-P> do_push_anywhere
3665 bind . <Key-F5> ui_do_rescan
3666 bind . <$M1B-Key-r> ui_do_rescan
3667 bind . <$M1B-Key-R> ui_do_rescan
3668 bind . <$M1B-Key-s> do_signoff
3669 bind . <$M1B-Key-S> do_signoff
3670 bind . <$M1B-Key-t> do_add_selection
3671 bind . <$M1B-Key-T> do_add_selection
3672 bind . <$M1B-Key-j> do_revert_selection
3673 bind . <$M1B-Key-J> do_revert_selection
3674 bind . <$M1B-Key-i> do_add_all
3675 bind . <$M1B-Key-I> do_add_all
3676 bind . <$M1B-Key-minus> {show_less_context;break}
3677 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3678 bind . <$M1B-Key-equal> {show_more_context;break}
3679 bind . <$M1B-Key-plus> {show_more_context;break}
3680 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3681 bind . <$M1B-Key-Return> do_commit
3682 foreach i [list $ui_index $ui_workdir] {
3683 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3684 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3685 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3687 unset i
3689 set file_lists($ui_index) [list]
3690 set file_lists($ui_workdir) [list]
3692 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3693 focus -force $ui_comm
3695 # -- Warn the user about environmental problems. Cygwin's Tcl
3696 # does *not* pass its env array onto any processes it spawns.
3697 # This means that git processes get none of our environment.
3699 if {[is_Cygwin]} {
3700 set ignored_env 0
3701 set suggest_user {}
3702 set msg [mc "Possible environment issues exist.
3704 The following environment variables are probably
3705 going to be ignored by any Git subprocess run
3706 by %s:
3708 " [appname]]
3709 foreach name [array names env] {
3710 switch -regexp -- $name {
3711 {^GIT_INDEX_FILE$} -
3712 {^GIT_OBJECT_DIRECTORY$} -
3713 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3714 {^GIT_DIFF_OPTS$} -
3715 {^GIT_EXTERNAL_DIFF$} -
3716 {^GIT_PAGER$} -
3717 {^GIT_TRACE$} -
3718 {^GIT_CONFIG$} -
3719 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3720 append msg " - $name\n"
3721 incr ignored_env
3723 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3724 append msg " - $name\n"
3725 incr ignored_env
3726 set suggest_user $name
3730 if {$ignored_env > 0} {
3731 append msg [mc "
3732 This is due to a known issue with the
3733 Tcl binary distributed by Cygwin."]
3735 if {$suggest_user ne {}} {
3736 append msg [mc "
3738 A good replacement for %s
3739 is placing values for the user.name and
3740 user.email settings into your personal
3741 ~/.gitconfig file.
3742 " $suggest_user]
3744 warn_popup $msg
3746 unset ignored_env msg suggest_user name
3749 # -- Only initialize complex UI if we are going to stay running.
3751 if {[is_enabled transport]} {
3752 load_all_remotes
3754 set n [.mbar.remote index end]
3755 populate_remotes_menu
3756 set n [expr {[.mbar.remote index end] - $n}]
3757 if {$n > 0} {
3758 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3759 .mbar.remote insert $n separator
3761 unset n
3764 if {[winfo exists $ui_comm]} {
3765 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3767 # -- If both our backup and message files exist use the
3768 # newer of the two files to initialize the buffer.
3770 if {$GITGUI_BCK_exists} {
3771 set m [gitdir GITGUI_MSG]
3772 if {[file isfile $m]} {
3773 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3774 catch {file delete [gitdir GITGUI_MSG]}
3775 } else {
3776 $ui_comm delete 0.0 end
3777 $ui_comm edit reset
3778 $ui_comm edit modified false
3779 catch {file delete [gitdir GITGUI_BCK]}
3780 set GITGUI_BCK_exists 0
3783 unset m
3786 proc backup_commit_buffer {} {
3787 global ui_comm GITGUI_BCK_exists
3789 set m [$ui_comm edit modified]
3790 if {$m || $GITGUI_BCK_exists} {
3791 set msg [string trim [$ui_comm get 0.0 end]]
3792 regsub -all -line {[ \r\t]+$} $msg {} msg
3794 if {$msg eq {}} {
3795 if {$GITGUI_BCK_exists} {
3796 catch {file delete [gitdir GITGUI_BCK]}
3797 set GITGUI_BCK_exists 0
3799 } elseif {$m} {
3800 catch {
3801 set fd [open [gitdir GITGUI_BCK] w]
3802 puts -nonewline $fd $msg
3803 close $fd
3804 set GITGUI_BCK_exists 1
3808 $ui_comm edit modified false
3811 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3814 backup_commit_buffer
3816 # -- If the user has aspell available we can drive it
3817 # in pipe mode to spellcheck the commit message.
3819 set spell_cmd [list |]
3820 set spell_dict [get_config gui.spellingdictionary]
3821 lappend spell_cmd aspell
3822 if {$spell_dict ne {}} {
3823 lappend spell_cmd --master=$spell_dict
3825 lappend spell_cmd --mode=none
3826 lappend spell_cmd --encoding=utf-8
3827 lappend spell_cmd pipe
3828 if {$spell_dict eq {none}
3829 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3830 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3831 } else {
3832 set ui_comm_spell [spellcheck::init \
3833 $spell_fd \
3834 $ui_comm \
3835 $ui_comm_ctxm \
3838 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3841 lock_index begin-read
3842 if {![winfo ismapped .]} {
3843 wm deiconify .
3845 after 1 {
3846 if {[is_enabled initialamend]} {
3847 force_amend
3848 } else {
3849 do_rescan
3852 if {[is_enabled nocommitmsg]} {
3853 $ui_comm configure -state disabled -background gray
3856 if {[is_enabled multicommit]} {
3857 after 1000 hint_gc
3859 if {[is_enabled retcode]} {
3860 bind . <Destroy> {+terminate_me %W}
3862 if {$picked && [is_config_true gui.autoexplore]} {
3863 do_explore
3866 # Local variables:
3867 # mode: tcl
3868 # indent-tabs-mode: t
3869 # tab-width: 4
3870 # End: