2 # Tcl ignores the next line -*- tcl -*- \
3 if test "z$*" = zversion \
4 ||
test "z$*" = z--version
; \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
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
]
41 -title "git-gui: fatal error" \
46 catch
{rename send
{}} ; # What an evil concept...
48 ######################################################################
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
]
66 set oguimsg
[file join $oguilib msgs
]
70 ######################################################################
72 ## enable verbose loading?
74 if {![catch
{set _verbose
$env(GITGUI_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
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
97 set cmk
[string first @@
$fmt]
99 return [string range
$fmt 0 [expr {$cmk - 1}]]
104 proc mc
{en_fmt args
} {
105 set fmt [_mc_trim
[::msgcat
::mc
$en_fmt]]
106 if {[catch
{set msg
[eval [list format
$fmt] $args]} err
]} {
107 set msg
[eval [list format
[_mc_trim
$en_fmt]] $args]
113 return [join $args {}]
116 ::msgcat
::mcload
$oguimsg
119 ######################################################################
123 set _appname
{Git Gui
}
132 set _shellpath
{@@SHELL_PATH@@
}
134 set _trace
[lsearch
-exact $argv --trace]
136 set argv
[lreplace
$argv $_trace $_trace]
143 global _shellpath env
144 if {[string match @@
* $_shellpath]} {
145 if {[info exists env
(SHELL
)]} {
164 return [eval [list
file join $_gitdir] $args]
167 proc gitexec
{args
} {
169 if {$_gitexec eq
{}} {
170 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
171 error
"Git not installed?\n\n$err"
174 set _gitexec
[exec cygpath \
179 set _gitexec
[file normalize
$_gitexec]
185 return [eval [list
file join $_gitexec] $args]
188 proc githtmldir
{args
} {
190 if {$_githtmldir eq
{}} {
191 if {[catch
{set _githtmldir
[git
--html-path]}]} {
192 # Git not installed or option not yet supported
196 set _githtmldir
[exec cygpath \
201 set _githtmldir
[file normalize
$_githtmldir]
207 return [eval [list
file join $_githtmldir] $args]
215 if {[tk windowingsystem
] eq
{aqua
}} {
222 if {$
::tcl_platform
(platform
) eq
{windows
}} {
230 if {$_iscygwin eq
{}} {
231 if {$
::tcl_platform
(platform
) eq
{windows
}} {
232 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
244 proc is_enabled
{option
} {
245 global enabled_options
246 if {[catch
{set on
$enabled_options($option)}]} {return 0}
250 proc enable_option
{option
} {
251 global enabled_options
252 set enabled_options
($option) 1
255 proc disable_option
{option
} {
256 global enabled_options
257 set enabled_options
($option) 0
260 ######################################################################
264 proc is_many_config
{name
} {
265 switch
-glob -- $name {
275 proc is_config_true
{name
} {
277 if {[catch
{set v
$repo_config($name)}]} {
279 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
286 proc is_config_false
{name
} {
288 if {[catch
{set v
$repo_config($name)}]} {
290 } elseif
{$v eq
{false
} ||
$v eq
{0} ||
$v eq
{no
}} {
297 proc get_config
{name
} {
299 if {[catch
{set v
$repo_config($name)}]} {
311 if {$_isbare eq
{}} {
313 set _bare
[git rev-parse
--is-bare-repository]
315 true
{ set _isbare
1 }
316 false
{ set _isbare
0}
320 if {[is_config_true core.bare
]
321 ||
($_gitworktree eq
{}
322 && [lindex
[file split $_gitdir] end
] ne
{.git
})} {
332 ######################################################################
336 proc _trace_exec
{cmd
} {
337 if {!$
::_trace
} return
343 if {[regexp
{[ \t\r\n'"$?*]} $v]} {
351 #'" fix poor old emacs font-lock mode
353 proc _git_cmd {name} {
356 if {[catch {set v $_git_cmd_path($name)}]} {
360 --exec-path { return [list $::_git $name] }
363 set p [gitexec git-$name$::_search_exe]
364 if {[file exists $p]} {
366 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
367 # Try to determine what sort of magic will make
368 # git-$name go and do its thing, because native
369 # Tcl on Windows doesn't know it.
371 set p [gitexec git-$name]
376 switch -glob -- [lindex $s 0] {
378 #!*perl { set i perl }
379 #!*python { set i python }
380 default { error "git-
$name is not supported
: $s" }
384 if {![info exists interp]} {
385 set interp [_which $i]
388 error "git-
$name requires
$i (not
in PATH
)"
390 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
392 # Assume it is builtin to git somehow and we
393 # aren't actually able to see a file for it.
395 set v [list $::_git $name]
397 set _git_cmd_path($name) $v
402 proc _which {what args} {
403 global env _search_exe _search_path
405 if {$_search_path eq {}} {
406 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
407 set _search_path [split [exec cygpath \
413 } elseif {[is_Windows]} {
414 set gitguidir [file dirname [info script]]
415 regsub -all ";" $gitguidir "\\;" gitguidir
416 set env(PATH) "$gitguidir;$env(PATH
)"
417 set _search_path [split $env(PATH) {;}]
420 set _search_path [split $env(PATH) :]
425 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
428 set suffix $_search_exe
431 foreach p $_search_path {
432 set p [file join $p $what$suffix]
433 if {[file exists $p]} {
434 return [file normalize $p]
440 proc _lappend_nice {cmd_var} {
444 if {![info exists _nice]} {
445 set _nice [_which nice]
446 if {[catch {exec $_nice git version}]} {
448 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
461 switch -- [lindex $args 0] {
472 set args [lrange $args 1 end]
475 set cmdp [_git_cmd [lindex $args 0]]
476 set args [lrange $args 1 end]
478 _trace_exec [concat $opt $cmdp $args]
479 set result [eval exec $opt $cmdp $args]
481 puts stderr "< $result"
486 proc _open_stdout_stderr {cmd} {
489 set fd [open [concat [list | ] $cmd] r]
491 if { [lindex $cmd end] eq {2>@1}
492 && $err eq {can not find channel named "1"}
494 # Older versions of Tcl 8.4 don't have this 2>@1 IO
495 # redirect operator. Fallback to |& cat for those.
496 # The command was not actually started, so its safe
497 # to try to start it a second time.
499 set fd [open [concat \
501 [lrange $cmd 0 end-1] \
508 fconfigure $fd -eofchar {}
512 proc git_read {args} {
516 switch -- [lindex $args 0] {
531 set args [lrange $args 1 end]
534 set cmdp [_git_cmd [lindex $args 0]]
535 set args [lrange $args 1 end]
537 return [_open_stdout_stderr [concat $opt $cmdp $args]]
540 proc git_write {args} {
544 switch -- [lindex $args 0] {
555 set args [lrange $args 1 end]
558 set cmdp [_git_cmd [lindex $args 0]]
559 set args [lrange $args 1 end]
561 _trace_exec [concat $opt $cmdp $args]
562 return [open [concat [list | ] $opt $cmdp $args] w]
565 proc githook_read {hook_name args} {
566 set pchook [gitdir hooks $hook_name]
569 # On Windows [file executable] might lie so we need to ask
570 # the shell if the hook is executable. Yes that's annoying.
574 if {![info exists interp]} {
575 set interp [_which sh]
578 error "hook execution requires sh
(not
in PATH
)"
581 set scr {if test -x "$1";then exec "$@
";fi}
582 set sh_c [list $interp -c $scr $interp $pchook]
583 return [_open_stdout_stderr [concat $sh_c $args]]
586 if {[file executable $pchook]} {
587 return [_open_stdout_stderr [concat [list $pchook] $args]]
593 proc kill_file_process {fd} {
594 set process [pid $fd]
598 # Use a Cygwin-specific flag to allow killing
599 # native Windows processes
600 exec kill -f $process
607 proc gitattr {path attr default} {
608 if {[catch {set r [git check-attr $attr -- $path]}]} {
611 set r [join [lrange [split $r :] 2 end] :]
614 if {$r eq {unspecified}} {
621 regsub -all ' $value "'\\''" value
625 proc load_current_branch {} {
626 global current_branch is_detached
628 set fd [open [gitdir HEAD] r]
629 if {[gets $fd ref] < 1} {
634 set pfx {ref: refs/heads/}
635 set len [string length $pfx]
636 if {[string equal -length $len $pfx $ref]} {
637 # We're on a branch. It might not exist. But
638 # HEAD looks good enough to be a branch.
640 set current_branch
[string range
$ref $len end
]
643 # Assume this is a detached head.
645 set current_branch HEAD
650 auto_load tk_optionMenu
651 rename tk_optionMenu real__tkOptionMenu
652 proc tk_optionMenu
{w varName args
} {
653 set m
[eval real__tkOptionMenu
$w $varName $args]
654 $m configure
-font font_ui
655 $w configure
-font font_ui
659 proc rmsel_tag
{text
} {
661 -background [$text cget
-background] \
662 -foreground [$text cget
-foreground] \
664 $text tag conf in_sel
-background lightgray
665 bind $text <Motion
> break
671 bind .
<Visibility
> {
672 bind .
<Visibility
> {}
677 wm iconbitmap .
-default $oguilib/git-gui.ico
678 set ::tk
::AlwaysShowSelection
1
679 bind .
<Control-F2
> {console show
}
681 # Spoof an X11 display for SSH
682 if {![info exists env
(DISPLAY
)]} {
683 set env
(DISPLAY
) :9999
687 image create photo gitlogo
-width 16 -height 16
689 gitlogo put
#33CC33 -to 7 0 9 2
690 gitlogo put
#33CC33 -to 4 2 12 4
691 gitlogo put
#33CC33 -to 7 4 9 6
692 gitlogo put
#CC3333 -to 4 6 12 8
693 gitlogo put gray26
-to 4 9 6 10
694 gitlogo put gray26
-to 3 10 6 12
695 gitlogo put gray26
-to 8 9 13 11
696 gitlogo put gray26
-to 8 11 10 12
697 gitlogo put gray26
-to 11 11 13 14
698 gitlogo put gray26
-to 3 12 5 14
699 gitlogo put gray26
-to 5 13
700 gitlogo put gray26
-to 10 13
701 gitlogo put gray26
-to 4 14 12 15
702 gitlogo put gray26
-to 5 15 11 16
705 wm iconphoto .
-default gitlogo
709 ######################################################################
715 if {[lsearch
-exact [font names
] TkDefaultFont
] != -1} {
716 eval [linsert
[font actual TkDefaultFont
] 0 font configure font_ui
]
717 eval [linsert
[font actual TkFixedFont
] 0 font create font_diff
]
719 font create font_diff
-family Courier
-size 10
722 eval font configure font_ui
[font actual
[.dummy cget
-font]]
727 font create font_uiitalic
728 font create font_uibold
729 font create font_diffbold
730 font create font_diffitalic
732 foreach class
{Button Checkbutton Entry Label
733 Labelframe Listbox Message
734 Radiobutton Spinbox Text
} {
735 option add
*$class.font font_ui
738 option add
*Menu.font font_ui
739 option add
*Entry.borderWidth
1 startupFile
740 option add
*Entry.relief sunken startupFile
741 option add
*RadioButton.anchor w startupFile
745 if {[is_Windows
] ||
[is_MacOSX
]} {
746 option add
*Menu.tearOff
0
757 proc bind_button3
{w cmd
} {
758 bind $w <Any-Button-3
> $cmd
760 # Mac OS X sends Button-2 on right click through three-button mouse,
761 # or through trackpad right-clicking (two-finger touch + click).
762 bind $w <Any-Button-2
> $cmd
763 bind $w <Control-Button-1
> $cmd
767 proc apply_config
{} {
768 global repo_config font_descs
770 foreach option
$font_descs {
771 set name
[lindex
$option 0]
772 set font
[lindex
$option 1]
775 foreach
{cn cv
} $repo_config(gui.
$name) {
776 if {$cn eq
{-weight}} {
779 font configure
$font $cn $cv
782 font configure
$font -weight normal
785 error_popup
[strcat
[mc
"Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
787 foreach
{cn cv
} [font configure
$font] {
788 font configure
${font}bold
$cn $cv
789 font configure
${font}italic
$cn $cv
791 font configure
${font}bold
-weight bold
792 font configure
${font}italic
-slant italic
798 if {$repo_config(gui.usettk
)} {
799 set use_ttk
[package vsatisfies
[package provide Tk
] 8.5]
802 bind [winfo class .
] <<ThemeChanged>> [list InitTheme]
808 set default_config(branch.autosetupmerge) true
809 set default_config(merge.tool) {}
810 set default_config(mergetool.keepbackup) true
811 set default_config(merge.diffstat) true
812 set default_config(merge.summary) false
813 set default_config(merge.verbosity) 2
814 set default_config(user.name) {}
815 set default_config(user.email) {}
817 set default_config(gui.encoding) [encoding system]
818 set default_config(gui.matchtrackingbranch) false
819 set default_config(gui.textconv) true
820 set default_config(gui.pruneduringfetch) false
821 set default_config(gui.trustmtime) false
822 set default_config(gui.fastcopyblame) false
823 set default_config(gui.copyblamethreshold) 40
824 set default_config(gui.blamehistoryctx) 7
825 set default_config(gui.diffcontext) 5
826 set default_config(gui.commitmsgwidth) 75
827 set default_config(gui.newbranchtemplate) {}
828 set default_config(gui.spellingdictionary) {}
829 set default_config(gui.fontui) [font configure font_ui]
830 set default_config(gui.fontdiff) [font configure font_diff]
831 # TODO: this option should be added to the git-config documentation
832 set default_config(gui.maxfilesdisplayed) 5000
833 set default_config(gui.usettk) 1
835 {fontui font_ui {mc "Main Font"}}
836 {fontdiff font_diff {mc "Diff/Console Font"}}
839 ######################################################################
843 set _git [_which git]
845 catch {wm withdraw .}
849 -title [mc "git-gui: fatal error"] \
850 -message [mc "Cannot find git in PATH."]
854 ######################################################################
858 if {[catch {set _git_version [git --version]} err]} {
859 catch {wm withdraw .}
863 -title [mc "git-gui: fatal error"] \
864 -message "Cannot determine Git version:
868 [appname] requires Git 1.5.0 or later."
871 if {![regsub {^git version } $_git_version {} _git_version]} {
872 catch {wm withdraw .}
876 -title [mc "git-gui: fatal error"] \
877 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
881 proc get_trimmed_version {s} {
883 foreach x [split $s -._] {
884 if {[string is integer -strict $x]} {
892 set _real_git_version $_git_version
893 set _git_version [get_trimmed_version $_git_version]
895 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
896 catch {wm withdraw .}
901 -title "[appname]: warning" \
902 -message [mc "Git version cannot be determined.
904 %s claims it is version '%s'.
906 %s requires at least Git 1.5.0 or later.
908 Assume '%s' is version 1.5.0?
909 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
910 set _git_version 1.5.0
915 unset _real_git_version
917 proc git-version {args} {
920 switch [llength $args] {
926 set op [lindex $args 0]
927 set vr [lindex $args 1]
928 set cm [package vcompare $_git_version $vr]
929 return [expr $cm $op 0]
933 set type [lindex $args 0]
934 set name [lindex $args 1]
935 set parm [lindex $args 2]
936 set body [lindex $args 3]
938 if {($type ne {proc} && $type ne {method})} {
939 error "Invalid arguments to git-version"
941 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
942 error "Last arm of $type $name must be default"
945 foreach {op vr cb} [lrange $body 0 end-2] {
946 if {[git-version $op $vr]} {
947 return [uplevel [list $type $name $parm $cb]]
951 return [uplevel [list $type $name $parm [lindex $body end]]]
955 error "git-version >= x"
961 if {[git-version < 1.5]} {
962 catch {wm withdraw .}
966 -title [mc "git-gui: fatal error"] \
967 -message "[appname] requires Git 1.5.0 or later.
969 You are using [git-version]:
975 ######################################################################
977 ## configure our library
979 set idx [file join $oguilib tclIndex]
980 if {[catch {set fd [open $idx r]} err]} {
981 catch {wm withdraw .}
985 -title [mc "git-gui: fatal error"] \
989 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
991 while {[gets $fd n] >= 0} {
992 if {$n ne {} && ![string match #* $n]} {
1004 if {[lsearch -exact $loaded $p] >= 0} continue
1005 source [file join $oguilib $p]
1010 set auto_path [concat [list $oguilib] $auto_path]
1012 unset -nocomplain idx fd
1014 ######################################################################
1016 ## config file parsing
1018 git-version proc _parse_config {arr_name args} {
1025 [list git_read config] \
1027 [list --null --list]]
1028 fconfigure $fd_rc -translation binary
1029 set buf [read $fd_rc]
1032 foreach line [split $buf "\0"] {
1033 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1034 if {[is_many_config $name]} {
1035 lappend arr($name) $value
1037 set arr($name) $value
1046 set fd_rc [eval [list git_read config --list] $args]
1047 while {[gets $fd_rc line] >= 0} {
1048 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1049 if {[is_many_config $name]} {
1050 lappend arr($name) $value
1052 set arr($name) $value
1061 proc load_config {include_global} {
1062 global repo_config global_config system_config default_config
1064 if {$include_global} {
1065 _parse_config system_config --system
1066 _parse_config global_config --global
1068 _parse_config repo_config
1070 foreach name [array names default_config] {
1071 if {[catch {set v $system_config($name)}]} {
1072 set system_config($name) $default_config($name)
1075 foreach name [array names system_config] {
1076 if {[catch {set v $global_config($name)}]} {
1077 set global_config($name) $system_config($name)
1079 if {[catch {set v $repo_config($name)}]} {
1080 set repo_config($name) $system_config($name)
1085 ######################################################################
1087 ## feature option selection
1089 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1094 if {$subcommand eq {gui.sh}} {
1097 if {$subcommand eq {gui} && [llength $argv] > 0} {
1098 set subcommand [lindex $argv 0]
1099 set argv [lrange $argv 1 end]
1102 enable_option multicommit
1103 enable_option branch
1104 enable_option transport
1107 switch -- $subcommand {
1112 disable_option multicommit
1113 disable_option branch
1114 disable_option transport
1117 enable_option singlecommit
1118 enable_option retcode
1120 disable_option multicommit
1121 disable_option branch
1122 disable_option transport
1124 while {[llength $argv] > 0} {
1125 set a [lindex $argv 0]
1128 enable_option initialamend
1131 enable_option nocommit
1132 enable_option nocommitmsg
1135 disable_option nocommitmsg
1142 set argv [lrange $argv 1 end]
1147 ######################################################################
1149 ## execution environment
1151 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1153 # Suggest our implementation of askpass, if none is set
1154 if {![info exists env(SSH_ASKPASS)]} {
1155 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1158 ######################################################################
1164 set _gitdir $env(GIT_DIR)
1168 # beware that from the .git dir this sets _gitdir to .
1169 # and _prefix to the empty string
1170 set _gitdir [git rev-parse --git-dir]
1171 set _prefix [git rev-parse --show-prefix]
1175 choose_repository::pick
1179 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1180 # run from the .git dir itself) lest the routines to find the worktree
1182 if {$_gitdir eq "."} {
1186 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1187 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1189 if {![file isdirectory $_gitdir]} {
1190 catch {wm withdraw .}
1191 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1194 # _gitdir exists, so try loading the config
1198 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1199 if {[package vsatisfies $_git_version 1.7.0]} {
1200 set _gitworktree [git rev-parse --show-toplevel]
1202 # try to set work tree from environment, core.worktree or use
1203 # cdup to obtain a relative path to the top of the worktree. If
1204 # run from the top, the ./ prefix ensures normalize expands pwd.
1205 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1206 set _gitworktree [get_config core.worktree]
1207 if {$_gitworktree eq ""} {
1208 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1213 if {$_prefix ne {}} {
1214 if {$_gitworktree eq {}} {
1215 regsub -all {[^/]+/} $_prefix ../ cdup
1217 set cdup $_gitworktree
1219 if {[catch {cd $cdup} err]} {
1220 catch {wm withdraw .}
1221 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1224 set _gitworktree [pwd]
1226 } elseif {![is_enabled bare]} {
1228 catch {wm withdraw .}
1229 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1232 if {$_gitworktree eq {}} {
1233 set _gitworktree [file dirname $_gitdir]
1235 if {[catch {cd $_gitworktree} err]} {
1236 catch {wm withdraw .}
1237 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1240 set _gitworktree [pwd]
1242 set _reponame [file split [file normalize $_gitdir]]
1243 if {[lindex $_reponame end] eq {.git}} {
1244 set _reponame [lindex $_reponame end-1]
1246 set _reponame [lindex $_reponame end]
1249 ######################################################################
1253 set current_diff_path {}
1254 set current_diff_side {}
1255 set diff_actions [list]
1259 set MERGE_HEAD [list]
1262 set current_branch {}
1264 set current_diff_path {}
1266 set is_submodule_diff 0
1267 set is_conflict_diff 0
1268 set selected_commit_type new
1269 set diff_empty_count 0
1271 set nullid "0000000000000000000000000000000000000000"
1272 set nullid2 "0000000000000000000000000000000000000001"
1274 ######################################################################
1282 set disable_on_lock [list]
1283 set index_lock_type none
1285 proc lock_index {type} {
1286 global index_lock_type disable_on_lock
1288 if {$index_lock_type eq {none}} {
1289 set index_lock_type $type
1290 foreach w $disable_on_lock {
1291 uplevel #0 $w disabled
1294 } elseif {$index_lock_type eq "begin-$type"} {
1295 set index_lock_type $type
1301 proc unlock_index {} {
1302 global index_lock_type disable_on_lock
1304 set index_lock_type none
1305 foreach w $disable_on_lock {
1306 uplevel #0 $w normal
1310 ######################################################################
1314 proc repository_state {ctvar hdvar mhvar} {
1315 global current_branch
1316 upvar $ctvar ct $hdvar hd $mhvar mh
1321 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1327 set merge_head [gitdir MERGE_HEAD]
1328 if {[file exists $merge_head]} {
1330 set fd_mh [open $merge_head r]
1331 while {[gets $fd_mh line] >= 0} {
1342 global PARENT empty_tree
1344 set p [lindex $PARENT 0]
1348 if {$empty_tree eq {}} {
1349 set empty_tree [git mktree << {}]
1354 proc force_amend {} {
1355 global selected_commit_type
1356 global HEAD PARENT MERGE_HEAD commit_type
1358 repository_state newType newHEAD newMERGE_HEAD
1361 set MERGE_HEAD $newMERGE_HEAD
1362 set commit_type $newType
1364 set selected_commit_type amend
1365 do_select_commit_type
1368 proc rescan {after {honor_trustmtime 1}} {
1369 global HEAD PARENT MERGE_HEAD commit_type
1370 global ui_index ui_workdir ui_comm
1371 global rescan_active file_states
1374 if {$rescan_active > 0 || ![lock_index read]} return
1376 repository_state newType newHEAD newMERGE_HEAD
1377 if {[string match amend* $commit_type]
1378 && $newType eq {normal}
1379 && $newHEAD eq $HEAD} {
1383 set MERGE_HEAD $newMERGE_HEAD
1384 set commit_type $newType
1387 array unset file_states
1389 if {!$::GITGUI_BCK_exists &&
1390 (![$ui_comm edit modified]
1391 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1392 if {[string match amend* $commit_type]} {
1393 } elseif {[load_message GITGUI_MSG]} {
1394 } elseif {[run_prepare_commit_msg_hook]} {
1395 } elseif {[load_message MERGE_MSG]} {
1396 } elseif {[load_message SQUASH_MSG]} {
1399 $ui_comm edit modified false
1402 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1403 rescan_stage2 {} $after
1406 ui_status [mc "Refreshing file status..."]
1407 set fd_rf [git_read update-index \
1413 fconfigure $fd_rf -blocking 0 -translation binary
1414 fileevent $fd_rf readable \
1415 [list rescan_stage2 $fd_rf $after]
1420 set is_git_info_exclude {}
1421 proc have_info_exclude {} {
1422 global is_git_info_exclude
1424 if {$is_git_info_exclude eq {}} {
1425 if {[catch {exec test -f [gitdir info exclude]}]} {
1426 set is_git_info_exclude 0
1428 set is_git_info_exclude 1
1431 return $is_git_info_exclude
1434 proc have_info_exclude {} {
1435 return [file readable [gitdir info exclude]]
1439 proc rescan_stage2 {fd after} {
1440 global rescan_active buf_rdi buf_rdf buf_rlo
1444 if {![eof $fd]} return
1448 set ls_others [list --exclude-per-directory=.gitignore]
1449 if {[have_info_exclude]} {
1450 lappend ls_others "--exclude-from=[gitdir info exclude]"
1452 set user_exclude [get_config core.excludesfile]
1453 if {$user_exclude ne {} && [file readable $user_exclude]} {
1454 lappend ls_others "--exclude-from=$user_exclude"
1462 ui_status [mc "Scanning for modified files ..."]
1463 set fd_di [git_read diff-index --cached -z [PARENT]]
1464 set fd_df [git_read diff-files -z]
1465 set fd_lo [eval git_read ls-files --others -z $ls_others]
1467 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1468 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1469 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1470 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1471 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1472 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1475 proc load_message {file} {
1478 set f [gitdir $file]
1479 if {[file isfile $f]} {
1480 if {[catch {set fd [open $f r]}]} {
1483 fconfigure $fd -eofchar {}
1484 set content [string trim [read $fd]]
1486 regsub -all -line {[ \r\t]+$} $content {} content
1487 $ui_comm delete 0.0 end
1488 $ui_comm insert end $content
1494 proc run_prepare_commit_msg_hook {} {
1497 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1498 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1499 # empty file but existant file.
1501 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1503 if {[file isfile [gitdir MERGE_MSG]]} {
1504 set pcm_source "merge"
1505 set fd_mm [open [gitdir MERGE_MSG] r]
1506 puts -nonewline $fd_pcm [read $fd_mm]
1508 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1509 set pcm_source "squash"
1510 set fd_sm [open [gitdir SQUASH_MSG] r]
1511 puts -nonewline $fd_pcm [read $fd_sm]
1519 set fd_ph [githook_read prepare-commit-msg \
1520 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1522 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1526 ui_status [mc "Calling prepare-commit-msg hook..."]
1529 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1530 fileevent $fd_ph readable \
1531 [list prepare_commit_msg_hook_wait $fd_ph]
1536 proc prepare_commit_msg_hook_wait {fd_ph} {
1539 append pch_error [read $fd_ph]
1540 fconfigure $fd_ph -blocking 1
1542 if {[catch {close $fd_ph}]} {
1543 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1544 hook_failed_popup prepare-commit-msg $pch_error
1545 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1548 load_message PREPARE_COMMIT_MSG
1551 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1554 fconfigure $fd_ph -blocking 0
1555 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1558 proc read_diff_index {fd after} {
1561 append buf_rdi [read $fd]
1563 set n [string length $buf_rdi]
1565 set z1 [string first "\0" $buf_rdi $c]
1566 if {$z1 == -1} break
1568 set z2 [string first "\0" $buf_rdi $z1]
1569 if {$z2 == -1} break
1572 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1573 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1575 [encoding convertfrom $p] \
1577 [list [lindex $i 0] [lindex $i 2]] \
1583 set buf_rdi [string range $buf_rdi $c end]
1588 rescan_done $fd buf_rdi $after
1591 proc read_diff_files {fd after} {
1594 append buf_rdf [read $fd]
1596 set n [string length $buf_rdf]
1598 set z1 [string first "\0" $buf_rdf $c]
1599 if {$z1 == -1} break
1601 set z2 [string first "\0" $buf_rdf $z1]
1602 if {$z2 == -1} break
1605 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1606 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1608 [encoding convertfrom $p] \
1611 [list [lindex $i 0] [lindex $i 2]]
1616 set buf_rdf [string range $buf_rdf $c end]
1621 rescan_done $fd buf_rdf $after
1624 proc read_ls_others {fd after} {
1627 append buf_rlo [read $fd]
1628 set pck [split $buf_rlo "\0"]
1629 set buf_rlo [lindex $pck end]
1630 foreach p [lrange $pck 0 end-1] {
1631 set p [encoding convertfrom $p]
1632 if {[string index $p end] eq {/}} {
1633 set p [string range $p 0 end-1]
1637 rescan_done $fd buf_rlo $after
1640 proc rescan_done {fd buf after} {
1641 global rescan_active current_diff_path
1642 global file_states repo_config
1645 if {![eof $fd]} return
1648 if {[incr rescan_active -1] > 0} return
1653 if {$current_diff_path ne {}} { reshow_diff $after }
1654 if {$current_diff_path eq {}} { select_first_diff $after }
1657 proc prune_selection {} {
1658 global file_states selected_paths
1660 foreach path [array names selected_paths] {
1661 if {[catch {set still_here $file_states($path)}]} {
1662 unset selected_paths($path)
1667 ######################################################################
1671 proc mapicon {w state path} {
1674 if {[catch {set r $all_icons($state$w)}]} {
1675 puts "error: no icon for $w state={$state} $path"
1681 proc mapdesc {state path} {
1684 if {[catch {set r $all_descs($state)}]} {
1685 puts "error: no desc for state={$state} $path"
1691 proc ui_status {msg} {
1693 if {[info exists main_status]} {
1694 $main_status show $msg
1698 proc ui_ready {{test {}}} {
1700 if {[info exists main_status]} {
1701 $main_status show [mc "Ready."] $test
1705 proc escape_path {path} {
1706 regsub -all {\\} $path "\\\\" path
1707 regsub -all "\n" $path "\\n" path
1711 proc short_path {path} {
1712 return [escape_path [lindex [file split $path] end]]
1716 set null_sha1 [string repeat 0 40]
1718 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1719 global file_states next_icon_id null_sha1
1721 set s0 [string index $new_state 0]
1722 set s1 [string index $new_state 1]
1724 if {[catch {set info $file_states($path)}]} {
1726 set icon n[incr next_icon_id]
1728 set state [lindex $info 0]
1729 set icon [lindex $info 1]
1730 if {$head_info eq {}} {set head_info [lindex $info 2]}
1731 if {$index_info eq {}} {set index_info [lindex $info 3]}
1734 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1735 elseif {$s0 eq {_}} {set s0 _}
1737 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1738 elseif {$s1 eq {_}} {set s1 _}
1740 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1741 set head_info [list 0 $null_sha1]
1742 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1743 && $head_info eq {}} {
1744 set head_info $index_info
1745 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1746 set index_info $head_info
1750 set file_states($path) [list $s0$s1 $icon \
1751 $head_info $index_info \
1756 proc display_file_helper {w path icon_name old_m new_m} {
1759 if {$new_m eq {_}} {
1760 set lno [lsearch -sorted -exact $file_lists($w) $path]
1762 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1764 $w conf -state normal
1765 $w delete $lno.0 [expr {$lno + 1}].0
1766 $w conf -state disabled
1768 } elseif {$old_m eq {_} && $new_m ne {_}} {
1769 lappend file_lists($w) $path
1770 set file_lists($w) [lsort -unique $file_lists($w)]
1771 set lno [lsearch -sorted -exact $file_lists($w) $path]
1773 $w conf -state normal
1774 $w image create $lno.0 \
1775 -align center -padx 5 -pady 1 \
1777 -image [mapicon $w $new_m $path]
1778 $w insert $lno.1 "[escape_path $path]\n"
1779 $w conf -state disabled
1780 } elseif {$old_m ne $new_m} {
1781 $w conf -state normal
1782 $w image conf $icon_name -image [mapicon $w $new_m $path]
1783 $w conf -state disabled
1787 proc display_file {path state} {
1788 global file_states selected_paths
1789 global ui_index ui_workdir
1791 set old_m [merge_state $path $state]
1792 set s $file_states($path)
1793 set new_m [lindex $s 0]
1794 set icon_name [lindex $s 1]
1796 set o [string index $old_m 0]
1797 set n [string index $new_m 0]
1804 display_file_helper $ui_index $path $icon_name $o $n
1806 if {[string index $old_m 0] eq {U}} {
1809 set o [string index $old_m 1]
1811 if {[string index $new_m 0] eq {U}} {
1814 set n [string index $new_m 1]
1816 display_file_helper $ui_workdir $path $icon_name $o $n
1818 if {$new_m eq {__}} {
1819 unset file_states($path)
1820 catch {unset selected_paths($path)}
1824 proc display_all_files_helper {w path icon_name m} {
1827 lappend file_lists($w) $path
1828 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1829 $w image create end \
1830 -align center -padx 5 -pady 1 \
1832 -image [mapicon $w $m $path]
1833 $w insert end "[escape_path $path]\n"
1837 proc display_all_files {} {
1838 global ui_index ui_workdir
1839 global file_states file_lists
1841 global files_warning
1843 $ui_index conf -state normal
1844 $ui_workdir conf -state normal
1846 $ui_index delete 0.0 end
1847 $ui_workdir delete 0.0 end
1850 set file_lists($ui_index) [list]
1851 set file_lists($ui_workdir) [list]
1853 set to_display [lsort [array names file_states]]
1854 set display_limit [get_config gui.maxfilesdisplayed]
1855 if {[llength $to_display] > $display_limit} {
1856 if {!$files_warning} {
1857 # do not repeatedly warn:
1859 info_popup [mc "Displaying only %s of %s files." \
1860 $display_limit [llength $to_display]]
1862 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1864 foreach path $to_display {
1865 set s $file_states($path)
1867 set icon_name [lindex $s 1]
1869 set s [string index $m 0]
1870 if {$s ne {U} && $s ne {_}} {
1871 display_all_files_helper $ui_index $path \
1875 if {[string index $m 0] eq {U}} {
1878 set s [string index $m 1]
1881 display_all_files_helper $ui_workdir $path \
1886 $ui_index conf -state disabled
1887 $ui_workdir conf -state disabled
1890 ######################################################################
1895 #define mask_width 14
1896 #define mask_height 15
1897 static unsigned char mask_bits[] = {
1898 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1899 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1900 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1903 image create bitmap file_plain -background white -foreground black -data {
1904 #define plain_width 14
1905 #define plain_height 15
1906 static unsigned char plain_bits[] = {
1907 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1908 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1909 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1910 } -maskdata $filemask
1912 image create bitmap file_mod -background white -foreground blue -data {
1913 #define mod_width 14
1914 #define mod_height 15
1915 static unsigned char mod_bits[] = {
1916 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1917 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1918 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1919 } -maskdata $filemask
1921 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1922 #define file_fulltick_width 14
1923 #define file_fulltick_height 15
1924 static unsigned char file_fulltick_bits[] = {
1925 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1926 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1927 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1928 } -maskdata $filemask
1930 image create bitmap file_question -background white -foreground black -data {
1931 #define file_question_width 14
1932 #define file_question_height 15
1933 static unsigned char file_question_bits[] = {
1934 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1935 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1936 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1937 } -maskdata $filemask
1939 image create bitmap file_removed -background white -foreground red -data {
1940 #define file_removed_width 14
1941 #define file_removed_height 15
1942 static unsigned char file_removed_bits[] = {
1943 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1944 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1945 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1946 } -maskdata $filemask
1948 image create bitmap file_merge -background white -foreground blue -data {
1949 #define file_merge_width 14
1950 #define file_merge_height 15
1951 static unsigned char file_merge_bits[] = {
1952 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1953 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1954 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1955 } -maskdata $filemask
1957 image create bitmap file_statechange -background white -foreground green -data {
1958 #define file_merge_width 14
1959 #define file_merge_height 15
1960 static unsigned char file_statechange_bits[] = {
1961 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
1962 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
1963 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1964 } -maskdata $filemask
1966 set ui_index .vpane.files.index.list
1967 set ui_workdir .vpane.files.workdir.list
1969 set all_icons(_$ui_index) file_plain
1970 set all_icons(A$ui_index) file_plain
1971 set all_icons(M$ui_index) file_fulltick
1972 set all_icons(D$ui_index) file_removed
1973 set all_icons(U$ui_index) file_merge
1974 set all_icons(T$ui_index) file_statechange
1976 set all_icons(_$ui_workdir) file_plain
1977 set all_icons(M$ui_workdir) file_mod
1978 set all_icons(D$ui_workdir) file_question
1979 set all_icons(U$ui_workdir) file_merge
1980 set all_icons(O$ui_workdir) file_plain
1981 set all_icons(T$ui_workdir) file_statechange
1983 set max_status_desc 0
1985 {__ {mc "Unmodified"}}
1987 {_M {mc "Modified, not staged"}}
1988 {M_ {mc "Staged for commit"}}
1989 {MM {mc "Portions staged for commit"}}
1990 {MD {mc "Staged for commit, missing"}}
1992 {_T {mc "File type changed, not staged"}}
1993 {T_ {mc "File type changed, staged"}}
1995 {_O {mc "Untracked, not staged"}}
1996 {A_ {mc "Staged for commit"}}
1997 {AM {mc "Portions staged for commit"}}
1998 {AD {mc "Staged for commit, missing"}}
2001 {D_ {mc "Staged for removal"}}
2002 {DO {mc "Staged for removal, still present"}}
2004 {_U {mc "Requires merge resolution"}}
2005 {U_ {mc "Requires merge resolution"}}
2006 {UU {mc "Requires merge resolution"}}
2007 {UM {mc "Requires merge resolution"}}
2008 {UD {mc "Requires merge resolution"}}
2009 {UT {mc "Requires merge resolution"}}
2011 set text [eval [lindex $i 1]]
2012 if {$max_status_desc < [string length $text]} {
2013 set max_status_desc [string length $text]
2015 set all_descs([lindex $i 0]) $text
2019 ######################################################################
2023 proc scrollbar2many {list mode args} {
2024 foreach w $list {eval $w $mode $args}
2027 proc many2scrollbar {list mode sb top bottom} {
2028 $sb set $top $bottom
2029 foreach w $list {$w $mode moveto $top}
2032 proc incr_font_size {font {amt 1}} {
2033 set sz [font configure $font -size]
2035 font configure $font -size $sz
2036 font configure ${font}bold -size $sz
2037 font configure ${font}italic -size $sz
2040 ######################################################################
2044 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2046 proc do_gitk {revs {is_submodule false}} {
2047 global current_diff_path file_states current_diff_side ui_index
2050 # -- Always start gitk through whatever we were loaded with. This
2051 # lets us bypass using shell process on Windows systems.
2053 set exe [_which gitk -script]
2054 set cmd [list [info nameofexecutable] $exe]
2056 error_popup [mc "Couldn't find gitk in PATH"]
2060 if {[info exists env(GIT_DIR)]} {
2061 set old_GIT_DIR $env(GIT_DIR)
2068 if {!$is_submodule} {
2072 set env(GIT_DIR) [file normalize [gitdir]]
2074 cd $current_diff_path
2075 if {$revs eq {--}} {
2076 set s $file_states($current_diff_path)
2079 switch -glob -- [lindex $s 0] {
2080 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2081 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2083 if {$current_diff_side eq $ui_index} {
2084 set old_sha1 [lindex [lindex $s 2] 1]
2085 set new_sha1 [lindex [lindex $s 3] 1]
2087 set old_sha1 [lindex [lindex $s 3] 1]
2091 set revs $old_sha1...$new_sha1
2093 if {[info exists env(GIT_DIR)]} {
2097 eval exec $cmd $revs "--" "--" &
2099 if {$old_GIT_DIR ne {}} {
2100 set env(GIT_DIR) $old_GIT_DIR
2104 ui_status $::starting_gitk_msg
2106 ui_ready $starting_gitk_msg
2111 proc do_git_gui {} {
2112 global current_diff_path
2114 # -- Always start git gui through whatever we were loaded with. This
2115 # lets us bypass using shell process on Windows systems.
2117 set exe [list [_which git]]
2119 error_popup [mc "Couldn't find git gui in PATH"]
2123 if {[info exists env(GIT_DIR)]} {
2124 set old_GIT_DIR $env(GIT_DIR)
2131 cd $current_diff_path
2133 eval exec $exe gui &
2135 if {$old_GIT_DIR ne {}} {
2136 set env(GIT_DIR) $old_GIT_DIR
2140 ui_status $::starting_gitk_msg
2142 ui_ready $starting_gitk_msg
2147 proc do_explore {} {
2150 if {[is_Cygwin] || [is_Windows]} {
2151 set explorer "explorer.exe"
2152 } elseif {[is_MacOSX]} {
2155 # freedesktop.org-conforming system is our best shot
2156 set explorer "xdg-open"
2158 eval exec $explorer [list [file nativename $_gitworktree]] &
2164 proc terminate_me {win} {
2166 if {$win ne {.}} return
2170 proc do_quit {{rc {1}}} {
2171 global ui_comm is_quitting repo_config commit_type
2172 global GITGUI_BCK_exists GITGUI_BCK_i
2173 global ui_comm_spell
2174 global ret_code use_ttk
2176 if {$is_quitting} return
2179 if {[winfo exists $ui_comm]} {
2180 # -- Stash our current commit buffer.
2182 set save [gitdir GITGUI_MSG]
2183 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2184 file rename -force [gitdir GITGUI_BCK] $save
2185 set GITGUI_BCK_exists 0
2187 set msg [string trim [$ui_comm get 0.0 end]]
2188 regsub -all -line {[ \r\t]+$} $msg {} msg
2189 if {(![string match amend* $commit_type]
2190 || [$ui_comm edit modified])
2193 set fd [open $save w]
2194 puts -nonewline $fd $msg
2198 catch {file delete $save}
2202 # -- Cancel our spellchecker if its running.
2204 if {[info exists ui_comm_spell]} {
2208 # -- Remove our editor backup, its not needed.
2210 after cancel $GITGUI_BCK_i
2211 if {$GITGUI_BCK_exists} {
2212 catch {file delete [gitdir GITGUI_BCK]}
2215 # -- Stash our current window geometry into this repository.
2217 set cfg_wmstate [wm state .]
2218 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2221 if {$cfg_wmstate ne $rc_wmstate} {
2222 catch {git config gui.wmstate $cfg_wmstate}
2224 if {$cfg_wmstate eq {zoomed}} {
2225 # on Windows wm geometry will lie about window
2226 # position (but not size) when window is zoomed
2227 # restore the window before querying wm geometry
2230 set cfg_geometry [list]
2231 lappend cfg_geometry [wm geometry .]
2233 lappend cfg_geometry [.vpane sashpos 0]
2234 lappend cfg_geometry [.vpane.files sashpos 0]
2236 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2237 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2239 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2242 if {$cfg_geometry ne $rc_geometry} {
2243 catch {git config gui.geometry $cfg_geometry}
2249 # Briefly enable send again, working around Tk bug
2250 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2251 tk appname [appname]
2260 proc ui_do_rescan {} {
2261 rescan {force_first_diff ui_ready}
2268 proc next_diff {{after {}}} {
2269 global next_diff_p next_diff_w next_diff_i
2270 show_diff $next_diff_p $next_diff_w {} {} $after
2273 proc find_anchor_pos {lst name} {
2274 set lid [lsearch -sorted -exact $lst $name]
2278 foreach lname $lst {
2279 if {$lname >= $name} break
2287 proc find_file_from {flist idx delta path mmask} {
2290 set len [llength $flist]
2291 while {$idx >= 0 && $idx < $len} {
2292 set name [lindex $flist $idx]
2294 if {$name ne $path && [info exists file_states($name)]} {
2295 set state [lindex $file_states($name) 0]
2297 if {$mmask eq {} || [regexp $mmask $state]} {
2308 proc find_next_diff {w path {lno {}} {mmask {}}} {
2309 global next_diff_p next_diff_w next_diff_i
2310 global file_lists ui_index ui_workdir
2312 set flist $file_lists($w)
2314 set lno [find_anchor_pos $flist $path]
2319 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2320 if {$w eq $ui_index} {
2323 set mmask "$mmask\$"
2327 set idx [find_file_from $flist $lno 1 $path $mmask]
2330 set idx [find_file_from $flist $lno -1 $path $mmask]
2335 set next_diff_p [lindex $flist $idx]
2336 set next_diff_i [expr {$idx+1}]
2343 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2344 global current_diff_path
2346 if {$path ne $current_diff_path} {
2348 } elseif {[find_next_diff $w $path $lno $mmask]} {
2351 return {reshow_diff;}
2355 proc select_first_diff {after} {
2358 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2359 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2366 proc force_first_diff {after} {
2367 global ui_workdir current_diff_path file_states
2369 if {[info exists file_states($current_diff_path)]} {
2370 set state [lindex $file_states($current_diff_path) 0]
2376 if {[string first {U} $state] >= 0} {
2377 # Already a conflict, do nothing
2378 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2380 } elseif {[string index $state 1] ne {O}} {
2381 # Already a diff & no conflicts, do nothing
2382 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2393 proc toggle_or_diff {w x y} {
2394 global file_states file_lists current_diff_path ui_index ui_workdir
2395 global last_clicked selected_paths
2397 set pos [split [$w index @$x,$y] .]
2398 set lno [lindex $pos 0]
2399 set col [lindex $pos 1]
2400 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2406 set last_clicked [list $w $lno]
2407 array unset selected_paths
2408 $ui_index tag remove in_sel 0.0 end
2409 $ui_workdir tag remove in_sel 0.0 end
2411 # Determine the state of the file
2412 if {[info exists file_states($path)]} {
2413 set state [lindex $file_states($path) 0]
2418 # Restage the file, or simply show the diff
2419 if {$col == 0 && $y > 1} {
2420 # Conflicts need special handling
2421 if {[string first {U} $state] >= 0} {
2422 # $w must always be $ui_workdir, but...
2423 if {$w ne $ui_workdir} { set lno {} }
2424 merge_stage_workdir $path $lno
2428 if {[string index $state 1] eq {O}} {
2434 set after [next_diff_after_action $w $path $lno $mmask]
2436 if {$w eq $ui_index} {
2438 "Unstaging [short_path $path] from commit" \
2440 [concat $after [list ui_ready]]
2441 } elseif {$w eq $ui_workdir} {
2443 "Adding [short_path $path]" \
2445 [concat $after [list ui_ready]]
2448 show_diff $path $w $lno
2452 proc add_one_to_selection {w x y} {
2453 global file_lists last_clicked selected_paths
2455 set lno [lindex [split [$w index @$x,$y] .] 0]
2456 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2462 if {$last_clicked ne {}
2463 && [lindex $last_clicked 0] ne $w} {
2464 array unset selected_paths
2465 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2468 set last_clicked [list $w $lno]
2469 if {[catch {set in_sel $selected_paths($path)}]} {
2473 unset selected_paths($path)
2474 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2476 set selected_paths($path) 1
2477 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2481 proc add_range_to_selection {w x y} {
2482 global file_lists last_clicked selected_paths
2484 if {[lindex $last_clicked 0] ne $w} {
2485 toggle_or_diff $w $x $y
2489 set lno [lindex [split [$w index @$x,$y] .] 0]
2490 set lc [lindex $last_clicked 1]
2499 foreach path [lrange $file_lists($w) \
2500 [expr {$begin - 1}] \
2501 [expr {$end - 1}]] {
2502 set selected_paths($path) 1
2504 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2507 proc show_more_context {} {
2509 if {$repo_config(gui.diffcontext) < 99} {
2510 incr repo_config(gui.diffcontext)
2515 proc show_less_context {} {
2517 if {$repo_config(gui.diffcontext) > 1} {
2518 incr repo_config(gui.diffcontext) -1
2523 ######################################################################
2531 menu .mbar -tearoff 0
2533 # -- Apple Menu (Mac OS X only)
2535 .mbar add cascade -label Apple -menu .mbar.apple
2538 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2539 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2540 if {[is_enabled branch]} {
2541 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2543 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2544 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2546 if {[is_enabled transport]} {
2547 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2548 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2550 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2551 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2554 # -- Repository Menu
2556 menu .mbar.repository
2559 .mbar.repository add command \
2560 -label [mc "Explore Working Copy"] \
2561 -command {do_explore}
2562 .mbar.repository add separator
2565 .mbar.repository add command \
2566 -label [mc "Browse Current Branch's Files"] \
2567 -command {browser::new $current_branch}
2568 set ui_browse_current [.mbar.repository index last]
2569 .mbar.repository add command \
2570 -label [mc "Browse Branch Files..."] \
2571 -command browser_open::dialog
2572 .mbar.repository add separator
2574 .mbar.repository add command \
2575 -label [mc "Visualize Current Branch's History"] \
2576 -command {do_gitk $current_branch}
2577 set ui_visualize_current [.mbar.repository index last]
2578 .mbar.repository add command \
2579 -label [mc "Visualize All Branch History"] \
2580 -command {do_gitk --all}
2581 .mbar.repository add separator
2583 proc current_branch_write {args} {
2584 global current_branch
2585 .mbar.repository entryconf $::ui_browse_current \
2586 -label [mc "Browse %s's Files" $current_branch]
2587 .mbar.repository entryconf $::ui_visualize_current \
2588 -label [mc "Visualize %s's History" $current_branch]
2590 trace add variable current_branch write current_branch_write
2592 if {[is_enabled multicommit]} {
2593 .mbar.repository add command -label [mc "Database Statistics"] \
2596 .mbar.repository add command -label [mc "Compress Database"] \
2599 .mbar.repository add command -label [mc "Verify Database"] \
2600 -command do_fsck_objects
2602 .mbar.repository add separator
2605 .mbar.repository add command \
2606 -label [mc "Create Desktop Icon"] \
2607 -command do_cygwin_shortcut
2608 } elseif {[is_Windows]} {
2609 .mbar.repository add command \
2610 -label [mc "Create Desktop Icon"] \
2611 -command do_windows_shortcut
2612 } elseif {[is_MacOSX]} {
2613 .mbar.repository add command \
2614 -label [mc "Create Desktop Icon"] \
2615 -command do_macosx_app
2620 proc ::tk::mac::Quit {args} { do_quit }
2622 .mbar.repository add command -label [mc Quit] \
2630 .mbar.edit add command -label [mc Undo] \
2631 -command {catch {[focus] edit undo}} \
2633 .mbar.edit add command -label [mc Redo] \
2634 -command {catch {[focus] edit redo}} \
2636 .mbar.edit add separator
2637 .mbar.edit add command -label [mc Cut] \
2638 -command {catch {tk_textCut [focus]}} \
2640 .mbar.edit add command -label [mc Copy] \
2641 -command {catch {tk_textCopy [focus]}} \
2643 .mbar.edit add command -label [mc Paste] \
2644 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2646 .mbar.edit add command -label [mc Delete] \
2647 -command {catch {[focus] delete sel.first sel.last}} \
2649 .mbar.edit add separator
2650 .mbar.edit add command -label [mc "Select All"] \
2651 -command {catch {[focus] tag add sel 0.0 end}} \
2656 if {[is_enabled branch]} {
2659 .mbar.branch add command -label [mc "Create..."] \
2660 -command branch_create::dialog \
2662 lappend disable_on_lock [list .mbar.branch entryconf \
2663 [.mbar.branch index last] -state]
2665 .mbar.branch add command -label [mc "Checkout..."] \
2666 -command branch_checkout::dialog \
2668 lappend disable_on_lock [list .mbar.branch entryconf \
2669 [.mbar.branch index last] -state]
2671 .mbar.branch add command -label [mc "Rename..."] \
2672 -command branch_rename::dialog
2673 lappend disable_on_lock [list .mbar.branch entryconf \
2674 [.mbar.branch index last] -state]
2676 .mbar.branch add command -label [mc "Delete..."] \
2677 -command branch_delete::dialog
2678 lappend disable_on_lock [list .mbar.branch entryconf \
2679 [.mbar.branch index last] -state]
2681 .mbar.branch add command -label [mc "Reset..."] \
2682 -command merge::reset_hard
2683 lappend disable_on_lock [list .mbar.branch entryconf \
2684 [.mbar.branch index last] -state]
2689 proc commit_btn_caption {} {
2690 if {[is_enabled nocommit]} {
2693 return [mc Commit@@verb]
2697 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2700 if {![is_enabled nocommit]} {
2701 .mbar.commit add radiobutton \
2702 -label [mc "New Commit"] \
2703 -command do_select_commit_type \
2704 -variable selected_commit_type \
2706 lappend disable_on_lock \
2707 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2709 .mbar.commit add radiobutton \
2710 -label [mc "Amend Last Commit"] \
2711 -command do_select_commit_type \
2712 -variable selected_commit_type \
2714 lappend disable_on_lock \
2715 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2717 .mbar.commit add separator
2720 .mbar.commit add command -label [mc Rescan] \
2721 -command ui_do_rescan \
2723 lappend disable_on_lock \
2724 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2726 .mbar.commit add command -label [mc "Stage To Commit"] \
2727 -command do_add_selection \
2729 lappend disable_on_lock \
2730 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2732 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2733 -command do_add_all \
2735 lappend disable_on_lock \
2736 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2738 .mbar.commit add command -label [mc "Unstage From Commit"] \
2739 -command do_unstage_selection \
2741 lappend disable_on_lock \
2742 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2744 .mbar.commit add command -label [mc "Revert Changes"] \
2745 -command do_revert_selection \
2747 lappend disable_on_lock \
2748 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2750 .mbar.commit add separator
2752 .mbar.commit add command -label [mc "Show Less Context"] \
2753 -command show_less_context \
2754 -accelerator $M1T-\-
2756 .mbar.commit add command -label [mc "Show More Context"] \
2757 -command show_more_context \
2760 .mbar.commit add separator
2762 if {![is_enabled nocommitmsg]} {
2763 .mbar.commit add command -label [mc "Sign Off"] \
2764 -command do_signoff \
2768 .mbar.commit add command -label [commit_btn_caption] \
2769 -command do_commit \
2770 -accelerator $M1T-Return
2771 lappend disable_on_lock \
2772 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2777 if {[is_enabled branch]} {
2779 .mbar.merge add command -label [mc "Local Merge..."] \
2780 -command merge::dialog \
2782 lappend disable_on_lock \
2783 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2784 .mbar.merge add command -label [mc "Abort Merge..."] \
2785 -command merge::reset_hard
2786 lappend disable_on_lock \
2787 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2792 if {[is_enabled transport]} {
2795 .mbar.remote add command \
2796 -label [mc "Add..."] \
2797 -command remote_add::dialog \
2799 .mbar.remote add command \
2800 -label [mc "Push..."] \
2801 -command do_push_anywhere \
2803 .mbar.remote add command \
2804 -label [mc "Delete Branch..."] \
2805 -command remote_branch_delete::dialog
2809 proc ::tk::mac::ShowPreferences {} {do_options}
2813 .mbar.edit add separator
2814 .mbar.edit add command -label [mc "Options..."] \
2820 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2821 set tools_menubar .mbar.tools
2823 $tools_menubar add separator
2824 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2825 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2827 if {[array names repo_config guitool.*.cmd] ne {}} {
2834 .mbar add cascade -label [mc Help] -menu .mbar.help
2838 .mbar.apple add command -label [mc "About %s" [appname]] \
2840 .mbar.apple add separator
2842 .mbar.help add command -label [mc "About %s" [appname]] \
2845 . configure -menu .mbar
2847 set doc_path [githtmldir]
2848 if {$doc_path ne {}} {
2849 set doc_path [file join $doc_path index.html]
2852 set doc_path [exec cygpath --mixed $doc_path]
2856 if {[file isfile $doc_path]} {
2857 set doc_url "file:$doc_path"
2859 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2862 proc start_browser {url} {
2863 git "web--browse" $url
2866 .mbar.help add command -label [mc "Online Documentation"] \
2867 -command [list start_browser $doc_url]
2869 .mbar.help add command -label [mc "Show SSH Key"] \
2872 unset doc_path doc_url
2874 # -- Standard bindings
2876 wm protocol . WM_DELETE_WINDOW do_quit
2877 bind all <$M1B-Key-q> do_quit
2878 bind all <$M1B-Key-Q> do_quit
2879 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2880 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2882 set subcommand_args {}
2884 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2885 if {[tk windowingsystem] eq "win32"} {
2887 tk_messageBox -icon info -message $s \
2895 proc normalize_relpath {path} {
2897 foreach item [file split $path] {
2898 if {$item eq {.}} continue
2899 if {$item eq {..} && [llength $elements] > 0
2900 && [lindex $elements end] ne {..}} {
2901 set elements [lrange $elements 0 end-1]
2904 lappend elements $item
2906 return [eval file join $elements]
2909 # -- Not a normal commit type invocation? Do that instead!
2911 switch -- $subcommand {
2914 if {$subcommand eq "blame"} {
2915 set subcommand_args {[--line=<num>] rev? path}
2917 set subcommand_args {rev? path}
2919 if {$argv eq {}} usage
2925 if {$is_path || [file exists $_prefix$a]} {
2926 if {$path ne {}} usage
2927 set path [normalize_relpath $_prefix$a]
2929 } elseif {$a eq {--}} {
2931 if {$head ne {}} usage
2936 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2937 if {$jump_spec ne {} || $head ne {}} usage
2938 set jump_spec [list $lnum]
2939 } elseif {$head eq {}} {
2940 if {$head ne {}} usage
2949 if {$head ne {} && $path eq {}} {
2950 set path [normalize_relpath $_prefix$head]
2957 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2959 set head [git rev-parse --verify $head]
2961 if {[tk windowingsystem] eq "win32"} {
2962 tk_messageBox -icon error -title [mc Error] -message $err
2969 set current_branch $head
2973 switch -- $subcommand {
2975 if {$jump_spec ne {}} usage
2977 if {$path ne {} && [file isdirectory $path]} {
2978 set head $current_branch
2984 browser::new $head $path
2987 if {$head eq {} && ![file exists $path]} {
2988 catch {wm withdraw .}
2992 -title [mc "git-gui: fatal error"] \
2993 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
2996 blame::new $head $path $jump_spec
3003 if {[llength $argv] != 0} {
3006 # fall through to setup UI for commits
3009 set err "usage: $argv0 \[{blame|browser|citool}\]"
3010 if {[tk windowingsystem] eq "win32"} {
3012 tk_messageBox -icon error -message $err \
3023 ${NS}::frame .branch
3024 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3025 ${NS}::label .branch.l1 \
3026 -text [mc "Current Branch:"] \
3029 ${NS}::label .branch.cb \
3030 -textvariable current_branch \
3033 pack .branch.l1 -side left
3034 pack .branch.cb -side left -fill x
3035 pack .branch -side top -fill x
3037 # -- Main Window Layout
3039 ${NS}::panedwindow .vpane -orient horizontal
3040 ${NS}::panedwindow .vpane.files -orient vertical
3042 .vpane add .vpane.files
3044 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3046 pack .vpane -anchor n -side top -fill both -expand 1
3048 # -- Index File List
3050 ${NS}::frame .vpane.files.index -height 100 -width 200
3051 tlabel .vpane.files.index.title \
3052 -text [mc "Staged Changes (Will Commit)"] \
3053 -background lightgreen -foreground black
3054 text $ui_index -background white -foreground black \
3056 -width 20 -height 10 \
3058 -cursor $cursor_ptr \
3059 -xscrollcommand {.vpane.files.index.sx set} \
3060 -yscrollcommand {.vpane.files.index.sy set} \
3062 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3063 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3064 pack .vpane.files.index.title -side top -fill x
3065 pack .vpane.files.index.sx -side bottom -fill x
3066 pack .vpane.files.index.sy -side right -fill y
3067 pack $ui_index -side left -fill both -expand 1
3069 # -- Working Directory File List
3071 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3072 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3073 -background lightsalmon -foreground black
3074 text $ui_workdir -background white -foreground black \
3076 -width 20 -height 10 \
3078 -cursor $cursor_ptr \
3079 -xscrollcommand {.vpane.files.workdir.sx set} \
3080 -yscrollcommand {.vpane.files.workdir.sy set} \
3082 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3083 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3084 pack .vpane.files.workdir.title -side top -fill x
3085 pack .vpane.files.workdir.sx -side bottom -fill x
3086 pack .vpane.files.workdir.sy -side right -fill y
3087 pack $ui_workdir -side left -fill both -expand 1
3089 .vpane.files add .vpane.files.workdir
3090 .vpane.files add .vpane.files.index
3092 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3093 .vpane.files paneconfigure .vpane.files.index -sticky news
3096 foreach i [list $ui_index $ui_workdir] {
3098 $i tag conf in_diff -background [$i tag cget in_sel -background]
3102 # -- Diff and Commit Area
3104 ${NS}::frame .vpane.lower -height 300 -width 400
3105 ${NS}::frame .vpane.lower.commarea
3106 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3107 pack .vpane.lower.diff -fill both -expand 1
3108 pack .vpane.lower.commarea -side bottom -fill x
3109 .vpane add .vpane.lower
3110 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3112 # -- Commit Area Buttons
3114 ${NS}::frame .vpane.lower.commarea.buttons
3115 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3118 pack .vpane.lower.commarea.buttons.l -side top -fill x
3119 pack .vpane.lower.commarea.buttons -side left -fill y
3121 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3122 -command ui_do_rescan
3123 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3124 lappend disable_on_lock \
3125 {.vpane.lower.commarea.buttons.rescan conf -state}
3127 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3129 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3130 lappend disable_on_lock \
3131 {.vpane.lower.commarea.buttons.incall conf -state}
3133 if {![is_enabled nocommitmsg]} {
3134 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3136 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3139 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3141 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3142 lappend disable_on_lock \
3143 {.vpane.lower.commarea.buttons.commit conf -state}
3145 if {![is_enabled nocommit]} {
3146 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3147 -command do_push_anywhere
3148 pack .vpane.lower.commarea.buttons.push -side top -fill x
3151 # -- Commit Message Buffer
3153 ${NS}::frame .vpane.lower.commarea.buffer
3154 ${NS}::frame .vpane.lower.commarea.buffer.header
3155 set ui_comm .vpane.lower.commarea.buffer.t
3156 set ui_coml .vpane.lower.commarea.buffer.header.l
3158 if {![is_enabled nocommit]} {
3159 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3160 -text [mc "New Commit"] \
3161 -command do_select_commit_type \
3162 -variable selected_commit_type \
3164 lappend disable_on_lock \
3165 [list .vpane.lower.commarea.buffer.header.new conf -state]
3166 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3167 -text [mc "Amend Last Commit"] \
3168 -command do_select_commit_type \
3169 -variable selected_commit_type \
3171 lappend disable_on_lock \
3172 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3175 ${NS}::label $ui_coml \
3178 proc trace_commit_type {varname args} {
3179 global ui_coml commit_type
3180 switch -glob -- $commit_type {
3181 initial {set txt [mc "Initial Commit Message:"]}
3182 amend {set txt [mc "Amended Commit Message:"]}
3183 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3184 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3185 merge {set txt [mc "Merge Commit Message:"]}
3186 * {set txt [mc "Commit Message:"]}
3188 $ui_coml conf -text $txt
3190 trace add variable commit_type write trace_commit_type
3191 pack $ui_coml -side left -fill x
3193 if {![is_enabled nocommit]} {
3194 pack .vpane.lower.commarea.buffer.header.amend -side right
3195 pack .vpane.lower.commarea.buffer.header.new -side right
3198 text $ui_comm -background white -foreground black \
3202 -autoseparators true \
3204 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3206 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3207 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3208 -command [list $ui_comm yview]
3209 pack .vpane.lower.commarea.buffer.header -side top -fill x
3210 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3211 pack $ui_comm -side left -fill y
3212 pack .vpane.lower.commarea.buffer -side left -fill y
3214 # -- Commit Message Buffer Context Menu
3216 set ctxm .vpane.lower.commarea.buffer.ctxm
3217 menu $ctxm -tearoff 0
3220 -command {tk_textCut $ui_comm}
3223 -command {tk_textCopy $ui_comm}
3226 -command {tk_textPaste $ui_comm}
3228 -label [mc Delete] \
3229 -command {catch {$ui_comm delete sel.first sel.last}}
3232 -label [mc "Select All"] \
3233 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3235 -label [mc "Copy All"] \
3237 $ui_comm tag add sel 0.0 end
3238 tk_textCopy $ui_comm
3239 $ui_comm tag remove sel 0.0 end
3243 -label [mc "Sign Off"] \
3245 set ui_comm_ctxm $ctxm
3249 proc trace_current_diff_path {varname args} {
3250 global current_diff_path diff_actions file_states
3251 if {$current_diff_path eq {}} {
3257 set p $current_diff_path
3258 set s [mapdesc [lindex $file_states($p) 0] $p]
3260 set p [escape_path $p]
3264 .vpane.lower.diff.header.status configure -text $s
3265 .vpane.lower.diff.header.file configure -text $f
3266 .vpane.lower.diff.header.path configure -text $p
3267 foreach w $diff_actions {
3271 trace add variable current_diff_path write trace_current_diff_path
3273 gold_frame .vpane.lower.diff.header
3274 tlabel .vpane.lower.diff.header.status \
3277 -width $max_status_desc \
3280 tlabel .vpane.lower.diff.header.file \
3285 tlabel .vpane.lower.diff.header.path \
3290 pack .vpane.lower.diff.header.status -side left
3291 pack .vpane.lower.diff.header.file -side left
3292 pack .vpane.lower.diff.header.path -fill x
3293 set ctxm .vpane.lower.diff.header.ctxm
3294 menu $ctxm -tearoff 0
3302 -- $current_diff_path
3304 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3305 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3309 ${NS}::frame .vpane.lower.diff.body
3310 set ui_diff .vpane.lower.diff.body.t
3311 text $ui_diff -background white -foreground black \
3313 -width 80 -height 5 -wrap none \
3315 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3316 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3318 catch {$ui_diff configure -tabstyle wordprocessor}
3319 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3320 -command [list $ui_diff xview]
3321 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3322 -command [list $ui_diff yview]
3323 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3324 pack .vpane.lower.diff.body.sby -side right -fill y
3325 pack $ui_diff -side left -fill both -expand 1
3326 pack .vpane.lower.diff.header -side top -fill x
3327 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3329 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3330 $ui_diff tag configure clr4$n -background $c
3331 $ui_diff tag configure clri4$n -foreground $c
3332 $ui_diff tag configure clr3$n -foreground $c
3333 $ui_diff tag configure clri3$n -background $c
3335 $ui_diff tag configure clr1 -font font_diffbold
3337 $ui_diff tag conf d_cr -elide true
3338 $ui_diff tag conf d_@ -font font_diffbold
3339 $ui_diff tag conf d_+ -foreground {#00a000}
3340 $ui_diff tag conf d_- -foreground red
3342 $ui_diff tag conf d_++ -foreground {#00a000}
3343 $ui_diff tag conf d_-- -foreground red
3344 $ui_diff tag conf d_+s \
3345 -foreground {#00a000} \
3346 -background {#e2effa}
3347 $ui_diff tag conf d_-s \
3349 -background {#e2effa}
3350 $ui_diff tag conf d_s+ \
3351 -foreground {#00a000} \
3353 $ui_diff tag conf d_s- \
3357 $ui_diff tag conf d<<<<<<< \
3358 -foreground orange \
3360 $ui_diff tag conf d======= \
3361 -foreground orange \
3363 $ui_diff tag conf d>>>>>>> \
3364 -foreground orange \
3367 $ui_diff tag raise sel
3369 # -- Diff Body Context Menu
3372 proc create_common_diff_popup {ctxm} {
3374 -label [mc Refresh] \
3375 -command reshow_diff
3376 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3379 -command {tk_textCopy $ui_diff}
3380 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3382 -label [mc "Select All"] \
3383 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3384 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3386 -label [mc "Copy All"] \
3388 $ui_diff tag add sel 0.0 end
3389 tk_textCopy $ui_diff
3390 $ui_diff tag remove sel 0.0 end
3392 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3395 -label [mc "Decrease Font Size"] \
3396 -command {incr_font_size font_diff -1}
3397 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3399 -label [mc "Increase Font Size"] \
3400 -command {incr_font_size font_diff 1}
3401 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3405 build_encoding_menu $emenu [list force_diff_encoding]
3407 -label [mc "Encoding"] \
3409 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3411 $ctxm add command -label [mc "Options..."] \
3415 set ctxm .vpane.lower.diff.body.ctxm
3416 menu $ctxm -tearoff 0
3418 -label [mc "Apply/Reverse Hunk"] \
3419 -command {apply_hunk $cursorX $cursorY}
3420 set ui_diff_applyhunk [$ctxm index last]
3421 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3423 -label [mc "Apply/Reverse Line"] \
3424 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3425 set ui_diff_applyline [$ctxm index last]
3426 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3429 -label [mc "Show Less Context"] \
3430 -command show_less_context
3431 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3433 -label [mc "Show More Context"] \
3434 -command show_more_context
3435 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3437 create_common_diff_popup $ctxm
3439 set ctxmmg .vpane.lower.diff.body.ctxmmg
3440 menu $ctxmmg -tearoff 0
3441 $ctxmmg add command \
3442 -label [mc "Run Merge Tool"] \
3443 -command {merge_resolve_tool}
3444 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3445 $ctxmmg add separator
3446 $ctxmmg add command \
3447 -label [mc "Use Remote Version"] \
3448 -command {merge_resolve_one 3}
3449 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3450 $ctxmmg add command \
3451 -label [mc "Use Local Version"] \
3452 -command {merge_resolve_one 2}
3453 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3454 $ctxmmg add command \
3455 -label [mc "Revert To Base"] \
3456 -command {merge_resolve_one 1}
3457 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3458 $ctxmmg add separator
3459 $ctxmmg add command \
3460 -label [mc "Show Less Context"] \
3461 -command show_less_context
3462 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3463 $ctxmmg add command \
3464 -label [mc "Show More Context"] \
3465 -command show_more_context
3466 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3467 $ctxmmg add separator
3468 create_common_diff_popup $ctxmmg
3470 set ctxmsm .vpane.lower.diff.body.ctxmsm
3471 menu $ctxmsm -tearoff 0
3472 $ctxmsm add command \
3473 -label [mc "Visualize These Changes In The Submodule"] \
3474 -command {do_gitk -- true}
3475 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3476 $ctxmsm add command \
3477 -label [mc "Visualize Current Branch History In The Submodule"] \
3478 -command {do_gitk {} true}
3479 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3480 $ctxmsm add command \
3481 -label [mc "Visualize All Branch History In The Submodule"] \
3482 -command {do_gitk --all true}
3483 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3484 $ctxmsm add separator
3485 $ctxmsm add command \
3486 -label [mc "Start git gui In The Submodule"] \
3487 -command {do_git_gui}
3488 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3489 $ctxmsm add separator
3490 create_common_diff_popup $ctxmsm
3492 proc has_textconv {path} {
3493 if {[is_config_false gui.textconv]} {
3496 set filter [gitattr $path diff set]
3497 set textconv [get_config [join [list diff $filter textconv] .]]
3498 if {$filter ne {set} && $textconv ne {}} {
3505 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3506 global current_diff_path file_states
3509 if {[info exists file_states($current_diff_path)]} {
3510 set state [lindex $file_states($current_diff_path) 0]
3514 if {[string first {U} $state] >= 0} {
3515 tk_popup $ctxmmg $X $Y
3516 } elseif {$::is_submodule_diff} {
3517 tk_popup $ctxmsm $X $Y
3519 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3520 if {$::ui_index eq $::current_diff_side} {
3521 set l [mc "Unstage Hunk From Commit"]
3523 set t [mc "Unstage Lines From Commit"]
3525 set t [mc "Unstage Line From Commit"]
3528 set l [mc "Stage Hunk For Commit"]
3530 set t [mc "Stage Lines For Commit"]
3532 set t [mc "Stage Line For Commit"]
3536 || $current_diff_path eq {}
3541 || [has_textconv $current_diff_path]} {
3546 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3547 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3548 tk_popup $ctxm $X $Y
3551 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3555 set main_status [::status_bar::new .status]
3556 pack .status -anchor w -side bottom -fill x
3557 $main_status show [mc "Initializing..."]
3561 proc on_ttk_pane_mapped {w pane pos} {
3563 after 0 [list after idle [list $w sashpos $pane $pos]]
3565 proc on_tk_pane_mapped {w pane x y} {
3567 after 0 [list after idle [list $w sash place $pane $x $y]]
3569 proc on_application_mapped {} {
3570 global repo_config use_ttk
3572 set gm $repo_config(gui.geometry)
3575 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3576 bind .vpane.files <Map> \
3577 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3580 [list on_tk_pane_mapped %W 0 \
3582 [lindex [.vpane sash coord 0] 1]]
3583 bind .vpane.files <Map> \
3584 [list on_tk_pane_mapped %W 0 \
3585 [lindex [.vpane.files sash coord 0] 0] \
3588 wm geometry . [lindex $gm 0]
3590 if {[info exists repo_config(gui.geometry)]} {
3591 bind . <Map> [list on_application_mapped]
3592 wm geometry . [lindex $repo_config(gui.geometry) 0]
3595 # -- Load window state
3597 if {[info exists repo_config(gui.wmstate)]} {
3598 catch {wm state . $repo_config(gui.wmstate)}
3603 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3604 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3605 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3606 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3607 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3608 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3609 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3610 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3611 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3612 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3613 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3614 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3615 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3616 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3617 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3618 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3619 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3620 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3621 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3622 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3623 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3624 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3626 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3627 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3628 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3629 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3630 bind $ui_diff <$M1B-Key-v> {break}
3631 bind $ui_diff <$M1B-Key-V> {break}
3632 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3633 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3634 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3635 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3636 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3637 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3638 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3639 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3640 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3641 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3642 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3643 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3644 bind $ui_diff <Button-1> {focus %W}
3646 if {[is_enabled branch]} {
3647 bind . <$M1B-Key-n> branch_create::dialog
3648 bind . <$M1B-Key-N> branch_create::dialog
3649 bind . <$M1B-Key-o> branch_checkout::dialog
3650 bind . <$M1B-Key-O> branch_checkout::dialog
3651 bind . <$M1B-Key-m> merge::dialog
3652 bind . <$M1B-Key-M> merge::dialog
3654 if {[is_enabled transport]} {
3655 bind . <$M1B-Key-p> do_push_anywhere
3656 bind . <$M1B-Key-P> do_push_anywhere
3659 bind . <Key-F5> ui_do_rescan
3660 bind . <$M1B-Key-r> ui_do_rescan
3661 bind . <$M1B-Key-R> ui_do_rescan
3662 bind . <$M1B-Key-s> do_signoff
3663 bind . <$M1B-Key-S> do_signoff
3664 bind . <$M1B-Key-t> do_add_selection
3665 bind . <$M1B-Key-T> do_add_selection
3666 bind . <$M1B-Key-j> do_revert_selection
3667 bind . <$M1B-Key-J> do_revert_selection
3668 bind . <$M1B-Key-i> do_add_all
3669 bind . <$M1B-Key-I> do_add_all
3670 bind . <$M1B-Key-minus> {show_less_context;break}
3671 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3672 bind . <$M1B-Key-equal> {show_more_context;break}
3673 bind . <$M1B-Key-plus> {show_more_context;break}
3674 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3675 bind . <$M1B-Key-Return> do_commit
3676 foreach i [list $ui_index $ui_workdir] {
3677 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3678 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3679 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3683 set file_lists($ui_index) [list]
3684 set file_lists($ui_workdir) [list]
3686 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3687 focus -force $ui_comm
3689 # -- Warn the user about environmental problems. Cygwin's Tcl
3690 # does *not* pass its env array onto any processes it spawns.
3691 # This means that git processes get none of our environment.
3696 set msg [mc "Possible environment issues exist.
3698 The following environment variables are probably
3699 going to be ignored by any Git subprocess run
3703 foreach name [array names env] {
3704 switch -regexp -- $name {
3705 {^GIT_INDEX_FILE$} -
3706 {^GIT_OBJECT_DIRECTORY$} -
3707 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3709 {^GIT_EXTERNAL_DIFF$} -
3713 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3714 append msg " - $name\n"
3717 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3718 append msg " - $name\n"
3720 set suggest_user $name
3724 if {$ignored_env > 0} {
3726 This is due to a known issue with the
3727 Tcl binary distributed by Cygwin."]
3729 if {$suggest_user ne {}} {
3732 A good replacement for %s
3733 is placing values for the user.name and
3734 user.email settings into your personal
3740 unset ignored_env msg suggest_user name
3743 # -- Only initialize complex UI if we are going to stay running.
3745 if {[is_enabled transport]} {
3748 set n [.mbar.remote index end]
3749 populate_remotes_menu
3750 set n [expr {[.mbar.remote index end] - $n}]
3752 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3753 .mbar.remote insert $n separator
3758 if {[winfo exists $ui_comm]} {
3759 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3761 # -- If both our backup and message files exist use the
3762 # newer of the two files to initialize the buffer.
3764 if {$GITGUI_BCK_exists} {
3765 set m [gitdir GITGUI_MSG]
3766 if {[file isfile $m]} {
3767 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3768 catch {file delete [gitdir GITGUI_MSG]}
3770 $ui_comm delete 0.0 end
3772 $ui_comm edit modified false
3773 catch {file delete [gitdir GITGUI_BCK]}
3774 set GITGUI_BCK_exists 0
3780 proc backup_commit_buffer {} {
3781 global ui_comm GITGUI_BCK_exists
3783 set m [$ui_comm edit modified]
3784 if {$m || $GITGUI_BCK_exists} {
3785 set msg [string trim [$ui_comm get 0.0 end]]
3786 regsub -all -line {[ \r\t]+$} $msg {} msg
3789 if {$GITGUI_BCK_exists} {
3790 catch {file delete [gitdir GITGUI_BCK]}
3791 set GITGUI_BCK_exists 0
3795 set fd [open [gitdir GITGUI_BCK] w]
3796 puts -nonewline $fd $msg
3798 set GITGUI_BCK_exists 1
3802 $ui_comm edit modified false
3805 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3808 backup_commit_buffer
3810 # -- If the user has aspell available we can drive it
3811 # in pipe mode to spellcheck the commit message.
3813 set spell_cmd [list |]
3814 set spell_dict [get_config gui.spellingdictionary]
3815 lappend spell_cmd aspell
3816 if {$spell_dict ne {}} {
3817 lappend spell_cmd --master=$spell_dict
3819 lappend spell_cmd --mode=none
3820 lappend spell_cmd --encoding=utf-8
3821 lappend spell_cmd pipe
3822 if {$spell_dict eq {none}
3823 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3824 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3826 set ui_comm_spell [spellcheck::init \
3832 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3835 lock_index begin-read
3836 if {![winfo ismapped .]} {
3840 if {[is_enabled initialamend]} {
3846 if {[is_enabled nocommitmsg]} {
3847 $ui_comm configure -state disabled -background gray
3850 if {[is_enabled multicommit]} {
3853 if {[is_enabled retcode]} {
3854 bind . <Destroy> {+terminate_me %W}
3856 if {$picked && [is_config_true gui.autoexplore]} {
3862 # indent-tabs-mode: t