French translation: copy -> copie.
[git/dscho.git] / git-gui / git-gui.sh
blob240164da779092b316007ec99fcec9e4435ac65e
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 if {[tk windowingsystem] eq "win32"} { console show }
158 } else {
159 set _trace 0
162 # variable for the last merged branch (useful for a default when deleting
163 # branches).
164 set _last_merged_branch {}
166 proc shellpath {} {
167 global _shellpath env
168 if {[string match @@* $_shellpath]} {
169 if {[info exists env(SHELL)]} {
170 return $env(SHELL)
171 } else {
172 return /bin/sh
175 return $_shellpath
178 proc appname {} {
179 global _appname
180 return $_appname
183 proc gitdir {args} {
184 global _gitdir
185 if {$args eq {}} {
186 return $_gitdir
188 return [eval [list file join $_gitdir] $args]
191 proc gitexec {args} {
192 global _gitexec
193 if {$_gitexec eq {}} {
194 if {[catch {set _gitexec [git --exec-path]} err]} {
195 error "Git not installed?\n\n$err"
197 if {[is_Cygwin]} {
198 set _gitexec [exec cygpath \
199 --windows \
200 --absolute \
201 $_gitexec]
202 } else {
203 set _gitexec [file normalize $_gitexec]
206 if {$args eq {}} {
207 return $_gitexec
209 return [eval [list file join $_gitexec] $args]
212 proc githtmldir {args} {
213 global _githtmldir
214 if {$_githtmldir eq {}} {
215 if {[catch {set _githtmldir [git --html-path]}]} {
216 # Git not installed or option not yet supported
217 return {}
219 if {[is_Cygwin]} {
220 set _githtmldir [exec cygpath \
221 --windows \
222 --absolute \
223 $_githtmldir]
224 } else {
225 set _githtmldir [file normalize $_githtmldir]
228 if {$args eq {}} {
229 return $_githtmldir
231 return [eval [list file join $_githtmldir] $args]
234 proc reponame {} {
235 return $::_reponame
238 proc is_MacOSX {} {
239 if {[tk windowingsystem] eq {aqua}} {
240 return 1
242 return 0
245 proc is_Windows {} {
246 if {$::tcl_platform(platform) eq {windows}} {
247 return 1
249 return 0
252 proc is_Cygwin {} {
253 global _iscygwin
254 if {$_iscygwin eq {}} {
255 if {$::tcl_platform(platform) eq {windows}} {
256 if {[catch {set p [exec cygpath --windir]} err]} {
257 set _iscygwin 0
258 } else {
259 set _iscygwin 1
261 } else {
262 set _iscygwin 0
265 return $_iscygwin
268 proc is_enabled {option} {
269 global enabled_options
270 if {[catch {set on $enabled_options($option)}]} {return 0}
271 return $on
274 proc enable_option {option} {
275 global enabled_options
276 set enabled_options($option) 1
279 proc disable_option {option} {
280 global enabled_options
281 set enabled_options($option) 0
284 ######################################################################
286 ## config
288 proc is_many_config {name} {
289 switch -glob -- $name {
290 gui.recentrepo -
291 remote.*.fetch -
292 remote.*.push
293 {return 1}
295 {return 0}
299 proc is_config_true {name} {
300 global repo_config
301 if {[catch {set v $repo_config($name)}]} {
302 return 0
304 set v [string tolower $v]
305 if {$v eq {} || $v eq {true} || $v eq {1} || $v eq {yes} || $v eq {on}} {
306 return 1
307 } else {
308 return 0
312 proc is_config_false {name} {
313 global repo_config
314 if {[catch {set v $repo_config($name)}]} {
315 return 0
317 set v [string tolower $v]
318 if {$v eq {false} || $v eq {0} || $v eq {no} || $v eq {off}} {
319 return 1
320 } else {
321 return 0
325 proc get_config {name} {
326 global repo_config
327 if {[catch {set v $repo_config($name)}]} {
328 return {}
329 } else {
330 return $v
334 proc is_bare {} {
335 global _isbare
336 global _gitdir
337 global _gitworktree
339 if {$_isbare eq {}} {
340 if {[catch {
341 set _bare [git rev-parse --is-bare-repository]
342 switch -- $_bare {
343 true { set _isbare 1 }
344 false { set _isbare 0}
345 default { throw }
347 }]} {
348 if {[is_config_true core.bare]
349 || ($_gitworktree eq {}
350 && [lindex [file split $_gitdir] end] ne {.git})} {
351 set _isbare 1
352 } else {
353 set _isbare 0
357 return $_isbare
360 ######################################################################
362 ## handy utils
364 proc _trace_exec {cmd} {
365 if {!$::_trace} return
366 set d {}
367 foreach v $cmd {
368 if {$d ne {}} {
369 append d { }
371 if {[regexp {[ \t\r\n'"$?*]} $v]} {
372 set v [sq $v]
374 append d $v
376 puts stderr $d
379 #'" fix poor old emacs font-lock mode
381 proc _git_cmd {name} {
382 global _git_cmd_path
384 if {[catch {set v $_git_cmd_path($name)}]} {
385 switch -- $name {
386 version -
387 --version -
388 --exec-path { return [list $::_git $name] }
391 set p [gitexec git-$name$::_search_exe]
392 if {[file exists $p]} {
393 set v [list $p]
394 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
395 # Try to determine what sort of magic will make
396 # git-$name go and do its thing, because native
397 # Tcl on Windows doesn't know it.
399 set p [gitexec git-$name]
400 set f [open $p r]
401 set s [gets $f]
402 close $f
404 switch -glob -- [lindex $s 0] {
405 #!*sh { set i sh }
406 #!*perl { set i perl }
407 #!*python { set i python }
408 default { error "git-$name is not supported: $s" }
411 upvar #0 _$i interp
412 if {![info exists interp]} {
413 set interp [_which $i]
415 if {$interp eq {}} {
416 error "git-$name requires $i (not in PATH)"
418 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
419 } else {
420 # Assume it is builtin to git somehow and we
421 # aren't actually able to see a file for it.
423 set v [list $::_git $name]
425 set _git_cmd_path($name) $v
427 return $v
430 proc _which {what args} {
431 global env _search_exe _search_path
433 if {$_search_path eq {}} {
434 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
435 set _search_path [split [exec cygpath \
436 --windows \
437 --path \
438 --absolute \
439 $env(PATH)] {;}]
440 set _search_exe .exe
441 } elseif {[is_Windows]} {
442 set gitguidir [file dirname [info script]]
443 regsub -all ";" $gitguidir "\\;" gitguidir
444 set env(PATH) "$gitguidir;$env(PATH)"
445 set _search_path [split $env(PATH) {;}]
446 set _search_exe .exe
447 } else {
448 set _search_path [split $env(PATH) :]
449 set _search_exe {}
453 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
454 set suffix {}
455 } else {
456 set suffix $_search_exe
459 foreach p $_search_path {
460 set p [file join $p $what$suffix]
461 if {[file exists $p]} {
462 return [file normalize $p]
465 return {}
468 # Test a file for a hashbang to identify executable scripts on Windows.
469 proc is_shellscript {filename} {
470 if {![file exists $filename]} {return 0}
471 set f [open $filename r]
472 fconfigure $f -encoding binary
473 set magic [read $f 2]
474 close $f
475 return [expr {$magic eq "#!"}]
478 # Run a command connected via pipes on stdout.
479 # This is for use with textconv filters and uses sh -c "..." to allow it to
480 # contain a command with arguments. On windows we must check for shell
481 # scripts specifically otherwise just call the filter command.
482 proc open_cmd_pipe {cmd path} {
483 global env
484 if {![file executable [shellpath]]} {
485 set exe [auto_execok [lindex $cmd 0]]
486 if {[is_shellscript [lindex $exe 0]]} {
487 set run [linsert [auto_execok sh] end -c "$cmd \"\$0\"" $path]
488 } else {
489 set run [concat $exe [lrange $cmd 1 end] $path]
491 } else {
492 set run [list [shellpath] -c "$cmd \"\$0\"" $path]
494 return [open |$run r]
497 proc _lappend_nice {cmd_var} {
498 global _nice
499 upvar $cmd_var cmd
501 if {![info exists _nice]} {
502 set _nice [_which nice]
503 if {[catch {exec $_nice git version}]} {
504 set _nice {}
505 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
506 set _nice {}
509 if {$_nice ne {}} {
510 lappend cmd $_nice
514 proc git {args} {
515 set opt [list]
517 while {1} {
518 switch -- [lindex $args 0] {
519 --nice {
520 _lappend_nice opt
523 default {
524 break
529 set args [lrange $args 1 end]
532 set cmdp [_git_cmd [lindex $args 0]]
533 set args [lrange $args 1 end]
535 _trace_exec [concat $opt $cmdp $args]
536 set result [eval exec $opt $cmdp $args]
537 if {[encoding system] != "utf-8"} {
538 set result [encoding convertfrom utf-8 [encoding convertto $result]]
540 if {$::_trace} {
541 puts stderr "< $result"
543 return $result
546 proc _open_stdout_stderr {cmd} {
547 _trace_exec $cmd
548 if {[catch {
549 set fd [open [concat [list | ] $cmd] r]
550 } err]} {
551 if { [lindex $cmd end] eq {2>@1}
552 && $err eq {can not find channel named "1"}
554 # Older versions of Tcl 8.4 don't have this 2>@1 IO
555 # redirect operator. Fallback to |& cat for those.
556 # The command was not actually started, so its safe
557 # to try to start it a second time.
559 set fd [open [concat \
560 [list | ] \
561 [lrange $cmd 0 end-1] \
562 [list |& cat] \
563 ] r]
564 } else {
565 error $err
568 fconfigure $fd -eofchar {}
569 return $fd
572 proc git_read {args} {
573 set opt [list]
575 while {1} {
576 switch -- [lindex $args 0] {
577 --nice {
578 _lappend_nice opt
581 --stderr {
582 lappend args 2>@1
585 default {
586 break
591 set args [lrange $args 1 end]
594 set cmdp [_git_cmd [lindex $args 0]]
595 set args [lrange $args 1 end]
597 return [_open_stdout_stderr [concat $opt $cmdp $args]]
600 proc git_write {args} {
601 set opt [list]
603 while {1} {
604 switch -- [lindex $args 0] {
605 --nice {
606 _lappend_nice opt
609 default {
610 break
615 set args [lrange $args 1 end]
618 set cmdp [_git_cmd [lindex $args 0]]
619 set args [lrange $args 1 end]
621 _trace_exec [concat $opt $cmdp $args]
622 return [open [concat [list | ] $opt $cmdp $args] w]
625 proc githook_read {hook_name args} {
626 set pchook [gitdir hooks $hook_name]
627 lappend args 2>@1
629 # On Windows [file executable] might lie so we need to ask
630 # the shell if the hook is executable. Yes that's annoying.
632 if {[is_Windows]} {
633 upvar #0 _sh interp
634 if {![info exists interp]} {
635 set interp [_which sh]
637 if {$interp eq {}} {
638 error "hook execution requires sh (not in PATH)"
641 set scr {if test -x "$1";then exec "$@";fi}
642 set sh_c [list $interp -c $scr $interp $pchook]
643 return [_open_stdout_stderr [concat $sh_c $args]]
646 if {[file executable $pchook]} {
647 return [_open_stdout_stderr [concat [list $pchook] $args]]
650 return {}
653 proc kill_file_process {fd} {
654 set process [pid $fd]
656 catch {
657 if {[is_Windows]} {
658 # Use a Cygwin-specific flag to allow killing
659 # native Windows processes
660 exec kill -f $process
661 } else {
662 exec kill $process
667 proc gitattr {path attr default} {
668 if {[catch {set r [git check-attr $attr -- $path]}]} {
669 set r unspecified
670 } else {
671 set r [join [lrange [split $r :] 2 end] :]
672 regsub {^ } $r {} r
674 if {$r eq {unspecified}} {
675 return $default
677 return $r
680 proc sq {value} {
681 regsub -all ' $value "'\\''" value
682 return "'$value'"
685 proc load_current_branch {} {
686 global current_branch is_detached
688 set fd [open [gitdir HEAD] r]
689 if {[gets $fd ref] < 1} {
690 set ref {}
692 close $fd
694 set pfx {ref: refs/heads/}
695 set len [string length $pfx]
696 if {[string equal -length $len $pfx $ref]} {
697 # We're on a branch. It might not exist. But
698 # HEAD looks good enough to be a branch.
700 set current_branch [string range $ref $len end]
701 set is_detached 0
702 } else {
703 # Assume this is a detached head.
705 set current_branch HEAD
706 set is_detached 1
710 auto_load tk_optionMenu
711 rename tk_optionMenu real__tkOptionMenu
712 proc tk_optionMenu {w varName args} {
713 set m [eval real__tkOptionMenu $w $varName $args]
714 $m configure -font font_ui
715 $w configure -font font_ui
716 return $m
719 proc rmsel_tag {text} {
720 $text tag conf sel \
721 -background [$text cget -background] \
722 -foreground [$text cget -foreground] \
723 -borderwidth 0
724 $text tag conf in_sel -background lightgray
725 bind $text <Motion> break
726 return $text
729 wm withdraw .
730 set root_exists 0
731 bind . <Visibility> {
732 bind . <Visibility> {}
733 set root_exists 1
736 if {[is_Windows]} {
737 wm iconbitmap . -default $oguilib/git-gui.ico
738 set ::tk::AlwaysShowSelection 1
739 bind . <Control-F2> {console show}
741 # Spoof an X11 display for SSH
742 if {![info exists env(DISPLAY)]} {
743 set env(DISPLAY) :9999
745 } else {
746 catch {
747 image create photo gitlogo -width 16 -height 16
749 gitlogo put #33CC33 -to 7 0 9 2
750 gitlogo put #33CC33 -to 4 2 12 4
751 gitlogo put #33CC33 -to 7 4 9 6
752 gitlogo put #CC3333 -to 4 6 12 8
753 gitlogo put gray26 -to 4 9 6 10
754 gitlogo put gray26 -to 3 10 6 12
755 gitlogo put gray26 -to 8 9 13 11
756 gitlogo put gray26 -to 8 11 10 12
757 gitlogo put gray26 -to 11 11 13 14
758 gitlogo put gray26 -to 3 12 5 14
759 gitlogo put gray26 -to 5 13
760 gitlogo put gray26 -to 10 13
761 gitlogo put gray26 -to 4 14 12 15
762 gitlogo put gray26 -to 5 15 11 16
763 gitlogo redither
765 image create photo gitlogo32 -width 32 -height 32
766 gitlogo32 copy gitlogo -zoom 2 2
768 wm iconphoto . -default gitlogo gitlogo32
772 ######################################################################
774 ## config defaults
776 set cursor_ptr arrow
777 font create font_ui
778 if {[lsearch -exact [font names] TkDefaultFont] != -1} {
779 eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
780 eval [linsert [font actual TkFixedFont] 0 font create font_diff]
781 } else {
782 font create font_diff -family Courier -size 10
783 catch {
784 label .dummy
785 eval font configure font_ui [font actual [.dummy cget -font]]
786 destroy .dummy
790 font create font_uiitalic
791 font create font_uibold
792 font create font_diffbold
793 font create font_diffitalic
795 foreach class {Button Checkbutton Entry Label
796 Labelframe Listbox Message
797 Radiobutton Spinbox Text} {
798 option add *$class.font font_ui
800 if {![is_MacOSX]} {
801 option add *Menu.font font_ui
802 option add *Entry.borderWidth 1 startupFile
803 option add *Entry.relief sunken startupFile
804 option add *RadioButton.anchor w startupFile
806 unset class
808 if {[is_Windows] || [is_MacOSX]} {
809 option add *Menu.tearOff 0
812 if {[is_MacOSX]} {
813 set M1B M1
814 set M1T Cmd
815 } else {
816 set M1B Control
817 set M1T Ctrl
820 proc bind_button3 {w cmd} {
821 bind $w <Any-Button-3> $cmd
822 if {[is_MacOSX]} {
823 # Mac OS X sends Button-2 on right click through three-button mouse,
824 # or through trackpad right-clicking (two-finger touch + click).
825 bind $w <Any-Button-2> $cmd
826 bind $w <Control-Button-1> $cmd
830 proc apply_config {} {
831 global repo_config font_descs
833 foreach option $font_descs {
834 set name [lindex $option 0]
835 set font [lindex $option 1]
836 if {[catch {
837 set need_weight 1
838 foreach {cn cv} $repo_config(gui.$name) {
839 if {$cn eq {-weight}} {
840 set need_weight 0
842 font configure $font $cn $cv
844 if {$need_weight} {
845 font configure $font -weight normal
847 } err]} {
848 error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
850 foreach {cn cv} [font configure $font] {
851 font configure ${font}bold $cn $cv
852 font configure ${font}italic $cn $cv
854 font configure ${font}bold -weight bold
855 font configure ${font}italic -slant italic
858 global use_ttk NS
859 set use_ttk 0
860 set NS {}
861 if {$repo_config(gui.usettk)} {
862 set use_ttk [package vsatisfies [package provide Tk] 8.5]
863 if {$use_ttk} {
864 set NS ttk
865 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
866 pave_toplevel .
871 set default_config(branch.autosetupmerge) true
872 set default_config(merge.tool) {}
873 set default_config(mergetool.keepbackup) true
874 set default_config(merge.diffstat) true
875 set default_config(merge.summary) false
876 set default_config(merge.verbosity) 2
877 set default_config(user.name) {}
878 set default_config(user.email) {}
880 set default_config(gui.encoding) [encoding system]
881 set default_config(gui.matchtrackingbranch) false
882 set default_config(gui.textconv) true
883 set default_config(gui.pruneduringfetch) false
884 set default_config(gui.trustmtime) false
885 set default_config(gui.fastcopyblame) false
886 set default_config(gui.copyblamethreshold) 40
887 set default_config(gui.blamehistoryctx) 7
888 set default_config(gui.diffcontext) 5
889 set default_config(gui.diffopts) {}
890 set default_config(gui.commitmsgwidth) 75
891 set default_config(gui.newbranchtemplate) {}
892 set default_config(gui.spellingdictionary) {}
893 set default_config(gui.fontui) [font configure font_ui]
894 set default_config(gui.fontdiff) [font configure font_diff]
895 # TODO: this option should be added to the git-config documentation
896 set default_config(gui.maxfilesdisplayed) 5000
897 set default_config(gui.usettk) 1
898 set default_config(gui.warndetachedcommit) 1
899 set font_descs {
900 {fontui font_ui {mc "Main Font"}}
901 {fontdiff font_diff {mc "Diff/Console Font"}}
903 set default_config(gui.stageuntracked) ask
905 ######################################################################
907 ## find git
909 set _git [_which git]
910 if {$_git eq {}} {
911 catch {wm withdraw .}
912 tk_messageBox \
913 -icon error \
914 -type ok \
915 -title [mc "git-gui: fatal error"] \
916 -message [mc "Cannot find git in PATH."]
917 exit 1
920 ######################################################################
922 ## version check
924 if {[catch {set _git_version [git --version]} err]} {
925 catch {wm withdraw .}
926 tk_messageBox \
927 -icon error \
928 -type ok \
929 -title [mc "git-gui: fatal error"] \
930 -message "Cannot determine Git version:
932 $err
934 [appname] requires Git 1.5.0 or later."
935 exit 1
937 if {![regsub {^git version } $_git_version {} _git_version]} {
938 catch {wm withdraw .}
939 tk_messageBox \
940 -icon error \
941 -type ok \
942 -title [mc "git-gui: fatal error"] \
943 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
944 exit 1
947 proc get_trimmed_version {s} {
948 set r {}
949 foreach x [split $s -._] {
950 if {[string is integer -strict $x]} {
951 lappend r $x
952 } else {
953 break
956 return [join $r .]
958 set _real_git_version $_git_version
959 set _git_version [get_trimmed_version $_git_version]
961 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
962 catch {wm withdraw .}
963 if {[tk_messageBox \
964 -icon warning \
965 -type yesno \
966 -default no \
967 -title "[appname]: warning" \
968 -message [mc "Git version cannot be determined.
970 %s claims it is version '%s'.
972 %s requires at least Git 1.5.0 or later.
974 Assume '%s' is version 1.5.0?
975 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
976 set _git_version 1.5.0
977 } else {
978 exit 1
981 unset _real_git_version
983 proc git-version {args} {
984 global _git_version
986 switch [llength $args] {
988 return $_git_version
992 set op [lindex $args 0]
993 set vr [lindex $args 1]
994 set cm [package vcompare $_git_version $vr]
995 return [expr $cm $op 0]
999 set type [lindex $args 0]
1000 set name [lindex $args 1]
1001 set parm [lindex $args 2]
1002 set body [lindex $args 3]
1004 if {($type ne {proc} && $type ne {method})} {
1005 error "Invalid arguments to git-version"
1007 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
1008 error "Last arm of $type $name must be default"
1011 foreach {op vr cb} [lrange $body 0 end-2] {
1012 if {[git-version $op $vr]} {
1013 return [uplevel [list $type $name $parm $cb]]
1017 return [uplevel [list $type $name $parm [lindex $body end]]]
1020 default {
1021 error "git-version >= x"
1027 if {[git-version < 1.5]} {
1028 catch {wm withdraw .}
1029 tk_messageBox \
1030 -icon error \
1031 -type ok \
1032 -title [mc "git-gui: fatal error"] \
1033 -message "[appname] requires Git 1.5.0 or later.
1035 You are using [git-version]:
1037 [git --version]"
1038 exit 1
1041 ######################################################################
1043 ## configure our library
1045 set idx [file join $oguilib tclIndex]
1046 if {[catch {set fd [open $idx r]} err]} {
1047 catch {wm withdraw .}
1048 tk_messageBox \
1049 -icon error \
1050 -type ok \
1051 -title [mc "git-gui: fatal error"] \
1052 -message $err
1053 exit 1
1055 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1056 set idx [list]
1057 while {[gets $fd n] >= 0} {
1058 if {$n ne {} && ![string match #* $n]} {
1059 lappend idx $n
1062 } else {
1063 set idx {}
1065 close $fd
1067 if {$idx ne {}} {
1068 set loaded [list]
1069 foreach p $idx {
1070 if {[lsearch -exact $loaded $p] >= 0} continue
1071 source [file join $oguilib $p]
1072 lappend loaded $p
1074 unset loaded p
1075 } else {
1076 set auto_path [concat [list $oguilib] $auto_path]
1078 unset -nocomplain idx fd
1080 ######################################################################
1082 ## config file parsing
1084 git-version proc _parse_config {arr_name args} {
1085 >= 1.5.3 {
1086 upvar $arr_name arr
1087 array unset arr
1088 set buf {}
1089 catch {
1090 set fd_rc [eval \
1091 [list git_read config] \
1092 $args \
1093 [list --null --list]]
1094 fconfigure $fd_rc -translation binary -encoding utf-8
1095 set buf [read $fd_rc]
1096 close $fd_rc
1098 foreach line [split $buf "\0"] {
1099 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1100 if {[is_many_config $name]} {
1101 lappend arr($name) $value
1102 } else {
1103 set arr($name) $value
1105 } elseif {[regexp {^([^\n]+)$} $line line name]} {
1106 # no value given, but interpreting them as
1107 # boolean will be handled as true
1108 set arr($name) {}
1112 default {
1113 upvar $arr_name arr
1114 array unset arr
1115 catch {
1116 set fd_rc [eval [list git_read config --list] $args]
1117 while {[gets $fd_rc line] >= 0} {
1118 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1119 if {[is_many_config $name]} {
1120 lappend arr($name) $value
1121 } else {
1122 set arr($name) $value
1124 } elseif {[regexp {^([^=]+)$} $line line name]} {
1125 # no value given, but interpreting them as
1126 # boolean will be handled as true
1127 set arr($name) {}
1130 close $fd_rc
1135 proc load_config {include_global} {
1136 global repo_config global_config system_config default_config
1138 if {$include_global} {
1139 _parse_config system_config --system
1140 _parse_config global_config --global
1142 _parse_config repo_config
1144 foreach name [array names default_config] {
1145 if {[catch {set v $system_config($name)}]} {
1146 set system_config($name) $default_config($name)
1149 foreach name [array names system_config] {
1150 if {[catch {set v $global_config($name)}]} {
1151 set global_config($name) $system_config($name)
1153 if {[catch {set v $repo_config($name)}]} {
1154 set repo_config($name) $system_config($name)
1159 ######################################################################
1161 ## feature option selection
1163 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1164 unset _junk
1165 } else {
1166 set subcommand gui
1168 if {$subcommand eq {gui.sh}} {
1169 set subcommand gui
1171 if {$subcommand eq {gui} && [llength $argv] > 0} {
1172 set subcommand [lindex $argv 0]
1173 set argv [lrange $argv 1 end]
1176 enable_option multicommit
1177 enable_option branch
1178 enable_option transport
1179 disable_option bare
1181 switch -- $subcommand {
1182 browser -
1183 blame {
1184 enable_option bare
1186 disable_option multicommit
1187 disable_option branch
1188 disable_option transport
1190 citool {
1191 enable_option singlecommit
1192 enable_option retcode
1194 disable_option multicommit
1195 disable_option branch
1196 disable_option transport
1198 while {[llength $argv] > 0} {
1199 set a [lindex $argv 0]
1200 switch -- $a {
1201 --amend {
1202 enable_option initialamend
1204 --nocommit {
1205 enable_option nocommit
1206 enable_option nocommitmsg
1208 --commitmsg {
1209 disable_option nocommitmsg
1211 default {
1212 break
1216 set argv [lrange $argv 1 end]
1221 ######################################################################
1223 ## execution environment
1225 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1227 # Suggest our implementation of askpass, if none is set
1228 if {![info exists env(SSH_ASKPASS)]} {
1229 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1231 if {![info exists env(GIT_ASKPASS)]} {
1232 set env(GIT_ASKPASS) [gitexec git-gui--askpass]
1234 if {![info exists env(GIT_ASK_YESNO)]} {
1235 set env(GIT_ASK_YESNO) [gitexec git-gui--askyesno]
1238 ######################################################################
1240 ## repository setup
1242 set picked 0
1243 if {[catch {
1244 set _gitdir $env(GIT_DIR)
1245 set _prefix {}
1247 && [catch {
1248 # beware that from the .git dir this sets _gitdir to .
1249 # and _prefix to the empty string
1250 set _gitdir [git rev-parse --git-dir]
1251 set _prefix [git rev-parse --show-prefix]
1252 } err]} {
1253 load_config 1
1254 apply_config
1255 choose_repository::pick
1256 set picked 1
1259 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1260 # run from the .git dir itself) lest the routines to find the worktree
1261 # get confused
1262 if {$_gitdir eq "."} {
1263 set _gitdir [pwd]
1266 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1267 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1269 if {![file isdirectory $_gitdir]} {
1270 catch {wm withdraw .}
1271 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1272 exit 1
1274 # _gitdir exists, so try loading the config
1275 load_config 0
1276 apply_config
1278 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1279 if {[package vsatisfies $_git_version 1.7.0]} {
1280 set _gitworktree [git rev-parse --show-toplevel]
1281 } else {
1282 # try to set work tree from environment, core.worktree or use
1283 # cdup to obtain a relative path to the top of the worktree. If
1284 # run from the top, the ./ prefix ensures normalize expands pwd.
1285 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1286 set _gitworktree [get_config core.worktree]
1287 if {$_gitworktree eq ""} {
1288 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1293 if {$_prefix ne {}} {
1294 if {$_gitworktree eq {}} {
1295 regsub -all {[^/]+/} $_prefix ../ cdup
1296 } else {
1297 set cdup $_gitworktree
1299 if {[catch {cd $cdup} err]} {
1300 catch {wm withdraw .}
1301 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1302 exit 1
1304 set _gitworktree [pwd]
1305 unset cdup
1306 } elseif {![is_enabled bare]} {
1307 if {[is_bare]} {
1308 catch {wm withdraw .}
1309 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1310 exit 1
1312 if {$_gitworktree eq {}} {
1313 set _gitworktree [file dirname $_gitdir]
1315 if {[catch {cd $_gitworktree} err]} {
1316 catch {wm withdraw .}
1317 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1318 exit 1
1320 set _gitworktree [pwd]
1322 set _reponame [file split [file normalize $_gitdir]]
1323 if {[lindex $_reponame end] eq {.git}} {
1324 set _reponame [lindex $_reponame end-1]
1325 } else {
1326 set _reponame [lindex $_reponame end]
1329 ######################################################################
1331 ## global init
1333 set current_diff_path {}
1334 set current_diff_side {}
1335 set diff_actions [list]
1337 set HEAD {}
1338 set PARENT {}
1339 set MERGE_HEAD [list]
1340 set commit_type {}
1341 set empty_tree {}
1342 set current_branch {}
1343 set is_detached 0
1344 set current_diff_path {}
1345 set is_3way_diff 0
1346 set is_submodule_diff 0
1347 set is_conflict_diff 0
1348 set selected_commit_type new
1349 set diff_empty_count 0
1351 set nullid "0000000000000000000000000000000000000000"
1352 set nullid2 "0000000000000000000000000000000000000001"
1354 ######################################################################
1356 ## task management
1358 set rescan_active 0
1359 set diff_active 0
1360 set last_clicked {}
1362 set disable_on_lock [list]
1363 set index_lock_type none
1365 proc lock_index {type} {
1366 global index_lock_type disable_on_lock
1368 if {$index_lock_type eq {none}} {
1369 set index_lock_type $type
1370 foreach w $disable_on_lock {
1371 uplevel #0 $w disabled
1373 return 1
1374 } elseif {$index_lock_type eq "begin-$type"} {
1375 set index_lock_type $type
1376 return 1
1378 return 0
1381 proc unlock_index {} {
1382 global index_lock_type disable_on_lock
1384 set index_lock_type none
1385 foreach w $disable_on_lock {
1386 uplevel #0 $w normal
1390 ######################################################################
1392 ## status
1394 proc repository_state {ctvar hdvar mhvar} {
1395 global current_branch
1396 upvar $ctvar ct $hdvar hd $mhvar mh
1398 set mh [list]
1400 load_current_branch
1401 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1402 set hd {}
1403 set ct initial
1404 return
1407 set merge_head [gitdir MERGE_HEAD]
1408 if {[file exists $merge_head]} {
1409 set ct merge
1410 set fd_mh [open $merge_head r]
1411 while {[gets $fd_mh line] >= 0} {
1412 lappend mh $line
1414 close $fd_mh
1415 return
1418 set ct normal
1421 proc PARENT {} {
1422 global PARENT empty_tree
1424 set p [lindex $PARENT 0]
1425 if {$p ne {}} {
1426 return $p
1428 if {$empty_tree eq {}} {
1429 set empty_tree [git mktree << {}]
1431 return $empty_tree
1434 proc force_amend {} {
1435 global selected_commit_type
1436 global HEAD PARENT MERGE_HEAD commit_type
1438 repository_state newType newHEAD newMERGE_HEAD
1439 set HEAD $newHEAD
1440 set PARENT $newHEAD
1441 set MERGE_HEAD $newMERGE_HEAD
1442 set commit_type $newType
1444 set selected_commit_type amend
1445 do_select_commit_type
1448 proc rescan {after {honor_trustmtime 1}} {
1449 global HEAD PARENT MERGE_HEAD commit_type
1450 global ui_index ui_workdir ui_comm
1451 global rescan_active file_states
1452 global repo_config
1454 if {$rescan_active > 0 || ![lock_index read]} return
1456 repository_state newType newHEAD newMERGE_HEAD
1457 if {[string match amend* $commit_type]
1458 && $newType eq {normal}
1459 && $newHEAD eq $HEAD} {
1460 } else {
1461 set HEAD $newHEAD
1462 set PARENT $newHEAD
1463 set MERGE_HEAD $newMERGE_HEAD
1464 set commit_type $newType
1467 array unset file_states
1469 if {!$::GITGUI_BCK_exists &&
1470 (![$ui_comm edit modified]
1471 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1472 if {[string match amend* $commit_type]} {
1473 } elseif {[load_message GITGUI_MSG utf-8]} {
1474 } elseif {[run_prepare_commit_msg_hook]} {
1475 } elseif {[load_message MERGE_MSG]} {
1476 } elseif {[load_message SQUASH_MSG]} {
1478 $ui_comm edit reset
1479 $ui_comm edit modified false
1482 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1483 rescan_stage2 {} $after
1484 } else {
1485 set rescan_active 1
1486 ui_status [mc "Refreshing file status..."]
1487 set fd_rf [git_read update-index \
1488 -q \
1489 --unmerged \
1490 --ignore-missing \
1491 --refresh \
1493 fconfigure $fd_rf -blocking 0 -translation binary
1494 fileevent $fd_rf readable \
1495 [list rescan_stage2 $fd_rf $after]
1499 if {[is_Cygwin]} {
1500 set is_git_info_exclude {}
1501 proc have_info_exclude {} {
1502 global is_git_info_exclude
1504 if {$is_git_info_exclude eq {}} {
1505 if {[catch {exec test -f [gitdir info exclude]}]} {
1506 set is_git_info_exclude 0
1507 } else {
1508 set is_git_info_exclude 1
1511 return $is_git_info_exclude
1513 } else {
1514 proc have_info_exclude {} {
1515 return [file readable [gitdir info exclude]]
1519 proc rescan_stage2 {fd after} {
1520 global rescan_active buf_rdi buf_rdf buf_rlo
1522 if {$fd ne {}} {
1523 read $fd
1524 if {![eof $fd]} return
1525 close $fd
1528 if {[package vsatisfies $::_git_version 1.6.3]} {
1529 set ls_others [list --exclude-standard]
1530 } else {
1531 set ls_others [list --exclude-per-directory=.gitignore]
1532 if {[have_info_exclude]} {
1533 lappend ls_others "--exclude-from=[gitdir info exclude]"
1535 set user_exclude [get_config core.excludesfile]
1536 if {$user_exclude ne {} && [file readable $user_exclude]} {
1537 lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1541 set buf_rdi {}
1542 set buf_rdf {}
1543 set buf_rlo {}
1545 set rescan_active 3
1546 ui_status [mc "Scanning for modified files ..."]
1547 set fd_di [git_read diff-index --cached -z [PARENT]]
1548 set fd_df [git_read diff-files -z]
1549 set fd_lo [eval git_read ls-files --others -z $ls_others]
1551 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1552 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1553 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1554 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1555 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1556 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1559 proc load_message {file {encoding {}}} {
1560 global ui_comm
1562 set f [gitdir $file]
1563 if {[file isfile $f]} {
1564 if {[catch {set fd [open $f r]}]} {
1565 return 0
1567 fconfigure $fd -eofchar {}
1568 if {$encoding ne {}} {
1569 fconfigure $fd -encoding $encoding
1571 set content [string trim [read $fd]]
1572 close $fd
1573 regsub -all -line {[ \r\t]+$} $content {} content
1574 $ui_comm delete 0.0 end
1575 $ui_comm insert end $content
1576 return 1
1578 return 0
1581 proc run_prepare_commit_msg_hook {} {
1582 global pch_error
1584 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1585 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1586 # empty file but existent file.
1588 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1590 if {[file isfile [gitdir MERGE_MSG]]} {
1591 set pcm_source "merge"
1592 set fd_mm [open [gitdir MERGE_MSG] r]
1593 puts -nonewline $fd_pcm [read $fd_mm]
1594 close $fd_mm
1595 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1596 set pcm_source "squash"
1597 set fd_sm [open [gitdir SQUASH_MSG] r]
1598 puts -nonewline $fd_pcm [read $fd_sm]
1599 close $fd_sm
1600 } else {
1601 set pcm_source ""
1604 close $fd_pcm
1606 set fd_ph [githook_read prepare-commit-msg \
1607 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1608 if {$fd_ph eq {}} {
1609 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1610 return 0;
1613 ui_status [mc "Calling prepare-commit-msg hook..."]
1614 set pch_error {}
1616 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1617 fileevent $fd_ph readable \
1618 [list prepare_commit_msg_hook_wait $fd_ph]
1620 return 1;
1623 proc prepare_commit_msg_hook_wait {fd_ph} {
1624 global pch_error
1626 append pch_error [read $fd_ph]
1627 fconfigure $fd_ph -blocking 1
1628 if {[eof $fd_ph]} {
1629 if {[catch {close $fd_ph}]} {
1630 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1631 hook_failed_popup prepare-commit-msg $pch_error
1632 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1633 exit 1
1634 } else {
1635 load_message PREPARE_COMMIT_MSG
1637 set pch_error {}
1638 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1639 return
1641 fconfigure $fd_ph -blocking 0
1642 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1645 proc read_diff_index {fd after} {
1646 global buf_rdi
1648 append buf_rdi [read $fd]
1649 set c 0
1650 set n [string length $buf_rdi]
1651 while {$c < $n} {
1652 set z1 [string first "\0" $buf_rdi $c]
1653 if {$z1 == -1} break
1654 incr z1
1655 set z2 [string first "\0" $buf_rdi $z1]
1656 if {$z2 == -1} break
1658 incr c
1659 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1660 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1661 merge_state \
1662 [encoding convertfrom utf-8 $p] \
1663 [lindex $i 4]? \
1664 [list [lindex $i 0] [lindex $i 2]] \
1665 [list]
1666 set c $z2
1667 incr c
1669 if {$c < $n} {
1670 set buf_rdi [string range $buf_rdi $c end]
1671 } else {
1672 set buf_rdi {}
1675 rescan_done $fd buf_rdi $after
1678 proc read_diff_files {fd after} {
1679 global buf_rdf
1681 append buf_rdf [read $fd]
1682 set c 0
1683 set n [string length $buf_rdf]
1684 while {$c < $n} {
1685 set z1 [string first "\0" $buf_rdf $c]
1686 if {$z1 == -1} break
1687 incr z1
1688 set z2 [string first "\0" $buf_rdf $z1]
1689 if {$z2 == -1} break
1691 incr c
1692 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1693 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1694 merge_state \
1695 [encoding convertfrom utf-8 $p] \
1696 ?[lindex $i 4] \
1697 [list] \
1698 [list [lindex $i 0] [lindex $i 2]]
1699 set c $z2
1700 incr c
1702 if {$c < $n} {
1703 set buf_rdf [string range $buf_rdf $c end]
1704 } else {
1705 set buf_rdf {}
1708 rescan_done $fd buf_rdf $after
1711 proc read_ls_others {fd after} {
1712 global buf_rlo
1714 append buf_rlo [read $fd]
1715 set pck [split $buf_rlo "\0"]
1716 set buf_rlo [lindex $pck end]
1717 foreach p [lrange $pck 0 end-1] {
1718 set p [encoding convertfrom utf-8 $p]
1719 if {[string index $p end] eq {/}} {
1720 set p [string range $p 0 end-1]
1722 merge_state $p ?O
1724 rescan_done $fd buf_rlo $after
1727 proc rescan_done {fd buf after} {
1728 global rescan_active current_diff_path
1729 global file_states repo_config
1730 upvar $buf to_clear
1732 if {![eof $fd]} return
1733 set to_clear {}
1734 close $fd
1735 if {[incr rescan_active -1] > 0} return
1737 prune_selection
1738 unlock_index
1739 display_all_files
1740 if {$current_diff_path ne {}} { reshow_diff $after }
1741 if {$current_diff_path eq {}} { select_first_diff $after }
1744 proc prune_selection {} {
1745 global file_states selected_paths
1747 foreach path [array names selected_paths] {
1748 if {[catch {set still_here $file_states($path)}]} {
1749 unset selected_paths($path)
1754 ######################################################################
1756 ## ui helpers
1758 proc mapicon {w state path} {
1759 global all_icons
1761 if {[catch {set r $all_icons($state$w)}]} {
1762 puts "error: no icon for $w state={$state} $path"
1763 return file_plain
1765 return $r
1768 proc mapdesc {state path} {
1769 global all_descs
1771 if {[catch {set r $all_descs($state)}]} {
1772 puts "error: no desc for state={$state} $path"
1773 return $state
1775 return $r
1778 proc ui_status {msg} {
1779 global main_status
1780 if {[info exists main_status]} {
1781 $main_status show $msg
1785 proc ui_ready {{test {}}} {
1786 global main_status
1787 if {[info exists main_status]} {
1788 $main_status show [mc "Ready."] $test
1792 proc escape_path {path} {
1793 regsub -all {\\} $path "\\\\" path
1794 regsub -all "\n" $path "\\n" path
1795 return $path
1798 proc short_path {path} {
1799 return [escape_path [lindex [file split $path] end]]
1802 set next_icon_id 0
1803 set null_sha1 [string repeat 0 40]
1805 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1806 global file_states next_icon_id null_sha1
1808 set s0 [string index $new_state 0]
1809 set s1 [string index $new_state 1]
1811 if {[catch {set info $file_states($path)}]} {
1812 set state __
1813 set icon n[incr next_icon_id]
1814 } else {
1815 set state [lindex $info 0]
1816 set icon [lindex $info 1]
1817 if {$head_info eq {}} {set head_info [lindex $info 2]}
1818 if {$index_info eq {}} {set index_info [lindex $info 3]}
1821 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1822 elseif {$s0 eq {_}} {set s0 _}
1824 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1825 elseif {$s1 eq {_}} {set s1 _}
1827 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1828 set head_info [list 0 $null_sha1]
1829 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1830 && $head_info eq {}} {
1831 set head_info $index_info
1832 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1833 set index_info $head_info
1834 set head_info {}
1837 set file_states($path) [list $s0$s1 $icon \
1838 $head_info $index_info \
1840 return $state
1843 proc display_file_helper {w path icon_name old_m new_m} {
1844 global file_lists
1846 if {$new_m eq {_}} {
1847 set lno [lsearch -sorted -exact $file_lists($w) $path]
1848 if {$lno >= 0} {
1849 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1850 incr lno
1851 $w conf -state normal
1852 $w delete $lno.0 [expr {$lno + 1}].0
1853 $w conf -state disabled
1855 } elseif {$old_m eq {_} && $new_m ne {_}} {
1856 lappend file_lists($w) $path
1857 set file_lists($w) [lsort -unique $file_lists($w)]
1858 set lno [lsearch -sorted -exact $file_lists($w) $path]
1859 incr lno
1860 $w conf -state normal
1861 $w image create $lno.0 \
1862 -align center -padx 5 -pady 1 \
1863 -name $icon_name \
1864 -image [mapicon $w $new_m $path]
1865 $w insert $lno.1 "[escape_path $path]\n"
1866 $w conf -state disabled
1867 } elseif {$old_m ne $new_m} {
1868 $w conf -state normal
1869 $w image conf $icon_name -image [mapicon $w $new_m $path]
1870 $w conf -state disabled
1874 proc display_file {path state} {
1875 global file_states selected_paths
1876 global ui_index ui_workdir
1878 set old_m [merge_state $path $state]
1879 set s $file_states($path)
1880 set new_m [lindex $s 0]
1881 set icon_name [lindex $s 1]
1883 set o [string index $old_m 0]
1884 set n [string index $new_m 0]
1885 if {$o eq {U}} {
1886 set o _
1888 if {$n eq {U}} {
1889 set n _
1891 display_file_helper $ui_index $path $icon_name $o $n
1893 if {[string index $old_m 0] eq {U}} {
1894 set o U
1895 } else {
1896 set o [string index $old_m 1]
1898 if {[string index $new_m 0] eq {U}} {
1899 set n U
1900 } else {
1901 set n [string index $new_m 1]
1903 display_file_helper $ui_workdir $path $icon_name $o $n
1905 if {$new_m eq {__}} {
1906 unset file_states($path)
1907 catch {unset selected_paths($path)}
1911 proc display_all_files_helper {w path icon_name m} {
1912 global file_lists
1914 lappend file_lists($w) $path
1915 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1916 $w image create end \
1917 -align center -padx 5 -pady 1 \
1918 -name $icon_name \
1919 -image [mapicon $w $m $path]
1920 $w insert end "[escape_path $path]\n"
1923 set files_warning 0
1924 proc display_all_files {} {
1925 global ui_index ui_workdir
1926 global file_states file_lists
1927 global last_clicked
1928 global files_warning
1930 $ui_index conf -state normal
1931 $ui_workdir conf -state normal
1933 $ui_index delete 0.0 end
1934 $ui_workdir delete 0.0 end
1935 set last_clicked {}
1937 set file_lists($ui_index) [list]
1938 set file_lists($ui_workdir) [list]
1940 set to_display [lsort [array names file_states]]
1941 set display_limit [get_config gui.maxfilesdisplayed]
1942 if {[llength $to_display] > $display_limit} {
1943 if {!$files_warning} {
1944 # do not repeatedly warn:
1945 set files_warning 1
1946 info_popup [mc "Displaying only %s of %s files." \
1947 $display_limit [llength $to_display]]
1949 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1951 foreach path $to_display {
1952 set s $file_states($path)
1953 set m [lindex $s 0]
1954 set icon_name [lindex $s 1]
1956 set s [string index $m 0]
1957 if {$s ne {U} && $s ne {_}} {
1958 display_all_files_helper $ui_index $path \
1959 $icon_name $s
1962 if {[string index $m 0] eq {U}} {
1963 set s U
1964 } else {
1965 set s [string index $m 1]
1967 if {$s ne {_}} {
1968 display_all_files_helper $ui_workdir $path \
1969 $icon_name $s
1973 $ui_index conf -state disabled
1974 $ui_workdir conf -state disabled
1977 ######################################################################
1979 ## icons
1981 set filemask {
1982 #define mask_width 14
1983 #define mask_height 15
1984 static unsigned char mask_bits[] = {
1985 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1986 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1987 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1990 image create bitmap file_plain -background white -foreground black -data {
1991 #define plain_width 14
1992 #define plain_height 15
1993 static unsigned char plain_bits[] = {
1994 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1995 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1996 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1997 } -maskdata $filemask
1999 image create bitmap file_mod -background white -foreground blue -data {
2000 #define mod_width 14
2001 #define mod_height 15
2002 static unsigned char mod_bits[] = {
2003 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2004 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2005 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2006 } -maskdata $filemask
2008 image create bitmap file_fulltick -background white -foreground "#007000" -data {
2009 #define file_fulltick_width 14
2010 #define file_fulltick_height 15
2011 static unsigned char file_fulltick_bits[] = {
2012 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2013 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2014 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2015 } -maskdata $filemask
2017 image create bitmap file_question -background white -foreground black -data {
2018 #define file_question_width 14
2019 #define file_question_height 15
2020 static unsigned char file_question_bits[] = {
2021 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2022 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2023 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2024 } -maskdata $filemask
2026 image create bitmap file_removed -background white -foreground red -data {
2027 #define file_removed_width 14
2028 #define file_removed_height 15
2029 static unsigned char file_removed_bits[] = {
2030 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2031 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2032 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2033 } -maskdata $filemask
2035 image create bitmap file_merge -background white -foreground blue -data {
2036 #define file_merge_width 14
2037 #define file_merge_height 15
2038 static unsigned char file_merge_bits[] = {
2039 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2040 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2041 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2042 } -maskdata $filemask
2044 image create bitmap file_statechange -background white -foreground green -data {
2045 #define file_statechange_width 14
2046 #define file_statechange_height 15
2047 static unsigned char file_statechange_bits[] = {
2048 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
2049 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
2050 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2051 } -maskdata $filemask
2053 set ui_index .vpane.files.index.list
2054 set ui_workdir .vpane.files.workdir.list
2056 set all_icons(_$ui_index) file_plain
2057 set all_icons(A$ui_index) file_plain
2058 set all_icons(M$ui_index) file_fulltick
2059 set all_icons(D$ui_index) file_removed
2060 set all_icons(U$ui_index) file_merge
2061 set all_icons(T$ui_index) file_statechange
2063 set all_icons(_$ui_workdir) file_plain
2064 set all_icons(M$ui_workdir) file_mod
2065 set all_icons(D$ui_workdir) file_question
2066 set all_icons(U$ui_workdir) file_merge
2067 set all_icons(O$ui_workdir) file_plain
2068 set all_icons(T$ui_workdir) file_statechange
2070 set max_status_desc 0
2071 foreach i {
2072 {__ {mc "Unmodified"}}
2074 {_M {mc "Modified, not staged"}}
2075 {M_ {mc "Staged for commit"}}
2076 {MM {mc "Portions staged for commit"}}
2077 {MD {mc "Staged for commit, missing"}}
2079 {_T {mc "File type changed, not staged"}}
2080 {MT {mc "File type changed, old type staged for commit"}}
2081 {AT {mc "File type changed, old type staged for commit"}}
2082 {T_ {mc "File type changed, staged"}}
2083 {TM {mc "File type change staged, modification not staged"}}
2084 {TD {mc "File type change staged, file missing"}}
2086 {_O {mc "Untracked, not staged"}}
2087 {A_ {mc "Staged for commit"}}
2088 {AM {mc "Portions staged for commit"}}
2089 {AD {mc "Staged for commit, missing"}}
2091 {_D {mc "Missing"}}
2092 {D_ {mc "Staged for removal"}}
2093 {DO {mc "Staged for removal, still present"}}
2095 {_U {mc "Requires merge resolution"}}
2096 {U_ {mc "Requires merge resolution"}}
2097 {UU {mc "Requires merge resolution"}}
2098 {UM {mc "Requires merge resolution"}}
2099 {UD {mc "Requires merge resolution"}}
2100 {UT {mc "Requires merge resolution"}}
2102 set text [eval [lindex $i 1]]
2103 if {$max_status_desc < [string length $text]} {
2104 set max_status_desc [string length $text]
2106 set all_descs([lindex $i 0]) $text
2108 unset i
2110 ######################################################################
2112 ## util
2114 proc scrollbar2many {list mode args} {
2115 foreach w $list {eval $w $mode $args}
2118 proc many2scrollbar {list mode sb top bottom} {
2119 $sb set $top $bottom
2120 foreach w $list {$w $mode moveto $top}
2123 proc incr_font_size {font {amt 1}} {
2124 set sz [font configure $font -size]
2125 incr sz $amt
2126 font configure $font -size $sz
2127 font configure ${font}bold -size $sz
2128 font configure ${font}italic -size $sz
2131 ######################################################################
2133 ## ui commands
2135 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2137 proc do_gitk {revs {is_submodule false}} {
2138 global current_diff_path file_states current_diff_side ui_index
2139 global _gitworktree
2141 # -- Always start gitk through whatever we were loaded with. This
2142 # lets us bypass using shell process on Windows systems.
2144 set exe [_which gitk -script]
2145 set cmd [list [info nameofexecutable] $exe]
2146 if {$exe eq {}} {
2147 error_popup [mc "Couldn't find gitk in PATH"]
2148 } else {
2149 global env
2151 if {[info exists env(GIT_DIR)]} {
2152 set old_GIT_DIR $env(GIT_DIR)
2153 } else {
2154 set old_GIT_DIR {}
2157 set pwd [pwd]
2159 if {!$is_submodule} {
2160 if {![is_bare]} {
2161 cd $_gitworktree
2163 set env(GIT_DIR) [file normalize [gitdir]]
2164 } else {
2165 cd $current_diff_path
2166 if {$revs eq {--}} {
2167 set s $file_states($current_diff_path)
2168 set old_sha1 {}
2169 set new_sha1 {}
2170 switch -glob -- [lindex $s 0] {
2171 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2172 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2173 MM {
2174 if {$current_diff_side eq $ui_index} {
2175 set old_sha1 [lindex [lindex $s 2] 1]
2176 set new_sha1 [lindex [lindex $s 3] 1]
2177 } else {
2178 set old_sha1 [lindex [lindex $s 3] 1]
2182 set revs $old_sha1...$new_sha1
2184 if {[info exists env(GIT_DIR)]} {
2185 unset env(GIT_DIR)
2188 eval exec $cmd $revs "--" "--" &
2190 if {$old_GIT_DIR ne {}} {
2191 set env(GIT_DIR) $old_GIT_DIR
2193 cd $pwd
2195 ui_status $::starting_gitk_msg
2196 after 10000 {
2197 ui_ready $starting_gitk_msg
2202 proc do_git_gui {} {
2203 global current_diff_path
2205 # -- Always start git gui through whatever we were loaded with. This
2206 # lets us bypass using shell process on Windows systems.
2208 set exe [list [_which git]]
2209 if {$exe eq {}} {
2210 error_popup [mc "Couldn't find git gui in PATH"]
2211 } else {
2212 global env
2214 if {[info exists env(GIT_DIR)]} {
2215 set old_GIT_DIR $env(GIT_DIR)
2216 unset env(GIT_DIR)
2217 } else {
2218 set old_GIT_DIR {}
2221 set pwd [pwd]
2222 cd $current_diff_path
2224 eval exec $exe gui &
2226 if {$old_GIT_DIR ne {}} {
2227 set env(GIT_DIR) $old_GIT_DIR
2229 cd $pwd
2231 ui_status $::starting_gitk_msg
2232 after 10000 {
2233 ui_ready $starting_gitk_msg
2238 proc do_explore {} {
2239 global _gitworktree
2240 set explorer {}
2241 if {[is_Cygwin] || [is_Windows]} {
2242 set explorer "explorer.exe"
2243 } elseif {[is_MacOSX]} {
2244 set explorer "open"
2245 } else {
2246 # freedesktop.org-conforming system is our best shot
2247 set explorer "xdg-open"
2249 eval exec $explorer [list [file nativename $_gitworktree]] &
2252 set is_quitting 0
2253 set ret_code 1
2255 proc terminate_me {win} {
2256 global ret_code
2257 if {$win ne {.}} return
2258 exit $ret_code
2261 proc do_quit {{rc {1}}} {
2262 global ui_comm is_quitting repo_config commit_type
2263 global GITGUI_BCK_exists GITGUI_BCK_i
2264 global ui_comm_spell
2265 global ret_code use_ttk
2267 if {$is_quitting} return
2268 set is_quitting 1
2270 if {[winfo exists $ui_comm]} {
2271 # -- Stash our current commit buffer.
2273 set save [gitdir GITGUI_MSG]
2274 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2275 file rename -force [gitdir GITGUI_BCK] $save
2276 set GITGUI_BCK_exists 0
2277 } else {
2278 set msg [string trim [$ui_comm get 0.0 end]]
2279 regsub -all -line {[ \r\t]+$} $msg {} msg
2280 if {(![string match amend* $commit_type]
2281 || [$ui_comm edit modified])
2282 && $msg ne {}} {
2283 catch {
2284 set fd [open $save w]
2285 fconfigure $fd -encoding utf-8
2286 puts -nonewline $fd $msg
2287 close $fd
2289 } else {
2290 catch {file delete $save}
2294 # -- Cancel our spellchecker if its running.
2296 if {[info exists ui_comm_spell]} {
2297 $ui_comm_spell stop
2300 # -- Remove our editor backup, its not needed.
2302 after cancel $GITGUI_BCK_i
2303 if {$GITGUI_BCK_exists} {
2304 catch {file delete [gitdir GITGUI_BCK]}
2307 # -- Stash our current window geometry into this repository.
2309 set cfg_wmstate [wm state .]
2310 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2311 set rc_wmstate {}
2313 if {$cfg_wmstate ne $rc_wmstate} {
2314 catch {git config gui.wmstate $cfg_wmstate}
2316 if {$cfg_wmstate eq {zoomed}} {
2317 # on Windows wm geometry will lie about window
2318 # position (but not size) when window is zoomed
2319 # restore the window before querying wm geometry
2320 wm state . normal
2322 set cfg_geometry [list]
2323 lappend cfg_geometry [wm geometry .]
2324 if {$use_ttk} {
2325 lappend cfg_geometry [.vpane sashpos 0]
2326 lappend cfg_geometry [.vpane.files sashpos 0]
2327 } else {
2328 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2329 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2331 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2332 set rc_geometry {}
2334 if {$cfg_geometry ne $rc_geometry} {
2335 catch {git config gui.geometry $cfg_geometry}
2339 set ret_code $rc
2341 # Briefly enable send again, working around Tk bug
2342 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2343 tk appname [appname]
2345 destroy .
2348 proc do_rescan {} {
2349 rescan ui_ready
2352 proc ui_do_rescan {} {
2353 rescan {force_first_diff ui_ready}
2356 proc do_commit {} {
2357 commit_tree
2360 proc next_diff {{after {}}} {
2361 global next_diff_p next_diff_w next_diff_i
2362 show_diff $next_diff_p $next_diff_w {} {} $after
2365 proc find_anchor_pos {lst name} {
2366 set lid [lsearch -sorted -exact $lst $name]
2368 if {$lid == -1} {
2369 set lid 0
2370 foreach lname $lst {
2371 if {$lname >= $name} break
2372 incr lid
2376 return $lid
2379 proc find_file_from {flist idx delta path mmask} {
2380 global file_states
2382 set len [llength $flist]
2383 while {$idx >= 0 && $idx < $len} {
2384 set name [lindex $flist $idx]
2386 if {$name ne $path && [info exists file_states($name)]} {
2387 set state [lindex $file_states($name) 0]
2389 if {$mmask eq {} || [regexp $mmask $state]} {
2390 return $idx
2394 incr idx $delta
2397 return {}
2400 proc find_next_diff {w path {lno {}} {mmask {}}} {
2401 global next_diff_p next_diff_w next_diff_i
2402 global file_lists ui_index ui_workdir
2404 set flist $file_lists($w)
2405 if {$lno eq {}} {
2406 set lno [find_anchor_pos $flist $path]
2407 } else {
2408 incr lno -1
2411 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2412 if {$w eq $ui_index} {
2413 set mmask "^$mmask"
2414 } else {
2415 set mmask "$mmask\$"
2419 set idx [find_file_from $flist $lno 1 $path $mmask]
2420 if {$idx eq {}} {
2421 incr lno -1
2422 set idx [find_file_from $flist $lno -1 $path $mmask]
2425 if {$idx ne {}} {
2426 set next_diff_w $w
2427 set next_diff_p [lindex $flist $idx]
2428 set next_diff_i [expr {$idx+1}]
2429 return 1
2430 } else {
2431 return 0
2435 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2436 global current_diff_path
2438 if {$path ne $current_diff_path} {
2439 return {}
2440 } elseif {[find_next_diff $w $path $lno $mmask]} {
2441 return {next_diff;}
2442 } else {
2443 return {reshow_diff;}
2447 proc select_first_diff {after} {
2448 global ui_workdir
2450 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2451 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2452 next_diff $after
2453 } else {
2454 uplevel #0 $after
2458 proc force_first_diff {after} {
2459 global ui_workdir current_diff_path file_states
2461 if {[info exists file_states($current_diff_path)]} {
2462 set state [lindex $file_states($current_diff_path) 0]
2463 } else {
2464 set state {OO}
2467 set reselect 0
2468 if {[string first {U} $state] >= 0} {
2469 # Already a conflict, do nothing
2470 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2471 set reselect 1
2472 } elseif {[string index $state 1] ne {O}} {
2473 # Already a diff & no conflicts, do nothing
2474 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2475 set reselect 1
2478 if {$reselect} {
2479 next_diff $after
2480 } else {
2481 uplevel #0 $after
2485 proc toggle_or_diff {w x y} {
2486 global file_states file_lists current_diff_path ui_index ui_workdir
2487 global last_clicked selected_paths
2489 set pos [split [$w index @$x,$y] .]
2490 set lno [lindex $pos 0]
2491 set col [lindex $pos 1]
2492 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2493 if {$path eq {}} {
2494 set last_clicked {}
2495 return
2498 set last_clicked [list $w $lno]
2499 array unset selected_paths
2500 $ui_index tag remove in_sel 0.0 end
2501 $ui_workdir tag remove in_sel 0.0 end
2503 # Determine the state of the file
2504 if {[info exists file_states($path)]} {
2505 set state [lindex $file_states($path) 0]
2506 } else {
2507 set state {__}
2510 # Restage the file, or simply show the diff
2511 if {$col == 0 && $y > 1} {
2512 # Conflicts need special handling
2513 if {[string first {U} $state] >= 0} {
2514 # $w must always be $ui_workdir, but...
2515 if {$w ne $ui_workdir} { set lno {} }
2516 merge_stage_workdir $path $lno
2517 return
2520 if {[string index $state 1] eq {O}} {
2521 set mmask {}
2522 } else {
2523 set mmask {[^O]}
2526 set after [next_diff_after_action $w $path $lno $mmask]
2528 if {$w eq $ui_index} {
2529 update_indexinfo \
2530 "Unstaging [short_path $path] from commit" \
2531 [list $path] \
2532 [concat $after [list ui_ready]]
2533 } elseif {$w eq $ui_workdir} {
2534 update_index \
2535 "Adding [short_path $path]" \
2536 [list $path] \
2537 [concat $after [list ui_ready]]
2539 } else {
2540 set selected_paths($path) 1
2541 show_diff $path $w $lno
2545 proc add_one_to_selection {w x y} {
2546 global file_lists last_clicked selected_paths
2548 set lno [lindex [split [$w index @$x,$y] .] 0]
2549 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2550 if {$path eq {}} {
2551 set last_clicked {}
2552 return
2555 if {$last_clicked ne {}
2556 && [lindex $last_clicked 0] ne $w} {
2557 array unset selected_paths
2558 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2561 set last_clicked [list $w $lno]
2562 if {[catch {set in_sel $selected_paths($path)}]} {
2563 set in_sel 0
2565 if {$in_sel} {
2566 unset selected_paths($path)
2567 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2568 } else {
2569 set selected_paths($path) 1
2570 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2574 proc add_range_to_selection {w x y} {
2575 global file_lists last_clicked selected_paths
2577 if {[lindex $last_clicked 0] ne $w} {
2578 toggle_or_diff $w $x $y
2579 return
2582 set lno [lindex [split [$w index @$x,$y] .] 0]
2583 set lc [lindex $last_clicked 1]
2584 if {$lc < $lno} {
2585 set begin $lc
2586 set end $lno
2587 } else {
2588 set begin $lno
2589 set end $lc
2592 foreach path [lrange $file_lists($w) \
2593 [expr {$begin - 1}] \
2594 [expr {$end - 1}]] {
2595 set selected_paths($path) 1
2597 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2600 proc show_more_context {} {
2601 global repo_config
2602 if {$repo_config(gui.diffcontext) < 99} {
2603 incr repo_config(gui.diffcontext)
2604 reshow_diff
2608 proc show_less_context {} {
2609 global repo_config
2610 if {$repo_config(gui.diffcontext) > 1} {
2611 incr repo_config(gui.diffcontext) -1
2612 reshow_diff
2616 ######################################################################
2618 ## ui construction
2620 set ui_comm {}
2622 # -- Menu Bar
2624 menu .mbar -tearoff 0
2625 if {[is_MacOSX]} {
2626 # -- Apple Menu (Mac OS X only)
2628 .mbar add cascade -label Apple -menu .mbar.apple
2629 menu .mbar.apple
2631 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2632 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2633 if {[is_enabled branch]} {
2634 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2636 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2637 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2639 if {[is_enabled transport]} {
2640 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2641 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2643 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2644 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2647 # -- Repository Menu
2649 menu .mbar.repository
2651 if {![is_bare]} {
2652 .mbar.repository add command \
2653 -label [mc "Explore Working Copy"] \
2654 -command {do_explore}
2655 .mbar.repository add separator
2658 .mbar.repository add command \
2659 -label [mc "Browse Current Branch's Files"] \
2660 -command {browser::new $current_branch}
2661 set ui_browse_current [.mbar.repository index last]
2662 .mbar.repository add command \
2663 -label [mc "Browse Branch Files..."] \
2664 -command browser_open::dialog
2665 .mbar.repository add separator
2667 .mbar.repository add command \
2668 -label [mc "Visualize Current Branch's History"] \
2669 -command {do_gitk $current_branch}
2670 set ui_visualize_current [.mbar.repository index last]
2671 .mbar.repository add command \
2672 -label [mc "Visualize All Branch History"] \
2673 -command {do_gitk --all}
2674 .mbar.repository add separator
2676 proc current_branch_write {args} {
2677 global current_branch
2678 .mbar.repository entryconf $::ui_browse_current \
2679 -label [mc "Browse %s's Files" $current_branch]
2680 .mbar.repository entryconf $::ui_visualize_current \
2681 -label [mc "Visualize %s's History" $current_branch]
2683 trace add variable current_branch write current_branch_write
2685 if {[is_enabled multicommit]} {
2686 .mbar.repository add command -label [mc "Database Statistics"] \
2687 -command do_stats
2689 .mbar.repository add command -label [mc "Compress Database"] \
2690 -command do_gc
2692 .mbar.repository add command -label [mc "Verify Database"] \
2693 -command do_fsck_objects
2695 .mbar.repository add separator
2697 if {[is_Cygwin]} {
2698 .mbar.repository add command \
2699 -label [mc "Create Desktop Icon"] \
2700 -command do_cygwin_shortcut
2701 } elseif {[is_Windows]} {
2702 .mbar.repository add command \
2703 -label [mc "Create Desktop Icon"] \
2704 -command do_windows_shortcut
2705 } elseif {[is_MacOSX]} {
2706 .mbar.repository add command \
2707 -label [mc "Create Desktop Icon"] \
2708 -command do_macosx_app
2712 if {[is_MacOSX]} {
2713 proc ::tk::mac::Quit {args} { do_quit }
2714 } else {
2715 .mbar.repository add command -label [mc Quit] \
2716 -command do_quit \
2717 -accelerator $M1T-Q
2720 # -- Edit Menu
2722 menu .mbar.edit
2723 .mbar.edit add command -label [mc Undo] \
2724 -command {catch {[focus] edit undo}} \
2725 -accelerator $M1T-Z
2726 .mbar.edit add command -label [mc Redo] \
2727 -command {catch {[focus] edit redo}} \
2728 -accelerator $M1T-Y
2729 .mbar.edit add separator
2730 .mbar.edit add command -label [mc Cut] \
2731 -command {catch {tk_textCut [focus]}} \
2732 -accelerator $M1T-X
2733 .mbar.edit add command -label [mc Copy] \
2734 -command {catch {tk_textCopy [focus]}} \
2735 -accelerator $M1T-C
2736 .mbar.edit add command -label [mc Paste] \
2737 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2738 -accelerator $M1T-V
2739 .mbar.edit add command -label [mc Delete] \
2740 -command {catch {[focus] delete sel.first sel.last}} \
2741 -accelerator Del
2742 .mbar.edit add separator
2743 .mbar.edit add command -label [mc "Select All"] \
2744 -command {catch {[focus] tag add sel 0.0 end}} \
2745 -accelerator $M1T-A
2747 # -- Branch Menu
2749 if {[is_enabled branch]} {
2750 menu .mbar.branch
2752 .mbar.branch add command -label [mc "Create..."] \
2753 -command branch_create::dialog \
2754 -accelerator $M1T-N
2755 lappend disable_on_lock [list .mbar.branch entryconf \
2756 [.mbar.branch index last] -state]
2758 .mbar.branch add command -label [mc "Checkout..."] \
2759 -command branch_checkout::dialog \
2760 -accelerator $M1T-O
2761 lappend disable_on_lock [list .mbar.branch entryconf \
2762 [.mbar.branch index last] -state]
2764 .mbar.branch add command -label [mc "Rename..."] \
2765 -command branch_rename::dialog
2766 lappend disable_on_lock [list .mbar.branch entryconf \
2767 [.mbar.branch index last] -state]
2769 .mbar.branch add command -label [mc "Delete..."] \
2770 -command branch_delete::dialog
2771 lappend disable_on_lock [list .mbar.branch entryconf \
2772 [.mbar.branch index last] -state]
2774 .mbar.branch add command -label [mc "Reset..."] \
2775 -command merge::reset_hard
2776 lappend disable_on_lock [list .mbar.branch entryconf \
2777 [.mbar.branch index last] -state]
2780 # -- Commit Menu
2782 proc commit_btn_caption {} {
2783 if {[is_enabled nocommit]} {
2784 return [mc "Done"]
2785 } else {
2786 return [mc Commit@@verb]
2790 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2791 menu .mbar.commit
2793 if {![is_enabled nocommit]} {
2794 .mbar.commit add radiobutton \
2795 -label [mc "New Commit"] \
2796 -command do_select_commit_type \
2797 -variable selected_commit_type \
2798 -value new
2799 lappend disable_on_lock \
2800 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2802 .mbar.commit add radiobutton \
2803 -label [mc "Amend Last Commit"] \
2804 -command do_select_commit_type \
2805 -variable selected_commit_type \
2806 -value amend
2807 lappend disable_on_lock \
2808 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2810 .mbar.commit add separator
2813 .mbar.commit add command -label [mc Rescan] \
2814 -command ui_do_rescan \
2815 -accelerator F5
2816 lappend disable_on_lock \
2817 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2819 .mbar.commit add command -label [mc "Stage To Commit"] \
2820 -command do_add_selection \
2821 -accelerator $M1T-T
2822 lappend disable_on_lock \
2823 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2825 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2826 -command do_add_all \
2827 -accelerator $M1T-I
2828 lappend disable_on_lock \
2829 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2831 .mbar.commit add command -label [mc "Unstage From Commit"] \
2832 -command do_unstage_selection \
2833 -accelerator $M1T-U
2834 lappend disable_on_lock \
2835 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2837 .mbar.commit add command -label [mc "Revert Changes"] \
2838 -command do_revert_selection \
2839 -accelerator $M1T-J
2840 lappend disable_on_lock \
2841 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2843 .mbar.commit add separator
2845 .mbar.commit add command -label [mc "Show Less Context"] \
2846 -command show_less_context \
2847 -accelerator $M1T-\-
2849 .mbar.commit add command -label [mc "Show More Context"] \
2850 -command show_more_context \
2851 -accelerator $M1T-=
2853 .mbar.commit add separator
2855 if {![is_enabled nocommitmsg]} {
2856 .mbar.commit add command -label [mc "Sign Off"] \
2857 -command do_signoff \
2858 -accelerator $M1T-S
2861 .mbar.commit add command -label [commit_btn_caption] \
2862 -command do_commit \
2863 -accelerator $M1T-Return
2864 lappend disable_on_lock \
2865 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2868 # -- Merge Menu
2870 if {[is_enabled branch]} {
2871 menu .mbar.merge
2872 .mbar.merge add command -label [mc "Local Merge..."] \
2873 -command merge::dialog \
2874 -accelerator $M1T-M
2875 lappend disable_on_lock \
2876 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2877 .mbar.merge add command -label [mc "Abort Merge..."] \
2878 -command merge::reset_hard
2879 lappend disable_on_lock \
2880 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2883 # -- Transport Menu
2885 if {[is_enabled transport]} {
2886 menu .mbar.remote
2888 .mbar.remote add command \
2889 -label [mc "Add..."] \
2890 -command remote_add::dialog \
2891 -accelerator $M1T-A
2892 .mbar.remote add command \
2893 -label [mc "Push..."] \
2894 -command do_push_anywhere \
2895 -accelerator $M1T-P
2896 .mbar.remote add command \
2897 -label [mc "Delete Branch..."] \
2898 -command remote_branch_delete::dialog
2901 if {[is_MacOSX]} {
2902 proc ::tk::mac::ShowPreferences {} {do_options}
2903 } else {
2904 # -- Edit Menu
2906 .mbar.edit add separator
2907 .mbar.edit add command -label [mc "Options..."] \
2908 -command do_options
2911 # -- Tools Menu
2913 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2914 set tools_menubar .mbar.tools
2915 menu $tools_menubar
2916 $tools_menubar add separator
2917 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2918 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2919 set tools_tailcnt 3
2920 if {[array names repo_config guitool.*.cmd] ne {}} {
2921 tools_populate_all
2925 # -- Help Menu
2927 .mbar add cascade -label [mc Help] -menu .mbar.help
2928 menu .mbar.help
2930 if {[is_MacOSX]} {
2931 .mbar.apple add command -label [mc "About %s" [appname]] \
2932 -command do_about
2933 .mbar.apple add separator
2934 } else {
2935 .mbar.help add command -label [mc "About %s" [appname]] \
2936 -command do_about
2938 . configure -menu .mbar
2940 set doc_path [githtmldir]
2941 if {$doc_path ne {}} {
2942 set doc_path [file join $doc_path index.html]
2944 if {[is_Cygwin]} {
2945 set doc_path [exec cygpath --mixed $doc_path]
2949 if {[file isfile $doc_path]} {
2950 set doc_url "file:$doc_path"
2951 } else {
2952 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2955 proc start_browser {url} {
2956 git "web--browse" $url
2959 .mbar.help add command -label [mc "Online Documentation"] \
2960 -command [list start_browser $doc_url]
2962 .mbar.help add command -label [mc "Show SSH Key"] \
2963 -command do_ssh_key
2965 unset doc_path doc_url
2967 # -- Standard bindings
2969 wm protocol . WM_DELETE_WINDOW do_quit
2970 bind all <$M1B-Key-q> do_quit
2971 bind all <$M1B-Key-Q> do_quit
2972 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2973 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2975 set subcommand_args {}
2976 proc usage {} {
2977 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2978 if {[tk windowingsystem] eq "win32"} {
2979 wm withdraw .
2980 tk_messageBox -icon info -message $s \
2981 -title [mc "Usage"]
2982 } else {
2983 puts stderr $s
2985 exit 1
2988 proc normalize_relpath {path} {
2989 set elements {}
2990 foreach item [file split $path] {
2991 if {$item eq {.}} continue
2992 if {$item eq {..} && [llength $elements] > 0
2993 && [lindex $elements end] ne {..}} {
2994 set elements [lrange $elements 0 end-1]
2995 continue
2997 lappend elements $item
2999 return [eval file join $elements]
3002 # -- Not a normal commit type invocation? Do that instead!
3004 switch -- $subcommand {
3005 browser -
3006 blame {
3007 if {$subcommand eq "blame"} {
3008 set subcommand_args {[--line=<num>] rev? path}
3009 } else {
3010 set subcommand_args {rev? path}
3012 if {$argv eq {}} usage
3013 set head {}
3014 set path {}
3015 set jump_spec {}
3016 set is_path 0
3017 foreach a $argv {
3018 if {[file exists $a]} {
3019 if {$path ne {}} usage
3020 set path [normalize_relpath $a]
3021 break
3022 } elseif {[file exists $_prefix$a]} {
3023 if {$path ne {}} usage
3024 set path [normalize_relpath $_prefix$a]
3025 break
3028 if {$is_path} {
3029 if {$path ne {}} usage
3030 break
3031 } elseif {$a eq {--}} {
3032 if {$path ne {}} {
3033 if {$head ne {}} usage
3034 set head $path
3035 set path {}
3037 set is_path 1
3038 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
3039 if {$jump_spec ne {} || $head ne {}} usage
3040 set jump_spec [list $lnum]
3041 } elseif {$head eq {}} {
3042 if {$head ne {}} usage
3043 set head $a
3044 set is_path 1
3045 } else {
3046 usage
3049 unset is_path
3051 if {$head ne {} && $path eq {}} {
3052 if {[string index $head 0] eq {/}} {
3053 set path [normalize_relpath $head]
3054 set head {}
3055 } else {
3056 set path [normalize_relpath $_prefix$head]
3057 set head {}
3061 if {$head eq {}} {
3062 load_current_branch
3063 } else {
3064 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
3065 if {[catch {
3066 set head [git rev-parse --verify $head]
3067 } err]} {
3068 if {[tk windowingsystem] eq "win32"} {
3069 tk_messageBox -icon error -title [mc Error] -message $err
3070 } else {
3071 puts stderr $err
3073 exit 1
3076 set current_branch $head
3079 wm deiconify .
3080 switch -- $subcommand {
3081 browser {
3082 if {$jump_spec ne {}} usage
3083 if {$head eq {}} {
3084 if {$path ne {} && [file isdirectory $path]} {
3085 set head $current_branch
3086 } else {
3087 set head $path
3088 set path {}
3091 browser::new $head $path
3093 blame {
3094 if {$head eq {} && ![file exists $path]} {
3095 catch {wm withdraw .}
3096 tk_messageBox \
3097 -icon error \
3098 -type ok \
3099 -title [mc "git-gui: fatal error"] \
3100 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
3101 exit 1
3103 blame::new $head $path $jump_spec
3106 return
3108 citool -
3109 gui {
3110 if {[llength $argv] != 0} {
3111 usage
3113 # fall through to setup UI for commits
3115 default {
3116 set err "usage: $argv0 \[{blame|browser|citool}\]"
3117 if {[tk windowingsystem] eq "win32"} {
3118 wm withdraw .
3119 tk_messageBox -icon error -message $err \
3120 -title [mc "Usage"]
3121 } else {
3122 puts stderr $err
3124 exit 1
3128 # -- Branch Control
3130 ${NS}::frame .branch
3131 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3132 ${NS}::label .branch.l1 \
3133 -text [mc "Current Branch:"] \
3134 -anchor w \
3135 -justify left
3136 ${NS}::label .branch.cb \
3137 -textvariable current_branch \
3138 -anchor w \
3139 -justify left
3140 pack .branch.l1 -side left
3141 pack .branch.cb -side left -fill x
3142 pack .branch -side top -fill x
3144 # -- Main Window Layout
3146 ${NS}::panedwindow .vpane -orient horizontal
3147 ${NS}::panedwindow .vpane.files -orient vertical
3148 if {$use_ttk} {
3149 .vpane add .vpane.files
3150 } else {
3151 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3153 pack .vpane -anchor n -side top -fill both -expand 1
3155 # -- Index File List
3157 ${NS}::frame .vpane.files.index -height 100 -width 200
3158 tlabel .vpane.files.index.title \
3159 -text [mc "Staged Changes (Will Commit)"] \
3160 -background lightgreen -foreground black
3161 text $ui_index -background white -foreground black \
3162 -borderwidth 0 \
3163 -width 20 -height 10 \
3164 -wrap none \
3165 -cursor $cursor_ptr \
3166 -xscrollcommand {.vpane.files.index.sx set} \
3167 -yscrollcommand {.vpane.files.index.sy set} \
3168 -state disabled
3169 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3170 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3171 pack .vpane.files.index.title -side top -fill x
3172 pack .vpane.files.index.sx -side bottom -fill x
3173 pack .vpane.files.index.sy -side right -fill y
3174 pack $ui_index -side left -fill both -expand 1
3176 # -- Working Directory File List
3178 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3179 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3180 -background lightsalmon -foreground black
3181 text $ui_workdir -background white -foreground black \
3182 -borderwidth 0 \
3183 -width 20 -height 10 \
3184 -wrap none \
3185 -cursor $cursor_ptr \
3186 -xscrollcommand {.vpane.files.workdir.sx set} \
3187 -yscrollcommand {.vpane.files.workdir.sy set} \
3188 -state disabled
3189 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3190 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3191 pack .vpane.files.workdir.title -side top -fill x
3192 pack .vpane.files.workdir.sx -side bottom -fill x
3193 pack .vpane.files.workdir.sy -side right -fill y
3194 pack $ui_workdir -side left -fill both -expand 1
3196 .vpane.files add .vpane.files.workdir
3197 .vpane.files add .vpane.files.index
3198 if {!$use_ttk} {
3199 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3200 .vpane.files paneconfigure .vpane.files.index -sticky news
3203 foreach i [list $ui_index $ui_workdir] {
3204 rmsel_tag $i
3205 $i tag conf in_diff -background [$i tag cget in_sel -background]
3207 unset i
3209 # -- Diff and Commit Area
3211 ${NS}::frame .vpane.lower -height 300 -width 400
3212 ${NS}::frame .vpane.lower.commarea
3213 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3214 pack .vpane.lower.diff -fill both -expand 1
3215 pack .vpane.lower.commarea -side bottom -fill x
3216 .vpane add .vpane.lower
3217 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3219 # -- Commit Area Buttons
3221 ${NS}::frame .vpane.lower.commarea.buttons
3222 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3223 -anchor w \
3224 -justify left
3225 pack .vpane.lower.commarea.buttons.l -side top -fill x
3226 pack .vpane.lower.commarea.buttons -side left -fill y
3228 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3229 -command ui_do_rescan
3230 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3231 lappend disable_on_lock \
3232 {.vpane.lower.commarea.buttons.rescan conf -state}
3234 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3235 -command do_add_all
3236 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3237 lappend disable_on_lock \
3238 {.vpane.lower.commarea.buttons.incall conf -state}
3240 if {![is_enabled nocommitmsg]} {
3241 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3242 -command do_signoff
3243 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3246 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3247 -command do_commit
3248 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3249 lappend disable_on_lock \
3250 {.vpane.lower.commarea.buttons.commit conf -state}
3252 if {![is_enabled nocommit]} {
3253 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3254 -command do_push_anywhere
3255 pack .vpane.lower.commarea.buttons.push -side top -fill x
3258 # -- Commit Message Buffer
3260 ${NS}::frame .vpane.lower.commarea.buffer
3261 ${NS}::frame .vpane.lower.commarea.buffer.header
3262 set ui_comm .vpane.lower.commarea.buffer.t
3263 set ui_coml .vpane.lower.commarea.buffer.header.l
3265 if {![is_enabled nocommit]} {
3266 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3267 -text [mc "New Commit"] \
3268 -command do_select_commit_type \
3269 -variable selected_commit_type \
3270 -value new
3271 lappend disable_on_lock \
3272 [list .vpane.lower.commarea.buffer.header.new conf -state]
3273 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3274 -text [mc "Amend Last Commit"] \
3275 -command do_select_commit_type \
3276 -variable selected_commit_type \
3277 -value amend
3278 lappend disable_on_lock \
3279 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3282 ${NS}::label $ui_coml \
3283 -anchor w \
3284 -justify left
3285 proc trace_commit_type {varname args} {
3286 global ui_coml commit_type
3287 switch -glob -- $commit_type {
3288 initial {set txt [mc "Initial Commit Message:"]}
3289 amend {set txt [mc "Amended Commit Message:"]}
3290 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3291 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3292 merge {set txt [mc "Merge Commit Message:"]}
3293 * {set txt [mc "Commit Message:"]}
3295 $ui_coml conf -text $txt
3297 trace add variable commit_type write trace_commit_type
3298 pack $ui_coml -side left -fill x
3300 if {![is_enabled nocommit]} {
3301 pack .vpane.lower.commarea.buffer.header.amend -side right
3302 pack .vpane.lower.commarea.buffer.header.new -side right
3305 text $ui_comm -background white -foreground black \
3306 -borderwidth 1 \
3307 -undo true \
3308 -maxundo 20 \
3309 -autoseparators true \
3310 -relief sunken \
3311 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3312 -font font_diff \
3313 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3314 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3315 -command [list $ui_comm yview]
3316 pack .vpane.lower.commarea.buffer.header -side top -fill x
3317 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3318 pack $ui_comm -side left -fill y
3319 pack .vpane.lower.commarea.buffer -side left -fill y
3321 # -- Commit Message Buffer Context Menu
3323 set ctxm .vpane.lower.commarea.buffer.ctxm
3324 menu $ctxm -tearoff 0
3325 $ctxm add command \
3326 -label [mc Cut] \
3327 -command {tk_textCut $ui_comm}
3328 $ctxm add command \
3329 -label [mc Copy] \
3330 -command {tk_textCopy $ui_comm}
3331 $ctxm add command \
3332 -label [mc Paste] \
3333 -command {tk_textPaste $ui_comm}
3334 $ctxm add command \
3335 -label [mc Delete] \
3336 -command {catch {$ui_comm delete sel.first sel.last}}
3337 $ctxm add separator
3338 $ctxm add command \
3339 -label [mc "Select All"] \
3340 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3341 $ctxm add command \
3342 -label [mc "Copy All"] \
3343 -command {
3344 $ui_comm tag add sel 0.0 end
3345 tk_textCopy $ui_comm
3346 $ui_comm tag remove sel 0.0 end
3348 $ctxm add separator
3349 $ctxm add command \
3350 -label [mc "Sign Off"] \
3351 -command do_signoff
3352 set ui_comm_ctxm $ctxm
3354 # -- Diff Header
3356 proc trace_current_diff_path {varname args} {
3357 global current_diff_path diff_actions file_states
3358 if {$current_diff_path eq {}} {
3359 set s {}
3360 set f {}
3361 set p {}
3362 set o disabled
3363 } else {
3364 set p $current_diff_path
3365 set s [mapdesc [lindex $file_states($p) 0] $p]
3366 set f [mc "File:"]
3367 set p [escape_path $p]
3368 set o normal
3371 .vpane.lower.diff.header.status configure -text $s
3372 .vpane.lower.diff.header.file configure -text $f
3373 .vpane.lower.diff.header.path configure -text $p
3374 foreach w $diff_actions {
3375 uplevel #0 $w $o
3378 trace add variable current_diff_path write trace_current_diff_path
3380 gold_frame .vpane.lower.diff.header
3381 tlabel .vpane.lower.diff.header.status \
3382 -background gold \
3383 -foreground black \
3384 -width $max_status_desc \
3385 -anchor w \
3386 -justify left
3387 tlabel .vpane.lower.diff.header.file \
3388 -background gold \
3389 -foreground black \
3390 -anchor w \
3391 -justify left
3392 tlabel .vpane.lower.diff.header.path \
3393 -background gold \
3394 -foreground black \
3395 -anchor w \
3396 -justify left
3397 pack .vpane.lower.diff.header.status -side left
3398 pack .vpane.lower.diff.header.file -side left
3399 pack .vpane.lower.diff.header.path -fill x
3400 set ctxm .vpane.lower.diff.header.ctxm
3401 menu $ctxm -tearoff 0
3402 $ctxm add command \
3403 -label [mc Copy] \
3404 -command {
3405 clipboard clear
3406 clipboard append \
3407 -format STRING \
3408 -type STRING \
3409 -- $current_diff_path
3411 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3412 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3414 # -- Diff Body
3416 ${NS}::frame .vpane.lower.diff.body
3417 set ui_diff .vpane.lower.diff.body.t
3418 text $ui_diff -background white -foreground black \
3419 -borderwidth 0 \
3420 -width 80 -height 5 -wrap none \
3421 -font font_diff \
3422 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3423 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3424 -state disabled
3425 catch {$ui_diff configure -tabstyle wordprocessor}
3426 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3427 -command [list $ui_diff xview]
3428 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3429 -command [list $ui_diff yview]
3430 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3431 pack .vpane.lower.diff.body.sby -side right -fill y
3432 pack $ui_diff -side left -fill both -expand 1
3433 pack .vpane.lower.diff.header -side top -fill x
3434 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3436 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3437 $ui_diff tag configure clr4$n -background $c
3438 $ui_diff tag configure clri4$n -foreground $c
3439 $ui_diff tag configure clr3$n -foreground $c
3440 $ui_diff tag configure clri3$n -background $c
3442 $ui_diff tag configure clr1 -font font_diffbold
3443 $ui_diff tag configure clr4 -underline 1
3445 $ui_diff tag conf d_info -foreground blue -font font_diffbold
3447 $ui_diff tag conf d_cr -elide true
3448 $ui_diff tag conf d_@ -font font_diffbold
3449 $ui_diff tag conf d_+ -foreground {#00a000}
3450 $ui_diff tag conf d_- -foreground red
3452 $ui_diff tag conf d_++ -foreground {#00a000}
3453 $ui_diff tag conf d_-- -foreground red
3454 $ui_diff tag conf d_+s \
3455 -foreground {#00a000} \
3456 -background {#e2effa}
3457 $ui_diff tag conf d_-s \
3458 -foreground red \
3459 -background {#e2effa}
3460 $ui_diff tag conf d_s+ \
3461 -foreground {#00a000} \
3462 -background ivory1
3463 $ui_diff tag conf d_s- \
3464 -foreground red \
3465 -background ivory1
3467 $ui_diff tag conf d< \
3468 -foreground orange \
3469 -font font_diffbold
3470 $ui_diff tag conf d= \
3471 -foreground orange \
3472 -font font_diffbold
3473 $ui_diff tag conf d> \
3474 -foreground orange \
3475 -font font_diffbold
3477 $ui_diff tag raise sel
3479 # -- Diff Body Context Menu
3482 proc create_common_diff_popup {ctxm} {
3483 $ctxm add command \
3484 -label [mc Refresh] \
3485 -command reshow_diff
3486 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3487 $ctxm add command \
3488 -label [mc Copy] \
3489 -command {tk_textCopy $ui_diff}
3490 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3491 $ctxm add command \
3492 -label [mc "Select All"] \
3493 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3494 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3495 $ctxm add command \
3496 -label [mc "Copy All"] \
3497 -command {
3498 $ui_diff tag add sel 0.0 end
3499 tk_textCopy $ui_diff
3500 $ui_diff tag remove sel 0.0 end
3502 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3503 $ctxm add separator
3504 $ctxm add command \
3505 -label [mc "Decrease Font Size"] \
3506 -command {incr_font_size font_diff -1}
3507 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3508 $ctxm add command \
3509 -label [mc "Increase Font Size"] \
3510 -command {incr_font_size font_diff 1}
3511 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3512 $ctxm add separator
3513 set emenu $ctxm.enc
3514 menu $emenu
3515 build_encoding_menu $emenu [list force_diff_encoding]
3516 $ctxm add cascade \
3517 -label [mc "Encoding"] \
3518 -menu $emenu
3519 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3520 $ctxm add separator
3521 $ctxm add command -label [mc "Options..."] \
3522 -command do_options
3525 set ctxm .vpane.lower.diff.body.ctxm
3526 menu $ctxm -tearoff 0
3527 $ctxm add command \
3528 -label [mc "Apply/Reverse Hunk"] \
3529 -command {apply_hunk $cursorX $cursorY}
3530 set ui_diff_applyhunk [$ctxm index last]
3531 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3532 $ctxm add command \
3533 -label [mc "Apply/Reverse Line"] \
3534 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3535 set ui_diff_applyline [$ctxm index last]
3536 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3537 $ctxm add separator
3538 $ctxm add command \
3539 -label [mc "Show Less Context"] \
3540 -command show_less_context
3541 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3542 $ctxm add command \
3543 -label [mc "Show More Context"] \
3544 -command show_more_context
3545 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3546 $ctxm add separator
3547 create_common_diff_popup $ctxm
3549 set ctxmmg .vpane.lower.diff.body.ctxmmg
3550 menu $ctxmmg -tearoff 0
3551 $ctxmmg add command \
3552 -label [mc "Run Merge Tool"] \
3553 -command {merge_resolve_tool}
3554 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3555 $ctxmmg add separator
3556 $ctxmmg add command \
3557 -label [mc "Use Remote Version"] \
3558 -command {merge_resolve_one 3}
3559 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3560 $ctxmmg add command \
3561 -label [mc "Use Local Version"] \
3562 -command {merge_resolve_one 2}
3563 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3564 $ctxmmg add command \
3565 -label [mc "Revert To Base"] \
3566 -command {merge_resolve_one 1}
3567 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3568 $ctxmmg add separator
3569 $ctxmmg add command \
3570 -label [mc "Show Less Context"] \
3571 -command show_less_context
3572 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3573 $ctxmmg add command \
3574 -label [mc "Show More Context"] \
3575 -command show_more_context
3576 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3577 $ctxmmg add separator
3578 create_common_diff_popup $ctxmmg
3580 set ctxmsm .vpane.lower.diff.body.ctxmsm
3581 menu $ctxmsm -tearoff 0
3582 $ctxmsm add command \
3583 -label [mc "Visualize These Changes In The Submodule"] \
3584 -command {do_gitk -- true}
3585 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3586 $ctxmsm add command \
3587 -label [mc "Visualize Current Branch History In The Submodule"] \
3588 -command {do_gitk {} true}
3589 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3590 $ctxmsm add command \
3591 -label [mc "Visualize All Branch History In The Submodule"] \
3592 -command {do_gitk --all true}
3593 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3594 $ctxmsm add separator
3595 $ctxmsm add command \
3596 -label [mc "Start git gui In The Submodule"] \
3597 -command {do_git_gui}
3598 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3599 $ctxmsm add separator
3600 create_common_diff_popup $ctxmsm
3602 proc has_textconv {path} {
3603 if {[is_config_false gui.textconv]} {
3604 return 0
3606 set filter [gitattr $path diff set]
3607 set textconv [get_config [join [list diff $filter textconv] .]]
3608 if {$filter ne {set} && $textconv ne {}} {
3609 return 1
3610 } else {
3611 return 0
3615 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3616 global current_diff_path file_states
3617 set ::cursorX $x
3618 set ::cursorY $y
3619 if {[info exists file_states($current_diff_path)]} {
3620 set state [lindex $file_states($current_diff_path) 0]
3621 } else {
3622 set state {__}
3624 if {[string first {U} $state] >= 0} {
3625 tk_popup $ctxmmg $X $Y
3626 } elseif {$::is_submodule_diff} {
3627 tk_popup $ctxmsm $X $Y
3628 } else {
3629 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3630 if {$::ui_index eq $::current_diff_side} {
3631 set l [mc "Unstage Hunk From Commit"]
3632 if {$has_range} {
3633 set t [mc "Unstage Lines From Commit"]
3634 } else {
3635 set t [mc "Unstage Line From Commit"]
3637 } else {
3638 set l [mc "Stage Hunk For Commit"]
3639 if {$has_range} {
3640 set t [mc "Stage Lines For Commit"]
3641 } else {
3642 set t [mc "Stage Line For Commit"]
3645 if {$::is_3way_diff
3646 || $current_diff_path eq {}
3647 || {__} eq $state
3648 || {_O} eq $state
3649 || [string match {?T} $state]
3650 || [string match {T?} $state]
3651 || [has_textconv $current_diff_path]} {
3652 set s disabled
3653 } else {
3654 set s normal
3656 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3657 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3658 tk_popup $ctxm $X $Y
3661 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3663 # -- Status Bar
3665 set main_status [::status_bar::new .status]
3666 pack .status -anchor w -side bottom -fill x
3667 $main_status show [mc "Initializing..."]
3669 # -- Load geometry
3671 proc on_ttk_pane_mapped {w pane pos} {
3672 bind $w <Map> {}
3673 after 0 [list after idle [list $w sashpos $pane $pos]]
3675 proc on_tk_pane_mapped {w pane x y} {
3676 bind $w <Map> {}
3677 after 0 [list after idle [list $w sash place $pane $x $y]]
3679 proc on_application_mapped {} {
3680 global repo_config use_ttk
3681 bind . <Map> {}
3682 set gm $repo_config(gui.geometry)
3683 if {$use_ttk} {
3684 bind .vpane <Map> \
3685 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3686 bind .vpane.files <Map> \
3687 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3688 } else {
3689 bind .vpane <Map> \
3690 [list on_tk_pane_mapped %W 0 \
3691 [lindex $gm 1] \
3692 [lindex [.vpane sash coord 0] 1]]
3693 bind .vpane.files <Map> \
3694 [list on_tk_pane_mapped %W 0 \
3695 [lindex [.vpane.files sash coord 0] 0] \
3696 [lindex $gm 2]]
3698 wm geometry . [lindex $gm 0]
3700 if {[info exists repo_config(gui.geometry)]} {
3701 bind . <Map> [list on_application_mapped]
3702 wm geometry . [lindex $repo_config(gui.geometry) 0]
3705 # -- Load window state
3707 if {[info exists repo_config(gui.wmstate)]} {
3708 catch {wm state . $repo_config(gui.wmstate)}
3711 # -- Key Bindings
3713 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3714 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3715 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3716 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3717 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3718 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3719 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3720 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3721 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3722 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3723 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3724 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3725 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3726 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3727 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3728 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3729 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3730 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3731 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3732 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3733 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3734 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3736 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3737 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3738 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3739 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3740 bind $ui_diff <$M1B-Key-v> {break}
3741 bind $ui_diff <$M1B-Key-V> {break}
3742 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3743 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3744 bind $ui_diff <$M1B-Key-j> {do_revert_selection;break}
3745 bind $ui_diff <$M1B-Key-J> {do_revert_selection;break}
3746 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3747 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3748 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3749 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3750 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3751 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3752 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3753 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3754 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3755 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3756 bind $ui_diff <Button-1> {focus %W}
3758 if {[is_enabled branch]} {
3759 bind . <$M1B-Key-n> branch_create::dialog
3760 bind . <$M1B-Key-N> branch_create::dialog
3761 bind . <$M1B-Key-o> branch_checkout::dialog
3762 bind . <$M1B-Key-O> branch_checkout::dialog
3763 bind . <$M1B-Key-m> merge::dialog
3764 bind . <$M1B-Key-M> merge::dialog
3766 if {[is_enabled transport]} {
3767 bind . <$M1B-Key-p> do_push_anywhere
3768 bind . <$M1B-Key-P> do_push_anywhere
3771 bind . <Key-F5> ui_do_rescan
3772 bind . <$M1B-Key-r> ui_do_rescan
3773 bind . <$M1B-Key-R> ui_do_rescan
3774 bind . <$M1B-Key-s> do_signoff
3775 bind . <$M1B-Key-S> do_signoff
3776 bind . <$M1B-Key-t> do_add_selection
3777 bind . <$M1B-Key-T> do_add_selection
3778 bind . <$M1B-Key-u> do_unstage_selection
3779 bind . <$M1B-Key-U> do_unstage_selection
3780 bind . <$M1B-Key-j> do_revert_selection
3781 bind . <$M1B-Key-J> do_revert_selection
3782 bind . <$M1B-Key-i> do_add_all
3783 bind . <$M1B-Key-I> do_add_all
3784 bind . <$M1B-Key-minus> {show_less_context;break}
3785 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3786 bind . <$M1B-Key-equal> {show_more_context;break}
3787 bind . <$M1B-Key-plus> {show_more_context;break}
3788 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3789 bind . <$M1B-Key-Return> do_commit
3790 foreach i [list $ui_index $ui_workdir] {
3791 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3792 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3793 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3795 unset i
3797 set file_lists($ui_index) [list]
3798 set file_lists($ui_workdir) [list]
3800 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3801 focus -force $ui_comm
3803 # -- Warn the user about environmental problems. Cygwin's Tcl
3804 # does *not* pass its env array onto any processes it spawns.
3805 # This means that git processes get none of our environment.
3807 if {[is_Cygwin]} {
3808 set ignored_env 0
3809 set suggest_user {}
3810 set msg [mc "Possible environment issues exist.
3812 The following environment variables are probably
3813 going to be ignored by any Git subprocess run
3814 by %s:
3816 " [appname]]
3817 foreach name [array names env] {
3818 switch -regexp -- $name {
3819 {^GIT_INDEX_FILE$} -
3820 {^GIT_OBJECT_DIRECTORY$} -
3821 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3822 {^GIT_DIFF_OPTS$} -
3823 {^GIT_EXTERNAL_DIFF$} -
3824 {^GIT_PAGER$} -
3825 {^GIT_TRACE$} -
3826 {^GIT_CONFIG$} -
3827 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3828 append msg " - $name\n"
3829 incr ignored_env
3831 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3832 append msg " - $name\n"
3833 incr ignored_env
3834 set suggest_user $name
3838 if {$ignored_env > 0} {
3839 append msg [mc "
3840 This is due to a known issue with the
3841 Tcl binary distributed by Cygwin."]
3843 if {$suggest_user ne {}} {
3844 append msg [mc "
3846 A good replacement for %s
3847 is placing values for the user.name and
3848 user.email settings into your personal
3849 ~/.gitconfig file.
3850 " $suggest_user]
3852 warn_popup $msg
3854 unset ignored_env msg suggest_user name
3857 # -- Only initialize complex UI if we are going to stay running.
3859 if {[is_enabled transport]} {
3860 load_all_remotes
3862 set n [.mbar.remote index end]
3863 populate_remotes_menu
3864 set n [expr {[.mbar.remote index end] - $n}]
3865 if {$n > 0} {
3866 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3867 .mbar.remote insert $n separator
3869 unset n
3872 if {[winfo exists $ui_comm]} {
3873 set GITGUI_BCK_exists [load_message GITGUI_BCK utf-8]
3875 # -- If both our backup and message files exist use the
3876 # newer of the two files to initialize the buffer.
3878 if {$GITGUI_BCK_exists} {
3879 set m [gitdir GITGUI_MSG]
3880 if {[file isfile $m]} {
3881 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3882 catch {file delete [gitdir GITGUI_MSG]}
3883 } else {
3884 $ui_comm delete 0.0 end
3885 $ui_comm edit reset
3886 $ui_comm edit modified false
3887 catch {file delete [gitdir GITGUI_BCK]}
3888 set GITGUI_BCK_exists 0
3891 unset m
3894 proc backup_commit_buffer {} {
3895 global ui_comm GITGUI_BCK_exists
3897 set m [$ui_comm edit modified]
3898 if {$m || $GITGUI_BCK_exists} {
3899 set msg [string trim [$ui_comm get 0.0 end]]
3900 regsub -all -line {[ \r\t]+$} $msg {} msg
3902 if {$msg eq {}} {
3903 if {$GITGUI_BCK_exists} {
3904 catch {file delete [gitdir GITGUI_BCK]}
3905 set GITGUI_BCK_exists 0
3907 } elseif {$m} {
3908 catch {
3909 set fd [open [gitdir GITGUI_BCK] w]
3910 fconfigure $fd -encoding utf-8
3911 puts -nonewline $fd $msg
3912 close $fd
3913 set GITGUI_BCK_exists 1
3917 $ui_comm edit modified false
3920 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3923 backup_commit_buffer
3925 # -- If the user has aspell available we can drive it
3926 # in pipe mode to spellcheck the commit message.
3928 set spell_cmd [list |]
3929 set spell_dict [get_config gui.spellingdictionary]
3930 lappend spell_cmd aspell
3931 if {$spell_dict ne {}} {
3932 lappend spell_cmd --master=$spell_dict
3934 lappend spell_cmd --mode=none
3935 lappend spell_cmd --encoding=utf-8
3936 lappend spell_cmd pipe
3937 if {$spell_dict eq {none}
3938 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3939 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3940 } else {
3941 set ui_comm_spell [spellcheck::init \
3942 $spell_fd \
3943 $ui_comm \
3944 $ui_comm_ctxm \
3947 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3950 lock_index begin-read
3951 if {![winfo ismapped .]} {
3952 wm deiconify .
3954 after 1 {
3955 if {[is_enabled initialamend]} {
3956 force_amend
3957 } else {
3958 do_rescan
3961 if {[is_enabled nocommitmsg]} {
3962 $ui_comm configure -state disabled -background gray
3965 if {[is_enabled multicommit] && ![is_config_false gui.gcwarning]} {
3966 after 1000 hint_gc
3968 if {[is_enabled retcode]} {
3969 bind . <Destroy> {+terminate_me %W}
3971 if {$picked && [is_config_true gui.autoexplore]} {
3972 do_explore
3975 # Local variables:
3976 # mode: tcl
3977 # indent-tabs-mode: t
3978 # tab-width: 4
3979 # End: