Give commit message reencoding for output on MinGW a chance
[git/mingw/4msysgit/gitPS1fix.git] / git-gui / git-gui.sh
blob0d5bd3465fde3699a3a0016dded575890efe29a6
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 # Check for Windows 7 MUI language pack (missed by msgcat < 1.4.4)
97 if {[tk windowingsystem] eq "win32"
98 && [package vcompare [package provide msgcat] 1.4.4] < 0
99 } then {
100 proc _mc_update_locale {} {
101 set key {HKEY_CURRENT_USER\Control Panel\Desktop}
102 if {![catch {
103 package require registry
104 set uilocale [registry get $key "PreferredUILanguages"]
105 msgcat::ConvertLocale [string map {- _} [lindex $uilocale 0]]
106 } uilocale]} {
107 if {[string length $uilocale] > 0} {
108 msgcat::mclocale $uilocale
112 _mc_update_locale
115 proc _mc_trim {fmt} {
116 set cmk [string first @@ $fmt]
117 if {$cmk > 0} {
118 return [string range $fmt 0 [expr {$cmk - 1}]]
120 return $fmt
123 proc mc {en_fmt args} {
124 set fmt [_mc_trim [::msgcat::mc $en_fmt]]
125 if {[catch {set msg [eval [list format $fmt] $args]} err]} {
126 set msg [eval [list format [_mc_trim $en_fmt]] $args]
128 return $msg
131 proc strcat {args} {
132 return [join $args {}]
135 ::msgcat::mcload $oguimsg
136 unset oguimsg
138 ######################################################################
140 ## read only globals
142 set _appname {Git Gui}
143 set _gitdir {}
144 set _gitworktree {}
145 set _isbare {}
146 set _gitexec {}
147 set _githtmldir {}
148 set _reponame {}
149 set _iscygwin {}
150 set _search_path {}
151 set _shellpath {@@SHELL_PATH@@}
153 set _trace [lsearch -exact $argv --trace]
154 if {$_trace >= 0} {
155 set argv [lreplace $argv $_trace $_trace]
156 set _trace 1
157 } else {
158 set _trace 0
161 # variable for the last merged branch (useful for a default when deleting
162 # branches).
163 set _last_merged_branch {}
165 proc shellpath {} {
166 global _shellpath env
167 if {[string match @@* $_shellpath]} {
168 if {[info exists env(SHELL)]} {
169 return $env(SHELL)
170 } else {
171 return /bin/sh
174 return $_shellpath
177 proc appname {} {
178 global _appname
179 return $_appname
182 proc gitdir {args} {
183 global _gitdir
184 if {$args eq {}} {
185 return $_gitdir
187 return [eval [list file join $_gitdir] $args]
190 proc gitexec {args} {
191 global _gitexec
192 if {$_gitexec eq {}} {
193 if {[catch {set _gitexec [git --exec-path]} err]} {
194 error "Git not installed?\n\n$err"
196 if {[is_Cygwin]} {
197 set _gitexec [exec cygpath \
198 --windows \
199 --absolute \
200 $_gitexec]
201 } else {
202 set _gitexec [file normalize $_gitexec]
205 if {$args eq {}} {
206 return $_gitexec
208 return [eval [list file join $_gitexec] $args]
211 proc githtmldir {args} {
212 global _githtmldir
213 if {$_githtmldir eq {}} {
214 if {[catch {set _githtmldir [git --html-path]}]} {
215 # Git not installed or option not yet supported
216 return {}
218 if {[is_Cygwin]} {
219 set _githtmldir [exec cygpath \
220 --windows \
221 --absolute \
222 $_githtmldir]
223 } else {
224 set _githtmldir [file normalize $_githtmldir]
227 if {$args eq {}} {
228 return $_githtmldir
230 return [eval [list file join $_githtmldir] $args]
233 proc reponame {} {
234 return $::_reponame
237 proc is_MacOSX {} {
238 if {[tk windowingsystem] eq {aqua}} {
239 return 1
241 return 0
244 proc is_Windows {} {
245 if {$::tcl_platform(platform) eq {windows}} {
246 return 1
248 return 0
251 proc is_Cygwin {} {
252 global _iscygwin
253 if {$_iscygwin eq {}} {
254 if {$::tcl_platform(platform) eq {windows}} {
255 if {[catch {set p [exec cygpath --windir]} err]} {
256 set _iscygwin 0
257 } else {
258 set _iscygwin 1
260 } else {
261 set _iscygwin 0
264 return $_iscygwin
267 proc is_enabled {option} {
268 global enabled_options
269 if {[catch {set on $enabled_options($option)}]} {return 0}
270 return $on
273 proc enable_option {option} {
274 global enabled_options
275 set enabled_options($option) 1
278 proc disable_option {option} {
279 global enabled_options
280 set enabled_options($option) 0
283 ######################################################################
285 ## config
287 proc is_many_config {name} {
288 switch -glob -- $name {
289 gui.recentrepo -
290 remote.*.fetch -
291 remote.*.push
292 {return 1}
294 {return 0}
298 proc is_config_true {name} {
299 global repo_config
300 if {[catch {set v $repo_config($name)}]} {
301 return 0
302 } elseif {$v eq {true} || $v eq {1} || $v eq {yes}} {
303 return 1
304 } else {
305 return 0
309 proc is_config_false {name} {
310 global repo_config
311 if {[catch {set v $repo_config($name)}]} {
312 return 0
313 } elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
314 return 1
315 } else {
316 return 0
320 proc get_config {name} {
321 global repo_config
322 if {[catch {set v $repo_config($name)}]} {
323 return {}
324 } else {
325 return $v
329 proc is_bare {} {
330 global _isbare
331 global _gitdir
332 global _gitworktree
334 if {$_isbare eq {}} {
335 if {[catch {
336 set _bare [git rev-parse --is-bare-repository]
337 switch -- $_bare {
338 true { set _isbare 1 }
339 false { set _isbare 0}
340 default { throw }
342 }]} {
343 if {[is_config_true core.bare]
344 || ($_gitworktree eq {}
345 && [lindex [file split $_gitdir] end] ne {.git})} {
346 set _isbare 1
347 } else {
348 set _isbare 0
352 return $_isbare
355 ######################################################################
357 ## handy utils
359 proc _trace_exec {cmd} {
360 if {!$::_trace} return
361 set d {}
362 foreach v $cmd {
363 if {$d ne {}} {
364 append d { }
366 if {[regexp {[ \t\r\n'"$?*]} $v]} {
367 set v [sq $v]
369 append d $v
371 puts stderr $d
374 #'" fix poor old emacs font-lock mode
376 proc _git_cmd {name} {
377 global _git_cmd_path
379 if {[catch {set v $_git_cmd_path($name)}]} {
380 switch -- $name {
381 version -
382 --version -
383 --exec-path { return [list $::_git $name] }
386 set p [gitexec git-$name$::_search_exe]
387 if {[file exists $p]} {
388 set v [list $p]
389 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
390 # Try to determine what sort of magic will make
391 # git-$name go and do its thing, because native
392 # Tcl on Windows doesn't know it.
394 set p [gitexec git-$name]
395 set f [open $p r]
396 set s [gets $f]
397 close $f
399 switch -glob -- [lindex $s 0] {
400 #!*sh { set i sh }
401 #!*perl { set i perl }
402 #!*python { set i python }
403 default { error "git-$name is not supported: $s" }
406 upvar #0 _$i interp
407 if {![info exists interp]} {
408 set interp [_which $i]
410 if {$interp eq {}} {
411 error "git-$name requires $i (not in PATH)"
413 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
414 } else {
415 # Assume it is builtin to git somehow and we
416 # aren't actually able to see a file for it.
418 set v [list $::_git $name]
420 set _git_cmd_path($name) $v
422 return $v
425 proc _which {what args} {
426 global env _search_exe _search_path
428 if {$_search_path eq {}} {
429 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
430 set _search_path [split [exec cygpath \
431 --windows \
432 --path \
433 --absolute \
434 $env(PATH)] {;}]
435 set _search_exe .exe
436 } elseif {[is_Windows]} {
437 set gitguidir [file dirname [info script]]
438 regsub -all ";" $gitguidir "\\;" gitguidir
439 set env(PATH) "$gitguidir;$env(PATH)"
440 set _search_path [split $env(PATH) {;}]
441 set _search_exe .exe
442 } else {
443 set _search_path [split $env(PATH) :]
444 set _search_exe {}
448 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
449 set suffix {}
450 } else {
451 set suffix $_search_exe
454 foreach p $_search_path {
455 set p [file join $p $what$suffix]
456 if {[file exists $p]} {
457 return [file normalize $p]
460 return {}
463 proc _lappend_nice {cmd_var} {
464 global _nice
465 upvar $cmd_var cmd
467 if {![info exists _nice]} {
468 set _nice [_which nice]
469 if {[catch {exec $_nice git version}]} {
470 set _nice {}
471 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
472 set _nice {}
475 if {$_nice ne {}} {
476 lappend cmd $_nice
480 proc git {args} {
481 set opt [list]
483 while {1} {
484 switch -- [lindex $args 0] {
485 --nice {
486 _lappend_nice opt
489 default {
490 break
495 set args [lrange $args 1 end]
498 set cmdp [_git_cmd [lindex $args 0]]
499 set args [lrange $args 1 end]
501 _trace_exec [concat $opt $cmdp $args]
502 set result [eval exec $opt $cmdp $args]
503 if {$::_trace} {
504 puts stderr "< $result"
506 return $result
509 proc _open_stdout_stderr {cmd} {
510 _trace_exec $cmd
511 if {[catch {
512 set fd [open [concat [list | ] $cmd] r]
513 } err]} {
514 if { [lindex $cmd end] eq {2>@1}
515 && $err eq {can not find channel named "1"}
517 # Older versions of Tcl 8.4 don't have this 2>@1 IO
518 # redirect operator. Fallback to |& cat for those.
519 # The command was not actually started, so its safe
520 # to try to start it a second time.
522 set fd [open [concat \
523 [list | ] \
524 [lrange $cmd 0 end-1] \
525 [list |& cat] \
526 ] r]
527 } else {
528 error $err
531 fconfigure $fd -eofchar {}
532 return $fd
535 proc git_read {args} {
536 set opt [list]
538 while {1} {
539 switch -- [lindex $args 0] {
540 --nice {
541 _lappend_nice opt
544 --stderr {
545 lappend args 2>@1
548 default {
549 break
554 set args [lrange $args 1 end]
557 set cmdp [_git_cmd [lindex $args 0]]
558 set args [lrange $args 1 end]
560 return [_open_stdout_stderr [concat $opt $cmdp $args]]
563 proc git_write {args} {
564 set opt [list]
566 while {1} {
567 switch -- [lindex $args 0] {
568 --nice {
569 _lappend_nice opt
572 default {
573 break
578 set args [lrange $args 1 end]
581 set cmdp [_git_cmd [lindex $args 0]]
582 set args [lrange $args 1 end]
584 _trace_exec [concat $opt $cmdp $args]
585 return [open [concat [list | ] $opt $cmdp $args] w]
588 proc githook_read {hook_name args} {
589 set pchook [gitdir hooks $hook_name]
590 lappend args 2>@1
592 # On Windows [file executable] might lie so we need to ask
593 # the shell if the hook is executable. Yes that's annoying.
595 if {[is_Windows]} {
596 upvar #0 _sh interp
597 if {![info exists interp]} {
598 set interp [_which sh]
600 if {$interp eq {}} {
601 error "hook execution requires sh (not in PATH)"
604 set scr {if test -x "$1";then exec "$@";fi}
605 set sh_c [list $interp -c $scr $interp $pchook]
606 return [_open_stdout_stderr [concat $sh_c $args]]
609 if {[file executable $pchook]} {
610 return [_open_stdout_stderr [concat [list $pchook] $args]]
613 return {}
616 proc kill_file_process {fd} {
617 set process [pid $fd]
619 catch {
620 if {[is_Windows]} {
621 # Use a Cygwin-specific flag to allow killing
622 # native Windows processes
623 exec kill -f $process
624 } else {
625 exec kill $process
630 proc gitattr {path attr default} {
631 if {[catch {set r [git check-attr $attr -- $path]}]} {
632 set r unspecified
633 } else {
634 set r [join [lrange [split $r :] 2 end] :]
635 regsub {^ } $r {} r
637 if {$r eq {unspecified}} {
638 return $default
640 return $r
643 proc sq {value} {
644 regsub -all ' $value "'\\''" value
645 return "'$value'"
648 proc load_current_branch {} {
649 global current_branch is_detached
651 set fd [open [gitdir HEAD] r]
652 if {[gets $fd ref] < 1} {
653 set ref {}
655 close $fd
657 set pfx {ref: refs/heads/}
658 set len [string length $pfx]
659 if {[string equal -length $len $pfx $ref]} {
660 # We're on a branch. It might not exist. But
661 # HEAD looks good enough to be a branch.
663 set current_branch [string range $ref $len end]
664 set is_detached 0
665 } else {
666 # Assume this is a detached head.
668 set current_branch HEAD
669 set is_detached 1
673 auto_load tk_optionMenu
674 rename tk_optionMenu real__tkOptionMenu
675 proc tk_optionMenu {w varName args} {
676 set m [eval real__tkOptionMenu $w $varName $args]
677 $m configure -font font_ui
678 $w configure -font font_ui
679 return $m
682 proc rmsel_tag {text} {
683 $text tag conf sel \
684 -background [$text cget -background] \
685 -foreground [$text cget -foreground] \
686 -borderwidth 0
687 $text tag conf in_sel -background lightgray
688 bind $text <Motion> break
689 return $text
692 wm withdraw .
693 set root_exists 0
694 bind . <Visibility> {
695 bind . <Visibility> {}
696 set root_exists 1
699 if {[is_Windows]} {
700 wm iconbitmap . -default $oguilib/git-gui.ico
701 set ::tk::AlwaysShowSelection 1
702 bind . <Control-F2> {console show}
704 # Spoof an X11 display for SSH
705 if {![info exists env(DISPLAY)]} {
706 set env(DISPLAY) :9999
708 } else {
709 catch {
710 image create photo gitlogo -width 16 -height 16
712 gitlogo put #33CC33 -to 7 0 9 2
713 gitlogo put #33CC33 -to 4 2 12 4
714 gitlogo put #33CC33 -to 7 4 9 6
715 gitlogo put #CC3333 -to 4 6 12 8
716 gitlogo put gray26 -to 4 9 6 10
717 gitlogo put gray26 -to 3 10 6 12
718 gitlogo put gray26 -to 8 9 13 11
719 gitlogo put gray26 -to 8 11 10 12
720 gitlogo put gray26 -to 11 11 13 14
721 gitlogo put gray26 -to 3 12 5 14
722 gitlogo put gray26 -to 5 13
723 gitlogo put gray26 -to 10 13
724 gitlogo put gray26 -to 4 14 12 15
725 gitlogo put gray26 -to 5 15 11 16
726 gitlogo redither
728 wm iconphoto . -default gitlogo
732 ######################################################################
734 ## config defaults
736 set cursor_ptr arrow
737 font create font_ui
738 if {[lsearch -exact [font names] TkDefaultFont] != -1} {
739 eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
740 eval [linsert [font actual TkFixedFont] 0 font create font_diff]
741 } else {
742 font create font_diff -family Courier -size 10
743 catch {
744 label .dummy
745 eval font configure font_ui [font actual [.dummy cget -font]]
746 destroy .dummy
750 font create font_uiitalic
751 font create font_uibold
752 font create font_diffbold
753 font create font_diffitalic
755 foreach class {Button Checkbutton Entry Label
756 Labelframe Listbox Message
757 Radiobutton Spinbox Text} {
758 option add *$class.font font_ui
760 if {![is_MacOSX]} {
761 option add *Menu.font font_ui
762 option add *Entry.borderWidth 1 startupFile
763 option add *Entry.relief sunken startupFile
764 option add *RadioButton.anchor w startupFile
766 unset class
768 if {[is_Windows] || [is_MacOSX]} {
769 option add *Menu.tearOff 0
772 if {[is_MacOSX]} {
773 set M1B M1
774 set M1T Cmd
775 } else {
776 set M1B Control
777 set M1T Ctrl
780 proc bind_button3 {w cmd} {
781 bind $w <Any-Button-3> $cmd
782 if {[is_MacOSX]} {
783 # Mac OS X sends Button-2 on right click through three-button mouse,
784 # or through trackpad right-clicking (two-finger touch + click).
785 bind $w <Any-Button-2> $cmd
786 bind $w <Control-Button-1> $cmd
790 proc apply_config {} {
791 global repo_config font_descs
793 foreach option $font_descs {
794 set name [lindex $option 0]
795 set font [lindex $option 1]
796 if {[catch {
797 set need_weight 1
798 foreach {cn cv} $repo_config(gui.$name) {
799 if {$cn eq {-weight}} {
800 set need_weight 0
802 font configure $font $cn $cv
804 if {$need_weight} {
805 font configure $font -weight normal
807 } err]} {
808 error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
810 foreach {cn cv} [font configure $font] {
811 font configure ${font}bold $cn $cv
812 font configure ${font}italic $cn $cv
814 font configure ${font}bold -weight bold
815 font configure ${font}italic -slant italic
818 global use_ttk NS
819 set use_ttk 0
820 set NS {}
821 if {$repo_config(gui.usettk)} {
822 set use_ttk [package vsatisfies [package provide Tk] 8.5]
823 if {$use_ttk} {
824 set NS ttk
825 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
826 pave_toplevel .
831 set default_config(branch.autosetupmerge) true
832 set default_config(merge.tool) {}
833 set default_config(mergetool.keepbackup) true
834 set default_config(merge.diffstat) true
835 set default_config(merge.summary) false
836 set default_config(merge.verbosity) 2
837 set default_config(user.name) {}
838 set default_config(user.email) {}
840 set default_config(gui.encoding) [encoding system]
841 set default_config(gui.matchtrackingbranch) false
842 set default_config(gui.textconv) true
843 set default_config(gui.pruneduringfetch) false
844 set default_config(gui.trustmtime) false
845 set default_config(gui.fastcopyblame) false
846 set default_config(gui.copyblamethreshold) 40
847 set default_config(gui.blamehistoryctx) 7
848 set default_config(gui.diffcontext) 5
849 set default_config(gui.commitmsgwidth) 75
850 set default_config(gui.newbranchtemplate) {}
851 set default_config(gui.spellingdictionary) {}
852 set default_config(gui.fontui) [font configure font_ui]
853 set default_config(gui.fontdiff) [font configure font_diff]
854 # TODO: this option should be added to the git-config documentation
855 set default_config(gui.maxfilesdisplayed) 5000
856 set default_config(gui.usettk) 1
857 set font_descs {
858 {fontui font_ui {mc "Main Font"}}
859 {fontdiff font_diff {mc "Diff/Console Font"}}
862 ######################################################################
864 ## find git
866 set _git [_which git]
867 if {$_git eq {}} {
868 catch {wm withdraw .}
869 tk_messageBox \
870 -icon error \
871 -type ok \
872 -title [mc "git-gui: fatal error"] \
873 -message [mc "Cannot find git in PATH."]
874 exit 1
877 ######################################################################
879 ## version check
881 if {[catch {set _git_version [git --version]} err]} {
882 catch {wm withdraw .}
883 tk_messageBox \
884 -icon error \
885 -type ok \
886 -title [mc "git-gui: fatal error"] \
887 -message "Cannot determine Git version:
889 $err
891 [appname] requires Git 1.5.0 or later."
892 exit 1
894 if {![regsub {^git version } $_git_version {} _git_version]} {
895 catch {wm withdraw .}
896 tk_messageBox \
897 -icon error \
898 -type ok \
899 -title [mc "git-gui: fatal error"] \
900 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
901 exit 1
904 proc get_trimmed_version {s} {
905 set r {}
906 foreach x [split $s -._] {
907 if {[string is integer -strict $x]} {
908 lappend r $x
909 } else {
910 break
913 return [join $r .]
915 set _real_git_version $_git_version
916 set _git_version [get_trimmed_version $_git_version]
918 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
919 catch {wm withdraw .}
920 if {[tk_messageBox \
921 -icon warning \
922 -type yesno \
923 -default no \
924 -title "[appname]: warning" \
925 -message [mc "Git version cannot be determined.
927 %s claims it is version '%s'.
929 %s requires at least Git 1.5.0 or later.
931 Assume '%s' is version 1.5.0?
932 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
933 set _git_version 1.5.0
934 } else {
935 exit 1
938 unset _real_git_version
940 proc git-version {args} {
941 global _git_version
943 switch [llength $args] {
945 return $_git_version
949 set op [lindex $args 0]
950 set vr [lindex $args 1]
951 set cm [package vcompare $_git_version $vr]
952 return [expr $cm $op 0]
956 set type [lindex $args 0]
957 set name [lindex $args 1]
958 set parm [lindex $args 2]
959 set body [lindex $args 3]
961 if {($type ne {proc} && $type ne {method})} {
962 error "Invalid arguments to git-version"
964 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
965 error "Last arm of $type $name must be default"
968 foreach {op vr cb} [lrange $body 0 end-2] {
969 if {[git-version $op $vr]} {
970 return [uplevel [list $type $name $parm $cb]]
974 return [uplevel [list $type $name $parm [lindex $body end]]]
977 default {
978 error "git-version >= x"
984 if {[git-version < 1.5]} {
985 catch {wm withdraw .}
986 tk_messageBox \
987 -icon error \
988 -type ok \
989 -title [mc "git-gui: fatal error"] \
990 -message "[appname] requires Git 1.5.0 or later.
992 You are using [git-version]:
994 [git --version]"
995 exit 1
998 ######################################################################
1000 ## configure our library
1002 set idx [file join $oguilib tclIndex]
1003 if {[catch {set fd [open $idx r]} err]} {
1004 catch {wm withdraw .}
1005 tk_messageBox \
1006 -icon error \
1007 -type ok \
1008 -title [mc "git-gui: fatal error"] \
1009 -message $err
1010 exit 1
1012 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1013 set idx [list]
1014 while {[gets $fd n] >= 0} {
1015 if {$n ne {} && ![string match #* $n]} {
1016 lappend idx $n
1019 } else {
1020 set idx {}
1022 close $fd
1024 if {$idx ne {}} {
1025 set loaded [list]
1026 foreach p $idx {
1027 if {[lsearch -exact $loaded $p] >= 0} continue
1028 source [file join $oguilib $p]
1029 lappend loaded $p
1031 unset loaded p
1032 } else {
1033 set auto_path [concat [list $oguilib] $auto_path]
1035 unset -nocomplain idx fd
1037 ######################################################################
1039 ## config file parsing
1041 git-version proc _parse_config {arr_name args} {
1042 >= 1.5.3 {
1043 upvar $arr_name arr
1044 array unset arr
1045 set buf {}
1046 catch {
1047 set fd_rc [eval \
1048 [list git_read config] \
1049 $args \
1050 [list --null --list]]
1051 fconfigure $fd_rc -translation binary
1052 set buf [read $fd_rc]
1053 close $fd_rc
1055 foreach line [split $buf "\0"] {
1056 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1057 if {[is_many_config $name]} {
1058 lappend arr($name) $value
1059 } else {
1060 set arr($name) $value
1065 default {
1066 upvar $arr_name arr
1067 array unset arr
1068 catch {
1069 set fd_rc [eval [list git_read config --list] $args]
1070 while {[gets $fd_rc line] >= 0} {
1071 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1072 if {[is_many_config $name]} {
1073 lappend arr($name) $value
1074 } else {
1075 set arr($name) $value
1079 close $fd_rc
1084 proc load_config {include_global} {
1085 global repo_config global_config system_config default_config
1087 if {$include_global} {
1088 _parse_config system_config --system
1089 _parse_config global_config --global
1091 _parse_config repo_config
1093 foreach name [array names default_config] {
1094 if {[catch {set v $system_config($name)}]} {
1095 set system_config($name) $default_config($name)
1098 foreach name [array names system_config] {
1099 if {[catch {set v $global_config($name)}]} {
1100 set global_config($name) $system_config($name)
1102 if {[catch {set v $repo_config($name)}]} {
1103 set repo_config($name) $system_config($name)
1108 ######################################################################
1110 ## feature option selection
1112 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1113 unset _junk
1114 } else {
1115 set subcommand gui
1117 if {$subcommand eq {gui.sh}} {
1118 set subcommand gui
1120 if {$subcommand eq {gui} && [llength $argv] > 0} {
1121 set subcommand [lindex $argv 0]
1122 set argv [lrange $argv 1 end]
1125 enable_option multicommit
1126 enable_option branch
1127 enable_option transport
1128 disable_option bare
1130 switch -- $subcommand {
1131 browser -
1132 blame {
1133 enable_option bare
1135 disable_option multicommit
1136 disable_option branch
1137 disable_option transport
1139 citool {
1140 enable_option singlecommit
1141 enable_option retcode
1143 disable_option multicommit
1144 disable_option branch
1145 disable_option transport
1147 while {[llength $argv] > 0} {
1148 set a [lindex $argv 0]
1149 switch -- $a {
1150 --amend {
1151 enable_option initialamend
1153 --nocommit {
1154 enable_option nocommit
1155 enable_option nocommitmsg
1157 --commitmsg {
1158 disable_option nocommitmsg
1160 default {
1161 break
1165 set argv [lrange $argv 1 end]
1170 ######################################################################
1172 ## execution environment
1174 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1176 # Suggest our implementation of askpass, if none is set
1177 if {![info exists env(SSH_ASKPASS)]} {
1178 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1180 if {![info exists env(GIT_ASKPASS)]} {
1181 set env(GIT_ASKPASS) [gitexec git-gui--askpass]
1183 if {![info exists env(GIT_ASK_YESNO)]} {
1184 set env(GIT_ASK_YESNO) [gitexec git-gui--askyesno]
1187 ######################################################################
1189 ## repository setup
1191 set picked 0
1192 if {[catch {
1193 set _gitdir $env(GIT_DIR)
1194 set _prefix {}
1196 && [catch {
1197 # beware that from the .git dir this sets _gitdir to .
1198 # and _prefix to the empty string
1199 set _gitdir [git rev-parse --git-dir]
1200 set _prefix [git rev-parse --show-prefix]
1201 } err]} {
1202 load_config 1
1203 apply_config
1204 choose_repository::pick
1205 set picked 1
1208 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1209 # run from the .git dir itself) lest the routines to find the worktree
1210 # get confused
1211 if {$_gitdir eq "."} {
1212 set _gitdir [pwd]
1215 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1216 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1218 if {![file isdirectory $_gitdir]} {
1219 catch {wm withdraw .}
1220 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1221 exit 1
1223 # _gitdir exists, so try loading the config
1224 load_config 0
1225 apply_config
1227 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1228 if {[package vsatisfies $_git_version 1.7.0]} {
1229 set _gitworktree [git rev-parse --show-toplevel]
1230 } else {
1231 # try to set work tree from environment, core.worktree or use
1232 # cdup to obtain a relative path to the top of the worktree. If
1233 # run from the top, the ./ prefix ensures normalize expands pwd.
1234 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1235 set _gitworktree [get_config core.worktree]
1236 if {$_gitworktree eq ""} {
1237 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1242 if {$_prefix ne {}} {
1243 if {$_gitworktree eq {}} {
1244 regsub -all {[^/]+/} $_prefix ../ cdup
1245 } else {
1246 set cdup $_gitworktree
1248 if {[catch {cd $cdup} err]} {
1249 catch {wm withdraw .}
1250 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1251 exit 1
1253 set _gitworktree [pwd]
1254 unset cdup
1255 } elseif {![is_enabled bare]} {
1256 if {[is_bare]} {
1257 catch {wm withdraw .}
1258 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1259 exit 1
1261 if {$_gitworktree eq {}} {
1262 set _gitworktree [file dirname $_gitdir]
1264 if {[catch {cd $_gitworktree} err]} {
1265 catch {wm withdraw .}
1266 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1267 exit 1
1269 set _gitworktree [pwd]
1271 set _reponame [file split [file normalize $_gitdir]]
1272 if {[lindex $_reponame end] eq {.git}} {
1273 set _reponame [lindex $_reponame end-1]
1274 } else {
1275 set _reponame [lindex $_reponame end]
1278 ######################################################################
1280 ## global init
1282 set current_diff_path {}
1283 set current_diff_side {}
1284 set diff_actions [list]
1286 set HEAD {}
1287 set PARENT {}
1288 set MERGE_HEAD [list]
1289 set commit_type {}
1290 set empty_tree {}
1291 set current_branch {}
1292 set is_detached 0
1293 set current_diff_path {}
1294 set is_3way_diff 0
1295 set is_submodule_diff 0
1296 set is_conflict_diff 0
1297 set selected_commit_type new
1298 set diff_empty_count 0
1300 set nullid "0000000000000000000000000000000000000000"
1301 set nullid2 "0000000000000000000000000000000000000001"
1303 ######################################################################
1305 ## task management
1307 set rescan_active 0
1308 set diff_active 0
1309 set last_clicked {}
1311 set disable_on_lock [list]
1312 set index_lock_type none
1314 proc lock_index {type} {
1315 global index_lock_type disable_on_lock
1317 if {$index_lock_type eq {none}} {
1318 set index_lock_type $type
1319 foreach w $disable_on_lock {
1320 uplevel #0 $w disabled
1322 return 1
1323 } elseif {$index_lock_type eq "begin-$type"} {
1324 set index_lock_type $type
1325 return 1
1327 return 0
1330 proc unlock_index {} {
1331 global index_lock_type disable_on_lock
1333 set index_lock_type none
1334 foreach w $disable_on_lock {
1335 uplevel #0 $w normal
1339 ######################################################################
1341 ## status
1343 proc repository_state {ctvar hdvar mhvar} {
1344 global current_branch
1345 upvar $ctvar ct $hdvar hd $mhvar mh
1347 set mh [list]
1349 load_current_branch
1350 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1351 set hd {}
1352 set ct initial
1353 return
1356 set merge_head [gitdir MERGE_HEAD]
1357 if {[file exists $merge_head]} {
1358 set ct merge
1359 set fd_mh [open $merge_head r]
1360 while {[gets $fd_mh line] >= 0} {
1361 lappend mh $line
1363 close $fd_mh
1364 return
1367 set ct normal
1370 proc PARENT {} {
1371 global PARENT empty_tree
1373 set p [lindex $PARENT 0]
1374 if {$p ne {}} {
1375 return $p
1377 if {$empty_tree eq {}} {
1378 set empty_tree [git mktree << {}]
1380 return $empty_tree
1383 proc force_amend {} {
1384 global selected_commit_type
1385 global HEAD PARENT MERGE_HEAD commit_type
1387 repository_state newType newHEAD newMERGE_HEAD
1388 set HEAD $newHEAD
1389 set PARENT $newHEAD
1390 set MERGE_HEAD $newMERGE_HEAD
1391 set commit_type $newType
1393 set selected_commit_type amend
1394 do_select_commit_type
1397 proc rescan {after {honor_trustmtime 1}} {
1398 global HEAD PARENT MERGE_HEAD commit_type
1399 global ui_index ui_workdir ui_comm
1400 global rescan_active file_states
1401 global repo_config
1403 if {$rescan_active > 0 || ![lock_index read]} return
1405 repository_state newType newHEAD newMERGE_HEAD
1406 if {[string match amend* $commit_type]
1407 && $newType eq {normal}
1408 && $newHEAD eq $HEAD} {
1409 } else {
1410 set HEAD $newHEAD
1411 set PARENT $newHEAD
1412 set MERGE_HEAD $newMERGE_HEAD
1413 set commit_type $newType
1416 array unset file_states
1418 if {!$::GITGUI_BCK_exists &&
1419 (![$ui_comm edit modified]
1420 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1421 if {[string match amend* $commit_type]} {
1422 } elseif {[load_message GITGUI_MSG]} {
1423 } elseif {[run_prepare_commit_msg_hook]} {
1424 } elseif {[load_message MERGE_MSG]} {
1425 } elseif {[load_message SQUASH_MSG]} {
1427 $ui_comm edit reset
1428 $ui_comm edit modified false
1431 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1432 rescan_stage2 {} $after
1433 } else {
1434 set rescan_active 1
1435 ui_status [mc "Refreshing file status..."]
1436 set fd_rf [git_read update-index \
1437 -q \
1438 --unmerged \
1439 --ignore-missing \
1440 --refresh \
1442 fconfigure $fd_rf -blocking 0 -translation binary
1443 fileevent $fd_rf readable \
1444 [list rescan_stage2 $fd_rf $after]
1448 if {[is_Cygwin]} {
1449 set is_git_info_exclude {}
1450 proc have_info_exclude {} {
1451 global is_git_info_exclude
1453 if {$is_git_info_exclude eq {}} {
1454 if {[catch {exec test -f [gitdir info exclude]}]} {
1455 set is_git_info_exclude 0
1456 } else {
1457 set is_git_info_exclude 1
1460 return $is_git_info_exclude
1462 } else {
1463 proc have_info_exclude {} {
1464 return [file readable [gitdir info exclude]]
1468 proc rescan_stage2 {fd after} {
1469 global rescan_active buf_rdi buf_rdf buf_rlo
1471 if {$fd ne {}} {
1472 read $fd
1473 if {![eof $fd]} return
1474 close $fd
1477 if {[package vsatisfies $::_git_version 1.6.3]} {
1478 set ls_others [list --exclude-standard]
1479 } else {
1480 set ls_others [list --exclude-per-directory=.gitignore]
1481 if {[have_info_exclude]} {
1482 lappend ls_others "--exclude-from=[gitdir info exclude]"
1484 set user_exclude [get_config core.excludesfile]
1485 if {$user_exclude ne {} && [file readable $user_exclude]} {
1486 lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1490 set buf_rdi {}
1491 set buf_rdf {}
1492 set buf_rlo {}
1494 set rescan_active 3
1495 ui_status [mc "Scanning for modified files ..."]
1496 set fd_di [git_read diff-index --cached -z [PARENT]]
1497 set fd_df [git_read diff-files -z]
1498 set fd_lo [eval git_read ls-files --others -z $ls_others]
1500 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1501 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1502 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1503 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1504 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1505 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1508 proc load_message {file} {
1509 global ui_comm
1511 set f [gitdir $file]
1512 if {[file isfile $f]} {
1513 if {[catch {set fd [open $f r]}]} {
1514 return 0
1516 fconfigure $fd -eofchar {}
1517 set content [string trim [read $fd]]
1518 close $fd
1519 regsub -all -line {[ \r\t]+$} $content {} content
1520 $ui_comm delete 0.0 end
1521 $ui_comm insert end $content
1522 return 1
1524 return 0
1527 proc run_prepare_commit_msg_hook {} {
1528 global pch_error
1530 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1531 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1532 # empty file but existant file.
1534 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1536 if {[file isfile [gitdir MERGE_MSG]]} {
1537 set pcm_source "merge"
1538 set fd_mm [open [gitdir MERGE_MSG] r]
1539 puts -nonewline $fd_pcm [read $fd_mm]
1540 close $fd_mm
1541 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1542 set pcm_source "squash"
1543 set fd_sm [open [gitdir SQUASH_MSG] r]
1544 puts -nonewline $fd_pcm [read $fd_sm]
1545 close $fd_sm
1546 } else {
1547 set pcm_source ""
1550 close $fd_pcm
1552 set fd_ph [githook_read prepare-commit-msg \
1553 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1554 if {$fd_ph eq {}} {
1555 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1556 return 0;
1559 ui_status [mc "Calling prepare-commit-msg hook..."]
1560 set pch_error {}
1562 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1563 fileevent $fd_ph readable \
1564 [list prepare_commit_msg_hook_wait $fd_ph]
1566 return 1;
1569 proc prepare_commit_msg_hook_wait {fd_ph} {
1570 global pch_error
1572 append pch_error [read $fd_ph]
1573 fconfigure $fd_ph -blocking 1
1574 if {[eof $fd_ph]} {
1575 if {[catch {close $fd_ph}]} {
1576 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1577 hook_failed_popup prepare-commit-msg $pch_error
1578 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1579 exit 1
1580 } else {
1581 load_message PREPARE_COMMIT_MSG
1583 set pch_error {}
1584 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1585 return
1587 fconfigure $fd_ph -blocking 0
1588 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1591 proc read_diff_index {fd after} {
1592 global buf_rdi
1594 append buf_rdi [read $fd]
1595 set c 0
1596 set n [string length $buf_rdi]
1597 while {$c < $n} {
1598 set z1 [string first "\0" $buf_rdi $c]
1599 if {$z1 == -1} break
1600 incr z1
1601 set z2 [string first "\0" $buf_rdi $z1]
1602 if {$z2 == -1} break
1604 incr c
1605 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1606 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1607 merge_state \
1608 [encoding convertfrom $p] \
1609 [lindex $i 4]? \
1610 [list [lindex $i 0] [lindex $i 2]] \
1611 [list]
1612 set c $z2
1613 incr c
1615 if {$c < $n} {
1616 set buf_rdi [string range $buf_rdi $c end]
1617 } else {
1618 set buf_rdi {}
1621 rescan_done $fd buf_rdi $after
1624 proc read_diff_files {fd after} {
1625 global buf_rdf
1627 append buf_rdf [read $fd]
1628 set c 0
1629 set n [string length $buf_rdf]
1630 while {$c < $n} {
1631 set z1 [string first "\0" $buf_rdf $c]
1632 if {$z1 == -1} break
1633 incr z1
1634 set z2 [string first "\0" $buf_rdf $z1]
1635 if {$z2 == -1} break
1637 incr c
1638 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1639 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1640 merge_state \
1641 [encoding convertfrom $p] \
1642 ?[lindex $i 4] \
1643 [list] \
1644 [list [lindex $i 0] [lindex $i 2]]
1645 set c $z2
1646 incr c
1648 if {$c < $n} {
1649 set buf_rdf [string range $buf_rdf $c end]
1650 } else {
1651 set buf_rdf {}
1654 rescan_done $fd buf_rdf $after
1657 proc read_ls_others {fd after} {
1658 global buf_rlo
1660 append buf_rlo [read $fd]
1661 set pck [split $buf_rlo "\0"]
1662 set buf_rlo [lindex $pck end]
1663 foreach p [lrange $pck 0 end-1] {
1664 set p [encoding convertfrom $p]
1665 if {[string index $p end] eq {/}} {
1666 set p [string range $p 0 end-1]
1668 merge_state $p ?O
1670 rescan_done $fd buf_rlo $after
1673 proc rescan_done {fd buf after} {
1674 global rescan_active current_diff_path
1675 global file_states repo_config
1676 upvar $buf to_clear
1678 if {![eof $fd]} return
1679 set to_clear {}
1680 close $fd
1681 if {[incr rescan_active -1] > 0} return
1683 prune_selection
1684 unlock_index
1685 display_all_files
1686 if {$current_diff_path ne {}} { reshow_diff $after }
1687 if {$current_diff_path eq {}} { select_first_diff $after }
1690 proc prune_selection {} {
1691 global file_states selected_paths
1693 foreach path [array names selected_paths] {
1694 if {[catch {set still_here $file_states($path)}]} {
1695 unset selected_paths($path)
1700 ######################################################################
1702 ## ui helpers
1704 proc mapicon {w state path} {
1705 global all_icons
1707 if {[catch {set r $all_icons($state$w)}]} {
1708 puts "error: no icon for $w state={$state} $path"
1709 return file_plain
1711 return $r
1714 proc mapdesc {state path} {
1715 global all_descs
1717 if {[catch {set r $all_descs($state)}]} {
1718 puts "error: no desc for state={$state} $path"
1719 return $state
1721 return $r
1724 proc ui_status {msg} {
1725 global main_status
1726 if {[info exists main_status]} {
1727 $main_status show $msg
1731 proc ui_ready {{test {}}} {
1732 global main_status
1733 if {[info exists main_status]} {
1734 $main_status show [mc "Ready."] $test
1738 proc escape_path {path} {
1739 regsub -all {\\} $path "\\\\" path
1740 regsub -all "\n" $path "\\n" path
1741 return $path
1744 proc short_path {path} {
1745 return [escape_path [lindex [file split $path] end]]
1748 set next_icon_id 0
1749 set null_sha1 [string repeat 0 40]
1751 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1752 global file_states next_icon_id null_sha1
1754 set s0 [string index $new_state 0]
1755 set s1 [string index $new_state 1]
1757 if {[catch {set info $file_states($path)}]} {
1758 set state __
1759 set icon n[incr next_icon_id]
1760 } else {
1761 set state [lindex $info 0]
1762 set icon [lindex $info 1]
1763 if {$head_info eq {}} {set head_info [lindex $info 2]}
1764 if {$index_info eq {}} {set index_info [lindex $info 3]}
1767 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1768 elseif {$s0 eq {_}} {set s0 _}
1770 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1771 elseif {$s1 eq {_}} {set s1 _}
1773 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1774 set head_info [list 0 $null_sha1]
1775 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1776 && $head_info eq {}} {
1777 set head_info $index_info
1778 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1779 set index_info $head_info
1780 set head_info {}
1783 set file_states($path) [list $s0$s1 $icon \
1784 $head_info $index_info \
1786 return $state
1789 proc display_file_helper {w path icon_name old_m new_m} {
1790 global file_lists
1792 if {$new_m eq {_}} {
1793 set lno [lsearch -sorted -exact $file_lists($w) $path]
1794 if {$lno >= 0} {
1795 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1796 incr lno
1797 $w conf -state normal
1798 $w delete $lno.0 [expr {$lno + 1}].0
1799 $w conf -state disabled
1801 } elseif {$old_m eq {_} && $new_m ne {_}} {
1802 lappend file_lists($w) $path
1803 set file_lists($w) [lsort -unique $file_lists($w)]
1804 set lno [lsearch -sorted -exact $file_lists($w) $path]
1805 incr lno
1806 $w conf -state normal
1807 $w image create $lno.0 \
1808 -align center -padx 5 -pady 1 \
1809 -name $icon_name \
1810 -image [mapicon $w $new_m $path]
1811 $w insert $lno.1 "[escape_path $path]\n"
1812 $w conf -state disabled
1813 } elseif {$old_m ne $new_m} {
1814 $w conf -state normal
1815 $w image conf $icon_name -image [mapicon $w $new_m $path]
1816 $w conf -state disabled
1820 proc display_file {path state} {
1821 global file_states selected_paths
1822 global ui_index ui_workdir
1824 set old_m [merge_state $path $state]
1825 set s $file_states($path)
1826 set new_m [lindex $s 0]
1827 set icon_name [lindex $s 1]
1829 set o [string index $old_m 0]
1830 set n [string index $new_m 0]
1831 if {$o eq {U}} {
1832 set o _
1834 if {$n eq {U}} {
1835 set n _
1837 display_file_helper $ui_index $path $icon_name $o $n
1839 if {[string index $old_m 0] eq {U}} {
1840 set o U
1841 } else {
1842 set o [string index $old_m 1]
1844 if {[string index $new_m 0] eq {U}} {
1845 set n U
1846 } else {
1847 set n [string index $new_m 1]
1849 display_file_helper $ui_workdir $path $icon_name $o $n
1851 if {$new_m eq {__}} {
1852 unset file_states($path)
1853 catch {unset selected_paths($path)}
1857 proc display_all_files_helper {w path icon_name m} {
1858 global file_lists
1860 lappend file_lists($w) $path
1861 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1862 $w image create end \
1863 -align center -padx 5 -pady 1 \
1864 -name $icon_name \
1865 -image [mapicon $w $m $path]
1866 $w insert end "[escape_path $path]\n"
1869 set files_warning 0
1870 proc display_all_files {} {
1871 global ui_index ui_workdir
1872 global file_states file_lists
1873 global last_clicked
1874 global files_warning
1876 $ui_index conf -state normal
1877 $ui_workdir conf -state normal
1879 $ui_index delete 0.0 end
1880 $ui_workdir delete 0.0 end
1881 set last_clicked {}
1883 set file_lists($ui_index) [list]
1884 set file_lists($ui_workdir) [list]
1886 set to_display [lsort [array names file_states]]
1887 set display_limit [get_config gui.maxfilesdisplayed]
1888 if {[llength $to_display] > $display_limit} {
1889 if {!$files_warning} {
1890 # do not repeatedly warn:
1891 set files_warning 1
1892 info_popup [mc "Displaying only %s of %s files." \
1893 $display_limit [llength $to_display]]
1895 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1897 foreach path $to_display {
1898 set s $file_states($path)
1899 set m [lindex $s 0]
1900 set icon_name [lindex $s 1]
1902 set s [string index $m 0]
1903 if {$s ne {U} && $s ne {_}} {
1904 display_all_files_helper $ui_index $path \
1905 $icon_name $s
1908 if {[string index $m 0] eq {U}} {
1909 set s U
1910 } else {
1911 set s [string index $m 1]
1913 if {$s ne {_}} {
1914 display_all_files_helper $ui_workdir $path \
1915 $icon_name $s
1919 $ui_index conf -state disabled
1920 $ui_workdir conf -state disabled
1923 ######################################################################
1925 ## icons
1927 set filemask {
1928 #define mask_width 14
1929 #define mask_height 15
1930 static unsigned char mask_bits[] = {
1931 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1932 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1933 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1936 image create bitmap file_plain -background white -foreground black -data {
1937 #define plain_width 14
1938 #define plain_height 15
1939 static unsigned char plain_bits[] = {
1940 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1941 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1942 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1943 } -maskdata $filemask
1945 image create bitmap file_mod -background white -foreground blue -data {
1946 #define mod_width 14
1947 #define mod_height 15
1948 static unsigned char mod_bits[] = {
1949 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1950 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1951 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1952 } -maskdata $filemask
1954 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1955 #define file_fulltick_width 14
1956 #define file_fulltick_height 15
1957 static unsigned char file_fulltick_bits[] = {
1958 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1959 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1960 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1961 } -maskdata $filemask
1963 image create bitmap file_question -background white -foreground black -data {
1964 #define file_question_width 14
1965 #define file_question_height 15
1966 static unsigned char file_question_bits[] = {
1967 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1968 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1969 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1970 } -maskdata $filemask
1972 image create bitmap file_removed -background white -foreground red -data {
1973 #define file_removed_width 14
1974 #define file_removed_height 15
1975 static unsigned char file_removed_bits[] = {
1976 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1977 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1978 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1979 } -maskdata $filemask
1981 image create bitmap file_merge -background white -foreground blue -data {
1982 #define file_merge_width 14
1983 #define file_merge_height 15
1984 static unsigned char file_merge_bits[] = {
1985 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1986 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1987 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1988 } -maskdata $filemask
1990 image create bitmap file_statechange -background white -foreground green -data {
1991 #define file_statechange_width 14
1992 #define file_statechange_height 15
1993 static unsigned char file_statechange_bits[] = {
1994 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
1995 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
1996 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1997 } -maskdata $filemask
1999 set ui_index .vpane.files.index.list
2000 set ui_workdir .vpane.files.workdir.list
2002 set all_icons(_$ui_index) file_plain
2003 set all_icons(A$ui_index) file_plain
2004 set all_icons(M$ui_index) file_fulltick
2005 set all_icons(D$ui_index) file_removed
2006 set all_icons(U$ui_index) file_merge
2007 set all_icons(T$ui_index) file_statechange
2009 set all_icons(_$ui_workdir) file_plain
2010 set all_icons(M$ui_workdir) file_mod
2011 set all_icons(D$ui_workdir) file_question
2012 set all_icons(U$ui_workdir) file_merge
2013 set all_icons(O$ui_workdir) file_plain
2014 set all_icons(T$ui_workdir) file_statechange
2016 set max_status_desc 0
2017 foreach i {
2018 {__ {mc "Unmodified"}}
2020 {_M {mc "Modified, not staged"}}
2021 {M_ {mc "Staged for commit"}}
2022 {MM {mc "Portions staged for commit"}}
2023 {MD {mc "Staged for commit, missing"}}
2025 {_T {mc "File type changed, not staged"}}
2026 {MT {mc "File type changed, old type staged for commit"}}
2027 {AT {mc "File type changed, old type staged for commit"}}
2028 {T_ {mc "File type changed, staged"}}
2029 {TM {mc "File type change staged, modification not staged"}}
2030 {TD {mc "File type change staged, file missing"}}
2032 {_O {mc "Untracked, not staged"}}
2033 {A_ {mc "Staged for commit"}}
2034 {AM {mc "Portions staged for commit"}}
2035 {AD {mc "Staged for commit, missing"}}
2037 {_D {mc "Missing"}}
2038 {D_ {mc "Staged for removal"}}
2039 {DO {mc "Staged for removal, still present"}}
2041 {_U {mc "Requires merge resolution"}}
2042 {U_ {mc "Requires merge resolution"}}
2043 {UU {mc "Requires merge resolution"}}
2044 {UM {mc "Requires merge resolution"}}
2045 {UD {mc "Requires merge resolution"}}
2046 {UT {mc "Requires merge resolution"}}
2048 set text [eval [lindex $i 1]]
2049 if {$max_status_desc < [string length $text]} {
2050 set max_status_desc [string length $text]
2052 set all_descs([lindex $i 0]) $text
2054 unset i
2056 ######################################################################
2058 ## util
2060 proc scrollbar2many {list mode args} {
2061 foreach w $list {eval $w $mode $args}
2064 proc many2scrollbar {list mode sb top bottom} {
2065 $sb set $top $bottom
2066 foreach w $list {$w $mode moveto $top}
2069 proc incr_font_size {font {amt 1}} {
2070 set sz [font configure $font -size]
2071 incr sz $amt
2072 font configure $font -size $sz
2073 font configure ${font}bold -size $sz
2074 font configure ${font}italic -size $sz
2077 ######################################################################
2079 ## ui commands
2081 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2083 proc do_gitk {revs {is_submodule false}} {
2084 global current_diff_path file_states current_diff_side ui_index
2085 global _gitworktree
2087 # -- Always start gitk through whatever we were loaded with. This
2088 # lets us bypass using shell process on Windows systems.
2090 set exe [_which gitk -script]
2091 set cmd [list [info nameofexecutable] $exe]
2092 if {$exe eq {}} {
2093 error_popup [mc "Couldn't find gitk in PATH"]
2094 } else {
2095 global env
2097 if {[info exists env(GIT_DIR)]} {
2098 set old_GIT_DIR $env(GIT_DIR)
2099 } else {
2100 set old_GIT_DIR {}
2103 set pwd [pwd]
2105 if {!$is_submodule} {
2106 if {![is_bare]} {
2107 cd $_gitworktree
2109 set env(GIT_DIR) [file normalize [gitdir]]
2110 } else {
2111 cd $current_diff_path
2112 if {$revs eq {--}} {
2113 set s $file_states($current_diff_path)
2114 set old_sha1 {}
2115 set new_sha1 {}
2116 switch -glob -- [lindex $s 0] {
2117 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2118 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2119 MM {
2120 if {$current_diff_side eq $ui_index} {
2121 set old_sha1 [lindex [lindex $s 2] 1]
2122 set new_sha1 [lindex [lindex $s 3] 1]
2123 } else {
2124 set old_sha1 [lindex [lindex $s 3] 1]
2128 set revs $old_sha1...$new_sha1
2130 if {[info exists env(GIT_DIR)]} {
2131 unset env(GIT_DIR)
2134 eval exec $cmd $revs "--" "--" &
2136 if {$old_GIT_DIR ne {}} {
2137 set env(GIT_DIR) $old_GIT_DIR
2139 cd $pwd
2141 ui_status $::starting_gitk_msg
2142 after 10000 {
2143 ui_ready $starting_gitk_msg
2148 proc do_git_gui {} {
2149 global current_diff_path
2151 # -- Always start git gui through whatever we were loaded with. This
2152 # lets us bypass using shell process on Windows systems.
2154 set exe [list [_which git]]
2155 if {$exe eq {}} {
2156 error_popup [mc "Couldn't find git gui in PATH"]
2157 } else {
2158 global env
2160 if {[info exists env(GIT_DIR)]} {
2161 set old_GIT_DIR $env(GIT_DIR)
2162 unset env(GIT_DIR)
2163 } else {
2164 set old_GIT_DIR {}
2167 set pwd [pwd]
2168 cd $current_diff_path
2170 eval exec $exe gui &
2172 if {$old_GIT_DIR ne {}} {
2173 set env(GIT_DIR) $old_GIT_DIR
2175 cd $pwd
2177 ui_status $::starting_gitk_msg
2178 after 10000 {
2179 ui_ready $starting_gitk_msg
2184 proc do_explore {} {
2185 global _gitworktree
2186 set explorer {}
2187 if {[is_Cygwin] || [is_Windows]} {
2188 set explorer "explorer.exe"
2189 } elseif {[is_MacOSX]} {
2190 set explorer "open"
2191 } else {
2192 # freedesktop.org-conforming system is our best shot
2193 set explorer "xdg-open"
2195 eval exec $explorer [list [file nativename $_gitworktree]] &
2198 set is_quitting 0
2199 set ret_code 1
2201 proc terminate_me {win} {
2202 global ret_code
2203 if {$win ne {.}} return
2204 exit $ret_code
2207 proc do_quit {{rc {1}}} {
2208 global ui_comm is_quitting repo_config commit_type
2209 global GITGUI_BCK_exists GITGUI_BCK_i
2210 global ui_comm_spell
2211 global ret_code use_ttk
2213 if {$is_quitting} return
2214 set is_quitting 1
2216 if {[winfo exists $ui_comm]} {
2217 # -- Stash our current commit buffer.
2219 set save [gitdir GITGUI_MSG]
2220 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2221 file rename -force [gitdir GITGUI_BCK] $save
2222 set GITGUI_BCK_exists 0
2223 } else {
2224 set msg [string trim [$ui_comm get 0.0 end]]
2225 regsub -all -line {[ \r\t]+$} $msg {} msg
2226 if {(![string match amend* $commit_type]
2227 || [$ui_comm edit modified])
2228 && $msg ne {}} {
2229 catch {
2230 set fd [open $save w]
2231 puts -nonewline $fd $msg
2232 close $fd
2234 } else {
2235 catch {file delete $save}
2239 # -- Cancel our spellchecker if its running.
2241 if {[info exists ui_comm_spell]} {
2242 $ui_comm_spell stop
2245 # -- Remove our editor backup, its not needed.
2247 after cancel $GITGUI_BCK_i
2248 if {$GITGUI_BCK_exists} {
2249 catch {file delete [gitdir GITGUI_BCK]}
2252 # -- Stash our current window geometry into this repository.
2254 set cfg_wmstate [wm state .]
2255 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2256 set rc_wmstate {}
2258 if {$cfg_wmstate ne $rc_wmstate} {
2259 catch {git config gui.wmstate $cfg_wmstate}
2261 if {$cfg_wmstate eq {zoomed}} {
2262 # on Windows wm geometry will lie about window
2263 # position (but not size) when window is zoomed
2264 # restore the window before querying wm geometry
2265 wm state . normal
2267 set cfg_geometry [list]
2268 lappend cfg_geometry [wm geometry .]
2269 if {$use_ttk} {
2270 lappend cfg_geometry [.vpane sashpos 0]
2271 lappend cfg_geometry [.vpane.files sashpos 0]
2272 } else {
2273 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2274 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2276 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2277 set rc_geometry {}
2279 if {$cfg_geometry ne $rc_geometry} {
2280 catch {git config gui.geometry $cfg_geometry}
2284 set ret_code $rc
2286 # Briefly enable send again, working around Tk bug
2287 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2288 tk appname [appname]
2290 destroy .
2293 proc do_rescan {} {
2294 rescan ui_ready
2297 proc ui_do_rescan {} {
2298 rescan {force_first_diff ui_ready}
2301 proc do_commit {} {
2302 commit_tree
2305 proc next_diff {{after {}}} {
2306 global next_diff_p next_diff_w next_diff_i
2307 show_diff $next_diff_p $next_diff_w {} {} $after
2310 proc find_anchor_pos {lst name} {
2311 set lid [lsearch -sorted -exact $lst $name]
2313 if {$lid == -1} {
2314 set lid 0
2315 foreach lname $lst {
2316 if {$lname >= $name} break
2317 incr lid
2321 return $lid
2324 proc find_file_from {flist idx delta path mmask} {
2325 global file_states
2327 set len [llength $flist]
2328 while {$idx >= 0 && $idx < $len} {
2329 set name [lindex $flist $idx]
2331 if {$name ne $path && [info exists file_states($name)]} {
2332 set state [lindex $file_states($name) 0]
2334 if {$mmask eq {} || [regexp $mmask $state]} {
2335 return $idx
2339 incr idx $delta
2342 return {}
2345 proc find_next_diff {w path {lno {}} {mmask {}}} {
2346 global next_diff_p next_diff_w next_diff_i
2347 global file_lists ui_index ui_workdir
2349 set flist $file_lists($w)
2350 if {$lno eq {}} {
2351 set lno [find_anchor_pos $flist $path]
2352 } else {
2353 incr lno -1
2356 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2357 if {$w eq $ui_index} {
2358 set mmask "^$mmask"
2359 } else {
2360 set mmask "$mmask\$"
2364 set idx [find_file_from $flist $lno 1 $path $mmask]
2365 if {$idx eq {}} {
2366 incr lno -1
2367 set idx [find_file_from $flist $lno -1 $path $mmask]
2370 if {$idx ne {}} {
2371 set next_diff_w $w
2372 set next_diff_p [lindex $flist $idx]
2373 set next_diff_i [expr {$idx+1}]
2374 return 1
2375 } else {
2376 return 0
2380 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2381 global current_diff_path
2383 if {$path ne $current_diff_path} {
2384 return {}
2385 } elseif {[find_next_diff $w $path $lno $mmask]} {
2386 return {next_diff;}
2387 } else {
2388 return {reshow_diff;}
2392 proc select_first_diff {after} {
2393 global ui_workdir
2395 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2396 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2397 next_diff $after
2398 } else {
2399 uplevel #0 $after
2403 proc force_first_diff {after} {
2404 global ui_workdir current_diff_path file_states
2406 if {[info exists file_states($current_diff_path)]} {
2407 set state [lindex $file_states($current_diff_path) 0]
2408 } else {
2409 set state {OO}
2412 set reselect 0
2413 if {[string first {U} $state] >= 0} {
2414 # Already a conflict, do nothing
2415 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2416 set reselect 1
2417 } elseif {[string index $state 1] ne {O}} {
2418 # Already a diff & no conflicts, do nothing
2419 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2420 set reselect 1
2423 if {$reselect} {
2424 next_diff $after
2425 } else {
2426 uplevel #0 $after
2430 proc toggle_or_diff {w x y} {
2431 global file_states file_lists current_diff_path ui_index ui_workdir
2432 global last_clicked selected_paths
2434 set pos [split [$w index @$x,$y] .]
2435 set lno [lindex $pos 0]
2436 set col [lindex $pos 1]
2437 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2438 if {$path eq {}} {
2439 set last_clicked {}
2440 return
2443 set last_clicked [list $w $lno]
2444 array unset selected_paths
2445 $ui_index tag remove in_sel 0.0 end
2446 $ui_workdir tag remove in_sel 0.0 end
2448 # Determine the state of the file
2449 if {[info exists file_states($path)]} {
2450 set state [lindex $file_states($path) 0]
2451 } else {
2452 set state {__}
2455 # Restage the file, or simply show the diff
2456 if {$col == 0 && $y > 1} {
2457 # Conflicts need special handling
2458 if {[string first {U} $state] >= 0} {
2459 # $w must always be $ui_workdir, but...
2460 if {$w ne $ui_workdir} { set lno {} }
2461 merge_stage_workdir $path $lno
2462 return
2465 if {[string index $state 1] eq {O}} {
2466 set mmask {}
2467 } else {
2468 set mmask {[^O]}
2471 set after [next_diff_after_action $w $path $lno $mmask]
2473 if {$w eq $ui_index} {
2474 update_indexinfo \
2475 "Unstaging [short_path $path] from commit" \
2476 [list $path] \
2477 [concat $after [list ui_ready]]
2478 } elseif {$w eq $ui_workdir} {
2479 update_index \
2480 "Adding [short_path $path]" \
2481 [list $path] \
2482 [concat $after [list ui_ready]]
2484 } else {
2485 show_diff $path $w $lno
2489 proc add_one_to_selection {w x y} {
2490 global file_lists last_clicked selected_paths
2492 set lno [lindex [split [$w index @$x,$y] .] 0]
2493 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2494 if {$path eq {}} {
2495 set last_clicked {}
2496 return
2499 if {$last_clicked ne {}
2500 && [lindex $last_clicked 0] ne $w} {
2501 array unset selected_paths
2502 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2505 set last_clicked [list $w $lno]
2506 if {[catch {set in_sel $selected_paths($path)}]} {
2507 set in_sel 0
2509 if {$in_sel} {
2510 unset selected_paths($path)
2511 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2512 } else {
2513 set selected_paths($path) 1
2514 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2518 proc add_range_to_selection {w x y} {
2519 global file_lists last_clicked selected_paths
2521 if {[lindex $last_clicked 0] ne $w} {
2522 toggle_or_diff $w $x $y
2523 return
2526 set lno [lindex [split [$w index @$x,$y] .] 0]
2527 set lc [lindex $last_clicked 1]
2528 if {$lc < $lno} {
2529 set begin $lc
2530 set end $lno
2531 } else {
2532 set begin $lno
2533 set end $lc
2536 foreach path [lrange $file_lists($w) \
2537 [expr {$begin - 1}] \
2538 [expr {$end - 1}]] {
2539 set selected_paths($path) 1
2541 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2544 proc show_more_context {} {
2545 global repo_config
2546 if {$repo_config(gui.diffcontext) < 99} {
2547 incr repo_config(gui.diffcontext)
2548 reshow_diff
2552 proc show_less_context {} {
2553 global repo_config
2554 if {$repo_config(gui.diffcontext) > 1} {
2555 incr repo_config(gui.diffcontext) -1
2556 reshow_diff
2560 ######################################################################
2562 ## ui construction
2564 set ui_comm {}
2566 # -- Menu Bar
2568 menu .mbar -tearoff 0
2569 if {[is_MacOSX]} {
2570 # -- Apple Menu (Mac OS X only)
2572 .mbar add cascade -label Apple -menu .mbar.apple
2573 menu .mbar.apple
2575 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2576 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2577 if {[is_enabled branch]} {
2578 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2580 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2581 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2583 if {[is_enabled transport]} {
2584 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2585 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2587 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2588 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2591 # -- Repository Menu
2593 menu .mbar.repository
2595 if {![is_bare]} {
2596 .mbar.repository add command \
2597 -label [mc "Explore Working Copy"] \
2598 -command {do_explore}
2599 .mbar.repository add separator
2602 .mbar.repository add command \
2603 -label [mc "Browse Current Branch's Files"] \
2604 -command {browser::new $current_branch}
2605 set ui_browse_current [.mbar.repository index last]
2606 .mbar.repository add command \
2607 -label [mc "Browse Branch Files..."] \
2608 -command browser_open::dialog
2609 .mbar.repository add separator
2611 .mbar.repository add command \
2612 -label [mc "Visualize Current Branch's History"] \
2613 -command {do_gitk $current_branch}
2614 set ui_visualize_current [.mbar.repository index last]
2615 .mbar.repository add command \
2616 -label [mc "Visualize All Branch History"] \
2617 -command {do_gitk --all}
2618 .mbar.repository add separator
2620 proc current_branch_write {args} {
2621 global current_branch
2622 .mbar.repository entryconf $::ui_browse_current \
2623 -label [mc "Browse %s's Files" $current_branch]
2624 .mbar.repository entryconf $::ui_visualize_current \
2625 -label [mc "Visualize %s's History" $current_branch]
2627 trace add variable current_branch write current_branch_write
2629 if {[is_enabled multicommit]} {
2630 .mbar.repository add command -label [mc "Database Statistics"] \
2631 -command do_stats
2633 .mbar.repository add command -label [mc "Compress Database"] \
2634 -command do_gc
2636 .mbar.repository add command -label [mc "Verify Database"] \
2637 -command do_fsck_objects
2639 .mbar.repository add separator
2641 if {[is_Cygwin]} {
2642 .mbar.repository add command \
2643 -label [mc "Create Desktop Icon"] \
2644 -command do_cygwin_shortcut
2645 } elseif {[is_Windows]} {
2646 .mbar.repository add command \
2647 -label [mc "Create Desktop Icon"] \
2648 -command do_windows_shortcut
2649 } elseif {[is_MacOSX]} {
2650 .mbar.repository add command \
2651 -label [mc "Create Desktop Icon"] \
2652 -command do_macosx_app
2656 if {[is_MacOSX]} {
2657 proc ::tk::mac::Quit {args} { do_quit }
2658 } else {
2659 .mbar.repository add command -label [mc Quit] \
2660 -command do_quit \
2661 -accelerator $M1T-Q
2664 # -- Edit Menu
2666 menu .mbar.edit
2667 .mbar.edit add command -label [mc Undo] \
2668 -command {catch {[focus] edit undo}} \
2669 -accelerator $M1T-Z
2670 .mbar.edit add command -label [mc Redo] \
2671 -command {catch {[focus] edit redo}} \
2672 -accelerator $M1T-Y
2673 .mbar.edit add separator
2674 .mbar.edit add command -label [mc Cut] \
2675 -command {catch {tk_textCut [focus]}} \
2676 -accelerator $M1T-X
2677 .mbar.edit add command -label [mc Copy] \
2678 -command {catch {tk_textCopy [focus]}} \
2679 -accelerator $M1T-C
2680 .mbar.edit add command -label [mc Paste] \
2681 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2682 -accelerator $M1T-V
2683 .mbar.edit add command -label [mc Delete] \
2684 -command {catch {[focus] delete sel.first sel.last}} \
2685 -accelerator Del
2686 .mbar.edit add separator
2687 .mbar.edit add command -label [mc "Select All"] \
2688 -command {catch {[focus] tag add sel 0.0 end}} \
2689 -accelerator $M1T-A
2691 # -- Branch Menu
2693 if {[is_enabled branch]} {
2694 menu .mbar.branch
2696 .mbar.branch add command -label [mc "Create..."] \
2697 -command branch_create::dialog \
2698 -accelerator $M1T-N
2699 lappend disable_on_lock [list .mbar.branch entryconf \
2700 [.mbar.branch index last] -state]
2702 .mbar.branch add command -label [mc "Checkout..."] \
2703 -command branch_checkout::dialog \
2704 -accelerator $M1T-O
2705 lappend disable_on_lock [list .mbar.branch entryconf \
2706 [.mbar.branch index last] -state]
2708 .mbar.branch add command -label [mc "Rename..."] \
2709 -command branch_rename::dialog
2710 lappend disable_on_lock [list .mbar.branch entryconf \
2711 [.mbar.branch index last] -state]
2713 .mbar.branch add command -label [mc "Delete..."] \
2714 -command branch_delete::dialog
2715 lappend disable_on_lock [list .mbar.branch entryconf \
2716 [.mbar.branch index last] -state]
2718 .mbar.branch add command -label [mc "Reset..."] \
2719 -command merge::reset_hard
2720 lappend disable_on_lock [list .mbar.branch entryconf \
2721 [.mbar.branch index last] -state]
2724 # -- Commit Menu
2726 proc commit_btn_caption {} {
2727 if {[is_enabled nocommit]} {
2728 return [mc "Done"]
2729 } else {
2730 return [mc Commit@@verb]
2734 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2735 menu .mbar.commit
2737 if {![is_enabled nocommit]} {
2738 .mbar.commit add radiobutton \
2739 -label [mc "New Commit"] \
2740 -command do_select_commit_type \
2741 -variable selected_commit_type \
2742 -value new
2743 lappend disable_on_lock \
2744 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2746 .mbar.commit add radiobutton \
2747 -label [mc "Amend Last Commit"] \
2748 -command do_select_commit_type \
2749 -variable selected_commit_type \
2750 -value amend
2751 lappend disable_on_lock \
2752 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2754 .mbar.commit add separator
2757 .mbar.commit add command -label [mc Rescan] \
2758 -command ui_do_rescan \
2759 -accelerator F5
2760 lappend disable_on_lock \
2761 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2763 .mbar.commit add command -label [mc "Stage To Commit"] \
2764 -command do_add_selection \
2765 -accelerator $M1T-T
2766 lappend disable_on_lock \
2767 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2769 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2770 -command do_add_all \
2771 -accelerator $M1T-I
2772 lappend disable_on_lock \
2773 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2775 .mbar.commit add command -label [mc "Unstage From Commit"] \
2776 -command do_unstage_selection \
2777 -accelerator $M1T-U
2778 lappend disable_on_lock \
2779 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2781 .mbar.commit add command -label [mc "Revert Changes"] \
2782 -command do_revert_selection \
2783 -accelerator $M1T-J
2784 lappend disable_on_lock \
2785 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2787 .mbar.commit add separator
2789 .mbar.commit add command -label [mc "Show Less Context"] \
2790 -command show_less_context \
2791 -accelerator $M1T-\-
2793 .mbar.commit add command -label [mc "Show More Context"] \
2794 -command show_more_context \
2795 -accelerator $M1T-=
2797 .mbar.commit add separator
2799 if {![is_enabled nocommitmsg]} {
2800 .mbar.commit add command -label [mc "Sign Off"] \
2801 -command do_signoff \
2802 -accelerator $M1T-S
2805 .mbar.commit add command -label [commit_btn_caption] \
2806 -command do_commit \
2807 -accelerator $M1T-Return
2808 lappend disable_on_lock \
2809 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2812 # -- Merge Menu
2814 if {[is_enabled branch]} {
2815 menu .mbar.merge
2816 .mbar.merge add command -label [mc "Local Merge..."] \
2817 -command merge::dialog \
2818 -accelerator $M1T-M
2819 lappend disable_on_lock \
2820 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2821 .mbar.merge add command -label [mc "Abort Merge..."] \
2822 -command merge::reset_hard
2823 lappend disable_on_lock \
2824 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2827 # -- Transport Menu
2829 if {[is_enabled transport]} {
2830 menu .mbar.remote
2832 .mbar.remote add command \
2833 -label [mc "Add..."] \
2834 -command remote_add::dialog \
2835 -accelerator $M1T-A
2836 .mbar.remote add command \
2837 -label [mc "Push..."] \
2838 -command do_push_anywhere \
2839 -accelerator $M1T-P
2840 .mbar.remote add command \
2841 -label [mc "Delete Branch..."] \
2842 -command remote_branch_delete::dialog
2845 if {[is_MacOSX]} {
2846 proc ::tk::mac::ShowPreferences {} {do_options}
2847 } else {
2848 # -- Edit Menu
2850 .mbar.edit add separator
2851 .mbar.edit add command -label [mc "Options..."] \
2852 -command do_options
2855 # -- Tools Menu
2857 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2858 set tools_menubar .mbar.tools
2859 menu $tools_menubar
2860 $tools_menubar add separator
2861 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2862 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2863 set tools_tailcnt 3
2864 if {[array names repo_config guitool.*.cmd] ne {}} {
2865 tools_populate_all
2869 # -- Help Menu
2871 .mbar add cascade -label [mc Help] -menu .mbar.help
2872 menu .mbar.help
2874 if {[is_MacOSX]} {
2875 .mbar.apple add command -label [mc "About %s" [appname]] \
2876 -command do_about
2877 .mbar.apple add separator
2878 } else {
2879 .mbar.help add command -label [mc "About %s" [appname]] \
2880 -command do_about
2882 . configure -menu .mbar
2884 set doc_path [githtmldir]
2885 if {$doc_path ne {}} {
2886 set doc_path [file join $doc_path index.html]
2888 if {[is_Cygwin]} {
2889 set doc_path [exec cygpath --mixed $doc_path]
2893 if {[file isfile $doc_path]} {
2894 set doc_url "file:$doc_path"
2895 } else {
2896 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2899 proc start_browser {url} {
2900 git "web--browse" $url
2903 .mbar.help add command -label [mc "Online Documentation"] \
2904 -command [list start_browser $doc_url]
2906 .mbar.help add command -label [mc "Show SSH Key"] \
2907 -command do_ssh_key
2909 unset doc_path doc_url
2911 # -- Standard bindings
2913 wm protocol . WM_DELETE_WINDOW do_quit
2914 bind all <$M1B-Key-q> do_quit
2915 bind all <$M1B-Key-Q> do_quit
2916 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2917 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2919 set subcommand_args {}
2920 proc usage {} {
2921 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2922 if {[tk windowingsystem] eq "win32"} {
2923 wm withdraw .
2924 tk_messageBox -icon info -message $s \
2925 -title [mc "Usage"]
2926 } else {
2927 puts stderr $s
2929 exit 1
2932 proc normalize_relpath {path} {
2933 set elements {}
2934 foreach item [file split $path] {
2935 if {$item eq {.}} continue
2936 if {$item eq {..} && [llength $elements] > 0
2937 && [lindex $elements end] ne {..}} {
2938 set elements [lrange $elements 0 end-1]
2939 continue
2941 lappend elements $item
2943 return [eval file join $elements]
2946 # -- Not a normal commit type invocation? Do that instead!
2948 switch -- $subcommand {
2949 browser -
2950 blame {
2951 if {$subcommand eq "blame"} {
2952 set subcommand_args {[--line=<num>] rev? path}
2953 } else {
2954 set subcommand_args {rev? path}
2956 if {$argv eq {}} usage
2957 set head {}
2958 set path {}
2959 set jump_spec {}
2960 set is_path 0
2961 foreach a $argv {
2962 if {$is_path || [file exists $_prefix$a]} {
2963 if {$path ne {}} usage
2964 set path [normalize_relpath $_prefix$a]
2965 break
2966 } elseif {$a eq {--}} {
2967 if {$path ne {}} {
2968 if {$head ne {}} usage
2969 set head $path
2970 set path {}
2972 set is_path 1
2973 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2974 if {$jump_spec ne {} || $head ne {}} usage
2975 set jump_spec [list $lnum]
2976 } elseif {$head eq {}} {
2977 if {$head ne {}} usage
2978 set head $a
2979 set is_path 1
2980 } else {
2981 usage
2984 unset is_path
2986 if {$head ne {} && $path eq {}} {
2987 set path [normalize_relpath $_prefix$head]
2988 set head {}
2991 if {$head eq {}} {
2992 load_current_branch
2993 } else {
2994 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2995 if {[catch {
2996 set head [git rev-parse --verify $head]
2997 } err]} {
2998 if {[tk windowingsystem] eq "win32"} {
2999 tk_messageBox -icon error -title [mc Error] -message $err
3000 } else {
3001 puts stderr $err
3003 exit 1
3006 set current_branch $head
3009 wm deiconify .
3010 switch -- $subcommand {
3011 browser {
3012 if {$jump_spec ne {}} usage
3013 if {$head eq {}} {
3014 if {$path ne {} && [file isdirectory $path]} {
3015 set head $current_branch
3016 } else {
3017 set head $path
3018 set path {}
3021 browser::new $head $path
3023 blame {
3024 if {$head eq {} && ![file exists $path]} {
3025 catch {wm withdraw .}
3026 tk_messageBox \
3027 -icon error \
3028 -type ok \
3029 -title [mc "git-gui: fatal error"] \
3030 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
3031 exit 1
3033 blame::new $head $path $jump_spec
3036 return
3038 citool -
3039 gui {
3040 if {[llength $argv] != 0} {
3041 usage
3043 # fall through to setup UI for commits
3045 default {
3046 set err "usage: $argv0 \[{blame|browser|citool}\]"
3047 if {[tk windowingsystem] eq "win32"} {
3048 wm withdraw .
3049 tk_messageBox -icon error -message $err \
3050 -title [mc "Usage"]
3051 } else {
3052 puts stderr $err
3054 exit 1
3058 # -- Branch Control
3060 ${NS}::frame .branch
3061 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3062 ${NS}::label .branch.l1 \
3063 -text [mc "Current Branch:"] \
3064 -anchor w \
3065 -justify left
3066 ${NS}::label .branch.cb \
3067 -textvariable current_branch \
3068 -anchor w \
3069 -justify left
3070 pack .branch.l1 -side left
3071 pack .branch.cb -side left -fill x
3072 pack .branch -side top -fill x
3074 # -- Main Window Layout
3076 ${NS}::panedwindow .vpane -orient horizontal
3077 ${NS}::panedwindow .vpane.files -orient vertical
3078 if {$use_ttk} {
3079 .vpane add .vpane.files
3080 } else {
3081 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3083 pack .vpane -anchor n -side top -fill both -expand 1
3085 # -- Index File List
3087 ${NS}::frame .vpane.files.index -height 100 -width 200
3088 tlabel .vpane.files.index.title \
3089 -text [mc "Staged Changes (Will Commit)"] \
3090 -background lightgreen -foreground black
3091 text $ui_index -background white -foreground black \
3092 -borderwidth 0 \
3093 -width 20 -height 10 \
3094 -wrap none \
3095 -cursor $cursor_ptr \
3096 -xscrollcommand {.vpane.files.index.sx set} \
3097 -yscrollcommand {.vpane.files.index.sy set} \
3098 -state disabled
3099 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3100 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3101 pack .vpane.files.index.title -side top -fill x
3102 pack .vpane.files.index.sx -side bottom -fill x
3103 pack .vpane.files.index.sy -side right -fill y
3104 pack $ui_index -side left -fill both -expand 1
3106 # -- Working Directory File List
3108 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3109 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3110 -background lightsalmon -foreground black
3111 text $ui_workdir -background white -foreground black \
3112 -borderwidth 0 \
3113 -width 20 -height 10 \
3114 -wrap none \
3115 -cursor $cursor_ptr \
3116 -xscrollcommand {.vpane.files.workdir.sx set} \
3117 -yscrollcommand {.vpane.files.workdir.sy set} \
3118 -state disabled
3119 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3120 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3121 pack .vpane.files.workdir.title -side top -fill x
3122 pack .vpane.files.workdir.sx -side bottom -fill x
3123 pack .vpane.files.workdir.sy -side right -fill y
3124 pack $ui_workdir -side left -fill both -expand 1
3126 .vpane.files add .vpane.files.workdir
3127 .vpane.files add .vpane.files.index
3128 if {!$use_ttk} {
3129 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3130 .vpane.files paneconfigure .vpane.files.index -sticky news
3133 foreach i [list $ui_index $ui_workdir] {
3134 rmsel_tag $i
3135 $i tag conf in_diff -background [$i tag cget in_sel -background]
3137 unset i
3139 # -- Diff and Commit Area
3141 ${NS}::frame .vpane.lower -height 300 -width 400
3142 ${NS}::frame .vpane.lower.commarea
3143 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3144 pack .vpane.lower.diff -fill both -expand 1
3145 pack .vpane.lower.commarea -side bottom -fill x
3146 .vpane add .vpane.lower
3147 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3149 # -- Commit Area Buttons
3151 ${NS}::frame .vpane.lower.commarea.buttons
3152 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3153 -anchor w \
3154 -justify left
3155 pack .vpane.lower.commarea.buttons.l -side top -fill x
3156 pack .vpane.lower.commarea.buttons -side left -fill y
3158 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3159 -command ui_do_rescan
3160 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3161 lappend disable_on_lock \
3162 {.vpane.lower.commarea.buttons.rescan conf -state}
3164 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3165 -command do_add_all
3166 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3167 lappend disable_on_lock \
3168 {.vpane.lower.commarea.buttons.incall conf -state}
3170 if {![is_enabled nocommitmsg]} {
3171 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3172 -command do_signoff
3173 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3176 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3177 -command do_commit
3178 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3179 lappend disable_on_lock \
3180 {.vpane.lower.commarea.buttons.commit conf -state}
3182 if {![is_enabled nocommit]} {
3183 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3184 -command do_push_anywhere
3185 pack .vpane.lower.commarea.buttons.push -side top -fill x
3188 # -- Commit Message Buffer
3190 ${NS}::frame .vpane.lower.commarea.buffer
3191 ${NS}::frame .vpane.lower.commarea.buffer.header
3192 set ui_comm .vpane.lower.commarea.buffer.t
3193 set ui_coml .vpane.lower.commarea.buffer.header.l
3195 if {![is_enabled nocommit]} {
3196 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3197 -text [mc "New Commit"] \
3198 -command do_select_commit_type \
3199 -variable selected_commit_type \
3200 -value new
3201 lappend disable_on_lock \
3202 [list .vpane.lower.commarea.buffer.header.new conf -state]
3203 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3204 -text [mc "Amend Last Commit"] \
3205 -command do_select_commit_type \
3206 -variable selected_commit_type \
3207 -value amend
3208 lappend disable_on_lock \
3209 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3212 ${NS}::label $ui_coml \
3213 -anchor w \
3214 -justify left
3215 proc trace_commit_type {varname args} {
3216 global ui_coml commit_type
3217 switch -glob -- $commit_type {
3218 initial {set txt [mc "Initial Commit Message:"]}
3219 amend {set txt [mc "Amended Commit Message:"]}
3220 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3221 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3222 merge {set txt [mc "Merge Commit Message:"]}
3223 * {set txt [mc "Commit Message:"]}
3225 $ui_coml conf -text $txt
3227 trace add variable commit_type write trace_commit_type
3228 pack $ui_coml -side left -fill x
3230 if {![is_enabled nocommit]} {
3231 pack .vpane.lower.commarea.buffer.header.amend -side right
3232 pack .vpane.lower.commarea.buffer.header.new -side right
3235 text $ui_comm -background white -foreground black \
3236 -borderwidth 1 \
3237 -undo true \
3238 -maxundo 20 \
3239 -autoseparators true \
3240 -relief sunken \
3241 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3242 -font font_diff \
3243 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3244 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3245 -command [list $ui_comm yview]
3246 pack .vpane.lower.commarea.buffer.header -side top -fill x
3247 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3248 pack $ui_comm -side left -fill y
3249 pack .vpane.lower.commarea.buffer -side left -fill y
3251 # -- Commit Message Buffer Context Menu
3253 set ctxm .vpane.lower.commarea.buffer.ctxm
3254 menu $ctxm -tearoff 0
3255 $ctxm add command \
3256 -label [mc Cut] \
3257 -command {tk_textCut $ui_comm}
3258 $ctxm add command \
3259 -label [mc Copy] \
3260 -command {tk_textCopy $ui_comm}
3261 $ctxm add command \
3262 -label [mc Paste] \
3263 -command {tk_textPaste $ui_comm}
3264 $ctxm add command \
3265 -label [mc Delete] \
3266 -command {catch {$ui_comm delete sel.first sel.last}}
3267 $ctxm add separator
3268 $ctxm add command \
3269 -label [mc "Select All"] \
3270 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3271 $ctxm add command \
3272 -label [mc "Copy All"] \
3273 -command {
3274 $ui_comm tag add sel 0.0 end
3275 tk_textCopy $ui_comm
3276 $ui_comm tag remove sel 0.0 end
3278 $ctxm add separator
3279 $ctxm add command \
3280 -label [mc "Sign Off"] \
3281 -command do_signoff
3282 set ui_comm_ctxm $ctxm
3284 # -- Diff Header
3286 proc trace_current_diff_path {varname args} {
3287 global current_diff_path diff_actions file_states
3288 if {$current_diff_path eq {}} {
3289 set s {}
3290 set f {}
3291 set p {}
3292 set o disabled
3293 } else {
3294 set p $current_diff_path
3295 set s [mapdesc [lindex $file_states($p) 0] $p]
3296 set f [mc "File:"]
3297 set p [escape_path $p]
3298 set o normal
3301 .vpane.lower.diff.header.status configure -text $s
3302 .vpane.lower.diff.header.file configure -text $f
3303 .vpane.lower.diff.header.path configure -text $p
3304 foreach w $diff_actions {
3305 uplevel #0 $w $o
3308 trace add variable current_diff_path write trace_current_diff_path
3310 gold_frame .vpane.lower.diff.header
3311 tlabel .vpane.lower.diff.header.status \
3312 -background gold \
3313 -foreground black \
3314 -width $max_status_desc \
3315 -anchor w \
3316 -justify left
3317 tlabel .vpane.lower.diff.header.file \
3318 -background gold \
3319 -foreground black \
3320 -anchor w \
3321 -justify left
3322 tlabel .vpane.lower.diff.header.path \
3323 -background gold \
3324 -foreground black \
3325 -anchor w \
3326 -justify left
3327 pack .vpane.lower.diff.header.status -side left
3328 pack .vpane.lower.diff.header.file -side left
3329 pack .vpane.lower.diff.header.path -fill x
3330 set ctxm .vpane.lower.diff.header.ctxm
3331 menu $ctxm -tearoff 0
3332 $ctxm add command \
3333 -label [mc Copy] \
3334 -command {
3335 clipboard clear
3336 clipboard append \
3337 -format STRING \
3338 -type STRING \
3339 -- $current_diff_path
3341 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3342 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3344 # -- Diff Body
3346 ${NS}::frame .vpane.lower.diff.body
3347 set ui_diff .vpane.lower.diff.body.t
3348 text $ui_diff -background white -foreground black \
3349 -borderwidth 0 \
3350 -width 80 -height 5 -wrap none \
3351 -font font_diff \
3352 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3353 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3354 -state disabled
3355 catch {$ui_diff configure -tabstyle wordprocessor}
3356 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3357 -command [list $ui_diff xview]
3358 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3359 -command [list $ui_diff yview]
3360 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3361 pack .vpane.lower.diff.body.sby -side right -fill y
3362 pack $ui_diff -side left -fill both -expand 1
3363 pack .vpane.lower.diff.header -side top -fill x
3364 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3366 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3367 $ui_diff tag configure clr4$n -background $c
3368 $ui_diff tag configure clri4$n -foreground $c
3369 $ui_diff tag configure clr3$n -foreground $c
3370 $ui_diff tag configure clri3$n -background $c
3372 $ui_diff tag configure clr1 -font font_diffbold
3374 $ui_diff tag conf d_info -foreground blue -font font_diffbold
3376 $ui_diff tag conf d_cr -elide true
3377 $ui_diff tag conf d_@ -font font_diffbold
3378 $ui_diff tag conf d_+ -foreground {#00a000}
3379 $ui_diff tag conf d_- -foreground red
3381 $ui_diff tag conf d_++ -foreground {#00a000}
3382 $ui_diff tag conf d_-- -foreground red
3383 $ui_diff tag conf d_+s \
3384 -foreground {#00a000} \
3385 -background {#e2effa}
3386 $ui_diff tag conf d_-s \
3387 -foreground red \
3388 -background {#e2effa}
3389 $ui_diff tag conf d_s+ \
3390 -foreground {#00a000} \
3391 -background ivory1
3392 $ui_diff tag conf d_s- \
3393 -foreground red \
3394 -background ivory1
3396 $ui_diff tag conf d< \
3397 -foreground orange \
3398 -font font_diffbold
3399 $ui_diff tag conf d= \
3400 -foreground orange \
3401 -font font_diffbold
3402 $ui_diff tag conf d> \
3403 -foreground orange \
3404 -font font_diffbold
3406 $ui_diff tag raise sel
3408 # -- Diff Body Context Menu
3411 proc create_common_diff_popup {ctxm} {
3412 $ctxm add command \
3413 -label [mc Refresh] \
3414 -command reshow_diff
3415 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3416 $ctxm add command \
3417 -label [mc Copy] \
3418 -command {tk_textCopy $ui_diff}
3419 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3420 $ctxm add command \
3421 -label [mc "Select All"] \
3422 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3423 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3424 $ctxm add command \
3425 -label [mc "Copy All"] \
3426 -command {
3427 $ui_diff tag add sel 0.0 end
3428 tk_textCopy $ui_diff
3429 $ui_diff tag remove sel 0.0 end
3431 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3432 $ctxm add separator
3433 $ctxm add command \
3434 -label [mc "Decrease Font Size"] \
3435 -command {incr_font_size font_diff -1}
3436 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3437 $ctxm add command \
3438 -label [mc "Increase Font Size"] \
3439 -command {incr_font_size font_diff 1}
3440 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3441 $ctxm add separator
3442 set emenu $ctxm.enc
3443 menu $emenu
3444 build_encoding_menu $emenu [list force_diff_encoding]
3445 $ctxm add cascade \
3446 -label [mc "Encoding"] \
3447 -menu $emenu
3448 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3449 $ctxm add separator
3450 $ctxm add command -label [mc "Options..."] \
3451 -command do_options
3454 set ctxm .vpane.lower.diff.body.ctxm
3455 menu $ctxm -tearoff 0
3456 $ctxm add command \
3457 -label [mc "Apply/Reverse Hunk"] \
3458 -command {apply_hunk $cursorX $cursorY}
3459 set ui_diff_applyhunk [$ctxm index last]
3460 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3461 $ctxm add command \
3462 -label [mc "Apply/Reverse Line"] \
3463 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3464 set ui_diff_applyline [$ctxm index last]
3465 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3466 $ctxm add separator
3467 $ctxm add command \
3468 -label [mc "Show Less Context"] \
3469 -command show_less_context
3470 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3471 $ctxm add command \
3472 -label [mc "Show More Context"] \
3473 -command show_more_context
3474 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3475 $ctxm add separator
3476 create_common_diff_popup $ctxm
3478 set ctxmmg .vpane.lower.diff.body.ctxmmg
3479 menu $ctxmmg -tearoff 0
3480 $ctxmmg add command \
3481 -label [mc "Run Merge Tool"] \
3482 -command {merge_resolve_tool}
3483 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3484 $ctxmmg add separator
3485 $ctxmmg add command \
3486 -label [mc "Use Remote Version"] \
3487 -command {merge_resolve_one 3}
3488 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3489 $ctxmmg add command \
3490 -label [mc "Use Local Version"] \
3491 -command {merge_resolve_one 2}
3492 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3493 $ctxmmg add command \
3494 -label [mc "Revert To Base"] \
3495 -command {merge_resolve_one 1}
3496 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3497 $ctxmmg add separator
3498 $ctxmmg add command \
3499 -label [mc "Show Less Context"] \
3500 -command show_less_context
3501 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3502 $ctxmmg add command \
3503 -label [mc "Show More Context"] \
3504 -command show_more_context
3505 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3506 $ctxmmg add separator
3507 create_common_diff_popup $ctxmmg
3509 set ctxmsm .vpane.lower.diff.body.ctxmsm
3510 menu $ctxmsm -tearoff 0
3511 $ctxmsm add command \
3512 -label [mc "Visualize These Changes In The Submodule"] \
3513 -command {do_gitk -- true}
3514 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3515 $ctxmsm add command \
3516 -label [mc "Visualize Current Branch History In The Submodule"] \
3517 -command {do_gitk {} true}
3518 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3519 $ctxmsm add command \
3520 -label [mc "Visualize All Branch History In The Submodule"] \
3521 -command {do_gitk --all true}
3522 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3523 $ctxmsm add separator
3524 $ctxmsm add command \
3525 -label [mc "Start git gui In The Submodule"] \
3526 -command {do_git_gui}
3527 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3528 $ctxmsm add separator
3529 create_common_diff_popup $ctxmsm
3531 proc has_textconv {path} {
3532 if {[is_config_false gui.textconv]} {
3533 return 0
3535 set filter [gitattr $path diff set]
3536 set textconv [get_config [join [list diff $filter textconv] .]]
3537 if {$filter ne {set} && $textconv ne {}} {
3538 return 1
3539 } else {
3540 return 0
3544 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3545 global current_diff_path file_states
3546 set ::cursorX $x
3547 set ::cursorY $y
3548 if {[info exists file_states($current_diff_path)]} {
3549 set state [lindex $file_states($current_diff_path) 0]
3550 } else {
3551 set state {__}
3553 if {[string first {U} $state] >= 0} {
3554 tk_popup $ctxmmg $X $Y
3555 } elseif {$::is_submodule_diff} {
3556 tk_popup $ctxmsm $X $Y
3557 } else {
3558 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3559 if {$::ui_index eq $::current_diff_side} {
3560 set l [mc "Unstage Hunk From Commit"]
3561 if {$has_range} {
3562 set t [mc "Unstage Lines From Commit"]
3563 } else {
3564 set t [mc "Unstage Line From Commit"]
3566 } else {
3567 set l [mc "Stage Hunk For Commit"]
3568 if {$has_range} {
3569 set t [mc "Stage Lines For Commit"]
3570 } else {
3571 set t [mc "Stage Line For Commit"]
3574 if {$::is_3way_diff
3575 || $current_diff_path eq {}
3576 || {__} eq $state
3577 || {_O} eq $state
3578 || [string match {?T} $state]
3579 || [string match {T?} $state]
3580 || [has_textconv $current_diff_path]} {
3581 set s disabled
3582 } else {
3583 set s normal
3585 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3586 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3587 tk_popup $ctxm $X $Y
3590 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3592 # -- Status Bar
3594 set main_status [::status_bar::new .status]
3595 pack .status -anchor w -side bottom -fill x
3596 $main_status show [mc "Initializing..."]
3598 # -- Load geometry
3600 proc on_ttk_pane_mapped {w pane pos} {
3601 bind $w <Map> {}
3602 after 0 [list after idle [list $w sashpos $pane $pos]]
3604 proc on_tk_pane_mapped {w pane x y} {
3605 bind $w <Map> {}
3606 after 0 [list after idle [list $w sash place $pane $x $y]]
3608 proc on_application_mapped {} {
3609 global repo_config use_ttk
3610 bind . <Map> {}
3611 set gm $repo_config(gui.geometry)
3612 if {$use_ttk} {
3613 bind .vpane <Map> \
3614 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3615 bind .vpane.files <Map> \
3616 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3617 } else {
3618 bind .vpane <Map> \
3619 [list on_tk_pane_mapped %W 0 \
3620 [lindex $gm 1] \
3621 [lindex [.vpane sash coord 0] 1]]
3622 bind .vpane.files <Map> \
3623 [list on_tk_pane_mapped %W 0 \
3624 [lindex [.vpane.files sash coord 0] 0] \
3625 [lindex $gm 2]]
3627 wm geometry . [lindex $gm 0]
3629 if {[info exists repo_config(gui.geometry)]} {
3630 bind . <Map> [list on_application_mapped]
3631 wm geometry . [lindex $repo_config(gui.geometry) 0]
3634 # -- Load window state
3636 if {[info exists repo_config(gui.wmstate)]} {
3637 catch {wm state . $repo_config(gui.wmstate)}
3640 # -- Key Bindings
3642 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3643 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3644 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3645 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3646 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3647 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3648 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3649 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3650 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3651 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3652 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3653 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3654 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3655 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3656 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3657 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3658 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3659 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3660 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3661 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3662 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3663 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3665 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3666 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3667 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3668 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3669 bind $ui_diff <$M1B-Key-v> {break}
3670 bind $ui_diff <$M1B-Key-V> {break}
3671 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3672 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3673 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3674 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3675 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3676 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3677 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3678 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3679 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3680 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3681 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3682 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3683 bind $ui_diff <Button-1> {focus %W}
3685 if {[is_enabled branch]} {
3686 bind . <$M1B-Key-n> branch_create::dialog
3687 bind . <$M1B-Key-N> branch_create::dialog
3688 bind . <$M1B-Key-o> branch_checkout::dialog
3689 bind . <$M1B-Key-O> branch_checkout::dialog
3690 bind . <$M1B-Key-m> merge::dialog
3691 bind . <$M1B-Key-M> merge::dialog
3693 if {[is_enabled transport]} {
3694 bind . <$M1B-Key-p> do_push_anywhere
3695 bind . <$M1B-Key-P> do_push_anywhere
3698 bind . <Key-F5> ui_do_rescan
3699 bind . <$M1B-Key-r> ui_do_rescan
3700 bind . <$M1B-Key-R> ui_do_rescan
3701 bind . <$M1B-Key-s> do_signoff
3702 bind . <$M1B-Key-S> do_signoff
3703 bind . <$M1B-Key-t> do_add_selection
3704 bind . <$M1B-Key-T> do_add_selection
3705 bind . <$M1B-Key-j> do_revert_selection
3706 bind . <$M1B-Key-J> do_revert_selection
3707 bind . <$M1B-Key-i> do_add_all
3708 bind . <$M1B-Key-I> do_add_all
3709 bind . <$M1B-Key-minus> {show_less_context;break}
3710 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3711 bind . <$M1B-Key-equal> {show_more_context;break}
3712 bind . <$M1B-Key-plus> {show_more_context;break}
3713 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3714 bind . <$M1B-Key-Return> do_commit
3715 foreach i [list $ui_index $ui_workdir] {
3716 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3717 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3718 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3720 unset i
3722 set file_lists($ui_index) [list]
3723 set file_lists($ui_workdir) [list]
3725 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3726 focus -force $ui_comm
3728 # -- Warn the user about environmental problems. Cygwin's Tcl
3729 # does *not* pass its env array onto any processes it spawns.
3730 # This means that git processes get none of our environment.
3732 if {[is_Cygwin]} {
3733 set ignored_env 0
3734 set suggest_user {}
3735 set msg [mc "Possible environment issues exist.
3737 The following environment variables are probably
3738 going to be ignored by any Git subprocess run
3739 by %s:
3741 " [appname]]
3742 foreach name [array names env] {
3743 switch -regexp -- $name {
3744 {^GIT_INDEX_FILE$} -
3745 {^GIT_OBJECT_DIRECTORY$} -
3746 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3747 {^GIT_DIFF_OPTS$} -
3748 {^GIT_EXTERNAL_DIFF$} -
3749 {^GIT_PAGER$} -
3750 {^GIT_TRACE$} -
3751 {^GIT_CONFIG$} -
3752 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3753 append msg " - $name\n"
3754 incr ignored_env
3756 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3757 append msg " - $name\n"
3758 incr ignored_env
3759 set suggest_user $name
3763 if {$ignored_env > 0} {
3764 append msg [mc "
3765 This is due to a known issue with the
3766 Tcl binary distributed by Cygwin."]
3768 if {$suggest_user ne {}} {
3769 append msg [mc "
3771 A good replacement for %s
3772 is placing values for the user.name and
3773 user.email settings into your personal
3774 ~/.gitconfig file.
3775 " $suggest_user]
3777 warn_popup $msg
3779 unset ignored_env msg suggest_user name
3782 # -- Only initialize complex UI if we are going to stay running.
3784 if {[is_enabled transport]} {
3785 load_all_remotes
3787 set n [.mbar.remote index end]
3788 populate_remotes_menu
3789 set n [expr {[.mbar.remote index end] - $n}]
3790 if {$n > 0} {
3791 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3792 .mbar.remote insert $n separator
3794 unset n
3797 if {[winfo exists $ui_comm]} {
3798 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3800 # -- If both our backup and message files exist use the
3801 # newer of the two files to initialize the buffer.
3803 if {$GITGUI_BCK_exists} {
3804 set m [gitdir GITGUI_MSG]
3805 if {[file isfile $m]} {
3806 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3807 catch {file delete [gitdir GITGUI_MSG]}
3808 } else {
3809 $ui_comm delete 0.0 end
3810 $ui_comm edit reset
3811 $ui_comm edit modified false
3812 catch {file delete [gitdir GITGUI_BCK]}
3813 set GITGUI_BCK_exists 0
3816 unset m
3819 proc backup_commit_buffer {} {
3820 global ui_comm GITGUI_BCK_exists
3822 set m [$ui_comm edit modified]
3823 if {$m || $GITGUI_BCK_exists} {
3824 set msg [string trim [$ui_comm get 0.0 end]]
3825 regsub -all -line {[ \r\t]+$} $msg {} msg
3827 if {$msg eq {}} {
3828 if {$GITGUI_BCK_exists} {
3829 catch {file delete [gitdir GITGUI_BCK]}
3830 set GITGUI_BCK_exists 0
3832 } elseif {$m} {
3833 catch {
3834 set fd [open [gitdir GITGUI_BCK] w]
3835 puts -nonewline $fd $msg
3836 close $fd
3837 set GITGUI_BCK_exists 1
3841 $ui_comm edit modified false
3844 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3847 backup_commit_buffer
3849 # -- If the user has aspell available we can drive it
3850 # in pipe mode to spellcheck the commit message.
3852 set spell_cmd [list |]
3853 set spell_dict [get_config gui.spellingdictionary]
3854 lappend spell_cmd aspell
3855 if {$spell_dict ne {}} {
3856 lappend spell_cmd --master=$spell_dict
3858 lappend spell_cmd --mode=none
3859 lappend spell_cmd --encoding=utf-8
3860 lappend spell_cmd pipe
3861 if {$spell_dict eq {none}
3862 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3863 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3864 } else {
3865 set ui_comm_spell [spellcheck::init \
3866 $spell_fd \
3867 $ui_comm \
3868 $ui_comm_ctxm \
3871 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3874 lock_index begin-read
3875 if {![winfo ismapped .]} {
3876 wm deiconify .
3878 after 1 {
3879 if {[is_enabled initialamend]} {
3880 force_amend
3881 } else {
3882 do_rescan
3885 if {[is_enabled nocommitmsg]} {
3886 $ui_comm configure -state disabled -background gray
3889 if {[is_enabled multicommit]} {
3890 after 1000 hint_gc
3892 if {[is_enabled retcode]} {
3893 bind . <Destroy> {+terminate_me %W}
3895 if {$picked && [is_config_true gui.autoexplore]} {
3896 do_explore
3899 # Local variables:
3900 # mode: tcl
3901 # indent-tabs-mode: t
3902 # tab-width: 4
3903 # End: