Win32: patch Windows environment on startup
[git/mingw/4msysgit/kblees.git] / git-gui / git-gui.sh
blob5f1faebf6712956d6dc74a203a39ee48e5c9ce9f
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 default_config(gui.warndetachedcommit) 1
858 set font_descs {
859 {fontui font_ui {mc "Main Font"}}
860 {fontdiff font_diff {mc "Diff/Console Font"}}
863 ######################################################################
865 ## find git
867 set _git [_which git]
868 if {$_git eq {}} {
869 catch {wm withdraw .}
870 tk_messageBox \
871 -icon error \
872 -type ok \
873 -title [mc "git-gui: fatal error"] \
874 -message [mc "Cannot find git in PATH."]
875 exit 1
878 ######################################################################
880 ## version check
882 if {[catch {set _git_version [git --version]} err]} {
883 catch {wm withdraw .}
884 tk_messageBox \
885 -icon error \
886 -type ok \
887 -title [mc "git-gui: fatal error"] \
888 -message "Cannot determine Git version:
890 $err
892 [appname] requires Git 1.5.0 or later."
893 exit 1
895 if {![regsub {^git version } $_git_version {} _git_version]} {
896 catch {wm withdraw .}
897 tk_messageBox \
898 -icon error \
899 -type ok \
900 -title [mc "git-gui: fatal error"] \
901 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
902 exit 1
905 proc get_trimmed_version {s} {
906 set r {}
907 foreach x [split $s -._] {
908 if {[string is integer -strict $x]} {
909 lappend r $x
910 } else {
911 break
914 return [join $r .]
916 set _real_git_version $_git_version
917 set _git_version [get_trimmed_version $_git_version]
919 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
920 catch {wm withdraw .}
921 if {[tk_messageBox \
922 -icon warning \
923 -type yesno \
924 -default no \
925 -title "[appname]: warning" \
926 -message [mc "Git version cannot be determined.
928 %s claims it is version '%s'.
930 %s requires at least Git 1.5.0 or later.
932 Assume '%s' is version 1.5.0?
933 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
934 set _git_version 1.5.0
935 } else {
936 exit 1
939 unset _real_git_version
941 proc git-version {args} {
942 global _git_version
944 switch [llength $args] {
946 return $_git_version
950 set op [lindex $args 0]
951 set vr [lindex $args 1]
952 set cm [package vcompare $_git_version $vr]
953 return [expr $cm $op 0]
957 set type [lindex $args 0]
958 set name [lindex $args 1]
959 set parm [lindex $args 2]
960 set body [lindex $args 3]
962 if {($type ne {proc} && $type ne {method})} {
963 error "Invalid arguments to git-version"
965 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
966 error "Last arm of $type $name must be default"
969 foreach {op vr cb} [lrange $body 0 end-2] {
970 if {[git-version $op $vr]} {
971 return [uplevel [list $type $name $parm $cb]]
975 return [uplevel [list $type $name $parm [lindex $body end]]]
978 default {
979 error "git-version >= x"
985 if {[git-version < 1.5]} {
986 catch {wm withdraw .}
987 tk_messageBox \
988 -icon error \
989 -type ok \
990 -title [mc "git-gui: fatal error"] \
991 -message "[appname] requires Git 1.5.0 or later.
993 You are using [git-version]:
995 [git --version]"
996 exit 1
999 ######################################################################
1001 ## configure our library
1003 set idx [file join $oguilib tclIndex]
1004 if {[catch {set fd [open $idx r]} err]} {
1005 catch {wm withdraw .}
1006 tk_messageBox \
1007 -icon error \
1008 -type ok \
1009 -title [mc "git-gui: fatal error"] \
1010 -message $err
1011 exit 1
1013 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1014 set idx [list]
1015 while {[gets $fd n] >= 0} {
1016 if {$n ne {} && ![string match #* $n]} {
1017 lappend idx $n
1020 } else {
1021 set idx {}
1023 close $fd
1025 if {$idx ne {}} {
1026 set loaded [list]
1027 foreach p $idx {
1028 if {[lsearch -exact $loaded $p] >= 0} continue
1029 source [file join $oguilib $p]
1030 lappend loaded $p
1032 unset loaded p
1033 } else {
1034 set auto_path [concat [list $oguilib] $auto_path]
1036 unset -nocomplain idx fd
1038 ######################################################################
1040 ## config file parsing
1042 git-version proc _parse_config {arr_name args} {
1043 >= 1.5.3 {
1044 upvar $arr_name arr
1045 array unset arr
1046 set buf {}
1047 catch {
1048 set fd_rc [eval \
1049 [list git_read config] \
1050 $args \
1051 [list --null --list]]
1052 fconfigure $fd_rc -translation binary
1053 set buf [read $fd_rc]
1054 close $fd_rc
1056 foreach line [split $buf "\0"] {
1057 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1058 if {[is_many_config $name]} {
1059 lappend arr($name) $value
1060 } else {
1061 set arr($name) $value
1066 default {
1067 upvar $arr_name arr
1068 array unset arr
1069 catch {
1070 set fd_rc [eval [list git_read config --list] $args]
1071 while {[gets $fd_rc line] >= 0} {
1072 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1073 if {[is_many_config $name]} {
1074 lappend arr($name) $value
1075 } else {
1076 set arr($name) $value
1080 close $fd_rc
1085 proc load_config {include_global} {
1086 global repo_config global_config system_config default_config
1088 if {$include_global} {
1089 _parse_config system_config --system
1090 _parse_config global_config --global
1092 _parse_config repo_config
1094 foreach name [array names default_config] {
1095 if {[catch {set v $system_config($name)}]} {
1096 set system_config($name) $default_config($name)
1099 foreach name [array names system_config] {
1100 if {[catch {set v $global_config($name)}]} {
1101 set global_config($name) $system_config($name)
1103 if {[catch {set v $repo_config($name)}]} {
1104 set repo_config($name) $system_config($name)
1109 ######################################################################
1111 ## feature option selection
1113 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1114 unset _junk
1115 } else {
1116 set subcommand gui
1118 if {$subcommand eq {gui.sh}} {
1119 set subcommand gui
1121 if {$subcommand eq {gui} && [llength $argv] > 0} {
1122 set subcommand [lindex $argv 0]
1123 set argv [lrange $argv 1 end]
1126 enable_option multicommit
1127 enable_option branch
1128 enable_option transport
1129 disable_option bare
1131 switch -- $subcommand {
1132 browser -
1133 blame {
1134 enable_option bare
1136 disable_option multicommit
1137 disable_option branch
1138 disable_option transport
1140 citool {
1141 enable_option singlecommit
1142 enable_option retcode
1144 disable_option multicommit
1145 disable_option branch
1146 disable_option transport
1148 while {[llength $argv] > 0} {
1149 set a [lindex $argv 0]
1150 switch -- $a {
1151 --amend {
1152 enable_option initialamend
1154 --nocommit {
1155 enable_option nocommit
1156 enable_option nocommitmsg
1158 --commitmsg {
1159 disable_option nocommitmsg
1161 default {
1162 break
1166 set argv [lrange $argv 1 end]
1171 ######################################################################
1173 ## execution environment
1175 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1177 # Suggest our implementation of askpass, if none is set
1178 if {![info exists env(SSH_ASKPASS)]} {
1179 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1181 if {![info exists env(GIT_ASKPASS)]} {
1182 set env(GIT_ASKPASS) [gitexec git-gui--askpass]
1184 if {![info exists env(GIT_ASK_YESNO)]} {
1185 set env(GIT_ASK_YESNO) [gitexec git-gui--askyesno]
1188 ######################################################################
1190 ## repository setup
1192 set picked 0
1193 if {[catch {
1194 set _gitdir $env(GIT_DIR)
1195 set _prefix {}
1197 && [catch {
1198 # beware that from the .git dir this sets _gitdir to .
1199 # and _prefix to the empty string
1200 set _gitdir [git rev-parse --git-dir]
1201 set _prefix [git rev-parse --show-prefix]
1202 } err]} {
1203 load_config 1
1204 apply_config
1205 choose_repository::pick
1206 set picked 1
1209 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1210 # run from the .git dir itself) lest the routines to find the worktree
1211 # get confused
1212 if {$_gitdir eq "."} {
1213 set _gitdir [pwd]
1216 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1217 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1219 if {![file isdirectory $_gitdir]} {
1220 catch {wm withdraw .}
1221 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1222 exit 1
1224 # _gitdir exists, so try loading the config
1225 load_config 0
1226 apply_config
1228 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1229 if {[package vsatisfies $_git_version 1.7.0]} {
1230 set _gitworktree [git rev-parse --show-toplevel]
1231 } else {
1232 # try to set work tree from environment, core.worktree or use
1233 # cdup to obtain a relative path to the top of the worktree. If
1234 # run from the top, the ./ prefix ensures normalize expands pwd.
1235 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1236 set _gitworktree [get_config core.worktree]
1237 if {$_gitworktree eq ""} {
1238 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1243 if {$_prefix ne {}} {
1244 if {$_gitworktree eq {}} {
1245 regsub -all {[^/]+/} $_prefix ../ cdup
1246 } else {
1247 set cdup $_gitworktree
1249 if {[catch {cd $cdup} err]} {
1250 catch {wm withdraw .}
1251 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1252 exit 1
1254 set _gitworktree [pwd]
1255 unset cdup
1256 } elseif {![is_enabled bare]} {
1257 if {[is_bare]} {
1258 catch {wm withdraw .}
1259 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1260 exit 1
1262 if {$_gitworktree eq {}} {
1263 set _gitworktree [file dirname $_gitdir]
1265 if {[catch {cd $_gitworktree} err]} {
1266 catch {wm withdraw .}
1267 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1268 exit 1
1270 set _gitworktree [pwd]
1272 set _reponame [file split [file normalize $_gitdir]]
1273 if {[lindex $_reponame end] eq {.git}} {
1274 set _reponame [lindex $_reponame end-1]
1275 } else {
1276 set _reponame [lindex $_reponame end]
1279 ######################################################################
1281 ## global init
1283 set current_diff_path {}
1284 set current_diff_side {}
1285 set diff_actions [list]
1287 set HEAD {}
1288 set PARENT {}
1289 set MERGE_HEAD [list]
1290 set commit_type {}
1291 set empty_tree {}
1292 set current_branch {}
1293 set is_detached 0
1294 set current_diff_path {}
1295 set is_3way_diff 0
1296 set is_submodule_diff 0
1297 set is_conflict_diff 0
1298 set selected_commit_type new
1299 set diff_empty_count 0
1301 set nullid "0000000000000000000000000000000000000000"
1302 set nullid2 "0000000000000000000000000000000000000001"
1304 ######################################################################
1306 ## task management
1308 set rescan_active 0
1309 set diff_active 0
1310 set last_clicked {}
1312 set disable_on_lock [list]
1313 set index_lock_type none
1315 proc lock_index {type} {
1316 global index_lock_type disable_on_lock
1318 if {$index_lock_type eq {none}} {
1319 set index_lock_type $type
1320 foreach w $disable_on_lock {
1321 uplevel #0 $w disabled
1323 return 1
1324 } elseif {$index_lock_type eq "begin-$type"} {
1325 set index_lock_type $type
1326 return 1
1328 return 0
1331 proc unlock_index {} {
1332 global index_lock_type disable_on_lock
1334 set index_lock_type none
1335 foreach w $disable_on_lock {
1336 uplevel #0 $w normal
1340 ######################################################################
1342 ## status
1344 proc repository_state {ctvar hdvar mhvar} {
1345 global current_branch
1346 upvar $ctvar ct $hdvar hd $mhvar mh
1348 set mh [list]
1350 load_current_branch
1351 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1352 set hd {}
1353 set ct initial
1354 return
1357 set merge_head [gitdir MERGE_HEAD]
1358 if {[file exists $merge_head]} {
1359 set ct merge
1360 set fd_mh [open $merge_head r]
1361 while {[gets $fd_mh line] >= 0} {
1362 lappend mh $line
1364 close $fd_mh
1365 return
1368 set ct normal
1371 proc PARENT {} {
1372 global PARENT empty_tree
1374 set p [lindex $PARENT 0]
1375 if {$p ne {}} {
1376 return $p
1378 if {$empty_tree eq {}} {
1379 set empty_tree [git mktree << {}]
1381 return $empty_tree
1384 proc force_amend {} {
1385 global selected_commit_type
1386 global HEAD PARENT MERGE_HEAD commit_type
1388 repository_state newType newHEAD newMERGE_HEAD
1389 set HEAD $newHEAD
1390 set PARENT $newHEAD
1391 set MERGE_HEAD $newMERGE_HEAD
1392 set commit_type $newType
1394 set selected_commit_type amend
1395 do_select_commit_type
1398 proc rescan {after {honor_trustmtime 1}} {
1399 global HEAD PARENT MERGE_HEAD commit_type
1400 global ui_index ui_workdir ui_comm
1401 global rescan_active file_states
1402 global repo_config
1404 if {$rescan_active > 0 || ![lock_index read]} return
1406 repository_state newType newHEAD newMERGE_HEAD
1407 if {[string match amend* $commit_type]
1408 && $newType eq {normal}
1409 && $newHEAD eq $HEAD} {
1410 } else {
1411 set HEAD $newHEAD
1412 set PARENT $newHEAD
1413 set MERGE_HEAD $newMERGE_HEAD
1414 set commit_type $newType
1417 array unset file_states
1419 if {!$::GITGUI_BCK_exists &&
1420 (![$ui_comm edit modified]
1421 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1422 if {[string match amend* $commit_type]} {
1423 } elseif {[load_message GITGUI_MSG]} {
1424 } elseif {[run_prepare_commit_msg_hook]} {
1425 } elseif {[load_message MERGE_MSG]} {
1426 } elseif {[load_message SQUASH_MSG]} {
1428 $ui_comm edit reset
1429 $ui_comm edit modified false
1432 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1433 rescan_stage2 {} $after
1434 } else {
1435 set rescan_active 1
1436 ui_status [mc "Refreshing file status..."]
1437 set fd_rf [git_read update-index \
1438 -q \
1439 --unmerged \
1440 --ignore-missing \
1441 --refresh \
1443 fconfigure $fd_rf -blocking 0 -translation binary
1444 fileevent $fd_rf readable \
1445 [list rescan_stage2 $fd_rf $after]
1449 if {[is_Cygwin]} {
1450 set is_git_info_exclude {}
1451 proc have_info_exclude {} {
1452 global is_git_info_exclude
1454 if {$is_git_info_exclude eq {}} {
1455 if {[catch {exec test -f [gitdir info exclude]}]} {
1456 set is_git_info_exclude 0
1457 } else {
1458 set is_git_info_exclude 1
1461 return $is_git_info_exclude
1463 } else {
1464 proc have_info_exclude {} {
1465 return [file readable [gitdir info exclude]]
1469 proc rescan_stage2 {fd after} {
1470 global rescan_active buf_rdi buf_rdf buf_rlo
1472 if {$fd ne {}} {
1473 read $fd
1474 if {![eof $fd]} return
1475 close $fd
1478 if {[package vsatisfies $::_git_version 1.6.3]} {
1479 set ls_others [list --exclude-standard]
1480 } else {
1481 set ls_others [list --exclude-per-directory=.gitignore]
1482 if {[have_info_exclude]} {
1483 lappend ls_others "--exclude-from=[gitdir info exclude]"
1485 set user_exclude [get_config core.excludesfile]
1486 if {$user_exclude ne {} && [file readable $user_exclude]} {
1487 lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1491 set buf_rdi {}
1492 set buf_rdf {}
1493 set buf_rlo {}
1495 set rescan_active 3
1496 ui_status [mc "Scanning for modified files ..."]
1497 set fd_di [git_read diff-index --cached -z [PARENT]]
1498 set fd_df [git_read diff-files -z]
1499 set fd_lo [eval git_read ls-files --others -z $ls_others]
1501 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1502 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1503 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1504 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1505 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1506 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1509 proc load_message {file} {
1510 global ui_comm
1512 set f [gitdir $file]
1513 if {[file isfile $f]} {
1514 if {[catch {set fd [open $f r]}]} {
1515 return 0
1517 fconfigure $fd -eofchar {}
1518 set content [string trim [read $fd]]
1519 close $fd
1520 regsub -all -line {[ \r\t]+$} $content {} content
1521 $ui_comm delete 0.0 end
1522 $ui_comm insert end $content
1523 return 1
1525 return 0
1528 proc run_prepare_commit_msg_hook {} {
1529 global pch_error
1531 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1532 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1533 # empty file but existent file.
1535 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1537 if {[file isfile [gitdir MERGE_MSG]]} {
1538 set pcm_source "merge"
1539 set fd_mm [open [gitdir MERGE_MSG] r]
1540 puts -nonewline $fd_pcm [read $fd_mm]
1541 close $fd_mm
1542 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1543 set pcm_source "squash"
1544 set fd_sm [open [gitdir SQUASH_MSG] r]
1545 puts -nonewline $fd_pcm [read $fd_sm]
1546 close $fd_sm
1547 } else {
1548 set pcm_source ""
1551 close $fd_pcm
1553 set fd_ph [githook_read prepare-commit-msg \
1554 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1555 if {$fd_ph eq {}} {
1556 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1557 return 0;
1560 ui_status [mc "Calling prepare-commit-msg hook..."]
1561 set pch_error {}
1563 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1564 fileevent $fd_ph readable \
1565 [list prepare_commit_msg_hook_wait $fd_ph]
1567 return 1;
1570 proc prepare_commit_msg_hook_wait {fd_ph} {
1571 global pch_error
1573 append pch_error [read $fd_ph]
1574 fconfigure $fd_ph -blocking 1
1575 if {[eof $fd_ph]} {
1576 if {[catch {close $fd_ph}]} {
1577 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1578 hook_failed_popup prepare-commit-msg $pch_error
1579 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1580 exit 1
1581 } else {
1582 load_message PREPARE_COMMIT_MSG
1584 set pch_error {}
1585 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1586 return
1588 fconfigure $fd_ph -blocking 0
1589 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1592 proc read_diff_index {fd after} {
1593 global buf_rdi
1595 append buf_rdi [read $fd]
1596 set c 0
1597 set n [string length $buf_rdi]
1598 while {$c < $n} {
1599 set z1 [string first "\0" $buf_rdi $c]
1600 if {$z1 == -1} break
1601 incr z1
1602 set z2 [string first "\0" $buf_rdi $z1]
1603 if {$z2 == -1} break
1605 incr c
1606 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1607 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1608 merge_state \
1609 [encoding convertfrom utf-8 $p] \
1610 [lindex $i 4]? \
1611 [list [lindex $i 0] [lindex $i 2]] \
1612 [list]
1613 set c $z2
1614 incr c
1616 if {$c < $n} {
1617 set buf_rdi [string range $buf_rdi $c end]
1618 } else {
1619 set buf_rdi {}
1622 rescan_done $fd buf_rdi $after
1625 proc read_diff_files {fd after} {
1626 global buf_rdf
1628 append buf_rdf [read $fd]
1629 set c 0
1630 set n [string length $buf_rdf]
1631 while {$c < $n} {
1632 set z1 [string first "\0" $buf_rdf $c]
1633 if {$z1 == -1} break
1634 incr z1
1635 set z2 [string first "\0" $buf_rdf $z1]
1636 if {$z2 == -1} break
1638 incr c
1639 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1640 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1641 merge_state \
1642 [encoding convertfrom utf-8 $p] \
1643 ?[lindex $i 4] \
1644 [list] \
1645 [list [lindex $i 0] [lindex $i 2]]
1646 set c $z2
1647 incr c
1649 if {$c < $n} {
1650 set buf_rdf [string range $buf_rdf $c end]
1651 } else {
1652 set buf_rdf {}
1655 rescan_done $fd buf_rdf $after
1658 proc read_ls_others {fd after} {
1659 global buf_rlo
1661 append buf_rlo [read $fd]
1662 set pck [split $buf_rlo "\0"]
1663 set buf_rlo [lindex $pck end]
1664 foreach p [lrange $pck 0 end-1] {
1665 set p [encoding convertfrom utf-8 $p]
1666 if {[string index $p end] eq {/}} {
1667 set p [string range $p 0 end-1]
1669 merge_state $p ?O
1671 rescan_done $fd buf_rlo $after
1674 proc rescan_done {fd buf after} {
1675 global rescan_active current_diff_path
1676 global file_states repo_config
1677 upvar $buf to_clear
1679 if {![eof $fd]} return
1680 set to_clear {}
1681 close $fd
1682 if {[incr rescan_active -1] > 0} return
1684 prune_selection
1685 unlock_index
1686 display_all_files
1687 if {$current_diff_path ne {}} { reshow_diff $after }
1688 if {$current_diff_path eq {}} { select_first_diff $after }
1691 proc prune_selection {} {
1692 global file_states selected_paths
1694 foreach path [array names selected_paths] {
1695 if {[catch {set still_here $file_states($path)}]} {
1696 unset selected_paths($path)
1701 ######################################################################
1703 ## ui helpers
1705 proc mapicon {w state path} {
1706 global all_icons
1708 if {[catch {set r $all_icons($state$w)}]} {
1709 puts "error: no icon for $w state={$state} $path"
1710 return file_plain
1712 return $r
1715 proc mapdesc {state path} {
1716 global all_descs
1718 if {[catch {set r $all_descs($state)}]} {
1719 puts "error: no desc for state={$state} $path"
1720 return $state
1722 return $r
1725 proc ui_status {msg} {
1726 global main_status
1727 if {[info exists main_status]} {
1728 $main_status show $msg
1732 proc ui_ready {{test {}}} {
1733 global main_status
1734 if {[info exists main_status]} {
1735 $main_status show [mc "Ready."] $test
1739 proc escape_path {path} {
1740 regsub -all {\\} $path "\\\\" path
1741 regsub -all "\n" $path "\\n" path
1742 return $path
1745 proc short_path {path} {
1746 return [escape_path [lindex [file split $path] end]]
1749 set next_icon_id 0
1750 set null_sha1 [string repeat 0 40]
1752 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1753 global file_states next_icon_id null_sha1
1755 set s0 [string index $new_state 0]
1756 set s1 [string index $new_state 1]
1758 if {[catch {set info $file_states($path)}]} {
1759 set state __
1760 set icon n[incr next_icon_id]
1761 } else {
1762 set state [lindex $info 0]
1763 set icon [lindex $info 1]
1764 if {$head_info eq {}} {set head_info [lindex $info 2]}
1765 if {$index_info eq {}} {set index_info [lindex $info 3]}
1768 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1769 elseif {$s0 eq {_}} {set s0 _}
1771 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1772 elseif {$s1 eq {_}} {set s1 _}
1774 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1775 set head_info [list 0 $null_sha1]
1776 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1777 && $head_info eq {}} {
1778 set head_info $index_info
1779 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1780 set index_info $head_info
1781 set head_info {}
1784 set file_states($path) [list $s0$s1 $icon \
1785 $head_info $index_info \
1787 return $state
1790 proc display_file_helper {w path icon_name old_m new_m} {
1791 global file_lists
1793 if {$new_m eq {_}} {
1794 set lno [lsearch -sorted -exact $file_lists($w) $path]
1795 if {$lno >= 0} {
1796 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1797 incr lno
1798 $w conf -state normal
1799 $w delete $lno.0 [expr {$lno + 1}].0
1800 $w conf -state disabled
1802 } elseif {$old_m eq {_} && $new_m ne {_}} {
1803 lappend file_lists($w) $path
1804 set file_lists($w) [lsort -unique $file_lists($w)]
1805 set lno [lsearch -sorted -exact $file_lists($w) $path]
1806 incr lno
1807 $w conf -state normal
1808 $w image create $lno.0 \
1809 -align center -padx 5 -pady 1 \
1810 -name $icon_name \
1811 -image [mapicon $w $new_m $path]
1812 $w insert $lno.1 "[escape_path $path]\n"
1813 $w conf -state disabled
1814 } elseif {$old_m ne $new_m} {
1815 $w conf -state normal
1816 $w image conf $icon_name -image [mapicon $w $new_m $path]
1817 $w conf -state disabled
1821 proc display_file {path state} {
1822 global file_states selected_paths
1823 global ui_index ui_workdir
1825 set old_m [merge_state $path $state]
1826 set s $file_states($path)
1827 set new_m [lindex $s 0]
1828 set icon_name [lindex $s 1]
1830 set o [string index $old_m 0]
1831 set n [string index $new_m 0]
1832 if {$o eq {U}} {
1833 set o _
1835 if {$n eq {U}} {
1836 set n _
1838 display_file_helper $ui_index $path $icon_name $o $n
1840 if {[string index $old_m 0] eq {U}} {
1841 set o U
1842 } else {
1843 set o [string index $old_m 1]
1845 if {[string index $new_m 0] eq {U}} {
1846 set n U
1847 } else {
1848 set n [string index $new_m 1]
1850 display_file_helper $ui_workdir $path $icon_name $o $n
1852 if {$new_m eq {__}} {
1853 unset file_states($path)
1854 catch {unset selected_paths($path)}
1858 proc display_all_files_helper {w path icon_name m} {
1859 global file_lists
1861 lappend file_lists($w) $path
1862 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1863 $w image create end \
1864 -align center -padx 5 -pady 1 \
1865 -name $icon_name \
1866 -image [mapicon $w $m $path]
1867 $w insert end "[escape_path $path]\n"
1870 set files_warning 0
1871 proc display_all_files {} {
1872 global ui_index ui_workdir
1873 global file_states file_lists
1874 global last_clicked
1875 global files_warning
1877 $ui_index conf -state normal
1878 $ui_workdir conf -state normal
1880 $ui_index delete 0.0 end
1881 $ui_workdir delete 0.0 end
1882 set last_clicked {}
1884 set file_lists($ui_index) [list]
1885 set file_lists($ui_workdir) [list]
1887 set to_display [lsort [array names file_states]]
1888 set display_limit [get_config gui.maxfilesdisplayed]
1889 if {[llength $to_display] > $display_limit} {
1890 if {!$files_warning} {
1891 # do not repeatedly warn:
1892 set files_warning 1
1893 info_popup [mc "Displaying only %s of %s files." \
1894 $display_limit [llength $to_display]]
1896 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1898 foreach path $to_display {
1899 set s $file_states($path)
1900 set m [lindex $s 0]
1901 set icon_name [lindex $s 1]
1903 set s [string index $m 0]
1904 if {$s ne {U} && $s ne {_}} {
1905 display_all_files_helper $ui_index $path \
1906 $icon_name $s
1909 if {[string index $m 0] eq {U}} {
1910 set s U
1911 } else {
1912 set s [string index $m 1]
1914 if {$s ne {_}} {
1915 display_all_files_helper $ui_workdir $path \
1916 $icon_name $s
1920 $ui_index conf -state disabled
1921 $ui_workdir conf -state disabled
1924 ######################################################################
1926 ## icons
1928 set filemask {
1929 #define mask_width 14
1930 #define mask_height 15
1931 static unsigned char mask_bits[] = {
1932 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1933 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1934 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1937 image create bitmap file_plain -background white -foreground black -data {
1938 #define plain_width 14
1939 #define plain_height 15
1940 static unsigned char plain_bits[] = {
1941 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1942 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1943 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1944 } -maskdata $filemask
1946 image create bitmap file_mod -background white -foreground blue -data {
1947 #define mod_width 14
1948 #define mod_height 15
1949 static unsigned char mod_bits[] = {
1950 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1951 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1952 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1953 } -maskdata $filemask
1955 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1956 #define file_fulltick_width 14
1957 #define file_fulltick_height 15
1958 static unsigned char file_fulltick_bits[] = {
1959 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1960 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1961 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1962 } -maskdata $filemask
1964 image create bitmap file_question -background white -foreground black -data {
1965 #define file_question_width 14
1966 #define file_question_height 15
1967 static unsigned char file_question_bits[] = {
1968 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1969 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1970 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1971 } -maskdata $filemask
1973 image create bitmap file_removed -background white -foreground red -data {
1974 #define file_removed_width 14
1975 #define file_removed_height 15
1976 static unsigned char file_removed_bits[] = {
1977 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1978 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1979 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1980 } -maskdata $filemask
1982 image create bitmap file_merge -background white -foreground blue -data {
1983 #define file_merge_width 14
1984 #define file_merge_height 15
1985 static unsigned char file_merge_bits[] = {
1986 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1987 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1988 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1989 } -maskdata $filemask
1991 image create bitmap file_statechange -background white -foreground green -data {
1992 #define file_statechange_width 14
1993 #define file_statechange_height 15
1994 static unsigned char file_statechange_bits[] = {
1995 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
1996 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
1997 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1998 } -maskdata $filemask
2000 set ui_index .vpane.files.index.list
2001 set ui_workdir .vpane.files.workdir.list
2003 set all_icons(_$ui_index) file_plain
2004 set all_icons(A$ui_index) file_plain
2005 set all_icons(M$ui_index) file_fulltick
2006 set all_icons(D$ui_index) file_removed
2007 set all_icons(U$ui_index) file_merge
2008 set all_icons(T$ui_index) file_statechange
2010 set all_icons(_$ui_workdir) file_plain
2011 set all_icons(M$ui_workdir) file_mod
2012 set all_icons(D$ui_workdir) file_question
2013 set all_icons(U$ui_workdir) file_merge
2014 set all_icons(O$ui_workdir) file_plain
2015 set all_icons(T$ui_workdir) file_statechange
2017 set max_status_desc 0
2018 foreach i {
2019 {__ {mc "Unmodified"}}
2021 {_M {mc "Modified, not staged"}}
2022 {M_ {mc "Staged for commit"}}
2023 {MM {mc "Portions staged for commit"}}
2024 {MD {mc "Staged for commit, missing"}}
2026 {_T {mc "File type changed, not staged"}}
2027 {MT {mc "File type changed, old type staged for commit"}}
2028 {AT {mc "File type changed, old type staged for commit"}}
2029 {T_ {mc "File type changed, staged"}}
2030 {TM {mc "File type change staged, modification not staged"}}
2031 {TD {mc "File type change staged, file missing"}}
2033 {_O {mc "Untracked, not staged"}}
2034 {A_ {mc "Staged for commit"}}
2035 {AM {mc "Portions staged for commit"}}
2036 {AD {mc "Staged for commit, missing"}}
2038 {_D {mc "Missing"}}
2039 {D_ {mc "Staged for removal"}}
2040 {DO {mc "Staged for removal, still present"}}
2042 {_U {mc "Requires merge resolution"}}
2043 {U_ {mc "Requires merge resolution"}}
2044 {UU {mc "Requires merge resolution"}}
2045 {UM {mc "Requires merge resolution"}}
2046 {UD {mc "Requires merge resolution"}}
2047 {UT {mc "Requires merge resolution"}}
2049 set text [eval [lindex $i 1]]
2050 if {$max_status_desc < [string length $text]} {
2051 set max_status_desc [string length $text]
2053 set all_descs([lindex $i 0]) $text
2055 unset i
2057 ######################################################################
2059 ## util
2061 proc scrollbar2many {list mode args} {
2062 foreach w $list {eval $w $mode $args}
2065 proc many2scrollbar {list mode sb top bottom} {
2066 $sb set $top $bottom
2067 foreach w $list {$w $mode moveto $top}
2070 proc incr_font_size {font {amt 1}} {
2071 set sz [font configure $font -size]
2072 incr sz $amt
2073 font configure $font -size $sz
2074 font configure ${font}bold -size $sz
2075 font configure ${font}italic -size $sz
2078 ######################################################################
2080 ## ui commands
2082 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2084 proc do_gitk {revs {is_submodule false}} {
2085 global current_diff_path file_states current_diff_side ui_index
2086 global _gitworktree
2088 # -- Always start gitk through whatever we were loaded with. This
2089 # lets us bypass using shell process on Windows systems.
2091 set exe [_which gitk -script]
2092 set cmd [list [info nameofexecutable] $exe]
2093 if {$exe eq {}} {
2094 error_popup [mc "Couldn't find gitk in PATH"]
2095 } else {
2096 global env
2098 if {[info exists env(GIT_DIR)]} {
2099 set old_GIT_DIR $env(GIT_DIR)
2100 } else {
2101 set old_GIT_DIR {}
2104 set pwd [pwd]
2106 if {!$is_submodule} {
2107 if {![is_bare]} {
2108 cd $_gitworktree
2110 set env(GIT_DIR) [file normalize [gitdir]]
2111 } else {
2112 cd $current_diff_path
2113 if {$revs eq {--}} {
2114 set s $file_states($current_diff_path)
2115 set old_sha1 {}
2116 set new_sha1 {}
2117 switch -glob -- [lindex $s 0] {
2118 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2119 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2120 MM {
2121 if {$current_diff_side eq $ui_index} {
2122 set old_sha1 [lindex [lindex $s 2] 1]
2123 set new_sha1 [lindex [lindex $s 3] 1]
2124 } else {
2125 set old_sha1 [lindex [lindex $s 3] 1]
2129 set revs $old_sha1...$new_sha1
2131 if {[info exists env(GIT_DIR)]} {
2132 unset env(GIT_DIR)
2135 eval exec $cmd $revs "--" "--" &
2137 if {$old_GIT_DIR ne {}} {
2138 set env(GIT_DIR) $old_GIT_DIR
2140 cd $pwd
2142 ui_status $::starting_gitk_msg
2143 after 10000 {
2144 ui_ready $starting_gitk_msg
2149 proc do_git_gui {} {
2150 global current_diff_path
2152 # -- Always start git gui through whatever we were loaded with. This
2153 # lets us bypass using shell process on Windows systems.
2155 set exe [list [_which git]]
2156 if {$exe eq {}} {
2157 error_popup [mc "Couldn't find git gui in PATH"]
2158 } else {
2159 global env
2161 if {[info exists env(GIT_DIR)]} {
2162 set old_GIT_DIR $env(GIT_DIR)
2163 unset env(GIT_DIR)
2164 } else {
2165 set old_GIT_DIR {}
2168 set pwd [pwd]
2169 cd $current_diff_path
2171 eval exec $exe gui &
2173 if {$old_GIT_DIR ne {}} {
2174 set env(GIT_DIR) $old_GIT_DIR
2176 cd $pwd
2178 ui_status $::starting_gitk_msg
2179 after 10000 {
2180 ui_ready $starting_gitk_msg
2185 proc do_explore {} {
2186 global _gitworktree
2187 set explorer {}
2188 if {[is_Cygwin] || [is_Windows]} {
2189 set explorer "explorer.exe"
2190 } elseif {[is_MacOSX]} {
2191 set explorer "open"
2192 } else {
2193 # freedesktop.org-conforming system is our best shot
2194 set explorer "xdg-open"
2196 eval exec $explorer [list [file nativename $_gitworktree]] &
2199 set is_quitting 0
2200 set ret_code 1
2202 proc terminate_me {win} {
2203 global ret_code
2204 if {$win ne {.}} return
2205 exit $ret_code
2208 proc do_quit {{rc {1}}} {
2209 global ui_comm is_quitting repo_config commit_type
2210 global GITGUI_BCK_exists GITGUI_BCK_i
2211 global ui_comm_spell
2212 global ret_code use_ttk
2214 if {$is_quitting} return
2215 set is_quitting 1
2217 if {[winfo exists $ui_comm]} {
2218 # -- Stash our current commit buffer.
2220 set save [gitdir GITGUI_MSG]
2221 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2222 file rename -force [gitdir GITGUI_BCK] $save
2223 set GITGUI_BCK_exists 0
2224 } else {
2225 set msg [string trim [$ui_comm get 0.0 end]]
2226 regsub -all -line {[ \r\t]+$} $msg {} msg
2227 if {(![string match amend* $commit_type]
2228 || [$ui_comm edit modified])
2229 && $msg ne {}} {
2230 catch {
2231 set fd [open $save w]
2232 puts -nonewline $fd $msg
2233 close $fd
2235 } else {
2236 catch {file delete $save}
2240 # -- Cancel our spellchecker if its running.
2242 if {[info exists ui_comm_spell]} {
2243 $ui_comm_spell stop
2246 # -- Remove our editor backup, its not needed.
2248 after cancel $GITGUI_BCK_i
2249 if {$GITGUI_BCK_exists} {
2250 catch {file delete [gitdir GITGUI_BCK]}
2253 # -- Stash our current window geometry into this repository.
2255 set cfg_wmstate [wm state .]
2256 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2257 set rc_wmstate {}
2259 if {$cfg_wmstate ne $rc_wmstate} {
2260 catch {git config gui.wmstate $cfg_wmstate}
2262 if {$cfg_wmstate eq {zoomed}} {
2263 # on Windows wm geometry will lie about window
2264 # position (but not size) when window is zoomed
2265 # restore the window before querying wm geometry
2266 wm state . normal
2268 set cfg_geometry [list]
2269 lappend cfg_geometry [wm geometry .]
2270 if {$use_ttk} {
2271 lappend cfg_geometry [.vpane sashpos 0]
2272 lappend cfg_geometry [.vpane.files sashpos 0]
2273 } else {
2274 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2275 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2277 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2278 set rc_geometry {}
2280 if {$cfg_geometry ne $rc_geometry} {
2281 catch {git config gui.geometry $cfg_geometry}
2285 set ret_code $rc
2287 # Briefly enable send again, working around Tk bug
2288 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2289 tk appname [appname]
2291 destroy .
2294 proc do_rescan {} {
2295 rescan ui_ready
2298 proc ui_do_rescan {} {
2299 rescan {force_first_diff ui_ready}
2302 proc do_commit {} {
2303 commit_tree
2306 proc next_diff {{after {}}} {
2307 global next_diff_p next_diff_w next_diff_i
2308 show_diff $next_diff_p $next_diff_w {} {} $after
2311 proc find_anchor_pos {lst name} {
2312 set lid [lsearch -sorted -exact $lst $name]
2314 if {$lid == -1} {
2315 set lid 0
2316 foreach lname $lst {
2317 if {$lname >= $name} break
2318 incr lid
2322 return $lid
2325 proc find_file_from {flist idx delta path mmask} {
2326 global file_states
2328 set len [llength $flist]
2329 while {$idx >= 0 && $idx < $len} {
2330 set name [lindex $flist $idx]
2332 if {$name ne $path && [info exists file_states($name)]} {
2333 set state [lindex $file_states($name) 0]
2335 if {$mmask eq {} || [regexp $mmask $state]} {
2336 return $idx
2340 incr idx $delta
2343 return {}
2346 proc find_next_diff {w path {lno {}} {mmask {}}} {
2347 global next_diff_p next_diff_w next_diff_i
2348 global file_lists ui_index ui_workdir
2350 set flist $file_lists($w)
2351 if {$lno eq {}} {
2352 set lno [find_anchor_pos $flist $path]
2353 } else {
2354 incr lno -1
2357 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2358 if {$w eq $ui_index} {
2359 set mmask "^$mmask"
2360 } else {
2361 set mmask "$mmask\$"
2365 set idx [find_file_from $flist $lno 1 $path $mmask]
2366 if {$idx eq {}} {
2367 incr lno -1
2368 set idx [find_file_from $flist $lno -1 $path $mmask]
2371 if {$idx ne {}} {
2372 set next_diff_w $w
2373 set next_diff_p [lindex $flist $idx]
2374 set next_diff_i [expr {$idx+1}]
2375 return 1
2376 } else {
2377 return 0
2381 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2382 global current_diff_path
2384 if {$path ne $current_diff_path} {
2385 return {}
2386 } elseif {[find_next_diff $w $path $lno $mmask]} {
2387 return {next_diff;}
2388 } else {
2389 return {reshow_diff;}
2393 proc select_first_diff {after} {
2394 global ui_workdir
2396 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2397 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2398 next_diff $after
2399 } else {
2400 uplevel #0 $after
2404 proc force_first_diff {after} {
2405 global ui_workdir current_diff_path file_states
2407 if {[info exists file_states($current_diff_path)]} {
2408 set state [lindex $file_states($current_diff_path) 0]
2409 } else {
2410 set state {OO}
2413 set reselect 0
2414 if {[string first {U} $state] >= 0} {
2415 # Already a conflict, do nothing
2416 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2417 set reselect 1
2418 } elseif {[string index $state 1] ne {O}} {
2419 # Already a diff & no conflicts, do nothing
2420 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2421 set reselect 1
2424 if {$reselect} {
2425 next_diff $after
2426 } else {
2427 uplevel #0 $after
2431 proc toggle_or_diff {w x y} {
2432 global file_states file_lists current_diff_path ui_index ui_workdir
2433 global last_clicked selected_paths
2435 set pos [split [$w index @$x,$y] .]
2436 set lno [lindex $pos 0]
2437 set col [lindex $pos 1]
2438 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2439 if {$path eq {}} {
2440 set last_clicked {}
2441 return
2444 set last_clicked [list $w $lno]
2445 array unset selected_paths
2446 $ui_index tag remove in_sel 0.0 end
2447 $ui_workdir tag remove in_sel 0.0 end
2449 # Determine the state of the file
2450 if {[info exists file_states($path)]} {
2451 set state [lindex $file_states($path) 0]
2452 } else {
2453 set state {__}
2456 # Restage the file, or simply show the diff
2457 if {$col == 0 && $y > 1} {
2458 # Conflicts need special handling
2459 if {[string first {U} $state] >= 0} {
2460 # $w must always be $ui_workdir, but...
2461 if {$w ne $ui_workdir} { set lno {} }
2462 merge_stage_workdir $path $lno
2463 return
2466 if {[string index $state 1] eq {O}} {
2467 set mmask {}
2468 } else {
2469 set mmask {[^O]}
2472 set after [next_diff_after_action $w $path $lno $mmask]
2474 if {$w eq $ui_index} {
2475 update_indexinfo \
2476 "Unstaging [short_path $path] from commit" \
2477 [list $path] \
2478 [concat $after [list ui_ready]]
2479 } elseif {$w eq $ui_workdir} {
2480 update_index \
2481 "Adding [short_path $path]" \
2482 [list $path] \
2483 [concat $after [list ui_ready]]
2485 } else {
2486 show_diff $path $w $lno
2490 proc add_one_to_selection {w x y} {
2491 global file_lists last_clicked selected_paths
2493 set lno [lindex [split [$w index @$x,$y] .] 0]
2494 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2495 if {$path eq {}} {
2496 set last_clicked {}
2497 return
2500 if {$last_clicked ne {}
2501 && [lindex $last_clicked 0] ne $w} {
2502 array unset selected_paths
2503 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2506 set last_clicked [list $w $lno]
2507 if {[catch {set in_sel $selected_paths($path)}]} {
2508 set in_sel 0
2510 if {$in_sel} {
2511 unset selected_paths($path)
2512 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2513 } else {
2514 set selected_paths($path) 1
2515 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2519 proc add_range_to_selection {w x y} {
2520 global file_lists last_clicked selected_paths
2522 if {[lindex $last_clicked 0] ne $w} {
2523 toggle_or_diff $w $x $y
2524 return
2527 set lno [lindex [split [$w index @$x,$y] .] 0]
2528 set lc [lindex $last_clicked 1]
2529 if {$lc < $lno} {
2530 set begin $lc
2531 set end $lno
2532 } else {
2533 set begin $lno
2534 set end $lc
2537 foreach path [lrange $file_lists($w) \
2538 [expr {$begin - 1}] \
2539 [expr {$end - 1}]] {
2540 set selected_paths($path) 1
2542 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2545 proc show_more_context {} {
2546 global repo_config
2547 if {$repo_config(gui.diffcontext) < 99} {
2548 incr repo_config(gui.diffcontext)
2549 reshow_diff
2553 proc show_less_context {} {
2554 global repo_config
2555 if {$repo_config(gui.diffcontext) > 1} {
2556 incr repo_config(gui.diffcontext) -1
2557 reshow_diff
2561 ######################################################################
2563 ## ui construction
2565 set ui_comm {}
2567 # -- Menu Bar
2569 menu .mbar -tearoff 0
2570 if {[is_MacOSX]} {
2571 # -- Apple Menu (Mac OS X only)
2573 .mbar add cascade -label Apple -menu .mbar.apple
2574 menu .mbar.apple
2576 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2577 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2578 if {[is_enabled branch]} {
2579 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2581 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2582 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2584 if {[is_enabled transport]} {
2585 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2586 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2588 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2589 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2592 # -- Repository Menu
2594 menu .mbar.repository
2596 if {![is_bare]} {
2597 .mbar.repository add command \
2598 -label [mc "Explore Working Copy"] \
2599 -command {do_explore}
2600 .mbar.repository add separator
2603 .mbar.repository add command \
2604 -label [mc "Browse Current Branch's Files"] \
2605 -command {browser::new $current_branch}
2606 set ui_browse_current [.mbar.repository index last]
2607 .mbar.repository add command \
2608 -label [mc "Browse Branch Files..."] \
2609 -command browser_open::dialog
2610 .mbar.repository add separator
2612 .mbar.repository add command \
2613 -label [mc "Visualize Current Branch's History"] \
2614 -command {do_gitk $current_branch}
2615 set ui_visualize_current [.mbar.repository index last]
2616 .mbar.repository add command \
2617 -label [mc "Visualize All Branch History"] \
2618 -command {do_gitk --all}
2619 .mbar.repository add separator
2621 proc current_branch_write {args} {
2622 global current_branch
2623 .mbar.repository entryconf $::ui_browse_current \
2624 -label [mc "Browse %s's Files" $current_branch]
2625 .mbar.repository entryconf $::ui_visualize_current \
2626 -label [mc "Visualize %s's History" $current_branch]
2628 trace add variable current_branch write current_branch_write
2630 if {[is_enabled multicommit]} {
2631 .mbar.repository add command -label [mc "Database Statistics"] \
2632 -command do_stats
2634 .mbar.repository add command -label [mc "Compress Database"] \
2635 -command do_gc
2637 .mbar.repository add command -label [mc "Verify Database"] \
2638 -command do_fsck_objects
2640 .mbar.repository add separator
2642 if {[is_Cygwin]} {
2643 .mbar.repository add command \
2644 -label [mc "Create Desktop Icon"] \
2645 -command do_cygwin_shortcut
2646 } elseif {[is_Windows]} {
2647 .mbar.repository add command \
2648 -label [mc "Create Desktop Icon"] \
2649 -command do_windows_shortcut
2650 } elseif {[is_MacOSX]} {
2651 .mbar.repository add command \
2652 -label [mc "Create Desktop Icon"] \
2653 -command do_macosx_app
2657 if {[is_MacOSX]} {
2658 proc ::tk::mac::Quit {args} { do_quit }
2659 } else {
2660 .mbar.repository add command -label [mc Quit] \
2661 -command do_quit \
2662 -accelerator $M1T-Q
2665 # -- Edit Menu
2667 menu .mbar.edit
2668 .mbar.edit add command -label [mc Undo] \
2669 -command {catch {[focus] edit undo}} \
2670 -accelerator $M1T-Z
2671 .mbar.edit add command -label [mc Redo] \
2672 -command {catch {[focus] edit redo}} \
2673 -accelerator $M1T-Y
2674 .mbar.edit add separator
2675 .mbar.edit add command -label [mc Cut] \
2676 -command {catch {tk_textCut [focus]}} \
2677 -accelerator $M1T-X
2678 .mbar.edit add command -label [mc Copy] \
2679 -command {catch {tk_textCopy [focus]}} \
2680 -accelerator $M1T-C
2681 .mbar.edit add command -label [mc Paste] \
2682 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2683 -accelerator $M1T-V
2684 .mbar.edit add command -label [mc Delete] \
2685 -command {catch {[focus] delete sel.first sel.last}} \
2686 -accelerator Del
2687 .mbar.edit add separator
2688 .mbar.edit add command -label [mc "Select All"] \
2689 -command {catch {[focus] tag add sel 0.0 end}} \
2690 -accelerator $M1T-A
2692 # -- Branch Menu
2694 if {[is_enabled branch]} {
2695 menu .mbar.branch
2697 .mbar.branch add command -label [mc "Create..."] \
2698 -command branch_create::dialog \
2699 -accelerator $M1T-N
2700 lappend disable_on_lock [list .mbar.branch entryconf \
2701 [.mbar.branch index last] -state]
2703 .mbar.branch add command -label [mc "Checkout..."] \
2704 -command branch_checkout::dialog \
2705 -accelerator $M1T-O
2706 lappend disable_on_lock [list .mbar.branch entryconf \
2707 [.mbar.branch index last] -state]
2709 .mbar.branch add command -label [mc "Rename..."] \
2710 -command branch_rename::dialog
2711 lappend disable_on_lock [list .mbar.branch entryconf \
2712 [.mbar.branch index last] -state]
2714 .mbar.branch add command -label [mc "Delete..."] \
2715 -command branch_delete::dialog
2716 lappend disable_on_lock [list .mbar.branch entryconf \
2717 [.mbar.branch index last] -state]
2719 .mbar.branch add command -label [mc "Reset..."] \
2720 -command merge::reset_hard
2721 lappend disable_on_lock [list .mbar.branch entryconf \
2722 [.mbar.branch index last] -state]
2725 # -- Commit Menu
2727 proc commit_btn_caption {} {
2728 if {[is_enabled nocommit]} {
2729 return [mc "Done"]
2730 } else {
2731 return [mc Commit@@verb]
2735 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2736 menu .mbar.commit
2738 if {![is_enabled nocommit]} {
2739 .mbar.commit add radiobutton \
2740 -label [mc "New Commit"] \
2741 -command do_select_commit_type \
2742 -variable selected_commit_type \
2743 -value new
2744 lappend disable_on_lock \
2745 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2747 .mbar.commit add radiobutton \
2748 -label [mc "Amend Last Commit"] \
2749 -command do_select_commit_type \
2750 -variable selected_commit_type \
2751 -value amend
2752 lappend disable_on_lock \
2753 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2755 .mbar.commit add separator
2758 .mbar.commit add command -label [mc Rescan] \
2759 -command ui_do_rescan \
2760 -accelerator F5
2761 lappend disable_on_lock \
2762 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2764 .mbar.commit add command -label [mc "Stage To Commit"] \
2765 -command do_add_selection \
2766 -accelerator $M1T-T
2767 lappend disable_on_lock \
2768 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2770 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2771 -command do_add_all \
2772 -accelerator $M1T-I
2773 lappend disable_on_lock \
2774 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2776 .mbar.commit add command -label [mc "Unstage From Commit"] \
2777 -command do_unstage_selection \
2778 -accelerator $M1T-U
2779 lappend disable_on_lock \
2780 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2782 .mbar.commit add command -label [mc "Revert Changes"] \
2783 -command do_revert_selection \
2784 -accelerator $M1T-J
2785 lappend disable_on_lock \
2786 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2788 .mbar.commit add separator
2790 .mbar.commit add command -label [mc "Show Less Context"] \
2791 -command show_less_context \
2792 -accelerator $M1T-\-
2794 .mbar.commit add command -label [mc "Show More Context"] \
2795 -command show_more_context \
2796 -accelerator $M1T-=
2798 .mbar.commit add separator
2800 if {![is_enabled nocommitmsg]} {
2801 .mbar.commit add command -label [mc "Sign Off"] \
2802 -command do_signoff \
2803 -accelerator $M1T-S
2806 .mbar.commit add command -label [commit_btn_caption] \
2807 -command do_commit \
2808 -accelerator $M1T-Return
2809 lappend disable_on_lock \
2810 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2813 # -- Merge Menu
2815 if {[is_enabled branch]} {
2816 menu .mbar.merge
2817 .mbar.merge add command -label [mc "Local Merge..."] \
2818 -command merge::dialog \
2819 -accelerator $M1T-M
2820 lappend disable_on_lock \
2821 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2822 .mbar.merge add command -label [mc "Abort Merge..."] \
2823 -command merge::reset_hard
2824 lappend disable_on_lock \
2825 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2828 # -- Transport Menu
2830 if {[is_enabled transport]} {
2831 menu .mbar.remote
2833 .mbar.remote add command \
2834 -label [mc "Add..."] \
2835 -command remote_add::dialog \
2836 -accelerator $M1T-A
2837 .mbar.remote add command \
2838 -label [mc "Push..."] \
2839 -command do_push_anywhere \
2840 -accelerator $M1T-P
2841 .mbar.remote add command \
2842 -label [mc "Delete Branch..."] \
2843 -command remote_branch_delete::dialog
2846 if {[is_MacOSX]} {
2847 proc ::tk::mac::ShowPreferences {} {do_options}
2848 } else {
2849 # -- Edit Menu
2851 .mbar.edit add separator
2852 .mbar.edit add command -label [mc "Options..."] \
2853 -command do_options
2856 # -- Tools Menu
2858 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2859 set tools_menubar .mbar.tools
2860 menu $tools_menubar
2861 $tools_menubar add separator
2862 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2863 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2864 set tools_tailcnt 3
2865 if {[array names repo_config guitool.*.cmd] ne {}} {
2866 tools_populate_all
2870 # -- Help Menu
2872 .mbar add cascade -label [mc Help] -menu .mbar.help
2873 menu .mbar.help
2875 if {[is_MacOSX]} {
2876 .mbar.apple add command -label [mc "About %s" [appname]] \
2877 -command do_about
2878 .mbar.apple add separator
2879 } else {
2880 .mbar.help add command -label [mc "About %s" [appname]] \
2881 -command do_about
2883 . configure -menu .mbar
2885 set doc_path [githtmldir]
2886 if {$doc_path ne {}} {
2887 set doc_path [file join $doc_path index.html]
2889 if {[is_Cygwin]} {
2890 set doc_path [exec cygpath --mixed $doc_path]
2894 if {[file isfile $doc_path]} {
2895 set doc_url "file:$doc_path"
2896 } else {
2897 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2900 proc start_browser {url} {
2901 git "web--browse" $url
2904 .mbar.help add command -label [mc "Online Documentation"] \
2905 -command [list start_browser $doc_url]
2907 .mbar.help add command -label [mc "Show SSH Key"] \
2908 -command do_ssh_key
2910 unset doc_path doc_url
2912 # -- Standard bindings
2914 wm protocol . WM_DELETE_WINDOW do_quit
2915 bind all <$M1B-Key-q> do_quit
2916 bind all <$M1B-Key-Q> do_quit
2917 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2918 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2920 set subcommand_args {}
2921 proc usage {} {
2922 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2923 if {[tk windowingsystem] eq "win32"} {
2924 wm withdraw .
2925 tk_messageBox -icon info -message $s \
2926 -title [mc "Usage"]
2927 } else {
2928 puts stderr $s
2930 exit 1
2933 proc normalize_relpath {path} {
2934 set elements {}
2935 foreach item [file split $path] {
2936 if {$item eq {.}} continue
2937 if {$item eq {..} && [llength $elements] > 0
2938 && [lindex $elements end] ne {..}} {
2939 set elements [lrange $elements 0 end-1]
2940 continue
2942 lappend elements $item
2944 return [eval file join $elements]
2947 # -- Not a normal commit type invocation? Do that instead!
2949 switch -- $subcommand {
2950 browser -
2951 blame {
2952 if {$subcommand eq "blame"} {
2953 set subcommand_args {[--line=<num>] rev? path}
2954 } else {
2955 set subcommand_args {rev? path}
2957 if {$argv eq {}} usage
2958 set head {}
2959 set path {}
2960 set jump_spec {}
2961 set is_path 0
2962 foreach a $argv {
2963 if {$is_path || [file exists $_prefix$a]} {
2964 if {$path ne {}} usage
2965 set path [normalize_relpath $_prefix$a]
2966 break
2967 } elseif {$a eq {--}} {
2968 if {$path ne {}} {
2969 if {$head ne {}} usage
2970 set head $path
2971 set path {}
2973 set is_path 1
2974 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2975 if {$jump_spec ne {} || $head ne {}} usage
2976 set jump_spec [list $lnum]
2977 } elseif {$head eq {}} {
2978 if {$head ne {}} usage
2979 set head $a
2980 set is_path 1
2981 } else {
2982 usage
2985 unset is_path
2987 if {$head ne {} && $path eq {}} {
2988 set path [normalize_relpath $_prefix$head]
2989 set head {}
2992 if {$head eq {}} {
2993 load_current_branch
2994 } else {
2995 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2996 if {[catch {
2997 set head [git rev-parse --verify $head]
2998 } err]} {
2999 if {[tk windowingsystem] eq "win32"} {
3000 tk_messageBox -icon error -title [mc Error] -message $err
3001 } else {
3002 puts stderr $err
3004 exit 1
3007 set current_branch $head
3010 wm deiconify .
3011 switch -- $subcommand {
3012 browser {
3013 if {$jump_spec ne {}} usage
3014 if {$head eq {}} {
3015 if {$path ne {} && [file isdirectory $path]} {
3016 set head $current_branch
3017 } else {
3018 set head $path
3019 set path {}
3022 browser::new $head $path
3024 blame {
3025 if {$head eq {} && ![file exists $path]} {
3026 catch {wm withdraw .}
3027 tk_messageBox \
3028 -icon error \
3029 -type ok \
3030 -title [mc "git-gui: fatal error"] \
3031 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
3032 exit 1
3034 blame::new $head $path $jump_spec
3037 return
3039 citool -
3040 gui {
3041 if {[llength $argv] != 0} {
3042 usage
3044 # fall through to setup UI for commits
3046 default {
3047 set err "usage: $argv0 \[{blame|browser|citool}\]"
3048 if {[tk windowingsystem] eq "win32"} {
3049 wm withdraw .
3050 tk_messageBox -icon error -message $err \
3051 -title [mc "Usage"]
3052 } else {
3053 puts stderr $err
3055 exit 1
3059 # -- Branch Control
3061 ${NS}::frame .branch
3062 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3063 ${NS}::label .branch.l1 \
3064 -text [mc "Current Branch:"] \
3065 -anchor w \
3066 -justify left
3067 ${NS}::label .branch.cb \
3068 -textvariable current_branch \
3069 -anchor w \
3070 -justify left
3071 pack .branch.l1 -side left
3072 pack .branch.cb -side left -fill x
3073 pack .branch -side top -fill x
3075 # -- Main Window Layout
3077 ${NS}::panedwindow .vpane -orient horizontal
3078 ${NS}::panedwindow .vpane.files -orient vertical
3079 if {$use_ttk} {
3080 .vpane add .vpane.files
3081 } else {
3082 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3084 pack .vpane -anchor n -side top -fill both -expand 1
3086 # -- Index File List
3088 ${NS}::frame .vpane.files.index -height 100 -width 200
3089 tlabel .vpane.files.index.title \
3090 -text [mc "Staged Changes (Will Commit)"] \
3091 -background lightgreen -foreground black
3092 text $ui_index -background white -foreground black \
3093 -borderwidth 0 \
3094 -width 20 -height 10 \
3095 -wrap none \
3096 -cursor $cursor_ptr \
3097 -xscrollcommand {.vpane.files.index.sx set} \
3098 -yscrollcommand {.vpane.files.index.sy set} \
3099 -state disabled
3100 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3101 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3102 pack .vpane.files.index.title -side top -fill x
3103 pack .vpane.files.index.sx -side bottom -fill x
3104 pack .vpane.files.index.sy -side right -fill y
3105 pack $ui_index -side left -fill both -expand 1
3107 # -- Working Directory File List
3109 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3110 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3111 -background lightsalmon -foreground black
3112 text $ui_workdir -background white -foreground black \
3113 -borderwidth 0 \
3114 -width 20 -height 10 \
3115 -wrap none \
3116 -cursor $cursor_ptr \
3117 -xscrollcommand {.vpane.files.workdir.sx set} \
3118 -yscrollcommand {.vpane.files.workdir.sy set} \
3119 -state disabled
3120 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3121 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3122 pack .vpane.files.workdir.title -side top -fill x
3123 pack .vpane.files.workdir.sx -side bottom -fill x
3124 pack .vpane.files.workdir.sy -side right -fill y
3125 pack $ui_workdir -side left -fill both -expand 1
3127 .vpane.files add .vpane.files.workdir
3128 .vpane.files add .vpane.files.index
3129 if {!$use_ttk} {
3130 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3131 .vpane.files paneconfigure .vpane.files.index -sticky news
3134 foreach i [list $ui_index $ui_workdir] {
3135 rmsel_tag $i
3136 $i tag conf in_diff -background [$i tag cget in_sel -background]
3138 unset i
3140 # -- Diff and Commit Area
3142 ${NS}::frame .vpane.lower -height 300 -width 400
3143 ${NS}::frame .vpane.lower.commarea
3144 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3145 pack .vpane.lower.diff -fill both -expand 1
3146 pack .vpane.lower.commarea -side bottom -fill x
3147 .vpane add .vpane.lower
3148 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3150 # -- Commit Area Buttons
3152 ${NS}::frame .vpane.lower.commarea.buttons
3153 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3154 -anchor w \
3155 -justify left
3156 pack .vpane.lower.commarea.buttons.l -side top -fill x
3157 pack .vpane.lower.commarea.buttons -side left -fill y
3159 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3160 -command ui_do_rescan
3161 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3162 lappend disable_on_lock \
3163 {.vpane.lower.commarea.buttons.rescan conf -state}
3165 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3166 -command do_add_all
3167 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3168 lappend disable_on_lock \
3169 {.vpane.lower.commarea.buttons.incall conf -state}
3171 if {![is_enabled nocommitmsg]} {
3172 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3173 -command do_signoff
3174 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3177 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3178 -command do_commit
3179 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3180 lappend disable_on_lock \
3181 {.vpane.lower.commarea.buttons.commit conf -state}
3183 if {![is_enabled nocommit]} {
3184 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3185 -command do_push_anywhere
3186 pack .vpane.lower.commarea.buttons.push -side top -fill x
3189 # -- Commit Message Buffer
3191 ${NS}::frame .vpane.lower.commarea.buffer
3192 ${NS}::frame .vpane.lower.commarea.buffer.header
3193 set ui_comm .vpane.lower.commarea.buffer.t
3194 set ui_coml .vpane.lower.commarea.buffer.header.l
3196 if {![is_enabled nocommit]} {
3197 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3198 -text [mc "New Commit"] \
3199 -command do_select_commit_type \
3200 -variable selected_commit_type \
3201 -value new
3202 lappend disable_on_lock \
3203 [list .vpane.lower.commarea.buffer.header.new conf -state]
3204 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3205 -text [mc "Amend Last Commit"] \
3206 -command do_select_commit_type \
3207 -variable selected_commit_type \
3208 -value amend
3209 lappend disable_on_lock \
3210 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3213 ${NS}::label $ui_coml \
3214 -anchor w \
3215 -justify left
3216 proc trace_commit_type {varname args} {
3217 global ui_coml commit_type
3218 switch -glob -- $commit_type {
3219 initial {set txt [mc "Initial Commit Message:"]}
3220 amend {set txt [mc "Amended Commit Message:"]}
3221 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3222 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3223 merge {set txt [mc "Merge Commit Message:"]}
3224 * {set txt [mc "Commit Message:"]}
3226 $ui_coml conf -text $txt
3228 trace add variable commit_type write trace_commit_type
3229 pack $ui_coml -side left -fill x
3231 if {![is_enabled nocommit]} {
3232 pack .vpane.lower.commarea.buffer.header.amend -side right
3233 pack .vpane.lower.commarea.buffer.header.new -side right
3236 text $ui_comm -background white -foreground black \
3237 -borderwidth 1 \
3238 -undo true \
3239 -maxundo 20 \
3240 -autoseparators true \
3241 -relief sunken \
3242 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3243 -font font_diff \
3244 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3245 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3246 -command [list $ui_comm yview]
3247 pack .vpane.lower.commarea.buffer.header -side top -fill x
3248 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3249 pack $ui_comm -side left -fill y
3250 pack .vpane.lower.commarea.buffer -side left -fill y
3252 # -- Commit Message Buffer Context Menu
3254 set ctxm .vpane.lower.commarea.buffer.ctxm
3255 menu $ctxm -tearoff 0
3256 $ctxm add command \
3257 -label [mc Cut] \
3258 -command {tk_textCut $ui_comm}
3259 $ctxm add command \
3260 -label [mc Copy] \
3261 -command {tk_textCopy $ui_comm}
3262 $ctxm add command \
3263 -label [mc Paste] \
3264 -command {tk_textPaste $ui_comm}
3265 $ctxm add command \
3266 -label [mc Delete] \
3267 -command {catch {$ui_comm delete sel.first sel.last}}
3268 $ctxm add separator
3269 $ctxm add command \
3270 -label [mc "Select All"] \
3271 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3272 $ctxm add command \
3273 -label [mc "Copy All"] \
3274 -command {
3275 $ui_comm tag add sel 0.0 end
3276 tk_textCopy $ui_comm
3277 $ui_comm tag remove sel 0.0 end
3279 $ctxm add separator
3280 $ctxm add command \
3281 -label [mc "Sign Off"] \
3282 -command do_signoff
3283 set ui_comm_ctxm $ctxm
3285 # -- Diff Header
3287 proc trace_current_diff_path {varname args} {
3288 global current_diff_path diff_actions file_states
3289 if {$current_diff_path eq {}} {
3290 set s {}
3291 set f {}
3292 set p {}
3293 set o disabled
3294 } else {
3295 set p $current_diff_path
3296 set s [mapdesc [lindex $file_states($p) 0] $p]
3297 set f [mc "File:"]
3298 set p [escape_path $p]
3299 set o normal
3302 .vpane.lower.diff.header.status configure -text $s
3303 .vpane.lower.diff.header.file configure -text $f
3304 .vpane.lower.diff.header.path configure -text $p
3305 foreach w $diff_actions {
3306 uplevel #0 $w $o
3309 trace add variable current_diff_path write trace_current_diff_path
3311 gold_frame .vpane.lower.diff.header
3312 tlabel .vpane.lower.diff.header.status \
3313 -background gold \
3314 -foreground black \
3315 -width $max_status_desc \
3316 -anchor w \
3317 -justify left
3318 tlabel .vpane.lower.diff.header.file \
3319 -background gold \
3320 -foreground black \
3321 -anchor w \
3322 -justify left
3323 tlabel .vpane.lower.diff.header.path \
3324 -background gold \
3325 -foreground black \
3326 -anchor w \
3327 -justify left
3328 pack .vpane.lower.diff.header.status -side left
3329 pack .vpane.lower.diff.header.file -side left
3330 pack .vpane.lower.diff.header.path -fill x
3331 set ctxm .vpane.lower.diff.header.ctxm
3332 menu $ctxm -tearoff 0
3333 $ctxm add command \
3334 -label [mc Copy] \
3335 -command {
3336 clipboard clear
3337 clipboard append \
3338 -format STRING \
3339 -type STRING \
3340 -- $current_diff_path
3342 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3343 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3345 # -- Diff Body
3347 ${NS}::frame .vpane.lower.diff.body
3348 set ui_diff .vpane.lower.diff.body.t
3349 text $ui_diff -background white -foreground black \
3350 -borderwidth 0 \
3351 -width 80 -height 5 -wrap none \
3352 -font font_diff \
3353 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3354 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3355 -state disabled
3356 catch {$ui_diff configure -tabstyle wordprocessor}
3357 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3358 -command [list $ui_diff xview]
3359 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3360 -command [list $ui_diff yview]
3361 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3362 pack .vpane.lower.diff.body.sby -side right -fill y
3363 pack $ui_diff -side left -fill both -expand 1
3364 pack .vpane.lower.diff.header -side top -fill x
3365 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3367 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3368 $ui_diff tag configure clr4$n -background $c
3369 $ui_diff tag configure clri4$n -foreground $c
3370 $ui_diff tag configure clr3$n -foreground $c
3371 $ui_diff tag configure clri3$n -background $c
3373 $ui_diff tag configure clr1 -font font_diffbold
3375 $ui_diff tag conf d_info -foreground blue -font font_diffbold
3377 $ui_diff tag conf d_cr -elide true
3378 $ui_diff tag conf d_@ -font font_diffbold
3379 $ui_diff tag conf d_+ -foreground {#00a000}
3380 $ui_diff tag conf d_- -foreground red
3382 $ui_diff tag conf d_++ -foreground {#00a000}
3383 $ui_diff tag conf d_-- -foreground red
3384 $ui_diff tag conf d_+s \
3385 -foreground {#00a000} \
3386 -background {#e2effa}
3387 $ui_diff tag conf d_-s \
3388 -foreground red \
3389 -background {#e2effa}
3390 $ui_diff tag conf d_s+ \
3391 -foreground {#00a000} \
3392 -background ivory1
3393 $ui_diff tag conf d_s- \
3394 -foreground red \
3395 -background ivory1
3397 $ui_diff tag conf d< \
3398 -foreground orange \
3399 -font font_diffbold
3400 $ui_diff tag conf d= \
3401 -foreground orange \
3402 -font font_diffbold
3403 $ui_diff tag conf d> \
3404 -foreground orange \
3405 -font font_diffbold
3407 $ui_diff tag raise sel
3409 # -- Diff Body Context Menu
3412 proc create_common_diff_popup {ctxm} {
3413 $ctxm add command \
3414 -label [mc Refresh] \
3415 -command reshow_diff
3416 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3417 $ctxm add command \
3418 -label [mc Copy] \
3419 -command {tk_textCopy $ui_diff}
3420 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3421 $ctxm add command \
3422 -label [mc "Select All"] \
3423 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3424 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3425 $ctxm add command \
3426 -label [mc "Copy All"] \
3427 -command {
3428 $ui_diff tag add sel 0.0 end
3429 tk_textCopy $ui_diff
3430 $ui_diff tag remove sel 0.0 end
3432 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3433 $ctxm add separator
3434 $ctxm add command \
3435 -label [mc "Decrease Font Size"] \
3436 -command {incr_font_size font_diff -1}
3437 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3438 $ctxm add command \
3439 -label [mc "Increase Font Size"] \
3440 -command {incr_font_size font_diff 1}
3441 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3442 $ctxm add separator
3443 set emenu $ctxm.enc
3444 menu $emenu
3445 build_encoding_menu $emenu [list force_diff_encoding]
3446 $ctxm add cascade \
3447 -label [mc "Encoding"] \
3448 -menu $emenu
3449 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3450 $ctxm add separator
3451 $ctxm add command -label [mc "Options..."] \
3452 -command do_options
3455 set ctxm .vpane.lower.diff.body.ctxm
3456 menu $ctxm -tearoff 0
3457 $ctxm add command \
3458 -label [mc "Apply/Reverse Hunk"] \
3459 -command {apply_hunk $cursorX $cursorY}
3460 set ui_diff_applyhunk [$ctxm index last]
3461 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3462 $ctxm add command \
3463 -label [mc "Apply/Reverse Line"] \
3464 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3465 set ui_diff_applyline [$ctxm index last]
3466 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3467 $ctxm add separator
3468 $ctxm add command \
3469 -label [mc "Show Less Context"] \
3470 -command show_less_context
3471 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3472 $ctxm add command \
3473 -label [mc "Show More Context"] \
3474 -command show_more_context
3475 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3476 $ctxm add separator
3477 create_common_diff_popup $ctxm
3479 set ctxmmg .vpane.lower.diff.body.ctxmmg
3480 menu $ctxmmg -tearoff 0
3481 $ctxmmg add command \
3482 -label [mc "Run Merge Tool"] \
3483 -command {merge_resolve_tool}
3484 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3485 $ctxmmg add separator
3486 $ctxmmg add command \
3487 -label [mc "Use Remote Version"] \
3488 -command {merge_resolve_one 3}
3489 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3490 $ctxmmg add command \
3491 -label [mc "Use Local Version"] \
3492 -command {merge_resolve_one 2}
3493 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3494 $ctxmmg add command \
3495 -label [mc "Revert To Base"] \
3496 -command {merge_resolve_one 1}
3497 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3498 $ctxmmg add separator
3499 $ctxmmg add command \
3500 -label [mc "Show Less Context"] \
3501 -command show_less_context
3502 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3503 $ctxmmg add command \
3504 -label [mc "Show More Context"] \
3505 -command show_more_context
3506 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3507 $ctxmmg add separator
3508 create_common_diff_popup $ctxmmg
3510 set ctxmsm .vpane.lower.diff.body.ctxmsm
3511 menu $ctxmsm -tearoff 0
3512 $ctxmsm add command \
3513 -label [mc "Visualize These Changes In The Submodule"] \
3514 -command {do_gitk -- true}
3515 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3516 $ctxmsm add command \
3517 -label [mc "Visualize Current Branch History In The Submodule"] \
3518 -command {do_gitk {} true}
3519 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3520 $ctxmsm add command \
3521 -label [mc "Visualize All Branch History In The Submodule"] \
3522 -command {do_gitk --all true}
3523 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3524 $ctxmsm add separator
3525 $ctxmsm add command \
3526 -label [mc "Start git gui In The Submodule"] \
3527 -command {do_git_gui}
3528 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3529 $ctxmsm add separator
3530 create_common_diff_popup $ctxmsm
3532 proc has_textconv {path} {
3533 if {[is_config_false gui.textconv]} {
3534 return 0
3536 set filter [gitattr $path diff set]
3537 set textconv [get_config [join [list diff $filter textconv] .]]
3538 if {$filter ne {set} && $textconv ne {}} {
3539 return 1
3540 } else {
3541 return 0
3545 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3546 global current_diff_path file_states
3547 set ::cursorX $x
3548 set ::cursorY $y
3549 if {[info exists file_states($current_diff_path)]} {
3550 set state [lindex $file_states($current_diff_path) 0]
3551 } else {
3552 set state {__}
3554 if {[string first {U} $state] >= 0} {
3555 tk_popup $ctxmmg $X $Y
3556 } elseif {$::is_submodule_diff} {
3557 tk_popup $ctxmsm $X $Y
3558 } else {
3559 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3560 if {$::ui_index eq $::current_diff_side} {
3561 set l [mc "Unstage Hunk From Commit"]
3562 if {$has_range} {
3563 set t [mc "Unstage Lines From Commit"]
3564 } else {
3565 set t [mc "Unstage Line From Commit"]
3567 } else {
3568 set l [mc "Stage Hunk For Commit"]
3569 if {$has_range} {
3570 set t [mc "Stage Lines For Commit"]
3571 } else {
3572 set t [mc "Stage Line For Commit"]
3575 if {$::is_3way_diff
3576 || $current_diff_path eq {}
3577 || {__} eq $state
3578 || {_O} eq $state
3579 || [string match {?T} $state]
3580 || [string match {T?} $state]
3581 || [has_textconv $current_diff_path]} {
3582 set s disabled
3583 } else {
3584 set s normal
3586 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3587 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3588 tk_popup $ctxm $X $Y
3591 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3593 # -- Status Bar
3595 set main_status [::status_bar::new .status]
3596 pack .status -anchor w -side bottom -fill x
3597 $main_status show [mc "Initializing..."]
3599 # -- Load geometry
3601 proc on_ttk_pane_mapped {w pane pos} {
3602 bind $w <Map> {}
3603 after 0 [list after idle [list $w sashpos $pane $pos]]
3605 proc on_tk_pane_mapped {w pane x y} {
3606 bind $w <Map> {}
3607 after 0 [list after idle [list $w sash place $pane $x $y]]
3609 proc on_application_mapped {} {
3610 global repo_config use_ttk
3611 bind . <Map> {}
3612 set gm $repo_config(gui.geometry)
3613 if {$use_ttk} {
3614 bind .vpane <Map> \
3615 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3616 bind .vpane.files <Map> \
3617 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3618 } else {
3619 bind .vpane <Map> \
3620 [list on_tk_pane_mapped %W 0 \
3621 [lindex $gm 1] \
3622 [lindex [.vpane sash coord 0] 1]]
3623 bind .vpane.files <Map> \
3624 [list on_tk_pane_mapped %W 0 \
3625 [lindex [.vpane.files sash coord 0] 0] \
3626 [lindex $gm 2]]
3628 wm geometry . [lindex $gm 0]
3630 if {[info exists repo_config(gui.geometry)]} {
3631 bind . <Map> [list on_application_mapped]
3632 wm geometry . [lindex $repo_config(gui.geometry) 0]
3635 # -- Load window state
3637 if {[info exists repo_config(gui.wmstate)]} {
3638 catch {wm state . $repo_config(gui.wmstate)}
3641 # -- Key Bindings
3643 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3644 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3645 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3646 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3647 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3648 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3649 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3650 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3651 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3652 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3653 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3654 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3655 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3656 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3657 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3658 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3659 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3660 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3661 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3662 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3663 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3664 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3666 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3667 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3668 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3669 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3670 bind $ui_diff <$M1B-Key-v> {break}
3671 bind $ui_diff <$M1B-Key-V> {break}
3672 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3673 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3674 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3675 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3676 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3677 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3678 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3679 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3680 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3681 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3682 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3683 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3684 bind $ui_diff <Button-1> {focus %W}
3686 if {[is_enabled branch]} {
3687 bind . <$M1B-Key-n> branch_create::dialog
3688 bind . <$M1B-Key-N> branch_create::dialog
3689 bind . <$M1B-Key-o> branch_checkout::dialog
3690 bind . <$M1B-Key-O> branch_checkout::dialog
3691 bind . <$M1B-Key-m> merge::dialog
3692 bind . <$M1B-Key-M> merge::dialog
3694 if {[is_enabled transport]} {
3695 bind . <$M1B-Key-p> do_push_anywhere
3696 bind . <$M1B-Key-P> do_push_anywhere
3699 bind . <Key-F5> ui_do_rescan
3700 bind . <$M1B-Key-r> ui_do_rescan
3701 bind . <$M1B-Key-R> ui_do_rescan
3702 bind . <$M1B-Key-s> do_signoff
3703 bind . <$M1B-Key-S> do_signoff
3704 bind . <$M1B-Key-t> do_add_selection
3705 bind . <$M1B-Key-T> do_add_selection
3706 bind . <$M1B-Key-j> do_revert_selection
3707 bind . <$M1B-Key-J> do_revert_selection
3708 bind . <$M1B-Key-i> do_add_all
3709 bind . <$M1B-Key-I> do_add_all
3710 bind . <$M1B-Key-minus> {show_less_context;break}
3711 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3712 bind . <$M1B-Key-equal> {show_more_context;break}
3713 bind . <$M1B-Key-plus> {show_more_context;break}
3714 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3715 bind . <$M1B-Key-Return> do_commit
3716 foreach i [list $ui_index $ui_workdir] {
3717 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3718 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3719 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3721 unset i
3723 set file_lists($ui_index) [list]
3724 set file_lists($ui_workdir) [list]
3726 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3727 focus -force $ui_comm
3729 # -- Warn the user about environmental problems. Cygwin's Tcl
3730 # does *not* pass its env array onto any processes it spawns.
3731 # This means that git processes get none of our environment.
3733 if {[is_Cygwin]} {
3734 set ignored_env 0
3735 set suggest_user {}
3736 set msg [mc "Possible environment issues exist.
3738 The following environment variables are probably
3739 going to be ignored by any Git subprocess run
3740 by %s:
3742 " [appname]]
3743 foreach name [array names env] {
3744 switch -regexp -- $name {
3745 {^GIT_INDEX_FILE$} -
3746 {^GIT_OBJECT_DIRECTORY$} -
3747 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3748 {^GIT_DIFF_OPTS$} -
3749 {^GIT_EXTERNAL_DIFF$} -
3750 {^GIT_PAGER$} -
3751 {^GIT_TRACE$} -
3752 {^GIT_CONFIG$} -
3753 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3754 append msg " - $name\n"
3755 incr ignored_env
3757 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3758 append msg " - $name\n"
3759 incr ignored_env
3760 set suggest_user $name
3764 if {$ignored_env > 0} {
3765 append msg [mc "
3766 This is due to a known issue with the
3767 Tcl binary distributed by Cygwin."]
3769 if {$suggest_user ne {}} {
3770 append msg [mc "
3772 A good replacement for %s
3773 is placing values for the user.name and
3774 user.email settings into your personal
3775 ~/.gitconfig file.
3776 " $suggest_user]
3778 warn_popup $msg
3780 unset ignored_env msg suggest_user name
3783 # -- Only initialize complex UI if we are going to stay running.
3785 if {[is_enabled transport]} {
3786 load_all_remotes
3788 set n [.mbar.remote index end]
3789 populate_remotes_menu
3790 set n [expr {[.mbar.remote index end] - $n}]
3791 if {$n > 0} {
3792 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3793 .mbar.remote insert $n separator
3795 unset n
3798 if {[winfo exists $ui_comm]} {
3799 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3801 # -- If both our backup and message files exist use the
3802 # newer of the two files to initialize the buffer.
3804 if {$GITGUI_BCK_exists} {
3805 set m [gitdir GITGUI_MSG]
3806 if {[file isfile $m]} {
3807 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3808 catch {file delete [gitdir GITGUI_MSG]}
3809 } else {
3810 $ui_comm delete 0.0 end
3811 $ui_comm edit reset
3812 $ui_comm edit modified false
3813 catch {file delete [gitdir GITGUI_BCK]}
3814 set GITGUI_BCK_exists 0
3817 unset m
3820 proc backup_commit_buffer {} {
3821 global ui_comm GITGUI_BCK_exists
3823 set m [$ui_comm edit modified]
3824 if {$m || $GITGUI_BCK_exists} {
3825 set msg [string trim [$ui_comm get 0.0 end]]
3826 regsub -all -line {[ \r\t]+$} $msg {} msg
3828 if {$msg eq {}} {
3829 if {$GITGUI_BCK_exists} {
3830 catch {file delete [gitdir GITGUI_BCK]}
3831 set GITGUI_BCK_exists 0
3833 } elseif {$m} {
3834 catch {
3835 set fd [open [gitdir GITGUI_BCK] w]
3836 puts -nonewline $fd $msg
3837 close $fd
3838 set GITGUI_BCK_exists 1
3842 $ui_comm edit modified false
3845 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3848 backup_commit_buffer
3850 # -- If the user has aspell available we can drive it
3851 # in pipe mode to spellcheck the commit message.
3853 set spell_cmd [list |]
3854 set spell_dict [get_config gui.spellingdictionary]
3855 lappend spell_cmd aspell
3856 if {$spell_dict ne {}} {
3857 lappend spell_cmd --master=$spell_dict
3859 lappend spell_cmd --mode=none
3860 lappend spell_cmd --encoding=utf-8
3861 lappend spell_cmd pipe
3862 if {$spell_dict eq {none}
3863 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3864 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3865 } else {
3866 set ui_comm_spell [spellcheck::init \
3867 $spell_fd \
3868 $ui_comm \
3869 $ui_comm_ctxm \
3872 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3875 lock_index begin-read
3876 if {![winfo ismapped .]} {
3877 wm deiconify .
3879 after 1 {
3880 if {[is_enabled initialamend]} {
3881 force_amend
3882 } else {
3883 do_rescan
3886 if {[is_enabled nocommitmsg]} {
3887 $ui_comm configure -state disabled -background gray
3890 if {[is_enabled multicommit]} {
3891 after 1000 hint_gc
3893 if {[is_enabled retcode]} {
3894 bind . <Destroy> {+terminate_me %W}
3896 if {$picked && [is_config_true gui.autoexplore]} {
3897 do_explore
3900 # Local variables:
3901 # mode: tcl
3902 # indent-tabs-mode: t
3903 # tab-width: 4
3904 # End: