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
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
100 proc _mc_update_locale
{} {
101 set key
{HKEY_CURRENT_USER\Control Panel\Desktop
}
103 package require registry
104 set uilocale
[registry get
$key "PreferredUILanguages"]
105 msgcat
::ConvertLocale
[string map
{- _
} [lindex
$uilocale 0]]
107 if {[string length
$uilocale] > 0} {
108 msgcat
::mclocale
$uilocale
115 proc _mc_trim
{fmt} {
116 set cmk
[string first @@
$fmt]
118 return [string range
$fmt 0 [expr {$cmk - 1}]]
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]
132 return [join $args {}]
135 ::msgcat
::mcload
$oguimsg
138 ######################################################################
142 set _appname
{Git Gui
}
151 set _shellpath
{@@SHELL_PATH@@
}
153 set _trace
[lsearch
-exact $argv --trace]
155 set argv
[lreplace
$argv $_trace $_trace]
161 # variable for the last merged branch (useful for a default when deleting
163 set _last_merged_branch
{}
166 global _shellpath env
167 if {[string match @@
* $_shellpath]} {
168 if {[info exists env
(SHELL
)]} {
187 return [eval [list
file join $_gitdir] $args]
190 proc gitexec
{args
} {
192 if {$_gitexec eq
{}} {
193 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
194 error
"Git not installed?\n\n$err"
197 set _gitexec
[exec cygpath \
202 set _gitexec
[file normalize
$_gitexec]
208 return [eval [list
file join $_gitexec] $args]
211 proc githtmldir
{args
} {
213 if {$_githtmldir eq
{}} {
214 if {[catch
{set _githtmldir
[git
--html-path]}]} {
215 # Git not installed or option not yet supported
219 set _githtmldir
[exec cygpath \
224 set _githtmldir
[file normalize
$_githtmldir]
230 return [eval [list
file join $_githtmldir] $args]
238 if {[tk windowingsystem
] eq
{aqua
}} {
245 if {$
::tcl_platform
(platform
) eq
{windows
}} {
253 if {$_iscygwin eq
{}} {
254 if {$
::tcl_platform
(platform
) eq
{windows
}} {
255 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
267 proc is_enabled
{option
} {
268 global enabled_options
269 if {[catch
{set on
$enabled_options($option)}]} {return 0}
273 proc enable_option
{option
} {
274 global enabled_options
275 set enabled_options
($option) 1
278 proc disable_option
{option
} {
279 global enabled_options
280 set enabled_options
($option) 0
283 ######################################################################
287 proc is_many_config
{name
} {
288 switch
-glob -- $name {
298 proc is_config_true
{name
} {
300 if {[catch
{set v
$repo_config($name)}]} {
303 set v
[string tolower
$v]
304 if {$v eq
{} ||
$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes} ||
$v eq
{on
}} {
311 proc is_config_false
{name
} {
313 if {[catch
{set v
$repo_config($name)}]} {
316 set v
[string tolower
$v]
317 if {$v eq
{false
} ||
$v eq
{0} ||
$v eq
{no
} ||
$v eq
{off
}} {
324 proc get_config
{name
} {
326 if {[catch
{set v
$repo_config($name)}]} {
338 if {$_isbare eq
{}} {
340 set _bare
[git rev-parse
--is-bare-repository]
342 true
{ set _isbare
1 }
343 false
{ set _isbare
0}
347 if {[is_config_true core.bare
]
348 ||
($_gitworktree eq
{}
349 && [lindex
[file split $_gitdir] end
] ne
{.git
})} {
359 ######################################################################
363 proc _trace_exec
{cmd
} {
364 if {!$
::_trace
} return
370 if {[regexp
{[ \t\r\n'"$?*]} $v]} {
378 #'" fix poor old emacs font-lock mode
380 proc _git_cmd {name} {
383 if {[catch {set v $_git_cmd_path($name)}]} {
387 --exec-path { return [list $::_git $name] }
390 set p [gitexec git-$name$::_search_exe]
391 if {[file exists $p]} {
393 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
394 # Try to determine what sort of magic will make
395 # git-$name go and do its thing, because native
396 # Tcl on Windows doesn't know it.
398 set p [gitexec git-$name]
403 switch -glob -- [lindex $s 0] {
405 #!*perl { set i perl }
406 #!*python { set i python }
407 default { error "git-
$name is not supported
: $s" }
411 if {![info exists interp]} {
412 set interp [_which $i]
415 error "git-
$name requires
$i (not
in PATH
)"
417 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
419 # Assume it is builtin to git somehow and we
420 # aren't actually able to see a file for it.
422 set v [list $::_git $name]
424 set _git_cmd_path($name) $v
429 proc _which {what args} {
430 global env _search_exe _search_path
432 if {$_search_path eq {}} {
433 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
434 set _search_path [split [exec cygpath \
440 } elseif {[is_Windows]} {
441 set gitguidir [file dirname [info script]]
442 regsub -all ";" $gitguidir "\\;" gitguidir
443 set env(PATH) "$gitguidir;$env(PATH
)"
444 set _search_path [split $env(PATH) {;}]
447 set _search_path [split $env(PATH) :]
452 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
455 set suffix $_search_exe
458 foreach p $_search_path {
459 set p [file join $p $what$suffix]
460 if {[file exists $p]} {
461 return [file normalize $p]
467 proc _lappend_nice {cmd_var} {
471 if {![info exists _nice]} {
472 set _nice [_which nice]
473 if {[catch {exec $_nice git version}]} {
475 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
488 switch -- [lindex $args 0] {
499 set args [lrange $args 1 end]
502 set cmdp [_git_cmd [lindex $args 0]]
503 set args [lrange $args 1 end]
505 _trace_exec [concat $opt $cmdp $args]
506 set result [eval exec $opt $cmdp $args]
508 puts stderr "< $result"
513 proc _open_stdout_stderr {cmd} {
516 set fd [open [concat [list | ] $cmd] r]
518 if { [lindex $cmd end] eq {2>@1}
519 && $err eq {can not find channel named "1"}
521 # Older versions of Tcl 8.4 don't have this 2>@1 IO
522 # redirect operator. Fallback to |& cat for those.
523 # The command was not actually started, so its safe
524 # to try to start it a second time.
526 set fd [open [concat \
528 [lrange $cmd 0 end-1] \
535 fconfigure $fd -eofchar {}
539 proc git_read {args} {
543 switch -- [lindex $args 0] {
558 set args [lrange $args 1 end]
561 set cmdp [_git_cmd [lindex $args 0]]
562 set args [lrange $args 1 end]
564 return [_open_stdout_stderr [concat $opt $cmdp $args]]
567 proc git_write {args} {
571 switch -- [lindex $args 0] {
582 set args [lrange $args 1 end]
585 set cmdp [_git_cmd [lindex $args 0]]
586 set args [lrange $args 1 end]
588 _trace_exec [concat $opt $cmdp $args]
589 return [open [concat [list | ] $opt $cmdp $args] w]
592 proc githook_read {hook_name args} {
593 set pchook [gitdir hooks $hook_name]
596 # On Windows [file executable] might lie so we need to ask
597 # the shell if the hook is executable. Yes that's annoying.
601 if {![info exists interp]} {
602 set interp [_which sh]
605 error "hook execution requires sh
(not
in PATH
)"
608 set scr {if test -x "$1";then exec "$@
";fi}
609 set sh_c [list $interp -c $scr $interp $pchook]
610 return [_open_stdout_stderr [concat $sh_c $args]]
613 if {[file executable $pchook]} {
614 return [_open_stdout_stderr [concat [list $pchook] $args]]
620 proc kill_file_process {fd} {
621 set process [pid $fd]
625 # Use a Cygwin-specific flag to allow killing
626 # native Windows processes
627 exec kill -f $process
634 proc gitattr {path attr default} {
635 if {[catch {set r [git check-attr $attr -- $path]}]} {
638 set r [join [lrange [split $r :] 2 end] :]
641 if {$r eq {unspecified}} {
648 regsub -all ' $value "'\\''" value
652 proc load_current_branch {} {
653 global current_branch is_detached
655 set fd [open [gitdir HEAD] r]
656 if {[gets $fd ref] < 1} {
661 set pfx {ref: refs/heads/}
662 set len [string length $pfx]
663 if {[string equal -length $len $pfx $ref]} {
664 # We're on a branch. It might not exist. But
665 # HEAD looks good enough to be a branch.
667 set current_branch
[string range
$ref $len end
]
670 # Assume this is a detached head.
672 set current_branch HEAD
677 auto_load tk_optionMenu
678 rename tk_optionMenu real__tkOptionMenu
679 proc tk_optionMenu
{w varName args
} {
680 set m
[eval real__tkOptionMenu
$w $varName $args]
681 $m configure
-font font_ui
682 $w configure
-font font_ui
686 proc rmsel_tag
{text
} {
688 -background [$text cget
-background] \
689 -foreground [$text cget
-foreground] \
691 $text tag conf in_sel
-background lightgray
692 bind $text <Motion
> break
698 bind .
<Visibility
> {
699 bind .
<Visibility
> {}
704 wm iconbitmap .
-default $oguilib/git-gui.ico
705 set ::tk
::AlwaysShowSelection
1
706 bind .
<Control-F2
> {console show
}
708 # Spoof an X11 display for SSH
709 if {![info exists env
(DISPLAY
)]} {
710 set env
(DISPLAY
) :9999
714 image create photo gitlogo
-width 16 -height 16
716 gitlogo put
#33CC33 -to 7 0 9 2
717 gitlogo put
#33CC33 -to 4 2 12 4
718 gitlogo put
#33CC33 -to 7 4 9 6
719 gitlogo put
#CC3333 -to 4 6 12 8
720 gitlogo put gray26
-to 4 9 6 10
721 gitlogo put gray26
-to 3 10 6 12
722 gitlogo put gray26
-to 8 9 13 11
723 gitlogo put gray26
-to 8 11 10 12
724 gitlogo put gray26
-to 11 11 13 14
725 gitlogo put gray26
-to 3 12 5 14
726 gitlogo put gray26
-to 5 13
727 gitlogo put gray26
-to 10 13
728 gitlogo put gray26
-to 4 14 12 15
729 gitlogo put gray26
-to 5 15 11 16
732 wm iconphoto .
-default gitlogo
736 ######################################################################
742 if {[lsearch
-exact [font names
] TkDefaultFont
] != -1} {
743 eval [linsert
[font actual TkDefaultFont
] 0 font configure font_ui
]
744 eval [linsert
[font actual TkFixedFont
] 0 font create font_diff
]
746 font create font_diff
-family Courier
-size 10
749 eval font configure font_ui
[font actual
[.dummy cget
-font]]
754 font create font_uiitalic
755 font create font_uibold
756 font create font_diffbold
757 font create font_diffitalic
759 foreach class
{Button Checkbutton Entry Label
760 Labelframe Listbox Message
761 Radiobutton Spinbox Text
} {
762 option add
*$class.font font_ui
765 option add
*Menu.font font_ui
766 option add
*Entry.borderWidth
1 startupFile
767 option add
*Entry.relief sunken startupFile
768 option add
*RadioButton.anchor w startupFile
772 if {[is_Windows
] ||
[is_MacOSX
]} {
773 option add
*Menu.tearOff
0
784 proc bind_button3
{w cmd
} {
785 bind $w <Any-Button-3
> $cmd
787 # Mac OS X sends Button-2 on right click through three-button mouse,
788 # or through trackpad right-clicking (two-finger touch + click).
789 bind $w <Any-Button-2
> $cmd
790 bind $w <Control-Button-1
> $cmd
794 proc apply_config
{} {
795 global repo_config font_descs
797 foreach option
$font_descs {
798 set name
[lindex
$option 0]
799 set font
[lindex
$option 1]
802 foreach
{cn cv
} $repo_config(gui.
$name) {
803 if {$cn eq
{-weight}} {
806 font configure
$font $cn $cv
809 font configure
$font -weight normal
812 error_popup
[strcat
[mc
"Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
814 foreach
{cn cv
} [font configure
$font] {
815 font configure
${font}bold
$cn $cv
816 font configure
${font}italic
$cn $cv
818 font configure
${font}bold
-weight bold
819 font configure
${font}italic
-slant italic
825 if {$repo_config(gui.usettk
)} {
826 set use_ttk
[package vsatisfies
[package provide Tk
] 8.5]
829 bind [winfo class .
] <<ThemeChanged>> [list InitTheme]
835 set default_config(branch.autosetupmerge) true
836 set default_config(merge.tool) {}
837 set default_config(mergetool.keepbackup) true
838 set default_config(merge.diffstat) true
839 set default_config(merge.summary) false
840 set default_config(merge.verbosity) 2
841 set default_config(user.name) {}
842 set default_config(user.email) {}
844 set default_config(gui.encoding) [encoding system]
845 set default_config(gui.matchtrackingbranch) false
846 set default_config(gui.textconv) true
847 set default_config(gui.pruneduringfetch) false
848 set default_config(gui.trustmtime) false
849 set default_config(gui.fastcopyblame) false
850 set default_config(gui.copyblamethreshold) 40
851 set default_config(gui.blamehistoryctx) 7
852 set default_config(gui.diffcontext) 5
853 set default_config(gui.commitmsgwidth) 75
854 set default_config(gui.newbranchtemplate) {}
855 set default_config(gui.spellingdictionary) {}
856 set default_config(gui.fontui) [font configure font_ui]
857 set default_config(gui.fontdiff) [font configure font_diff]
858 # TODO: this option should be added to the git-config documentation
859 set default_config(gui.maxfilesdisplayed) 5000
860 set default_config(gui.usettk) 1
861 set default_config(gui.warndetachedcommit) 1
863 {fontui font_ui {mc "Main Font"}}
864 {fontdiff font_diff {mc "Diff/Console Font"}}
867 ######################################################################
871 set _git [_which git]
873 catch {wm withdraw .}
877 -title [mc "git-gui: fatal error"] \
878 -message [mc "Cannot find git in PATH."]
882 ######################################################################
886 if {[catch {set _git_version [git --version]} err]} {
887 catch {wm withdraw .}
891 -title [mc "git-gui: fatal error"] \
892 -message "Cannot determine Git version:
896 [appname] requires Git 1.5.0 or later."
899 if {![regsub {^git version } $_git_version {} _git_version]} {
900 catch {wm withdraw .}
904 -title [mc "git-gui: fatal error"] \
905 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
909 proc get_trimmed_version {s} {
911 foreach x [split $s -._] {
912 if {[string is integer -strict $x]} {
920 set _real_git_version $_git_version
921 set _git_version [get_trimmed_version $_git_version]
923 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
924 catch {wm withdraw .}
929 -title "[appname]: warning" \
930 -message [mc "Git version cannot be determined.
932 %s claims it is version '%s'.
934 %s requires at least Git 1.5.0 or later.
936 Assume '%s' is version 1.5.0?
937 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
938 set _git_version 1.5.0
943 unset _real_git_version
945 proc git-version {args} {
948 switch [llength $args] {
954 set op [lindex $args 0]
955 set vr [lindex $args 1]
956 set cm [package vcompare $_git_version $vr]
957 return [expr $cm $op 0]
961 set type [lindex $args 0]
962 set name [lindex $args 1]
963 set parm [lindex $args 2]
964 set body [lindex $args 3]
966 if {($type ne {proc} && $type ne {method})} {
967 error "Invalid arguments to git-version"
969 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
970 error "Last arm of $type $name must be default"
973 foreach {op vr cb} [lrange $body 0 end-2] {
974 if {[git-version $op $vr]} {
975 return [uplevel [list $type $name $parm $cb]]
979 return [uplevel [list $type $name $parm [lindex $body end]]]
983 error "git-version >= x"
989 if {[git-version < 1.5]} {
990 catch {wm withdraw .}
994 -title [mc "git-gui: fatal error"] \
995 -message "[appname] requires Git 1.5.0 or later.
997 You are using [git-version]:
1003 ######################################################################
1005 ## configure our library
1007 set idx [file join $oguilib tclIndex]
1008 if {[catch {set fd [open $idx r]} err]} {
1009 catch {wm withdraw .}
1013 -title [mc "git-gui: fatal error"] \
1017 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1019 while {[gets $fd n] >= 0} {
1020 if {$n ne {} && ![string match #* $n]} {
1032 if {[lsearch -exact $loaded $p] >= 0} continue
1033 source [file join $oguilib $p]
1038 set auto_path [concat [list $oguilib] $auto_path]
1040 unset -nocomplain idx fd
1042 ######################################################################
1044 ## config file parsing
1046 git-version proc _parse_config {arr_name args} {
1053 [list git_read config] \
1055 [list --null --list]]
1056 fconfigure $fd_rc -translation binary
1057 set buf [read $fd_rc]
1060 foreach line [split $buf "\0"] {
1061 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1062 if {[is_many_config $name]} {
1063 lappend arr($name) $value
1065 set arr($name) $value
1067 } elseif {[regexp {^([^\n]+)$} $line line name]} {
1068 # no value given, but interpreting them as
1069 # boolean will be handled as true
1078 set fd_rc [eval [list git_read config --list] $args]
1079 while {[gets $fd_rc line] >= 0} {
1080 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1081 if {[is_many_config $name]} {
1082 lappend arr($name) $value
1084 set arr($name) $value
1086 } elseif {[regexp {^([^=]+)$} $line line name]} {
1087 # no value given, but interpreting them as
1088 # boolean will be handled as true
1097 proc load_config {include_global} {
1098 global repo_config global_config system_config default_config
1100 if {$include_global} {
1101 _parse_config system_config --system
1102 _parse_config global_config --global
1104 _parse_config repo_config
1106 foreach name [array names default_config] {
1107 if {[catch {set v $system_config($name)}]} {
1108 set system_config($name) $default_config($name)
1111 foreach name [array names system_config] {
1112 if {[catch {set v $global_config($name)}]} {
1113 set global_config($name) $system_config($name)
1115 if {[catch {set v $repo_config($name)}]} {
1116 set repo_config($name) $system_config($name)
1121 ######################################################################
1123 ## feature option selection
1125 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1130 if {$subcommand eq {gui.sh}} {
1133 if {$subcommand eq {gui} && [llength $argv] > 0} {
1134 set subcommand [lindex $argv 0]
1135 set argv [lrange $argv 1 end]
1138 enable_option multicommit
1139 enable_option branch
1140 enable_option transport
1143 switch -- $subcommand {
1148 disable_option multicommit
1149 disable_option branch
1150 disable_option transport
1153 enable_option singlecommit
1154 enable_option retcode
1156 disable_option multicommit
1157 disable_option branch
1158 disable_option transport
1160 while {[llength $argv] > 0} {
1161 set a [lindex $argv 0]
1164 enable_option initialamend
1167 enable_option nocommit
1168 enable_option nocommitmsg
1171 disable_option nocommitmsg
1178 set argv [lrange $argv 1 end]
1183 ######################################################################
1185 ## execution environment
1187 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1189 # Suggest our implementation of askpass, if none is set
1190 if {![info exists env(SSH_ASKPASS)]} {
1191 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1194 ######################################################################
1200 set _gitdir $env(GIT_DIR)
1204 # beware that from the .git dir this sets _gitdir to .
1205 # and _prefix to the empty string
1206 set _gitdir [git rev-parse --git-dir]
1207 set _prefix [git rev-parse --show-prefix]
1211 choose_repository::pick
1215 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1216 # run from the .git dir itself) lest the routines to find the worktree
1218 if {$_gitdir eq "."} {
1222 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1223 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1225 if {![file isdirectory $_gitdir]} {
1226 catch {wm withdraw .}
1227 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1230 # _gitdir exists, so try loading the config
1234 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1235 if {[package vsatisfies $_git_version 1.7.0]} {
1236 set _gitworktree [git rev-parse --show-toplevel]
1238 # try to set work tree from environment, core.worktree or use
1239 # cdup to obtain a relative path to the top of the worktree. If
1240 # run from the top, the ./ prefix ensures normalize expands pwd.
1241 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1242 set _gitworktree [get_config core.worktree]
1243 if {$_gitworktree eq ""} {
1244 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1249 if {$_prefix ne {}} {
1250 if {$_gitworktree eq {}} {
1251 regsub -all {[^/]+/} $_prefix ../ cdup
1253 set cdup $_gitworktree
1255 if {[catch {cd $cdup} err]} {
1256 catch {wm withdraw .}
1257 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1260 set _gitworktree [pwd]
1262 } elseif {![is_enabled bare]} {
1264 catch {wm withdraw .}
1265 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1268 if {$_gitworktree eq {}} {
1269 set _gitworktree [file dirname $_gitdir]
1271 if {[catch {cd $_gitworktree} err]} {
1272 catch {wm withdraw .}
1273 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1276 set _gitworktree [pwd]
1278 set _reponame [file split [file normalize $_gitdir]]
1279 if {[lindex $_reponame end] eq {.git}} {
1280 set _reponame [lindex $_reponame end-1]
1282 set _reponame [lindex $_reponame end]
1285 set env(GIT_DIR) $_gitdir
1286 set env(GIT_WORK_TREE) $_gitworktree
1288 ######################################################################
1292 set current_diff_path {}
1293 set current_diff_side {}
1294 set diff_actions [list]
1298 set MERGE_HEAD [list]
1301 set current_branch {}
1303 set current_diff_path {}
1305 set is_submodule_diff 0
1306 set is_conflict_diff 0
1307 set selected_commit_type new
1308 set diff_empty_count 0
1310 set nullid "0000000000000000000000000000000000000000"
1311 set nullid2 "0000000000000000000000000000000000000001"
1313 ######################################################################
1321 set disable_on_lock [list]
1322 set index_lock_type none
1324 proc lock_index {type} {
1325 global index_lock_type disable_on_lock
1327 if {$index_lock_type eq {none}} {
1328 set index_lock_type $type
1329 foreach w $disable_on_lock {
1330 uplevel #0 $w disabled
1333 } elseif {$index_lock_type eq "begin-$type"} {
1334 set index_lock_type $type
1340 proc unlock_index {} {
1341 global index_lock_type disable_on_lock
1343 set index_lock_type none
1344 foreach w $disable_on_lock {
1345 uplevel #0 $w normal
1349 ######################################################################
1353 proc repository_state {ctvar hdvar mhvar} {
1354 global current_branch
1355 upvar $ctvar ct $hdvar hd $mhvar mh
1360 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1366 set merge_head [gitdir MERGE_HEAD]
1367 if {[file exists $merge_head]} {
1369 set fd_mh [open $merge_head r]
1370 while {[gets $fd_mh line] >= 0} {
1381 global PARENT empty_tree
1383 set p [lindex $PARENT 0]
1387 if {$empty_tree eq {}} {
1388 set empty_tree [git mktree << {}]
1393 proc force_amend {} {
1394 global selected_commit_type
1395 global HEAD PARENT MERGE_HEAD commit_type
1397 repository_state newType newHEAD newMERGE_HEAD
1400 set MERGE_HEAD $newMERGE_HEAD
1401 set commit_type $newType
1403 set selected_commit_type amend
1404 do_select_commit_type
1407 proc rescan {after {honor_trustmtime 1}} {
1408 global HEAD PARENT MERGE_HEAD commit_type
1409 global ui_index ui_workdir ui_comm
1410 global rescan_active file_states
1413 if {$rescan_active > 0 || ![lock_index read]} return
1415 repository_state newType newHEAD newMERGE_HEAD
1416 if {[string match amend* $commit_type]
1417 && $newType eq {normal}
1418 && $newHEAD eq $HEAD} {
1422 set MERGE_HEAD $newMERGE_HEAD
1423 set commit_type $newType
1426 array unset file_states
1428 if {!$::GITGUI_BCK_exists &&
1429 (![$ui_comm edit modified]
1430 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1431 if {[string match amend* $commit_type]} {
1432 } elseif {[load_message GITGUI_MSG]} {
1433 } elseif {[run_prepare_commit_msg_hook]} {
1434 } elseif {[load_message MERGE_MSG]} {
1435 } elseif {[load_message SQUASH_MSG]} {
1438 $ui_comm edit modified false
1441 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1442 rescan_stage2 {} $after
1445 ui_status [mc "Refreshing file status..."]
1446 set fd_rf [git_read update-index \
1452 fconfigure $fd_rf -blocking 0 -translation binary
1453 fileevent $fd_rf readable \
1454 [list rescan_stage2 $fd_rf $after]
1459 set is_git_info_exclude {}
1460 proc have_info_exclude {} {
1461 global is_git_info_exclude
1463 if {$is_git_info_exclude eq {}} {
1464 if {[catch {exec test -f [gitdir info exclude]}]} {
1465 set is_git_info_exclude 0
1467 set is_git_info_exclude 1
1470 return $is_git_info_exclude
1473 proc have_info_exclude {} {
1474 return [file readable [gitdir info exclude]]
1478 proc rescan_stage2 {fd after} {
1479 global rescan_active buf_rdi buf_rdf buf_rlo
1483 if {![eof $fd]} return
1487 if {[package vsatisfies $::_git_version 1.6.3]} {
1488 set ls_others [list --exclude-standard]
1490 set ls_others [list --exclude-per-directory=.gitignore]
1491 if {[have_info_exclude]} {
1492 lappend ls_others "--exclude-from=[gitdir info exclude]"
1494 set user_exclude [get_config core.excludesfile]
1495 if {$user_exclude ne {} && [file readable $user_exclude]} {
1496 lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1505 ui_status [mc "Scanning for modified files ..."]
1506 set fd_di [git_read diff-index --cached -z [PARENT]]
1507 set fd_df [git_read diff-files -z]
1508 set fd_lo [eval git_read ls-files --others -z $ls_others]
1510 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1511 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1512 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1513 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1514 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1515 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1518 proc load_message {file} {
1521 set f [gitdir $file]
1522 if {[file isfile $f]} {
1523 if {[catch {set fd [open $f r]}]} {
1526 fconfigure $fd -eofchar {}
1527 set content [string trim [read $fd]]
1529 regsub -all -line {[ \r\t]+$} $content {} content
1530 $ui_comm delete 0.0 end
1531 $ui_comm insert end $content
1537 proc run_prepare_commit_msg_hook {} {
1540 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1541 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1542 # empty file but existent file.
1544 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1546 if {[file isfile [gitdir MERGE_MSG]]} {
1547 set pcm_source "merge"
1548 set fd_mm [open [gitdir MERGE_MSG] r]
1549 puts -nonewline $fd_pcm [read $fd_mm]
1551 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1552 set pcm_source "squash"
1553 set fd_sm [open [gitdir SQUASH_MSG] r]
1554 puts -nonewline $fd_pcm [read $fd_sm]
1562 set fd_ph [githook_read prepare-commit-msg \
1563 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1565 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1569 ui_status [mc "Calling prepare-commit-msg hook..."]
1572 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1573 fileevent $fd_ph readable \
1574 [list prepare_commit_msg_hook_wait $fd_ph]
1579 proc prepare_commit_msg_hook_wait {fd_ph} {
1582 append pch_error [read $fd_ph]
1583 fconfigure $fd_ph -blocking 1
1585 if {[catch {close $fd_ph}]} {
1586 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1587 hook_failed_popup prepare-commit-msg $pch_error
1588 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1591 load_message PREPARE_COMMIT_MSG
1594 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1597 fconfigure $fd_ph -blocking 0
1598 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1601 proc read_diff_index {fd after} {
1604 append buf_rdi [read $fd]
1606 set n [string length $buf_rdi]
1608 set z1 [string first "\0" $buf_rdi $c]
1609 if {$z1 == -1} break
1611 set z2 [string first "\0" $buf_rdi $z1]
1612 if {$z2 == -1} break
1615 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1616 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1618 [encoding convertfrom $p] \
1620 [list [lindex $i 0] [lindex $i 2]] \
1626 set buf_rdi [string range $buf_rdi $c end]
1631 rescan_done $fd buf_rdi $after
1634 proc read_diff_files {fd after} {
1637 append buf_rdf [read $fd]
1639 set n [string length $buf_rdf]
1641 set z1 [string first "\0" $buf_rdf $c]
1642 if {$z1 == -1} break
1644 set z2 [string first "\0" $buf_rdf $z1]
1645 if {$z2 == -1} break
1648 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1649 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1651 [encoding convertfrom $p] \
1654 [list [lindex $i 0] [lindex $i 2]]
1659 set buf_rdf [string range $buf_rdf $c end]
1664 rescan_done $fd buf_rdf $after
1667 proc read_ls_others {fd after} {
1670 append buf_rlo [read $fd]
1671 set pck [split $buf_rlo "\0"]
1672 set buf_rlo [lindex $pck end]
1673 foreach p [lrange $pck 0 end-1] {
1674 set p [encoding convertfrom $p]
1675 if {[string index $p end] eq {/}} {
1676 set p [string range $p 0 end-1]
1680 rescan_done $fd buf_rlo $after
1683 proc rescan_done {fd buf after} {
1684 global rescan_active current_diff_path
1685 global file_states repo_config
1688 if {![eof $fd]} return
1691 if {[incr rescan_active -1] > 0} return
1696 if {$current_diff_path ne {}} { reshow_diff $after }
1697 if {$current_diff_path eq {}} { select_first_diff $after }
1700 proc prune_selection {} {
1701 global file_states selected_paths
1703 foreach path [array names selected_paths] {
1704 if {[catch {set still_here $file_states($path)}]} {
1705 unset selected_paths($path)
1710 ######################################################################
1714 proc mapicon {w state path} {
1717 if {[catch {set r $all_icons($state$w)}]} {
1718 puts "error: no icon for $w state={$state} $path"
1724 proc mapdesc {state path} {
1727 if {[catch {set r $all_descs($state)}]} {
1728 puts "error: no desc for state={$state} $path"
1734 proc ui_status {msg} {
1736 if {[info exists main_status]} {
1737 $main_status show $msg
1741 proc ui_ready {{test {}}} {
1743 if {[info exists main_status]} {
1744 $main_status show [mc "Ready."] $test
1748 proc escape_path {path} {
1749 regsub -all {\\} $path "\\\\" path
1750 regsub -all "\n" $path "\\n" path
1754 proc short_path {path} {
1755 return [escape_path [lindex [file split $path] end]]
1759 set null_sha1 [string repeat 0 40]
1761 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1762 global file_states next_icon_id null_sha1
1764 set s0 [string index $new_state 0]
1765 set s1 [string index $new_state 1]
1767 if {[catch {set info $file_states($path)}]} {
1769 set icon n[incr next_icon_id]
1771 set state [lindex $info 0]
1772 set icon [lindex $info 1]
1773 if {$head_info eq {}} {set head_info [lindex $info 2]}
1774 if {$index_info eq {}} {set index_info [lindex $info 3]}
1777 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1778 elseif {$s0 eq {_}} {set s0 _}
1780 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1781 elseif {$s1 eq {_}} {set s1 _}
1783 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1784 set head_info [list 0 $null_sha1]
1785 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1786 && $head_info eq {}} {
1787 set head_info $index_info
1788 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1789 set index_info $head_info
1793 set file_states($path) [list $s0$s1 $icon \
1794 $head_info $index_info \
1799 proc display_file_helper {w path icon_name old_m new_m} {
1802 if {$new_m eq {_}} {
1803 set lno [lsearch -sorted -exact $file_lists($w) $path]
1805 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1807 $w conf -state normal
1808 $w delete $lno.0 [expr {$lno + 1}].0
1809 $w conf -state disabled
1811 } elseif {$old_m eq {_} && $new_m ne {_}} {
1812 lappend file_lists($w) $path
1813 set file_lists($w) [lsort -unique $file_lists($w)]
1814 set lno [lsearch -sorted -exact $file_lists($w) $path]
1816 $w conf -state normal
1817 $w image create $lno.0 \
1818 -align center -padx 5 -pady 1 \
1820 -image [mapicon $w $new_m $path]
1821 $w insert $lno.1 "[escape_path $path]\n"
1822 $w conf -state disabled
1823 } elseif {$old_m ne $new_m} {
1824 $w conf -state normal
1825 $w image conf $icon_name -image [mapicon $w $new_m $path]
1826 $w conf -state disabled
1830 proc display_file {path state} {
1831 global file_states selected_paths
1832 global ui_index ui_workdir
1834 set old_m [merge_state $path $state]
1835 set s $file_states($path)
1836 set new_m [lindex $s 0]
1837 set icon_name [lindex $s 1]
1839 set o [string index $old_m 0]
1840 set n [string index $new_m 0]
1847 display_file_helper $ui_index $path $icon_name $o $n
1849 if {[string index $old_m 0] eq {U}} {
1852 set o [string index $old_m 1]
1854 if {[string index $new_m 0] eq {U}} {
1857 set n [string index $new_m 1]
1859 display_file_helper $ui_workdir $path $icon_name $o $n
1861 if {$new_m eq {__}} {
1862 unset file_states($path)
1863 catch {unset selected_paths($path)}
1867 proc display_all_files_helper {w path icon_name m} {
1870 lappend file_lists($w) $path
1871 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1872 $w image create end \
1873 -align center -padx 5 -pady 1 \
1875 -image [mapicon $w $m $path]
1876 $w insert end "[escape_path $path]\n"
1880 proc display_all_files {} {
1881 global ui_index ui_workdir
1882 global file_states file_lists
1884 global files_warning
1886 $ui_index conf -state normal
1887 $ui_workdir conf -state normal
1889 $ui_index delete 0.0 end
1890 $ui_workdir delete 0.0 end
1893 set file_lists($ui_index) [list]
1894 set file_lists($ui_workdir) [list]
1896 set to_display [lsort [array names file_states]]
1897 set display_limit [get_config gui.maxfilesdisplayed]
1898 if {[llength $to_display] > $display_limit} {
1899 if {!$files_warning} {
1900 # do not repeatedly warn:
1902 info_popup [mc "Displaying only %s of %s files." \
1903 $display_limit [llength $to_display]]
1905 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1907 foreach path $to_display {
1908 set s $file_states($path)
1910 set icon_name [lindex $s 1]
1912 set s [string index $m 0]
1913 if {$s ne {U} && $s ne {_}} {
1914 display_all_files_helper $ui_index $path \
1918 if {[string index $m 0] eq {U}} {
1921 set s [string index $m 1]
1924 display_all_files_helper $ui_workdir $path \
1929 $ui_index conf -state disabled
1930 $ui_workdir conf -state disabled
1933 ######################################################################
1938 #define mask_width 14
1939 #define mask_height 15
1940 static unsigned char mask_bits[] = {
1941 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1942 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1943 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1946 image create bitmap file_plain -background white -foreground black -data {
1947 #define plain_width 14
1948 #define plain_height 15
1949 static unsigned char plain_bits[] = {
1950 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1951 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1952 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1953 } -maskdata $filemask
1955 image create bitmap file_mod -background white -foreground blue -data {
1956 #define mod_width 14
1957 #define mod_height 15
1958 static unsigned char mod_bits[] = {
1959 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1960 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1961 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1962 } -maskdata $filemask
1964 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1965 #define file_fulltick_width 14
1966 #define file_fulltick_height 15
1967 static unsigned char file_fulltick_bits[] = {
1968 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1969 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1970 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1971 } -maskdata $filemask
1973 image create bitmap file_question -background white -foreground black -data {
1974 #define file_question_width 14
1975 #define file_question_height 15
1976 static unsigned char file_question_bits[] = {
1977 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1978 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1979 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1980 } -maskdata $filemask
1982 image create bitmap file_removed -background white -foreground red -data {
1983 #define file_removed_width 14
1984 #define file_removed_height 15
1985 static unsigned char file_removed_bits[] = {
1986 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1987 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1988 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1989 } -maskdata $filemask
1991 image create bitmap file_merge -background white -foreground blue -data {
1992 #define file_merge_width 14
1993 #define file_merge_height 15
1994 static unsigned char file_merge_bits[] = {
1995 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1996 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1997 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1998 } -maskdata $filemask
2000 image create bitmap file_statechange -background white -foreground green -data {
2001 #define file_statechange_width 14
2002 #define file_statechange_height 15
2003 static unsigned char file_statechange_bits[] = {
2004 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
2005 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
2006 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2007 } -maskdata $filemask
2009 set ui_index .vpane.files.index.list
2010 set ui_workdir .vpane.files.workdir.list
2012 set all_icons(_$ui_index) file_plain
2013 set all_icons(A$ui_index) file_plain
2014 set all_icons(M$ui_index) file_fulltick
2015 set all_icons(D$ui_index) file_removed
2016 set all_icons(U$ui_index) file_merge
2017 set all_icons(T$ui_index) file_statechange
2019 set all_icons(_$ui_workdir) file_plain
2020 set all_icons(M$ui_workdir) file_mod
2021 set all_icons(D$ui_workdir) file_question
2022 set all_icons(U$ui_workdir) file_merge
2023 set all_icons(O$ui_workdir) file_plain
2024 set all_icons(T$ui_workdir) file_statechange
2026 set max_status_desc 0
2028 {__ {mc "Unmodified"}}
2030 {_M {mc "Modified, not staged"}}
2031 {M_ {mc "Staged for commit"}}
2032 {MM {mc "Portions staged for commit"}}
2033 {MD {mc "Staged for commit, missing"}}
2035 {_T {mc "File type changed, not staged"}}
2036 {MT {mc "File type changed, old type staged for commit"}}
2037 {AT {mc "File type changed, old type staged for commit"}}
2038 {T_ {mc "File type changed, staged"}}
2039 {TM {mc "File type change staged, modification not staged"}}
2040 {TD {mc "File type change staged, file missing"}}
2042 {_O {mc "Untracked, not staged"}}
2043 {A_ {mc "Staged for commit"}}
2044 {AM {mc "Portions staged for commit"}}
2045 {AD {mc "Staged for commit, missing"}}
2048 {D_ {mc "Staged for removal"}}
2049 {DO {mc "Staged for removal, still present"}}
2051 {_U {mc "Requires merge resolution"}}
2052 {U_ {mc "Requires merge resolution"}}
2053 {UU {mc "Requires merge resolution"}}
2054 {UM {mc "Requires merge resolution"}}
2055 {UD {mc "Requires merge resolution"}}
2056 {UT {mc "Requires merge resolution"}}
2058 set text [eval [lindex $i 1]]
2059 if {$max_status_desc < [string length $text]} {
2060 set max_status_desc [string length $text]
2062 set all_descs([lindex $i 0]) $text
2066 ######################################################################
2070 proc scrollbar2many {list mode args} {
2071 foreach w $list {eval $w $mode $args}
2074 proc many2scrollbar {list mode sb top bottom} {
2075 $sb set $top $bottom
2076 foreach w $list {$w $mode moveto $top}
2079 proc incr_font_size {font {amt 1}} {
2080 set sz [font configure $font -size]
2082 font configure $font -size $sz
2083 font configure ${font}bold -size $sz
2084 font configure ${font}italic -size $sz
2087 ######################################################################
2091 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2093 proc do_gitk {revs {is_submodule false}} {
2094 global current_diff_path file_states current_diff_side ui_index
2095 global _gitdir _gitworktree
2097 # -- Always start gitk through whatever we were loaded with. This
2098 # lets us bypass using shell process on Windows systems.
2100 set exe [_which gitk -script]
2101 set cmd [list [info nameofexecutable] $exe]
2103 error_popup [mc "Couldn't find gitk in PATH"]
2109 if {!$is_submodule} {
2114 cd $current_diff_path
2115 if {$revs eq {--}} {
2116 set s $file_states($current_diff_path)
2119 switch -glob -- [lindex $s 0] {
2120 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2121 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2123 if {$current_diff_side eq $ui_index} {
2124 set old_sha1 [lindex [lindex $s 2] 1]
2125 set new_sha1 [lindex [lindex $s 3] 1]
2127 set old_sha1 [lindex [lindex $s 3] 1]
2131 set revs $old_sha1...$new_sha1
2133 # GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2134 # we've been using for the main repository, so unset them.
2135 # TODO we could make life easier (start up faster?) for gitk
2136 # by setting these to the appropriate values to allow gitk
2137 # to skip the heuristics to find their proper value
2139 unset env(GIT_WORK_TREE)
2141 eval exec $cmd $revs "--" "--" &
2143 set env(GIT_DIR) $_gitdir
2144 set env(GIT_WORK_TREE) $_gitworktree
2147 ui_status $::starting_gitk_msg
2149 ui_ready $starting_gitk_msg
2154 proc do_git_gui {} {
2155 global current_diff_path
2157 # -- Always start git gui through whatever we were loaded with. This
2158 # lets us bypass using shell process on Windows systems.
2160 set exe [list [_which git]]
2162 error_popup [mc "Couldn't find git gui in PATH"]
2165 global _gitdir _gitworktree
2167 # see note in do_gitk about unsetting these vars when
2168 # running tools in a submodule
2170 unset env(GIT_WORK_TREE)
2173 cd $current_diff_path
2175 eval exec $exe gui &
2177 set env(GIT_DIR) $_gitdir
2178 set env(GIT_WORK_TREE) $_gitworktree
2181 ui_status $::starting_gitk_msg
2183 ui_ready $starting_gitk_msg
2188 proc do_explore {} {
2191 if {[is_Cygwin] || [is_Windows]} {
2192 set explorer "explorer.exe"
2193 } elseif {[is_MacOSX]} {
2196 # freedesktop.org-conforming system is our best shot
2197 set explorer "xdg-open"
2199 eval exec $explorer [list [file nativename $_gitworktree]] &
2205 proc terminate_me {win} {
2207 if {$win ne {.}} return
2211 proc do_quit {{rc {1}}} {
2212 global ui_comm is_quitting repo_config commit_type
2213 global GITGUI_BCK_exists GITGUI_BCK_i
2214 global ui_comm_spell
2215 global ret_code use_ttk
2217 if {$is_quitting} return
2220 if {[winfo exists $ui_comm]} {
2221 # -- Stash our current commit buffer.
2223 set save [gitdir GITGUI_MSG]
2224 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2225 file rename -force [gitdir GITGUI_BCK] $save
2226 set GITGUI_BCK_exists 0
2228 set msg [string trim [$ui_comm get 0.0 end]]
2229 regsub -all -line {[ \r\t]+$} $msg {} msg
2230 if {(![string match amend* $commit_type]
2231 || [$ui_comm edit modified])
2234 set fd [open $save w]
2235 puts -nonewline $fd $msg
2239 catch {file delete $save}
2243 # -- Cancel our spellchecker if its running.
2245 if {[info exists ui_comm_spell]} {
2249 # -- Remove our editor backup, its not needed.
2251 after cancel $GITGUI_BCK_i
2252 if {$GITGUI_BCK_exists} {
2253 catch {file delete [gitdir GITGUI_BCK]}
2256 # -- Stash our current window geometry into this repository.
2258 set cfg_wmstate [wm state .]
2259 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2262 if {$cfg_wmstate ne $rc_wmstate} {
2263 catch {git config gui.wmstate $cfg_wmstate}
2265 if {$cfg_wmstate eq {zoomed}} {
2266 # on Windows wm geometry will lie about window
2267 # position (but not size) when window is zoomed
2268 # restore the window before querying wm geometry
2271 set cfg_geometry [list]
2272 lappend cfg_geometry [wm geometry .]
2274 lappend cfg_geometry [.vpane sashpos 0]
2275 lappend cfg_geometry [.vpane.files sashpos 0]
2277 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2278 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2280 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2283 if {$cfg_geometry ne $rc_geometry} {
2284 catch {git config gui.geometry $cfg_geometry}
2290 # Briefly enable send again, working around Tk bug
2291 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2292 tk appname [appname]
2301 proc ui_do_rescan {} {
2302 rescan {force_first_diff ui_ready}
2309 proc next_diff {{after {}}} {
2310 global next_diff_p next_diff_w next_diff_i
2311 show_diff $next_diff_p $next_diff_w {} {} $after
2314 proc find_anchor_pos {lst name} {
2315 set lid [lsearch -sorted -exact $lst $name]
2319 foreach lname $lst {
2320 if {$lname >= $name} break
2328 proc find_file_from {flist idx delta path mmask} {
2331 set len [llength $flist]
2332 while {$idx >= 0 && $idx < $len} {
2333 set name [lindex $flist $idx]
2335 if {$name ne $path && [info exists file_states($name)]} {
2336 set state [lindex $file_states($name) 0]
2338 if {$mmask eq {} || [regexp $mmask $state]} {
2349 proc find_next_diff {w path {lno {}} {mmask {}}} {
2350 global next_diff_p next_diff_w next_diff_i
2351 global file_lists ui_index ui_workdir
2353 set flist $file_lists($w)
2355 set lno [find_anchor_pos $flist $path]
2360 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2361 if {$w eq $ui_index} {
2364 set mmask "$mmask\$"
2368 set idx [find_file_from $flist $lno 1 $path $mmask]
2371 set idx [find_file_from $flist $lno -1 $path $mmask]
2376 set next_diff_p [lindex $flist $idx]
2377 set next_diff_i [expr {$idx+1}]
2384 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2385 global current_diff_path
2387 if {$path ne $current_diff_path} {
2389 } elseif {[find_next_diff $w $path $lno $mmask]} {
2392 return {reshow_diff;}
2396 proc select_first_diff {after} {
2399 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2400 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2407 proc force_first_diff {after} {
2408 global ui_workdir current_diff_path file_states
2410 if {[info exists file_states($current_diff_path)]} {
2411 set state [lindex $file_states($current_diff_path) 0]
2417 if {[string first {U} $state] >= 0} {
2418 # Already a conflict, do nothing
2419 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2421 } elseif {[string index $state 1] ne {O}} {
2422 # Already a diff & no conflicts, do nothing
2423 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2434 proc toggle_or_diff {w x y} {
2435 global file_states file_lists current_diff_path ui_index ui_workdir
2436 global last_clicked selected_paths
2438 set pos [split [$w index @$x,$y] .]
2439 set lno [lindex $pos 0]
2440 set col [lindex $pos 1]
2441 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2447 set last_clicked [list $w $lno]
2448 array unset selected_paths
2449 $ui_index tag remove in_sel 0.0 end
2450 $ui_workdir tag remove in_sel 0.0 end
2452 # Determine the state of the file
2453 if {[info exists file_states($path)]} {
2454 set state [lindex $file_states($path) 0]
2459 # Restage the file, or simply show the diff
2460 if {$col == 0 && $y > 1} {
2461 # Conflicts need special handling
2462 if {[string first {U} $state] >= 0} {
2463 # $w must always be $ui_workdir, but...
2464 if {$w ne $ui_workdir} { set lno {} }
2465 merge_stage_workdir $path $lno
2469 if {[string index $state 1] eq {O}} {
2475 set after [next_diff_after_action $w $path $lno $mmask]
2477 if {$w eq $ui_index} {
2479 "Unstaging [short_path $path] from commit" \
2481 [concat $after [list ui_ready]]
2482 } elseif {$w eq $ui_workdir} {
2484 "Adding [short_path $path]" \
2486 [concat $after [list ui_ready]]
2489 set selected_paths($path) 1
2490 show_diff $path $w $lno
2494 proc add_one_to_selection {w x y} {
2495 global file_lists last_clicked selected_paths
2497 set lno [lindex [split [$w index @$x,$y] .] 0]
2498 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2504 if {$last_clicked ne {}
2505 && [lindex $last_clicked 0] ne $w} {
2506 array unset selected_paths
2507 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2510 set last_clicked [list $w $lno]
2511 if {[catch {set in_sel $selected_paths($path)}]} {
2515 unset selected_paths($path)
2516 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2518 set selected_paths($path) 1
2519 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2523 proc add_range_to_selection {w x y} {
2524 global file_lists last_clicked selected_paths
2526 if {[lindex $last_clicked 0] ne $w} {
2527 toggle_or_diff $w $x $y
2531 set lno [lindex [split [$w index @$x,$y] .] 0]
2532 set lc [lindex $last_clicked 1]
2541 foreach path [lrange $file_lists($w) \
2542 [expr {$begin - 1}] \
2543 [expr {$end - 1}]] {
2544 set selected_paths($path) 1
2546 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2549 proc show_more_context {} {
2551 if {$repo_config(gui.diffcontext) < 99} {
2552 incr repo_config(gui.diffcontext)
2557 proc show_less_context {} {
2559 if {$repo_config(gui.diffcontext) > 1} {
2560 incr repo_config(gui.diffcontext) -1
2565 ######################################################################
2573 menu .mbar -tearoff 0
2575 # -- Apple Menu (Mac OS X only)
2577 .mbar add cascade -label Apple -menu .mbar.apple
2580 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2581 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2582 if {[is_enabled branch]} {
2583 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2585 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2586 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2588 if {[is_enabled transport]} {
2589 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2590 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2592 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2593 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2596 # -- Repository Menu
2598 menu .mbar.repository
2601 .mbar.repository add command \
2602 -label [mc "Explore Working Copy"] \
2603 -command {do_explore}
2604 .mbar.repository add separator
2607 .mbar.repository add command \
2608 -label [mc "Browse Current Branch's Files"] \
2609 -command {browser::new $current_branch}
2610 set ui_browse_current [.mbar.repository index last]
2611 .mbar.repository add command \
2612 -label [mc "Browse Branch Files..."] \
2613 -command browser_open::dialog
2614 .mbar.repository add separator
2616 .mbar.repository add command \
2617 -label [mc "Visualize Current Branch's History"] \
2618 -command {do_gitk $current_branch}
2619 set ui_visualize_current [.mbar.repository index last]
2620 .mbar.repository add command \
2621 -label [mc "Visualize All Branch History"] \
2622 -command {do_gitk --all}
2623 .mbar.repository add separator
2625 proc current_branch_write {args} {
2626 global current_branch
2627 .mbar.repository entryconf $::ui_browse_current \
2628 -label [mc "Browse %s's Files" $current_branch]
2629 .mbar.repository entryconf $::ui_visualize_current \
2630 -label [mc "Visualize %s's History" $current_branch]
2632 trace add variable current_branch write current_branch_write
2634 if {[is_enabled multicommit]} {
2635 .mbar.repository add command -label [mc "Database Statistics"] \
2638 .mbar.repository add command -label [mc "Compress Database"] \
2641 .mbar.repository add command -label [mc "Verify Database"] \
2642 -command do_fsck_objects
2644 .mbar.repository add separator
2647 .mbar.repository add command \
2648 -label [mc "Create Desktop Icon"] \
2649 -command do_cygwin_shortcut
2650 } elseif {[is_Windows]} {
2651 .mbar.repository add command \
2652 -label [mc "Create Desktop Icon"] \
2653 -command do_windows_shortcut
2654 } elseif {[is_MacOSX]} {
2655 .mbar.repository add command \
2656 -label [mc "Create Desktop Icon"] \
2657 -command do_macosx_app
2662 proc ::tk::mac::Quit {args} { do_quit }
2664 .mbar.repository add command -label [mc Quit] \
2672 .mbar.edit add command -label [mc Undo] \
2673 -command {catch {[focus] edit undo}} \
2675 .mbar.edit add command -label [mc Redo] \
2676 -command {catch {[focus] edit redo}} \
2678 .mbar.edit add separator
2679 .mbar.edit add command -label [mc Cut] \
2680 -command {catch {tk_textCut [focus]}} \
2682 .mbar.edit add command -label [mc Copy] \
2683 -command {catch {tk_textCopy [focus]}} \
2685 .mbar.edit add command -label [mc Paste] \
2686 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2688 .mbar.edit add command -label [mc Delete] \
2689 -command {catch {[focus] delete sel.first sel.last}} \
2691 .mbar.edit add separator
2692 .mbar.edit add command -label [mc "Select All"] \
2693 -command {catch {[focus] tag add sel 0.0 end}} \
2698 if {[is_enabled branch]} {
2701 .mbar.branch add command -label [mc "Create..."] \
2702 -command branch_create::dialog \
2704 lappend disable_on_lock [list .mbar.branch entryconf \
2705 [.mbar.branch index last] -state]
2707 .mbar.branch add command -label [mc "Checkout..."] \
2708 -command branch_checkout::dialog \
2710 lappend disable_on_lock [list .mbar.branch entryconf \
2711 [.mbar.branch index last] -state]
2713 .mbar.branch add command -label [mc "Rename..."] \
2714 -command branch_rename::dialog
2715 lappend disable_on_lock [list .mbar.branch entryconf \
2716 [.mbar.branch index last] -state]
2718 .mbar.branch add command -label [mc "Delete..."] \
2719 -command branch_delete::dialog
2720 lappend disable_on_lock [list .mbar.branch entryconf \
2721 [.mbar.branch index last] -state]
2723 .mbar.branch add command -label [mc "Reset..."] \
2724 -command merge::reset_hard
2725 lappend disable_on_lock [list .mbar.branch entryconf \
2726 [.mbar.branch index last] -state]
2731 proc commit_btn_caption {} {
2732 if {[is_enabled nocommit]} {
2735 return [mc Commit@@verb]
2739 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2742 if {![is_enabled nocommit]} {
2743 .mbar.commit add radiobutton \
2744 -label [mc "New Commit"] \
2745 -command do_select_commit_type \
2746 -variable selected_commit_type \
2748 lappend disable_on_lock \
2749 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2751 .mbar.commit add radiobutton \
2752 -label [mc "Amend Last Commit"] \
2753 -command do_select_commit_type \
2754 -variable selected_commit_type \
2756 lappend disable_on_lock \
2757 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2759 .mbar.commit add separator
2762 .mbar.commit add command -label [mc Rescan] \
2763 -command ui_do_rescan \
2765 lappend disable_on_lock \
2766 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2768 .mbar.commit add command -label [mc "Stage To Commit"] \
2769 -command do_add_selection \
2771 lappend disable_on_lock \
2772 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2774 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2775 -command do_add_all \
2777 lappend disable_on_lock \
2778 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2780 .mbar.commit add command -label [mc "Unstage From Commit"] \
2781 -command do_unstage_selection \
2783 lappend disable_on_lock \
2784 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2786 .mbar.commit add command -label [mc "Revert Changes"] \
2787 -command do_revert_selection \
2789 lappend disable_on_lock \
2790 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2792 .mbar.commit add separator
2794 .mbar.commit add command -label [mc "Show Less Context"] \
2795 -command show_less_context \
2796 -accelerator $M1T-\-
2798 .mbar.commit add command -label [mc "Show More Context"] \
2799 -command show_more_context \
2802 .mbar.commit add separator
2804 if {![is_enabled nocommitmsg]} {
2805 .mbar.commit add command -label [mc "Sign Off"] \
2806 -command do_signoff \
2810 .mbar.commit add command -label [commit_btn_caption] \
2811 -command do_commit \
2812 -accelerator $M1T-Return
2813 lappend disable_on_lock \
2814 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2819 if {[is_enabled branch]} {
2821 .mbar.merge add command -label [mc "Local Merge..."] \
2822 -command merge::dialog \
2824 lappend disable_on_lock \
2825 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2826 .mbar.merge add command -label [mc "Abort Merge..."] \
2827 -command merge::reset_hard
2828 lappend disable_on_lock \
2829 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2834 if {[is_enabled transport]} {
2837 .mbar.remote add command \
2838 -label [mc "Add..."] \
2839 -command remote_add::dialog \
2841 .mbar.remote add command \
2842 -label [mc "Push..."] \
2843 -command do_push_anywhere \
2845 .mbar.remote add command \
2846 -label [mc "Delete Branch..."] \
2847 -command remote_branch_delete::dialog
2851 proc ::tk::mac::ShowPreferences {} {do_options}
2855 .mbar.edit add separator
2856 .mbar.edit add command -label [mc "Options..."] \
2862 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2863 set tools_menubar .mbar.tools
2865 $tools_menubar add separator
2866 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2867 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2869 if {[array names repo_config guitool.*.cmd] ne {}} {
2876 .mbar add cascade -label [mc Help] -menu .mbar.help
2880 .mbar.apple add command -label [mc "About %s" [appname]] \
2882 .mbar.apple add separator
2884 .mbar.help add command -label [mc "About %s" [appname]] \
2887 . configure -menu .mbar
2889 set doc_path [githtmldir]
2890 if {$doc_path ne {}} {
2891 set doc_path [file join $doc_path index.html]
2894 set doc_path [exec cygpath --mixed $doc_path]
2898 if {[file isfile $doc_path]} {
2899 set doc_url "file:$doc_path"
2901 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2904 proc start_browser {url} {
2905 git "web--browse" $url
2908 .mbar.help add command -label [mc "Online Documentation"] \
2909 -command [list start_browser $doc_url]
2911 .mbar.help add command -label [mc "Show SSH Key"] \
2914 unset doc_path doc_url
2916 # -- Standard bindings
2918 wm protocol . WM_DELETE_WINDOW do_quit
2919 bind all <$M1B-Key-q> do_quit
2920 bind all <$M1B-Key-Q> do_quit
2921 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2922 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2924 set subcommand_args {}
2926 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2927 if {[tk windowingsystem] eq "win32"} {
2929 tk_messageBox -icon info -message $s \
2937 proc normalize_relpath {path} {
2939 foreach item [file split $path] {
2940 if {$item eq {.}} continue
2941 if {$item eq {..} && [llength $elements] > 0
2942 && [lindex $elements end] ne {..}} {
2943 set elements [lrange $elements 0 end-1]
2946 lappend elements $item
2948 return [eval file join $elements]
2951 # -- Not a normal commit type invocation? Do that instead!
2953 switch -- $subcommand {
2956 if {$subcommand eq "blame"} {
2957 set subcommand_args {[--line=<num>] rev? path}
2959 set subcommand_args {rev? path}
2961 if {$argv eq {}} usage
2967 if {$is_path || [file exists $_prefix$a]} {
2968 if {$path ne {}} usage
2969 set path [normalize_relpath $_prefix$a]
2971 } elseif {$a eq {--}} {
2973 if {$head ne {}} usage
2978 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2979 if {$jump_spec ne {} || $head ne {}} usage
2980 set jump_spec [list $lnum]
2981 } elseif {$head eq {}} {
2982 if {$head ne {}} usage
2991 if {$head ne {} && $path eq {}} {
2992 set path [normalize_relpath $_prefix$head]
2999 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
3001 set head [git rev-parse --verify $head]
3003 if {[tk windowingsystem] eq "win32"} {
3004 tk_messageBox -icon error -title [mc Error] -message $err
3011 set current_branch $head
3015 switch -- $subcommand {
3017 if {$jump_spec ne {}} usage
3019 if {$path ne {} && [file isdirectory $path]} {
3020 set head $current_branch
3026 browser::new $head $path
3029 if {$head eq {} && ![file exists $path]} {
3030 catch {wm withdraw .}
3034 -title [mc "git-gui: fatal error"] \
3035 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
3038 blame::new $head $path $jump_spec
3045 if {[llength $argv] != 0} {
3048 # fall through to setup UI for commits
3051 set err "usage: $argv0 \[{blame|browser|citool}\]"
3052 if {[tk windowingsystem] eq "win32"} {
3054 tk_messageBox -icon error -message $err \
3065 ${NS}::frame .branch
3066 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3067 ${NS}::label .branch.l1 \
3068 -text [mc "Current Branch:"] \
3071 ${NS}::label .branch.cb \
3072 -textvariable current_branch \
3075 pack .branch.l1 -side left
3076 pack .branch.cb -side left -fill x
3077 pack .branch -side top -fill x
3079 # -- Main Window Layout
3081 ${NS}::panedwindow .vpane -orient horizontal
3082 ${NS}::panedwindow .vpane.files -orient vertical
3084 .vpane add .vpane.files
3086 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3088 pack .vpane -anchor n -side top -fill both -expand 1
3090 # -- Index File List
3092 ${NS}::frame .vpane.files.index -height 100 -width 200
3093 tlabel .vpane.files.index.title \
3094 -text [mc "Staged Changes (Will Commit)"] \
3095 -background lightgreen -foreground black
3096 text $ui_index -background white -foreground black \
3098 -width 20 -height 10 \
3100 -cursor $cursor_ptr \
3101 -xscrollcommand {.vpane.files.index.sx set} \
3102 -yscrollcommand {.vpane.files.index.sy set} \
3104 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3105 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3106 pack .vpane.files.index.title -side top -fill x
3107 pack .vpane.files.index.sx -side bottom -fill x
3108 pack .vpane.files.index.sy -side right -fill y
3109 pack $ui_index -side left -fill both -expand 1
3111 # -- Working Directory File List
3113 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3114 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3115 -background lightsalmon -foreground black
3116 text $ui_workdir -background white -foreground black \
3118 -width 20 -height 10 \
3120 -cursor $cursor_ptr \
3121 -xscrollcommand {.vpane.files.workdir.sx set} \
3122 -yscrollcommand {.vpane.files.workdir.sy set} \
3124 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3125 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3126 pack .vpane.files.workdir.title -side top -fill x
3127 pack .vpane.files.workdir.sx -side bottom -fill x
3128 pack .vpane.files.workdir.sy -side right -fill y
3129 pack $ui_workdir -side left -fill both -expand 1
3131 .vpane.files add .vpane.files.workdir
3132 .vpane.files add .vpane.files.index
3134 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3135 .vpane.files paneconfigure .vpane.files.index -sticky news
3138 foreach i [list $ui_index $ui_workdir] {
3140 $i tag conf in_diff -background [$i tag cget in_sel -background]
3144 # -- Diff and Commit Area
3146 ${NS}::frame .vpane.lower -height 300 -width 400
3147 ${NS}::frame .vpane.lower.commarea
3148 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3149 pack .vpane.lower.diff -fill both -expand 1
3150 pack .vpane.lower.commarea -side bottom -fill x
3151 .vpane add .vpane.lower
3152 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3154 # -- Commit Area Buttons
3156 ${NS}::frame .vpane.lower.commarea.buttons
3157 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3160 pack .vpane.lower.commarea.buttons.l -side top -fill x
3161 pack .vpane.lower.commarea.buttons -side left -fill y
3163 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3164 -command ui_do_rescan
3165 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3166 lappend disable_on_lock \
3167 {.vpane.lower.commarea.buttons.rescan conf -state}
3169 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3171 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3172 lappend disable_on_lock \
3173 {.vpane.lower.commarea.buttons.incall conf -state}
3175 if {![is_enabled nocommitmsg]} {
3176 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3178 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3181 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3183 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3184 lappend disable_on_lock \
3185 {.vpane.lower.commarea.buttons.commit conf -state}
3187 if {![is_enabled nocommit]} {
3188 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3189 -command do_push_anywhere
3190 pack .vpane.lower.commarea.buttons.push -side top -fill x
3193 # -- Commit Message Buffer
3195 ${NS}::frame .vpane.lower.commarea.buffer
3196 ${NS}::frame .vpane.lower.commarea.buffer.header
3197 set ui_comm .vpane.lower.commarea.buffer.t
3198 set ui_coml .vpane.lower.commarea.buffer.header.l
3200 if {![is_enabled nocommit]} {
3201 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3202 -text [mc "New Commit"] \
3203 -command do_select_commit_type \
3204 -variable selected_commit_type \
3206 lappend disable_on_lock \
3207 [list .vpane.lower.commarea.buffer.header.new conf -state]
3208 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3209 -text [mc "Amend Last Commit"] \
3210 -command do_select_commit_type \
3211 -variable selected_commit_type \
3213 lappend disable_on_lock \
3214 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3217 ${NS}::label $ui_coml \
3220 proc trace_commit_type {varname args} {
3221 global ui_coml commit_type
3222 switch -glob -- $commit_type {
3223 initial {set txt [mc "Initial Commit Message:"]}
3224 amend {set txt [mc "Amended Commit Message:"]}
3225 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3226 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3227 merge {set txt [mc "Merge Commit Message:"]}
3228 * {set txt [mc "Commit Message:"]}
3230 $ui_coml conf -text $txt
3232 trace add variable commit_type write trace_commit_type
3233 pack $ui_coml -side left -fill x
3235 if {![is_enabled nocommit]} {
3236 pack .vpane.lower.commarea.buffer.header.amend -side right
3237 pack .vpane.lower.commarea.buffer.header.new -side right
3240 text $ui_comm -background white -foreground black \
3244 -autoseparators true \
3246 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3248 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3249 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3250 -command [list $ui_comm yview]
3251 pack .vpane.lower.commarea.buffer.header -side top -fill x
3252 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3253 pack $ui_comm -side left -fill y
3254 pack .vpane.lower.commarea.buffer -side left -fill y
3256 # -- Commit Message Buffer Context Menu
3258 set ctxm .vpane.lower.commarea.buffer.ctxm
3259 menu $ctxm -tearoff 0
3262 -command {tk_textCut $ui_comm}
3265 -command {tk_textCopy $ui_comm}
3268 -command {tk_textPaste $ui_comm}
3270 -label [mc Delete] \
3271 -command {catch {$ui_comm delete sel.first sel.last}}
3274 -label [mc "Select All"] \
3275 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3277 -label [mc "Copy All"] \
3279 $ui_comm tag add sel 0.0 end
3280 tk_textCopy $ui_comm
3281 $ui_comm tag remove sel 0.0 end
3285 -label [mc "Sign Off"] \
3287 set ui_comm_ctxm $ctxm
3291 proc trace_current_diff_path {varname args} {
3292 global current_diff_path diff_actions file_states
3293 if {$current_diff_path eq {}} {
3299 set p $current_diff_path
3300 set s [mapdesc [lindex $file_states($p) 0] $p]
3302 set p [escape_path $p]
3306 .vpane.lower.diff.header.status configure -text $s
3307 .vpane.lower.diff.header.file configure -text $f
3308 .vpane.lower.diff.header.path configure -text $p
3309 foreach w $diff_actions {
3313 trace add variable current_diff_path write trace_current_diff_path
3315 gold_frame .vpane.lower.diff.header
3316 tlabel .vpane.lower.diff.header.status \
3319 -width $max_status_desc \
3322 tlabel .vpane.lower.diff.header.file \
3327 tlabel .vpane.lower.diff.header.path \
3332 pack .vpane.lower.diff.header.status -side left
3333 pack .vpane.lower.diff.header.file -side left
3334 pack .vpane.lower.diff.header.path -fill x
3335 set ctxm .vpane.lower.diff.header.ctxm
3336 menu $ctxm -tearoff 0
3344 -- $current_diff_path
3346 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3347 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3351 ${NS}::frame .vpane.lower.diff.body
3352 set ui_diff .vpane.lower.diff.body.t
3353 text $ui_diff -background white -foreground black \
3355 -width 80 -height 5 -wrap none \
3357 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3358 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3360 catch {$ui_diff configure -tabstyle wordprocessor}
3361 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3362 -command [list $ui_diff xview]
3363 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3364 -command [list $ui_diff yview]
3365 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3366 pack .vpane.lower.diff.body.sby -side right -fill y
3367 pack $ui_diff -side left -fill both -expand 1
3368 pack .vpane.lower.diff.header -side top -fill x
3369 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3371 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3372 $ui_diff tag configure clr4$n -background $c
3373 $ui_diff tag configure clri4$n -foreground $c
3374 $ui_diff tag configure clr3$n -foreground $c
3375 $ui_diff tag configure clri3$n -background $c
3377 $ui_diff tag configure clr1 -font font_diffbold
3379 $ui_diff tag conf d_info -foreground blue -font font_diffbold
3381 $ui_diff tag conf d_cr -elide true
3382 $ui_diff tag conf d_@ -font font_diffbold
3383 $ui_diff tag conf d_+ -foreground {#00a000}
3384 $ui_diff tag conf d_- -foreground red
3386 $ui_diff tag conf d_++ -foreground {#00a000}
3387 $ui_diff tag conf d_-- -foreground red
3388 $ui_diff tag conf d_+s \
3389 -foreground {#00a000} \
3390 -background {#e2effa}
3391 $ui_diff tag conf d_-s \
3393 -background {#e2effa}
3394 $ui_diff tag conf d_s+ \
3395 -foreground {#00a000} \
3397 $ui_diff tag conf d_s- \
3401 $ui_diff tag conf d< \
3402 -foreground orange \
3404 $ui_diff tag conf d= \
3405 -foreground orange \
3407 $ui_diff tag conf d> \
3408 -foreground orange \
3411 $ui_diff tag raise sel
3413 # -- Diff Body Context Menu
3416 proc create_common_diff_popup {ctxm} {
3418 -label [mc Refresh] \
3419 -command reshow_diff
3420 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3423 -command {tk_textCopy $ui_diff}
3424 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3426 -label [mc "Select All"] \
3427 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3428 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3430 -label [mc "Copy All"] \
3432 $ui_diff tag add sel 0.0 end
3433 tk_textCopy $ui_diff
3434 $ui_diff tag remove sel 0.0 end
3436 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3439 -label [mc "Decrease Font Size"] \
3440 -command {incr_font_size font_diff -1}
3441 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3443 -label [mc "Increase Font Size"] \
3444 -command {incr_font_size font_diff 1}
3445 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3449 build_encoding_menu $emenu [list force_diff_encoding]
3451 -label [mc "Encoding"] \
3453 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3455 $ctxm add command -label [mc "Options..."] \
3459 set ctxm .vpane.lower.diff.body.ctxm
3460 menu $ctxm -tearoff 0
3462 -label [mc "Apply/Reverse Hunk"] \
3463 -command {apply_hunk $cursorX $cursorY}
3464 set ui_diff_applyhunk [$ctxm index last]
3465 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3467 -label [mc "Apply/Reverse Line"] \
3468 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3469 set ui_diff_applyline [$ctxm index last]
3470 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3473 -label [mc "Show Less Context"] \
3474 -command show_less_context
3475 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3477 -label [mc "Show More Context"] \
3478 -command show_more_context
3479 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3481 create_common_diff_popup $ctxm
3483 set ctxmmg .vpane.lower.diff.body.ctxmmg
3484 menu $ctxmmg -tearoff 0
3485 $ctxmmg add command \
3486 -label [mc "Run Merge Tool"] \
3487 -command {merge_resolve_tool}
3488 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3489 $ctxmmg add separator
3490 $ctxmmg add command \
3491 -label [mc "Use Remote Version"] \
3492 -command {merge_resolve_one 3}
3493 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3494 $ctxmmg add command \
3495 -label [mc "Use Local Version"] \
3496 -command {merge_resolve_one 2}
3497 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3498 $ctxmmg add command \
3499 -label [mc "Revert To Base"] \
3500 -command {merge_resolve_one 1}
3501 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3502 $ctxmmg add separator
3503 $ctxmmg add command \
3504 -label [mc "Show Less Context"] \
3505 -command show_less_context
3506 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3507 $ctxmmg add command \
3508 -label [mc "Show More Context"] \
3509 -command show_more_context
3510 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3511 $ctxmmg add separator
3512 create_common_diff_popup $ctxmmg
3514 set ctxmsm .vpane.lower.diff.body.ctxmsm
3515 menu $ctxmsm -tearoff 0
3516 $ctxmsm add command \
3517 -label [mc "Visualize These Changes In The Submodule"] \
3518 -command {do_gitk -- true}
3519 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3520 $ctxmsm add command \
3521 -label [mc "Visualize Current Branch History In The Submodule"] \
3522 -command {do_gitk {} true}
3523 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3524 $ctxmsm add command \
3525 -label [mc "Visualize All Branch History In The Submodule"] \
3526 -command {do_gitk --all true}
3527 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3528 $ctxmsm add separator
3529 $ctxmsm add command \
3530 -label [mc "Start git gui In The Submodule"] \
3531 -command {do_git_gui}
3532 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3533 $ctxmsm add separator
3534 create_common_diff_popup $ctxmsm
3536 proc has_textconv {path} {
3537 if {[is_config_false gui.textconv]} {
3540 set filter [gitattr $path diff set]
3541 set textconv [get_config [join [list diff $filter textconv] .]]
3542 if {$filter ne {set} && $textconv ne {}} {
3549 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3550 global current_diff_path file_states
3553 if {[info exists file_states($current_diff_path)]} {
3554 set state [lindex $file_states($current_diff_path) 0]
3558 if {[string first {U} $state] >= 0} {
3559 tk_popup $ctxmmg $X $Y
3560 } elseif {$::is_submodule_diff} {
3561 tk_popup $ctxmsm $X $Y
3563 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3564 if {$::ui_index eq $::current_diff_side} {
3565 set l [mc "Unstage Hunk From Commit"]
3567 set t [mc "Unstage Lines From Commit"]
3569 set t [mc "Unstage Line From Commit"]
3572 set l [mc "Stage Hunk For Commit"]
3574 set t [mc "Stage Lines For Commit"]
3576 set t [mc "Stage Line For Commit"]
3580 || $current_diff_path eq {}
3583 || [string match {?T} $state]
3584 || [string match {T?} $state]
3585 || [has_textconv $current_diff_path]} {
3590 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3591 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3592 tk_popup $ctxm $X $Y
3595 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3599 set main_status [::status_bar::new .status]
3600 pack .status -anchor w -side bottom -fill x
3601 $main_status show [mc "Initializing..."]
3605 proc on_ttk_pane_mapped {w pane pos} {
3607 after 0 [list after idle [list $w sashpos $pane $pos]]
3609 proc on_tk_pane_mapped {w pane x y} {
3611 after 0 [list after idle [list $w sash place $pane $x $y]]
3613 proc on_application_mapped {} {
3614 global repo_config use_ttk
3616 set gm $repo_config(gui.geometry)
3619 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3620 bind .vpane.files <Map> \
3621 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3624 [list on_tk_pane_mapped %W 0 \
3626 [lindex [.vpane sash coord 0] 1]]
3627 bind .vpane.files <Map> \
3628 [list on_tk_pane_mapped %W 0 \
3629 [lindex [.vpane.files sash coord 0] 0] \
3632 wm geometry . [lindex $gm 0]
3634 if {[info exists repo_config(gui.geometry)]} {
3635 bind . <Map> [list on_application_mapped]
3636 wm geometry . [lindex $repo_config(gui.geometry) 0]
3639 # -- Load window state
3641 if {[info exists repo_config(gui.wmstate)]} {
3642 catch {wm state . $repo_config(gui.wmstate)}
3647 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3648 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3649 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3650 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3651 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3652 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3653 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3654 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3655 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3656 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3657 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3658 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3659 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3660 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3661 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3662 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3663 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3664 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3665 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3666 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3667 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3668 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3670 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3671 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3672 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3673 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3674 bind $ui_diff <$M1B-Key-v> {break}
3675 bind $ui_diff <$M1B-Key-V> {break}
3676 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3677 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3678 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3679 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3680 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3681 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3682 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3683 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3684 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3685 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3686 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3687 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3688 bind $ui_diff <Button-1> {focus %W}
3690 if {[is_enabled branch]} {
3691 bind . <$M1B-Key-n> branch_create::dialog
3692 bind . <$M1B-Key-N> branch_create::dialog
3693 bind . <$M1B-Key-o> branch_checkout::dialog
3694 bind . <$M1B-Key-O> branch_checkout::dialog
3695 bind . <$M1B-Key-m> merge::dialog
3696 bind . <$M1B-Key-M> merge::dialog
3698 if {[is_enabled transport]} {
3699 bind . <$M1B-Key-p> do_push_anywhere
3700 bind . <$M1B-Key-P> do_push_anywhere
3703 bind . <Key-F5> ui_do_rescan
3704 bind . <$M1B-Key-r> ui_do_rescan
3705 bind . <$M1B-Key-R> ui_do_rescan
3706 bind . <$M1B-Key-s> do_signoff
3707 bind . <$M1B-Key-S> do_signoff
3708 bind . <$M1B-Key-t> do_add_selection
3709 bind . <$M1B-Key-T> do_add_selection
3710 bind . <$M1B-Key-j> do_revert_selection
3711 bind . <$M1B-Key-J> do_revert_selection
3712 bind . <$M1B-Key-i> do_add_all
3713 bind . <$M1B-Key-I> do_add_all
3714 bind . <$M1B-Key-minus> {show_less_context;break}
3715 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3716 bind . <$M1B-Key-equal> {show_more_context;break}
3717 bind . <$M1B-Key-plus> {show_more_context;break}
3718 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3719 bind . <$M1B-Key-Return> do_commit
3720 foreach i [list $ui_index $ui_workdir] {
3721 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3722 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3723 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3727 set file_lists($ui_index) [list]
3728 set file_lists($ui_workdir) [list]
3730 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3731 focus -force $ui_comm
3733 # -- Warn the user about environmental problems. Cygwin's Tcl
3734 # does *not* pass its env array onto any processes it spawns.
3735 # This means that git processes get none of our environment.
3740 set msg [mc "Possible environment issues exist.
3742 The following environment variables are probably
3743 going to be ignored by any Git subprocess run
3747 foreach name [array names env] {
3748 switch -regexp -- $name {
3749 {^GIT_INDEX_FILE$} -
3750 {^GIT_OBJECT_DIRECTORY$} -
3751 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3753 {^GIT_EXTERNAL_DIFF$} -
3757 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3758 append msg " - $name\n"
3761 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3762 append msg " - $name\n"
3764 set suggest_user $name
3768 if {$ignored_env > 0} {
3770 This is due to a known issue with the
3771 Tcl binary distributed by Cygwin."]
3773 if {$suggest_user ne {}} {
3776 A good replacement for %s
3777 is placing values for the user.name and
3778 user.email settings into your personal
3784 unset ignored_env msg suggest_user name
3787 # -- Only initialize complex UI if we are going to stay running.
3789 if {[is_enabled transport]} {
3792 set n [.mbar.remote index end]
3793 populate_remotes_menu
3794 set n [expr {[.mbar.remote index end] - $n}]
3796 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3797 .mbar.remote insert $n separator
3802 if {[winfo exists $ui_comm]} {
3803 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3805 # -- If both our backup and message files exist use the
3806 # newer of the two files to initialize the buffer.
3808 if {$GITGUI_BCK_exists} {
3809 set m [gitdir GITGUI_MSG]
3810 if {[file isfile $m]} {
3811 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3812 catch {file delete [gitdir GITGUI_MSG]}
3814 $ui_comm delete 0.0 end
3816 $ui_comm edit modified false
3817 catch {file delete [gitdir GITGUI_BCK]}
3818 set GITGUI_BCK_exists 0
3824 proc backup_commit_buffer {} {
3825 global ui_comm GITGUI_BCK_exists
3827 set m [$ui_comm edit modified]
3828 if {$m || $GITGUI_BCK_exists} {
3829 set msg [string trim [$ui_comm get 0.0 end]]
3830 regsub -all -line {[ \r\t]+$} $msg {} msg
3833 if {$GITGUI_BCK_exists} {
3834 catch {file delete [gitdir GITGUI_BCK]}
3835 set GITGUI_BCK_exists 0
3839 set fd [open [gitdir GITGUI_BCK] w]
3840 puts -nonewline $fd $msg
3842 set GITGUI_BCK_exists 1
3846 $ui_comm edit modified false
3849 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3852 backup_commit_buffer
3854 # -- If the user has aspell available we can drive it
3855 # in pipe mode to spellcheck the commit message.
3857 set spell_cmd [list |]
3858 set spell_dict [get_config gui.spellingdictionary]
3859 lappend spell_cmd aspell
3860 if {$spell_dict ne {}} {
3861 lappend spell_cmd --master=$spell_dict
3863 lappend spell_cmd --mode=none
3864 lappend spell_cmd --encoding=utf-8
3865 lappend spell_cmd pipe
3866 if {$spell_dict eq {none}
3867 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3868 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3870 set ui_comm_spell [spellcheck::init \
3876 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3879 lock_index begin-read
3880 if {![winfo ismapped .]} {
3884 if {[is_enabled initialamend]} {
3890 if {[is_enabled nocommitmsg]} {
3891 $ui_comm configure -state disabled -background gray
3894 if {[is_enabled multicommit]} {
3897 if {[is_enabled retcode]} {
3898 bind . <Destroy> {+terminate_me %W}
3900 if {$picked && [is_config_true gui.autoexplore]} {
3906 # indent-tabs-mode: t