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)}]} {
302 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
309 proc is_config_false
{name
} {
311 if {[catch
{set v
$repo_config($name)}]} {
313 } elseif
{$v eq
{false
} ||
$v eq
{0} ||
$v eq
{no
}} {
320 proc get_config
{name
} {
322 if {[catch
{set v
$repo_config($name)}]} {
334 if {$_isbare eq
{}} {
336 set _bare
[git rev-parse
--is-bare-repository]
338 true
{ set _isbare
1 }
339 false
{ set _isbare
0}
343 if {[is_config_true core.bare
]
344 ||
($_gitworktree eq
{}
345 && [lindex
[file split $_gitdir] end
] ne
{.git
})} {
355 ######################################################################
359 proc _trace_exec
{cmd
} {
360 if {!$
::_trace
} return
366 if {[regexp
{[ \t\r\n'"$?*]} $v]} {
374 #'" fix poor old emacs font-lock mode
376 proc _git_cmd {name} {
379 if {[catch {set v $_git_cmd_path($name)}]} {
383 --exec-path { return [list $::_git $name] }
386 set p [gitexec git-$name$::_search_exe]
387 if {[file exists $p]} {
389 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
390 # Try to determine what sort of magic will make
391 # git-$name go and do its thing, because native
392 # Tcl on Windows doesn't know it.
394 set p [gitexec git-$name]
399 switch -glob -- [lindex $s 0] {
401 #!*perl { set i perl }
402 #!*python { set i python }
403 default { error "git-
$name is not supported
: $s" }
407 if {![info exists interp]} {
408 set interp [_which $i]
411 error "git-
$name requires
$i (not
in PATH
)"
413 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
415 # Assume it is builtin to git somehow and we
416 # aren't actually able to see a file for it.
418 set v [list $::_git $name]
420 set _git_cmd_path($name) $v
425 proc _which {what args} {
426 global env _search_exe _search_path
428 if {$_search_path eq {}} {
429 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
430 set _search_path [split [exec cygpath \
436 } elseif {[is_Windows]} {
437 set gitguidir [file dirname [info script]]
438 regsub -all ";" $gitguidir "\\;" gitguidir
439 set env(PATH) "$gitguidir;$env(PATH
)"
440 set _search_path [split $env(PATH) {;}]
443 set _search_path [split $env(PATH) :]
448 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
451 set suffix $_search_exe
454 foreach p $_search_path {
455 set p [file join $p $what$suffix]
456 if {[file exists $p]} {
457 return [file normalize $p]
463 proc _lappend_nice {cmd_var} {
467 if {![info exists _nice]} {
468 set _nice [_which nice]
469 if {[catch {exec $_nice git version}]} {
471 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
484 switch -- [lindex $args 0] {
495 set args [lrange $args 1 end]
498 set cmdp [_git_cmd [lindex $args 0]]
499 set args [lrange $args 1 end]
501 _trace_exec [concat $opt $cmdp $args]
502 set result [eval exec $opt $cmdp $args]
504 puts stderr "< $result"
509 proc _open_stdout_stderr {cmd} {
512 set fd [open [concat [list | ] $cmd] r]
514 if { [lindex $cmd end] eq {2>@1}
515 && $err eq {can not find channel named "1"}
517 # Older versions of Tcl 8.4 don't have this 2>@1 IO
518 # redirect operator. Fallback to |& cat for those.
519 # The command was not actually started, so its safe
520 # to try to start it a second time.
522 set fd [open [concat \
524 [lrange $cmd 0 end-1] \
531 fconfigure $fd -eofchar {}
535 proc git_read {args} {
539 switch -- [lindex $args 0] {
554 set args [lrange $args 1 end]
557 set cmdp [_git_cmd [lindex $args 0]]
558 set args [lrange $args 1 end]
560 return [_open_stdout_stderr [concat $opt $cmdp $args]]
563 proc git_write {args} {
567 switch -- [lindex $args 0] {
578 set args [lrange $args 1 end]
581 set cmdp [_git_cmd [lindex $args 0]]
582 set args [lrange $args 1 end]
584 _trace_exec [concat $opt $cmdp $args]
585 return [open [concat [list | ] $opt $cmdp $args] w]
588 proc githook_read {hook_name args} {
589 set pchook [gitdir hooks $hook_name]
592 # On Windows [file executable] might lie so we need to ask
593 # the shell if the hook is executable. Yes that's annoying.
597 if {![info exists interp]} {
598 set interp [_which sh]
601 error "hook execution requires sh
(not
in PATH
)"
604 set scr {if test -x "$1";then exec "$@
";fi}
605 set sh_c [list $interp -c $scr $interp $pchook]
606 return [_open_stdout_stderr [concat $sh_c $args]]
609 if {[file executable $pchook]} {
610 return [_open_stdout_stderr [concat [list $pchook] $args]]
616 proc kill_file_process {fd} {
617 set process [pid $fd]
621 # Use a Cygwin-specific flag to allow killing
622 # native Windows processes
623 exec kill -f $process
630 proc gitattr {path attr default} {
631 if {[catch {set r [git check-attr $attr -- $path]}]} {
634 set r [join [lrange [split $r :] 2 end] :]
637 if {$r eq {unspecified}} {
644 regsub -all ' $value "'\\''" value
648 proc load_current_branch {} {
649 global current_branch is_detached
651 set fd [open [gitdir HEAD] r]
652 if {[gets $fd ref] < 1} {
657 set pfx {ref: refs/heads/}
658 set len [string length $pfx]
659 if {[string equal -length $len $pfx $ref]} {
660 # We're on a branch. It might not exist. But
661 # HEAD looks good enough to be a branch.
663 set current_branch
[string range
$ref $len end
]
666 # Assume this is a detached head.
668 set current_branch HEAD
673 auto_load tk_optionMenu
674 rename tk_optionMenu real__tkOptionMenu
675 proc tk_optionMenu
{w varName args
} {
676 set m
[eval real__tkOptionMenu
$w $varName $args]
677 $m configure
-font font_ui
678 $w configure
-font font_ui
682 proc rmsel_tag
{text
} {
684 -background [$text cget
-background] \
685 -foreground [$text cget
-foreground] \
687 $text tag conf in_sel
-background lightgray
688 bind $text <Motion
> break
694 bind .
<Visibility
> {
695 bind .
<Visibility
> {}
700 wm iconbitmap .
-default $oguilib/git-gui.ico
701 set ::tk
::AlwaysShowSelection
1
702 bind .
<Control-F2
> {console show
}
704 # Spoof an X11 display for SSH
705 if {![info exists env
(DISPLAY
)]} {
706 set env
(DISPLAY
) :9999
710 image create photo gitlogo
-width 16 -height 16
712 gitlogo put
#33CC33 -to 7 0 9 2
713 gitlogo put
#33CC33 -to 4 2 12 4
714 gitlogo put
#33CC33 -to 7 4 9 6
715 gitlogo put
#CC3333 -to 4 6 12 8
716 gitlogo put gray26
-to 4 9 6 10
717 gitlogo put gray26
-to 3 10 6 12
718 gitlogo put gray26
-to 8 9 13 11
719 gitlogo put gray26
-to 8 11 10 12
720 gitlogo put gray26
-to 11 11 13 14
721 gitlogo put gray26
-to 3 12 5 14
722 gitlogo put gray26
-to 5 13
723 gitlogo put gray26
-to 10 13
724 gitlogo put gray26
-to 4 14 12 15
725 gitlogo put gray26
-to 5 15 11 16
728 wm iconphoto .
-default gitlogo
732 ######################################################################
738 if {[lsearch
-exact [font names
] TkDefaultFont
] != -1} {
739 eval [linsert
[font actual TkDefaultFont
] 0 font configure font_ui
]
740 eval [linsert
[font actual TkFixedFont
] 0 font create font_diff
]
742 font create font_diff
-family Courier
-size 10
745 eval font configure font_ui
[font actual
[.dummy cget
-font]]
750 font create font_uiitalic
751 font create font_uibold
752 font create font_diffbold
753 font create font_diffitalic
755 foreach class
{Button Checkbutton Entry Label
756 Labelframe Listbox Message
757 Radiobutton Spinbox Text
} {
758 option add
*$class.font font_ui
761 option add
*Menu.font font_ui
762 option add
*Entry.borderWidth
1 startupFile
763 option add
*Entry.relief sunken startupFile
764 option add
*RadioButton.anchor w startupFile
768 if {[is_Windows
] ||
[is_MacOSX
]} {
769 option add
*Menu.tearOff
0
780 proc bind_button3
{w cmd
} {
781 bind $w <Any-Button-3
> $cmd
783 # Mac OS X sends Button-2 on right click through three-button mouse,
784 # or through trackpad right-clicking (two-finger touch + click).
785 bind $w <Any-Button-2
> $cmd
786 bind $w <Control-Button-1
> $cmd
790 proc apply_config
{} {
791 global repo_config font_descs
793 foreach option
$font_descs {
794 set name
[lindex
$option 0]
795 set font
[lindex
$option 1]
798 foreach
{cn cv
} $repo_config(gui.
$name) {
799 if {$cn eq
{-weight}} {
802 font configure
$font $cn $cv
805 font configure
$font -weight normal
808 error_popup
[strcat
[mc
"Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
810 foreach
{cn cv
} [font configure
$font] {
811 font configure
${font}bold
$cn $cv
812 font configure
${font}italic
$cn $cv
814 font configure
${font}bold
-weight bold
815 font configure
${font}italic
-slant italic
821 if {$repo_config(gui.usettk
)} {
822 set use_ttk
[package vsatisfies
[package provide Tk
] 8.5]
825 bind [winfo class .
] <<ThemeChanged>> [list InitTheme]
831 set default_config(branch.autosetupmerge) true
832 set default_config(merge.tool) {}
833 set default_config(mergetool.keepbackup) true
834 set default_config(merge.diffstat) true
835 set default_config(merge.summary) false
836 set default_config(merge.verbosity) 2
837 set default_config(user.name) {}
838 set default_config(user.email) {}
840 set default_config(gui.encoding) [encoding system]
841 set default_config(gui.matchtrackingbranch) false
842 set default_config(gui.textconv) true
843 set default_config(gui.pruneduringfetch) false
844 set default_config(gui.trustmtime) false
845 set default_config(gui.fastcopyblame) false
846 set default_config(gui.copyblamethreshold) 40
847 set default_config(gui.blamehistoryctx) 7
848 set default_config(gui.diffcontext) 5
849 set default_config(gui.commitmsgwidth) 75
850 set default_config(gui.newbranchtemplate) {}
851 set default_config(gui.spellingdictionary) {}
852 set default_config(gui.fontui) [font configure font_ui]
853 set default_config(gui.fontdiff) [font configure font_diff]
854 # TODO: this option should be added to the git-config documentation
855 set default_config(gui.maxfilesdisplayed) 5000
856 set default_config(gui.usettk) 1
858 {fontui font_ui {mc "Main Font"}}
859 {fontdiff font_diff {mc "Diff/Console Font"}}
862 ######################################################################
866 set _git [_which git]
868 catch {wm withdraw .}
872 -title [mc "git-gui: fatal error"] \
873 -message [mc "Cannot find git in PATH."]
877 ######################################################################
881 if {[catch {set _git_version [git --version]} err]} {
882 catch {wm withdraw .}
886 -title [mc "git-gui: fatal error"] \
887 -message "Cannot determine Git version:
891 [appname] requires Git 1.5.0 or later."
894 if {![regsub {^git version } $_git_version {} _git_version]} {
895 catch {wm withdraw .}
899 -title [mc "git-gui: fatal error"] \
900 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
904 proc get_trimmed_version {s} {
906 foreach x [split $s -._] {
907 if {[string is integer -strict $x]} {
915 set _real_git_version $_git_version
916 set _git_version [get_trimmed_version $_git_version]
918 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
919 catch {wm withdraw .}
924 -title "[appname]: warning" \
925 -message [mc "Git version cannot be determined.
927 %s claims it is version '%s'.
929 %s requires at least Git 1.5.0 or later.
931 Assume '%s' is version 1.5.0?
932 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
933 set _git_version 1.5.0
938 unset _real_git_version
940 proc git-version {args} {
943 switch [llength $args] {
949 set op [lindex $args 0]
950 set vr [lindex $args 1]
951 set cm [package vcompare $_git_version $vr]
952 return [expr $cm $op 0]
956 set type [lindex $args 0]
957 set name [lindex $args 1]
958 set parm [lindex $args 2]
959 set body [lindex $args 3]
961 if {($type ne {proc} && $type ne {method})} {
962 error "Invalid arguments to git-version"
964 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
965 error "Last arm of $type $name must be default"
968 foreach {op vr cb} [lrange $body 0 end-2] {
969 if {[git-version $op $vr]} {
970 return [uplevel [list $type $name $parm $cb]]
974 return [uplevel [list $type $name $parm [lindex $body end]]]
978 error "git-version >= x"
984 if {[git-version < 1.5]} {
985 catch {wm withdraw .}
989 -title [mc "git-gui: fatal error"] \
990 -message "[appname] requires Git 1.5.0 or later.
992 You are using [git-version]:
998 ######################################################################
1000 ## configure our library
1002 set idx [file join $oguilib tclIndex]
1003 if {[catch {set fd [open $idx r]} err]} {
1004 catch {wm withdraw .}
1008 -title [mc "git-gui: fatal error"] \
1012 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1014 while {[gets $fd n] >= 0} {
1015 if {$n ne {} && ![string match #* $n]} {
1027 if {[lsearch -exact $loaded $p] >= 0} continue
1028 source [file join $oguilib $p]
1033 set auto_path [concat [list $oguilib] $auto_path]
1035 unset -nocomplain idx fd
1037 ######################################################################
1039 ## config file parsing
1041 git-version proc _parse_config {arr_name args} {
1048 [list git_read config] \
1050 [list --null --list]]
1051 fconfigure $fd_rc -translation binary
1052 set buf [read $fd_rc]
1055 foreach line [split $buf "\0"] {
1056 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1057 if {[is_many_config $name]} {
1058 lappend arr($name) $value
1060 set arr($name) $value
1069 set fd_rc [eval [list git_read config --list] $args]
1070 while {[gets $fd_rc line] >= 0} {
1071 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1072 if {[is_many_config $name]} {
1073 lappend arr($name) $value
1075 set arr($name) $value
1084 proc load_config {include_global} {
1085 global repo_config global_config system_config default_config
1087 if {$include_global} {
1088 _parse_config system_config --system
1089 _parse_config global_config --global
1091 _parse_config repo_config
1093 foreach name [array names default_config] {
1094 if {[catch {set v $system_config($name)}]} {
1095 set system_config($name) $default_config($name)
1098 foreach name [array names system_config] {
1099 if {[catch {set v $global_config($name)}]} {
1100 set global_config($name) $system_config($name)
1102 if {[catch {set v $repo_config($name)}]} {
1103 set repo_config($name) $system_config($name)
1108 ######################################################################
1110 ## feature option selection
1112 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1117 if {$subcommand eq {gui.sh}} {
1120 if {$subcommand eq {gui} && [llength $argv] > 0} {
1121 set subcommand [lindex $argv 0]
1122 set argv [lrange $argv 1 end]
1125 enable_option multicommit
1126 enable_option branch
1127 enable_option transport
1130 switch -- $subcommand {
1135 disable_option multicommit
1136 disable_option branch
1137 disable_option transport
1140 enable_option singlecommit
1141 enable_option retcode
1143 disable_option multicommit
1144 disable_option branch
1145 disable_option transport
1147 while {[llength $argv] > 0} {
1148 set a [lindex $argv 0]
1151 enable_option initialamend
1154 enable_option nocommit
1155 enable_option nocommitmsg
1158 disable_option nocommitmsg
1165 set argv [lrange $argv 1 end]
1170 ######################################################################
1172 ## execution environment
1174 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1176 # Suggest our implementation of askpass, if none is set
1177 if {![info exists env(SSH_ASKPASS)]} {
1178 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1180 if {![info exists env(GIT_ASK_YESNO)]} {
1181 set env(GIT_ASK_YESNO) [gitexec git-gui--askyesno]
1184 ######################################################################
1190 set _gitdir $env(GIT_DIR)
1194 # beware that from the .git dir this sets _gitdir to .
1195 # and _prefix to the empty string
1196 set _gitdir [git rev-parse --git-dir]
1197 set _prefix [git rev-parse --show-prefix]
1201 choose_repository::pick
1205 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1206 # run from the .git dir itself) lest the routines to find the worktree
1208 if {$_gitdir eq "."} {
1212 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1213 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1215 if {![file isdirectory $_gitdir]} {
1216 catch {wm withdraw .}
1217 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1220 # _gitdir exists, so try loading the config
1224 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1225 if {[package vsatisfies $_git_version 1.7.0]} {
1226 set _gitworktree [git rev-parse --show-toplevel]
1228 # try to set work tree from environment, core.worktree or use
1229 # cdup to obtain a relative path to the top of the worktree. If
1230 # run from the top, the ./ prefix ensures normalize expands pwd.
1231 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1232 set _gitworktree [get_config core.worktree]
1233 if {$_gitworktree eq ""} {
1234 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1239 if {$_prefix ne {}} {
1240 if {$_gitworktree eq {}} {
1241 regsub -all {[^/]+/} $_prefix ../ cdup
1243 set cdup $_gitworktree
1245 if {[catch {cd $cdup} err]} {
1246 catch {wm withdraw .}
1247 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1250 set _gitworktree [pwd]
1252 } elseif {![is_enabled bare]} {
1254 catch {wm withdraw .}
1255 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1258 if {$_gitworktree eq {}} {
1259 set _gitworktree [file dirname $_gitdir]
1261 if {[catch {cd $_gitworktree} err]} {
1262 catch {wm withdraw .}
1263 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1266 set _gitworktree [pwd]
1268 set _reponame [file split [file normalize $_gitdir]]
1269 if {[lindex $_reponame end] eq {.git}} {
1270 set _reponame [lindex $_reponame end-1]
1272 set _reponame [lindex $_reponame end]
1275 ######################################################################
1279 set current_diff_path {}
1280 set current_diff_side {}
1281 set diff_actions [list]
1285 set MERGE_HEAD [list]
1288 set current_branch {}
1290 set current_diff_path {}
1292 set is_submodule_diff 0
1293 set is_conflict_diff 0
1294 set selected_commit_type new
1295 set diff_empty_count 0
1297 set nullid "0000000000000000000000000000000000000000"
1298 set nullid2 "0000000000000000000000000000000000000001"
1300 ######################################################################
1308 set disable_on_lock [list]
1309 set index_lock_type none
1311 proc lock_index {type} {
1312 global index_lock_type disable_on_lock
1314 if {$index_lock_type eq {none}} {
1315 set index_lock_type $type
1316 foreach w $disable_on_lock {
1317 uplevel #0 $w disabled
1320 } elseif {$index_lock_type eq "begin-$type"} {
1321 set index_lock_type $type
1327 proc unlock_index {} {
1328 global index_lock_type disable_on_lock
1330 set index_lock_type none
1331 foreach w $disable_on_lock {
1332 uplevel #0 $w normal
1336 ######################################################################
1340 proc repository_state {ctvar hdvar mhvar} {
1341 global current_branch
1342 upvar $ctvar ct $hdvar hd $mhvar mh
1347 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1353 set merge_head [gitdir MERGE_HEAD]
1354 if {[file exists $merge_head]} {
1356 set fd_mh [open $merge_head r]
1357 while {[gets $fd_mh line] >= 0} {
1368 global PARENT empty_tree
1370 set p [lindex $PARENT 0]
1374 if {$empty_tree eq {}} {
1375 set empty_tree [git mktree << {}]
1380 proc force_amend {} {
1381 global selected_commit_type
1382 global HEAD PARENT MERGE_HEAD commit_type
1384 repository_state newType newHEAD newMERGE_HEAD
1387 set MERGE_HEAD $newMERGE_HEAD
1388 set commit_type $newType
1390 set selected_commit_type amend
1391 do_select_commit_type
1394 proc rescan {after {honor_trustmtime 1}} {
1395 global HEAD PARENT MERGE_HEAD commit_type
1396 global ui_index ui_workdir ui_comm
1397 global rescan_active file_states
1400 if {$rescan_active > 0 || ![lock_index read]} return
1402 repository_state newType newHEAD newMERGE_HEAD
1403 if {[string match amend* $commit_type]
1404 && $newType eq {normal}
1405 && $newHEAD eq $HEAD} {
1409 set MERGE_HEAD $newMERGE_HEAD
1410 set commit_type $newType
1413 array unset file_states
1415 if {!$::GITGUI_BCK_exists &&
1416 (![$ui_comm edit modified]
1417 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1418 if {[string match amend* $commit_type]} {
1419 } elseif {[load_message GITGUI_MSG]} {
1420 } elseif {[run_prepare_commit_msg_hook]} {
1421 } elseif {[load_message MERGE_MSG]} {
1422 } elseif {[load_message SQUASH_MSG]} {
1425 $ui_comm edit modified false
1428 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1429 rescan_stage2 {} $after
1432 ui_status [mc "Refreshing file status..."]
1433 set fd_rf [git_read update-index \
1439 fconfigure $fd_rf -blocking 0 -translation binary
1440 fileevent $fd_rf readable \
1441 [list rescan_stage2 $fd_rf $after]
1446 set is_git_info_exclude {}
1447 proc have_info_exclude {} {
1448 global is_git_info_exclude
1450 if {$is_git_info_exclude eq {}} {
1451 if {[catch {exec test -f [gitdir info exclude]}]} {
1452 set is_git_info_exclude 0
1454 set is_git_info_exclude 1
1457 return $is_git_info_exclude
1460 proc have_info_exclude {} {
1461 return [file readable [gitdir info exclude]]
1465 proc rescan_stage2 {fd after} {
1466 global rescan_active buf_rdi buf_rdf buf_rlo
1470 if {![eof $fd]} return
1474 if {[package vsatisfies $::_git_version 1.6.3]} {
1475 set ls_others [list --exclude-standard]
1477 set ls_others [list --exclude-per-directory=.gitignore]
1478 if {[have_info_exclude]} {
1479 lappend ls_others "--exclude-from=[gitdir info exclude]"
1481 set user_exclude [get_config core.excludesfile]
1482 if {$user_exclude ne {} && [file readable $user_exclude]} {
1483 lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1492 ui_status [mc "Scanning for modified files ..."]
1493 set fd_di [git_read diff-index --cached -z [PARENT]]
1494 set fd_df [git_read diff-files -z]
1495 set fd_lo [eval git_read ls-files --others -z $ls_others]
1497 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1498 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1499 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1500 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1501 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1502 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1505 proc load_message {file} {
1508 set f [gitdir $file]
1509 if {[file isfile $f]} {
1510 if {[catch {set fd [open $f r]}]} {
1513 fconfigure $fd -eofchar {}
1514 set content [string trim [read $fd]]
1516 regsub -all -line {[ \r\t]+$} $content {} content
1517 $ui_comm delete 0.0 end
1518 $ui_comm insert end $content
1524 proc run_prepare_commit_msg_hook {} {
1527 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1528 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1529 # empty file but existant file.
1531 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1533 if {[file isfile [gitdir MERGE_MSG]]} {
1534 set pcm_source "merge"
1535 set fd_mm [open [gitdir MERGE_MSG] r]
1536 puts -nonewline $fd_pcm [read $fd_mm]
1538 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1539 set pcm_source "squash"
1540 set fd_sm [open [gitdir SQUASH_MSG] r]
1541 puts -nonewline $fd_pcm [read $fd_sm]
1549 set fd_ph [githook_read prepare-commit-msg \
1550 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1552 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1556 ui_status [mc "Calling prepare-commit-msg hook..."]
1559 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1560 fileevent $fd_ph readable \
1561 [list prepare_commit_msg_hook_wait $fd_ph]
1566 proc prepare_commit_msg_hook_wait {fd_ph} {
1569 append pch_error [read $fd_ph]
1570 fconfigure $fd_ph -blocking 1
1572 if {[catch {close $fd_ph}]} {
1573 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1574 hook_failed_popup prepare-commit-msg $pch_error
1575 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1578 load_message PREPARE_COMMIT_MSG
1581 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1584 fconfigure $fd_ph -blocking 0
1585 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1588 proc read_diff_index {fd after} {
1591 append buf_rdi [read $fd]
1593 set n [string length $buf_rdi]
1595 set z1 [string first "\0" $buf_rdi $c]
1596 if {$z1 == -1} break
1598 set z2 [string first "\0" $buf_rdi $z1]
1599 if {$z2 == -1} break
1602 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1603 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1605 [encoding convertfrom $p] \
1607 [list [lindex $i 0] [lindex $i 2]] \
1613 set buf_rdi [string range $buf_rdi $c end]
1618 rescan_done $fd buf_rdi $after
1621 proc read_diff_files {fd after} {
1624 append buf_rdf [read $fd]
1626 set n [string length $buf_rdf]
1628 set z1 [string first "\0" $buf_rdf $c]
1629 if {$z1 == -1} break
1631 set z2 [string first "\0" $buf_rdf $z1]
1632 if {$z2 == -1} break
1635 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1636 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1638 [encoding convertfrom $p] \
1641 [list [lindex $i 0] [lindex $i 2]]
1646 set buf_rdf [string range $buf_rdf $c end]
1651 rescan_done $fd buf_rdf $after
1654 proc read_ls_others {fd after} {
1657 append buf_rlo [read $fd]
1658 set pck [split $buf_rlo "\0"]
1659 set buf_rlo [lindex $pck end]
1660 foreach p [lrange $pck 0 end-1] {
1661 set p [encoding convertfrom $p]
1662 if {[string index $p end] eq {/}} {
1663 set p [string range $p 0 end-1]
1667 rescan_done $fd buf_rlo $after
1670 proc rescan_done {fd buf after} {
1671 global rescan_active current_diff_path
1672 global file_states repo_config
1675 if {![eof $fd]} return
1678 if {[incr rescan_active -1] > 0} return
1683 if {$current_diff_path ne {}} { reshow_diff $after }
1684 if {$current_diff_path eq {}} { select_first_diff $after }
1687 proc prune_selection {} {
1688 global file_states selected_paths
1690 foreach path [array names selected_paths] {
1691 if {[catch {set still_here $file_states($path)}]} {
1692 unset selected_paths($path)
1697 ######################################################################
1701 proc mapicon {w state path} {
1704 if {[catch {set r $all_icons($state$w)}]} {
1705 puts "error: no icon for $w state={$state} $path"
1711 proc mapdesc {state path} {
1714 if {[catch {set r $all_descs($state)}]} {
1715 puts "error: no desc for state={$state} $path"
1721 proc ui_status {msg} {
1723 if {[info exists main_status]} {
1724 $main_status show $msg
1728 proc ui_ready {{test {}}} {
1730 if {[info exists main_status]} {
1731 $main_status show [mc "Ready."] $test
1735 proc escape_path {path} {
1736 regsub -all {\\} $path "\\\\" path
1737 regsub -all "\n" $path "\\n" path
1741 proc short_path {path} {
1742 return [escape_path [lindex [file split $path] end]]
1746 set null_sha1 [string repeat 0 40]
1748 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1749 global file_states next_icon_id null_sha1
1751 set s0 [string index $new_state 0]
1752 set s1 [string index $new_state 1]
1754 if {[catch {set info $file_states($path)}]} {
1756 set icon n[incr next_icon_id]
1758 set state [lindex $info 0]
1759 set icon [lindex $info 1]
1760 if {$head_info eq {}} {set head_info [lindex $info 2]}
1761 if {$index_info eq {}} {set index_info [lindex $info 3]}
1764 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1765 elseif {$s0 eq {_}} {set s0 _}
1767 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1768 elseif {$s1 eq {_}} {set s1 _}
1770 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1771 set head_info [list 0 $null_sha1]
1772 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1773 && $head_info eq {}} {
1774 set head_info $index_info
1775 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1776 set index_info $head_info
1780 set file_states($path) [list $s0$s1 $icon \
1781 $head_info $index_info \
1786 proc display_file_helper {w path icon_name old_m new_m} {
1789 if {$new_m eq {_}} {
1790 set lno [lsearch -sorted -exact $file_lists($w) $path]
1792 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1794 $w conf -state normal
1795 $w delete $lno.0 [expr {$lno + 1}].0
1796 $w conf -state disabled
1798 } elseif {$old_m eq {_} && $new_m ne {_}} {
1799 lappend file_lists($w) $path
1800 set file_lists($w) [lsort -unique $file_lists($w)]
1801 set lno [lsearch -sorted -exact $file_lists($w) $path]
1803 $w conf -state normal
1804 $w image create $lno.0 \
1805 -align center -padx 5 -pady 1 \
1807 -image [mapicon $w $new_m $path]
1808 $w insert $lno.1 "[escape_path $path]\n"
1809 $w conf -state disabled
1810 } elseif {$old_m ne $new_m} {
1811 $w conf -state normal
1812 $w image conf $icon_name -image [mapicon $w $new_m $path]
1813 $w conf -state disabled
1817 proc display_file {path state} {
1818 global file_states selected_paths
1819 global ui_index ui_workdir
1821 set old_m [merge_state $path $state]
1822 set s $file_states($path)
1823 set new_m [lindex $s 0]
1824 set icon_name [lindex $s 1]
1826 set o [string index $old_m 0]
1827 set n [string index $new_m 0]
1834 display_file_helper $ui_index $path $icon_name $o $n
1836 if {[string index $old_m 0] eq {U}} {
1839 set o [string index $old_m 1]
1841 if {[string index $new_m 0] eq {U}} {
1844 set n [string index $new_m 1]
1846 display_file_helper $ui_workdir $path $icon_name $o $n
1848 if {$new_m eq {__}} {
1849 unset file_states($path)
1850 catch {unset selected_paths($path)}
1854 proc display_all_files_helper {w path icon_name m} {
1857 lappend file_lists($w) $path
1858 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1859 $w image create end \
1860 -align center -padx 5 -pady 1 \
1862 -image [mapicon $w $m $path]
1863 $w insert end "[escape_path $path]\n"
1867 proc display_all_files {} {
1868 global ui_index ui_workdir
1869 global file_states file_lists
1871 global files_warning
1873 $ui_index conf -state normal
1874 $ui_workdir conf -state normal
1876 $ui_index delete 0.0 end
1877 $ui_workdir delete 0.0 end
1880 set file_lists($ui_index) [list]
1881 set file_lists($ui_workdir) [list]
1883 set to_display [lsort [array names file_states]]
1884 set display_limit [get_config gui.maxfilesdisplayed]
1885 if {[llength $to_display] > $display_limit} {
1886 if {!$files_warning} {
1887 # do not repeatedly warn:
1889 info_popup [mc "Displaying only %s of %s files." \
1890 $display_limit [llength $to_display]]
1892 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1894 foreach path $to_display {
1895 set s $file_states($path)
1897 set icon_name [lindex $s 1]
1899 set s [string index $m 0]
1900 if {$s ne {U} && $s ne {_}} {
1901 display_all_files_helper $ui_index $path \
1905 if {[string index $m 0] eq {U}} {
1908 set s [string index $m 1]
1911 display_all_files_helper $ui_workdir $path \
1916 $ui_index conf -state disabled
1917 $ui_workdir conf -state disabled
1920 ######################################################################
1925 #define mask_width 14
1926 #define mask_height 15
1927 static unsigned char mask_bits[] = {
1928 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1929 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1930 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1933 image create bitmap file_plain -background white -foreground black -data {
1934 #define plain_width 14
1935 #define plain_height 15
1936 static unsigned char plain_bits[] = {
1937 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1938 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1939 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1940 } -maskdata $filemask
1942 image create bitmap file_mod -background white -foreground blue -data {
1943 #define mod_width 14
1944 #define mod_height 15
1945 static unsigned char mod_bits[] = {
1946 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1947 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1948 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1949 } -maskdata $filemask
1951 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1952 #define file_fulltick_width 14
1953 #define file_fulltick_height 15
1954 static unsigned char file_fulltick_bits[] = {
1955 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1956 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1957 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1958 } -maskdata $filemask
1960 image create bitmap file_question -background white -foreground black -data {
1961 #define file_question_width 14
1962 #define file_question_height 15
1963 static unsigned char file_question_bits[] = {
1964 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1965 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1966 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1967 } -maskdata $filemask
1969 image create bitmap file_removed -background white -foreground red -data {
1970 #define file_removed_width 14
1971 #define file_removed_height 15
1972 static unsigned char file_removed_bits[] = {
1973 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1974 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1975 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1976 } -maskdata $filemask
1978 image create bitmap file_merge -background white -foreground blue -data {
1979 #define file_merge_width 14
1980 #define file_merge_height 15
1981 static unsigned char file_merge_bits[] = {
1982 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1983 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1984 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1985 } -maskdata $filemask
1987 image create bitmap file_statechange -background white -foreground green -data {
1988 #define file_statechange_width 14
1989 #define file_statechange_height 15
1990 static unsigned char file_statechange_bits[] = {
1991 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
1992 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
1993 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1994 } -maskdata $filemask
1996 set ui_index .vpane.files.index.list
1997 set ui_workdir .vpane.files.workdir.list
1999 set all_icons(_$ui_index) file_plain
2000 set all_icons(A$ui_index) file_plain
2001 set all_icons(M$ui_index) file_fulltick
2002 set all_icons(D$ui_index) file_removed
2003 set all_icons(U$ui_index) file_merge
2004 set all_icons(T$ui_index) file_statechange
2006 set all_icons(_$ui_workdir) file_plain
2007 set all_icons(M$ui_workdir) file_mod
2008 set all_icons(D$ui_workdir) file_question
2009 set all_icons(U$ui_workdir) file_merge
2010 set all_icons(O$ui_workdir) file_plain
2011 set all_icons(T$ui_workdir) file_statechange
2013 set max_status_desc 0
2015 {__ {mc "Unmodified"}}
2017 {_M {mc "Modified, not staged"}}
2018 {M_ {mc "Staged for commit"}}
2019 {MM {mc "Portions staged for commit"}}
2020 {MD {mc "Staged for commit, missing"}}
2022 {_T {mc "File type changed, not staged"}}
2023 {MT {mc "File type changed, old type staged for commit"}}
2024 {AT {mc "File type changed, old type staged for commit"}}
2025 {T_ {mc "File type changed, staged"}}
2026 {TM {mc "File type change staged, modification not staged"}}
2027 {TD {mc "File type change staged, file missing"}}
2029 {_O {mc "Untracked, not staged"}}
2030 {A_ {mc "Staged for commit"}}
2031 {AM {mc "Portions staged for commit"}}
2032 {AD {mc "Staged for commit, missing"}}
2035 {D_ {mc "Staged for removal"}}
2036 {DO {mc "Staged for removal, still present"}}
2038 {_U {mc "Requires merge resolution"}}
2039 {U_ {mc "Requires merge resolution"}}
2040 {UU {mc "Requires merge resolution"}}
2041 {UM {mc "Requires merge resolution"}}
2042 {UD {mc "Requires merge resolution"}}
2043 {UT {mc "Requires merge resolution"}}
2045 set text [eval [lindex $i 1]]
2046 if {$max_status_desc < [string length $text]} {
2047 set max_status_desc [string length $text]
2049 set all_descs([lindex $i 0]) $text
2053 ######################################################################
2057 proc scrollbar2many {list mode args} {
2058 foreach w $list {eval $w $mode $args}
2061 proc many2scrollbar {list mode sb top bottom} {
2062 $sb set $top $bottom
2063 foreach w $list {$w $mode moveto $top}
2066 proc incr_font_size {font {amt 1}} {
2067 set sz [font configure $font -size]
2069 font configure $font -size $sz
2070 font configure ${font}bold -size $sz
2071 font configure ${font}italic -size $sz
2074 ######################################################################
2078 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2080 proc do_gitk {revs {is_submodule false}} {
2081 global current_diff_path file_states current_diff_side ui_index
2084 # -- Always start gitk through whatever we were loaded with. This
2085 # lets us bypass using shell process on Windows systems.
2087 set exe [_which gitk -script]
2088 set cmd [list [info nameofexecutable] $exe]
2090 error_popup [mc "Couldn't find gitk in PATH"]
2094 if {[info exists env(GIT_DIR)]} {
2095 set old_GIT_DIR $env(GIT_DIR)
2102 if {!$is_submodule} {
2106 set env(GIT_DIR) [file normalize [gitdir]]
2108 cd $current_diff_path
2109 if {$revs eq {--}} {
2110 set s $file_states($current_diff_path)
2113 switch -glob -- [lindex $s 0] {
2114 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2115 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2117 if {$current_diff_side eq $ui_index} {
2118 set old_sha1 [lindex [lindex $s 2] 1]
2119 set new_sha1 [lindex [lindex $s 3] 1]
2121 set old_sha1 [lindex [lindex $s 3] 1]
2125 set revs $old_sha1...$new_sha1
2127 if {[info exists env(GIT_DIR)]} {
2131 eval exec $cmd $revs "--" "--" &
2133 if {$old_GIT_DIR ne {}} {
2134 set env(GIT_DIR) $old_GIT_DIR
2138 ui_status $::starting_gitk_msg
2140 ui_ready $starting_gitk_msg
2145 proc do_git_gui {} {
2146 global current_diff_path
2148 # -- Always start git gui through whatever we were loaded with. This
2149 # lets us bypass using shell process on Windows systems.
2151 set exe [list [_which git]]
2153 error_popup [mc "Couldn't find git gui in PATH"]
2157 if {[info exists env(GIT_DIR)]} {
2158 set old_GIT_DIR $env(GIT_DIR)
2165 cd $current_diff_path
2167 eval exec $exe gui &
2169 if {$old_GIT_DIR ne {}} {
2170 set env(GIT_DIR) $old_GIT_DIR
2174 ui_status $::starting_gitk_msg
2176 ui_ready $starting_gitk_msg
2181 proc do_explore {} {
2184 if {[is_Cygwin] || [is_Windows]} {
2185 set explorer "explorer.exe"
2186 } elseif {[is_MacOSX]} {
2189 # freedesktop.org-conforming system is our best shot
2190 set explorer "xdg-open"
2192 eval exec $explorer [list [file nativename $_gitworktree]] &
2198 proc terminate_me {win} {
2200 if {$win ne {.}} return
2204 proc do_quit {{rc {1}}} {
2205 global ui_comm is_quitting repo_config commit_type
2206 global GITGUI_BCK_exists GITGUI_BCK_i
2207 global ui_comm_spell
2208 global ret_code use_ttk
2210 if {$is_quitting} return
2213 if {[winfo exists $ui_comm]} {
2214 # -- Stash our current commit buffer.
2216 set save [gitdir GITGUI_MSG]
2217 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2218 file rename -force [gitdir GITGUI_BCK] $save
2219 set GITGUI_BCK_exists 0
2221 set msg [string trim [$ui_comm get 0.0 end]]
2222 regsub -all -line {[ \r\t]+$} $msg {} msg
2223 if {(![string match amend* $commit_type]
2224 || [$ui_comm edit modified])
2227 set fd [open $save w]
2228 puts -nonewline $fd $msg
2232 catch {file delete $save}
2236 # -- Cancel our spellchecker if its running.
2238 if {[info exists ui_comm_spell]} {
2242 # -- Remove our editor backup, its not needed.
2244 after cancel $GITGUI_BCK_i
2245 if {$GITGUI_BCK_exists} {
2246 catch {file delete [gitdir GITGUI_BCK]}
2249 # -- Stash our current window geometry into this repository.
2251 set cfg_wmstate [wm state .]
2252 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2255 if {$cfg_wmstate ne $rc_wmstate} {
2256 catch {git config gui.wmstate $cfg_wmstate}
2258 if {$cfg_wmstate eq {zoomed}} {
2259 # on Windows wm geometry will lie about window
2260 # position (but not size) when window is zoomed
2261 # restore the window before querying wm geometry
2264 set cfg_geometry [list]
2265 lappend cfg_geometry [wm geometry .]
2267 lappend cfg_geometry [.vpane sashpos 0]
2268 lappend cfg_geometry [.vpane.files sashpos 0]
2270 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2271 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2273 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2276 if {$cfg_geometry ne $rc_geometry} {
2277 catch {git config gui.geometry $cfg_geometry}
2283 # Briefly enable send again, working around Tk bug
2284 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2285 tk appname [appname]
2294 proc ui_do_rescan {} {
2295 rescan {force_first_diff ui_ready}
2302 proc next_diff {{after {}}} {
2303 global next_diff_p next_diff_w next_diff_i
2304 show_diff $next_diff_p $next_diff_w {} {} $after
2307 proc find_anchor_pos {lst name} {
2308 set lid [lsearch -sorted -exact $lst $name]
2312 foreach lname $lst {
2313 if {$lname >= $name} break
2321 proc find_file_from {flist idx delta path mmask} {
2324 set len [llength $flist]
2325 while {$idx >= 0 && $idx < $len} {
2326 set name [lindex $flist $idx]
2328 if {$name ne $path && [info exists file_states($name)]} {
2329 set state [lindex $file_states($name) 0]
2331 if {$mmask eq {} || [regexp $mmask $state]} {
2342 proc find_next_diff {w path {lno {}} {mmask {}}} {
2343 global next_diff_p next_diff_w next_diff_i
2344 global file_lists ui_index ui_workdir
2346 set flist $file_lists($w)
2348 set lno [find_anchor_pos $flist $path]
2353 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2354 if {$w eq $ui_index} {
2357 set mmask "$mmask\$"
2361 set idx [find_file_from $flist $lno 1 $path $mmask]
2364 set idx [find_file_from $flist $lno -1 $path $mmask]
2369 set next_diff_p [lindex $flist $idx]
2370 set next_diff_i [expr {$idx+1}]
2377 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2378 global current_diff_path
2380 if {$path ne $current_diff_path} {
2382 } elseif {[find_next_diff $w $path $lno $mmask]} {
2385 return {reshow_diff;}
2389 proc select_first_diff {after} {
2392 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2393 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2400 proc force_first_diff {after} {
2401 global ui_workdir current_diff_path file_states
2403 if {[info exists file_states($current_diff_path)]} {
2404 set state [lindex $file_states($current_diff_path) 0]
2410 if {[string first {U} $state] >= 0} {
2411 # Already a conflict, do nothing
2412 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2414 } elseif {[string index $state 1] ne {O}} {
2415 # Already a diff & no conflicts, do nothing
2416 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2427 proc toggle_or_diff {w x y} {
2428 global file_states file_lists current_diff_path ui_index ui_workdir
2429 global last_clicked selected_paths
2431 set pos [split [$w index @$x,$y] .]
2432 set lno [lindex $pos 0]
2433 set col [lindex $pos 1]
2434 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2440 set last_clicked [list $w $lno]
2441 array unset selected_paths
2442 $ui_index tag remove in_sel 0.0 end
2443 $ui_workdir tag remove in_sel 0.0 end
2445 # Determine the state of the file
2446 if {[info exists file_states($path)]} {
2447 set state [lindex $file_states($path) 0]
2452 # Restage the file, or simply show the diff
2453 if {$col == 0 && $y > 1} {
2454 # Conflicts need special handling
2455 if {[string first {U} $state] >= 0} {
2456 # $w must always be $ui_workdir, but...
2457 if {$w ne $ui_workdir} { set lno {} }
2458 merge_stage_workdir $path $lno
2462 if {[string index $state 1] eq {O}} {
2468 set after [next_diff_after_action $w $path $lno $mmask]
2470 if {$w eq $ui_index} {
2472 "Unstaging [short_path $path] from commit" \
2474 [concat $after [list ui_ready]]
2475 } elseif {$w eq $ui_workdir} {
2477 "Adding [short_path $path]" \
2479 [concat $after [list ui_ready]]
2482 show_diff $path $w $lno
2486 proc add_one_to_selection {w x y} {
2487 global file_lists last_clicked selected_paths
2489 set lno [lindex [split [$w index @$x,$y] .] 0]
2490 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2496 if {$last_clicked ne {}
2497 && [lindex $last_clicked 0] ne $w} {
2498 array unset selected_paths
2499 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2502 set last_clicked [list $w $lno]
2503 if {[catch {set in_sel $selected_paths($path)}]} {
2507 unset selected_paths($path)
2508 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2510 set selected_paths($path) 1
2511 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2515 proc add_range_to_selection {w x y} {
2516 global file_lists last_clicked selected_paths
2518 if {[lindex $last_clicked 0] ne $w} {
2519 toggle_or_diff $w $x $y
2523 set lno [lindex [split [$w index @$x,$y] .] 0]
2524 set lc [lindex $last_clicked 1]
2533 foreach path [lrange $file_lists($w) \
2534 [expr {$begin - 1}] \
2535 [expr {$end - 1}]] {
2536 set selected_paths($path) 1
2538 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2541 proc show_more_context {} {
2543 if {$repo_config(gui.diffcontext) < 99} {
2544 incr repo_config(gui.diffcontext)
2549 proc show_less_context {} {
2551 if {$repo_config(gui.diffcontext) > 1} {
2552 incr repo_config(gui.diffcontext) -1
2557 ######################################################################
2565 menu .mbar -tearoff 0
2567 # -- Apple Menu (Mac OS X only)
2569 .mbar add cascade -label Apple -menu .mbar.apple
2572 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2573 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2574 if {[is_enabled branch]} {
2575 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2577 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2578 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2580 if {[is_enabled transport]} {
2581 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2582 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2584 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2585 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2588 # -- Repository Menu
2590 menu .mbar.repository
2593 .mbar.repository add command \
2594 -label [mc "Explore Working Copy"] \
2595 -command {do_explore}
2596 .mbar.repository add separator
2599 .mbar.repository add command \
2600 -label [mc "Browse Current Branch's Files"] \
2601 -command {browser::new $current_branch}
2602 set ui_browse_current [.mbar.repository index last]
2603 .mbar.repository add command \
2604 -label [mc "Browse Branch Files..."] \
2605 -command browser_open::dialog
2606 .mbar.repository add separator
2608 .mbar.repository add command \
2609 -label [mc "Visualize Current Branch's History"] \
2610 -command {do_gitk $current_branch}
2611 set ui_visualize_current [.mbar.repository index last]
2612 .mbar.repository add command \
2613 -label [mc "Visualize All Branch History"] \
2614 -command {do_gitk --all}
2615 .mbar.repository add separator
2617 proc current_branch_write {args} {
2618 global current_branch
2619 .mbar.repository entryconf $::ui_browse_current \
2620 -label [mc "Browse %s's Files" $current_branch]
2621 .mbar.repository entryconf $::ui_visualize_current \
2622 -label [mc "Visualize %s's History" $current_branch]
2624 trace add variable current_branch write current_branch_write
2626 if {[is_enabled multicommit]} {
2627 .mbar.repository add command -label [mc "Database Statistics"] \
2630 .mbar.repository add command -label [mc "Compress Database"] \
2633 .mbar.repository add command -label [mc "Verify Database"] \
2634 -command do_fsck_objects
2636 .mbar.repository add separator
2639 .mbar.repository add command \
2640 -label [mc "Create Desktop Icon"] \
2641 -command do_cygwin_shortcut
2642 } elseif {[is_Windows]} {
2643 .mbar.repository add command \
2644 -label [mc "Create Desktop Icon"] \
2645 -command do_windows_shortcut
2646 } elseif {[is_MacOSX]} {
2647 .mbar.repository add command \
2648 -label [mc "Create Desktop Icon"] \
2649 -command do_macosx_app
2654 proc ::tk::mac::Quit {args} { do_quit }
2656 .mbar.repository add command -label [mc Quit] \
2664 .mbar.edit add command -label [mc Undo] \
2665 -command {catch {[focus] edit undo}} \
2667 .mbar.edit add command -label [mc Redo] \
2668 -command {catch {[focus] edit redo}} \
2670 .mbar.edit add separator
2671 .mbar.edit add command -label [mc Cut] \
2672 -command {catch {tk_textCut [focus]}} \
2674 .mbar.edit add command -label [mc Copy] \
2675 -command {catch {tk_textCopy [focus]}} \
2677 .mbar.edit add command -label [mc Paste] \
2678 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2680 .mbar.edit add command -label [mc Delete] \
2681 -command {catch {[focus] delete sel.first sel.last}} \
2683 .mbar.edit add separator
2684 .mbar.edit add command -label [mc "Select All"] \
2685 -command {catch {[focus] tag add sel 0.0 end}} \
2690 if {[is_enabled branch]} {
2693 .mbar.branch add command -label [mc "Create..."] \
2694 -command branch_create::dialog \
2696 lappend disable_on_lock [list .mbar.branch entryconf \
2697 [.mbar.branch index last] -state]
2699 .mbar.branch add command -label [mc "Checkout..."] \
2700 -command branch_checkout::dialog \
2702 lappend disable_on_lock [list .mbar.branch entryconf \
2703 [.mbar.branch index last] -state]
2705 .mbar.branch add command -label [mc "Rename..."] \
2706 -command branch_rename::dialog
2707 lappend disable_on_lock [list .mbar.branch entryconf \
2708 [.mbar.branch index last] -state]
2710 .mbar.branch add command -label [mc "Delete..."] \
2711 -command branch_delete::dialog
2712 lappend disable_on_lock [list .mbar.branch entryconf \
2713 [.mbar.branch index last] -state]
2715 .mbar.branch add command -label [mc "Reset..."] \
2716 -command merge::reset_hard
2717 lappend disable_on_lock [list .mbar.branch entryconf \
2718 [.mbar.branch index last] -state]
2723 proc commit_btn_caption {} {
2724 if {[is_enabled nocommit]} {
2727 return [mc Commit@@verb]
2731 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2734 if {![is_enabled nocommit]} {
2735 .mbar.commit add radiobutton \
2736 -label [mc "New Commit"] \
2737 -command do_select_commit_type \
2738 -variable selected_commit_type \
2740 lappend disable_on_lock \
2741 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2743 .mbar.commit add radiobutton \
2744 -label [mc "Amend Last 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 separator
2754 .mbar.commit add command -label [mc Rescan] \
2755 -command ui_do_rescan \
2757 lappend disable_on_lock \
2758 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2760 .mbar.commit add command -label [mc "Stage To Commit"] \
2761 -command do_add_selection \
2763 lappend disable_on_lock \
2764 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2766 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2767 -command do_add_all \
2769 lappend disable_on_lock \
2770 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2772 .mbar.commit add command -label [mc "Unstage From Commit"] \
2773 -command do_unstage_selection \
2775 lappend disable_on_lock \
2776 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2778 .mbar.commit add command -label [mc "Revert Changes"] \
2779 -command do_revert_selection \
2781 lappend disable_on_lock \
2782 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2784 .mbar.commit add separator
2786 .mbar.commit add command -label [mc "Show Less Context"] \
2787 -command show_less_context \
2788 -accelerator $M1T-\-
2790 .mbar.commit add command -label [mc "Show More Context"] \
2791 -command show_more_context \
2794 .mbar.commit add separator
2796 if {![is_enabled nocommitmsg]} {
2797 .mbar.commit add command -label [mc "Sign Off"] \
2798 -command do_signoff \
2802 .mbar.commit add command -label [commit_btn_caption] \
2803 -command do_commit \
2804 -accelerator $M1T-Return
2805 lappend disable_on_lock \
2806 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2811 if {[is_enabled branch]} {
2813 .mbar.merge add command -label [mc "Local Merge..."] \
2814 -command merge::dialog \
2816 lappend disable_on_lock \
2817 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2818 .mbar.merge add command -label [mc "Abort Merge..."] \
2819 -command merge::reset_hard
2820 lappend disable_on_lock \
2821 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2826 if {[is_enabled transport]} {
2829 .mbar.remote add command \
2830 -label [mc "Add..."] \
2831 -command remote_add::dialog \
2833 .mbar.remote add command \
2834 -label [mc "Push..."] \
2835 -command do_push_anywhere \
2837 .mbar.remote add command \
2838 -label [mc "Delete Branch..."] \
2839 -command remote_branch_delete::dialog
2843 proc ::tk::mac::ShowPreferences {} {do_options}
2847 .mbar.edit add separator
2848 .mbar.edit add command -label [mc "Options..."] \
2854 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2855 set tools_menubar .mbar.tools
2857 $tools_menubar add separator
2858 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2859 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2861 if {[array names repo_config guitool.*.cmd] ne {}} {
2868 .mbar add cascade -label [mc Help] -menu .mbar.help
2872 .mbar.apple add command -label [mc "About %s" [appname]] \
2874 .mbar.apple add separator
2876 .mbar.help add command -label [mc "About %s" [appname]] \
2879 . configure -menu .mbar
2881 set doc_path [githtmldir]
2882 if {$doc_path ne {}} {
2883 set doc_path [file join $doc_path index.html]
2886 set doc_path [exec cygpath --mixed $doc_path]
2890 if {[file isfile $doc_path]} {
2891 set doc_url "file:$doc_path"
2893 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2896 proc start_browser {url} {
2897 git "web--browse" $url
2900 .mbar.help add command -label [mc "Online Documentation"] \
2901 -command [list start_browser $doc_url]
2903 .mbar.help add command -label [mc "Show SSH Key"] \
2906 unset doc_path doc_url
2908 # -- Standard bindings
2910 wm protocol . WM_DELETE_WINDOW do_quit
2911 bind all <$M1B-Key-q> do_quit
2912 bind all <$M1B-Key-Q> do_quit
2913 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2914 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2916 set subcommand_args {}
2918 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2919 if {[tk windowingsystem] eq "win32"} {
2921 tk_messageBox -icon info -message $s \
2929 proc normalize_relpath {path} {
2931 foreach item [file split $path] {
2932 if {$item eq {.}} continue
2933 if {$item eq {..} && [llength $elements] > 0
2934 && [lindex $elements end] ne {..}} {
2935 set elements [lrange $elements 0 end-1]
2938 lappend elements $item
2940 return [eval file join $elements]
2943 # -- Not a normal commit type invocation? Do that instead!
2945 switch -- $subcommand {
2948 if {$subcommand eq "blame"} {
2949 set subcommand_args {[--line=<num>] rev? path}
2951 set subcommand_args {rev? path}
2953 if {$argv eq {}} usage
2959 if {$is_path || [file exists $_prefix$a]} {
2960 if {$path ne {}} usage
2961 set path [normalize_relpath $_prefix$a]
2963 } elseif {$a eq {--}} {
2965 if {$head ne {}} usage
2970 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2971 if {$jump_spec ne {} || $head ne {}} usage
2972 set jump_spec [list $lnum]
2973 } elseif {$head eq {}} {
2974 if {$head ne {}} usage
2983 if {$head ne {} && $path eq {}} {
2984 set path [normalize_relpath $_prefix$head]
2991 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2993 set head [git rev-parse --verify $head]
2995 if {[tk windowingsystem] eq "win32"} {
2996 tk_messageBox -icon error -title [mc Error] -message $err
3003 set current_branch $head
3007 switch -- $subcommand {
3009 if {$jump_spec ne {}} usage
3011 if {$path ne {} && [file isdirectory $path]} {
3012 set head $current_branch
3018 browser::new $head $path
3021 if {$head eq {} && ![file exists $path]} {
3022 catch {wm withdraw .}
3026 -title [mc "git-gui: fatal error"] \
3027 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
3030 blame::new $head $path $jump_spec
3037 if {[llength $argv] != 0} {
3040 # fall through to setup UI for commits
3043 set err "usage: $argv0 \[{blame|browser|citool}\]"
3044 if {[tk windowingsystem] eq "win32"} {
3046 tk_messageBox -icon error -message $err \
3057 ${NS}::frame .branch
3058 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3059 ${NS}::label .branch.l1 \
3060 -text [mc "Current Branch:"] \
3063 ${NS}::label .branch.cb \
3064 -textvariable current_branch \
3067 pack .branch.l1 -side left
3068 pack .branch.cb -side left -fill x
3069 pack .branch -side top -fill x
3071 # -- Main Window Layout
3073 ${NS}::panedwindow .vpane -orient horizontal
3074 ${NS}::panedwindow .vpane.files -orient vertical
3076 .vpane add .vpane.files
3078 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3080 pack .vpane -anchor n -side top -fill both -expand 1
3082 # -- Index File List
3084 ${NS}::frame .vpane.files.index -height 100 -width 200
3085 tlabel .vpane.files.index.title \
3086 -text [mc "Staged Changes (Will Commit)"] \
3087 -background lightgreen -foreground black
3088 text $ui_index -background white -foreground black \
3090 -width 20 -height 10 \
3092 -cursor $cursor_ptr \
3093 -xscrollcommand {.vpane.files.index.sx set} \
3094 -yscrollcommand {.vpane.files.index.sy set} \
3096 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3097 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3098 pack .vpane.files.index.title -side top -fill x
3099 pack .vpane.files.index.sx -side bottom -fill x
3100 pack .vpane.files.index.sy -side right -fill y
3101 pack $ui_index -side left -fill both -expand 1
3103 # -- Working Directory File List
3105 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3106 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3107 -background lightsalmon -foreground black
3108 text $ui_workdir -background white -foreground black \
3110 -width 20 -height 10 \
3112 -cursor $cursor_ptr \
3113 -xscrollcommand {.vpane.files.workdir.sx set} \
3114 -yscrollcommand {.vpane.files.workdir.sy set} \
3116 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3117 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3118 pack .vpane.files.workdir.title -side top -fill x
3119 pack .vpane.files.workdir.sx -side bottom -fill x
3120 pack .vpane.files.workdir.sy -side right -fill y
3121 pack $ui_workdir -side left -fill both -expand 1
3123 .vpane.files add .vpane.files.workdir
3124 .vpane.files add .vpane.files.index
3126 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3127 .vpane.files paneconfigure .vpane.files.index -sticky news
3130 foreach i [list $ui_index $ui_workdir] {
3132 $i tag conf in_diff -background [$i tag cget in_sel -background]
3136 # -- Diff and Commit Area
3138 ${NS}::frame .vpane.lower -height 300 -width 400
3139 ${NS}::frame .vpane.lower.commarea
3140 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3141 pack .vpane.lower.diff -fill both -expand 1
3142 pack .vpane.lower.commarea -side bottom -fill x
3143 .vpane add .vpane.lower
3144 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3146 # -- Commit Area Buttons
3148 ${NS}::frame .vpane.lower.commarea.buttons
3149 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3152 pack .vpane.lower.commarea.buttons.l -side top -fill x
3153 pack .vpane.lower.commarea.buttons -side left -fill y
3155 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3156 -command ui_do_rescan
3157 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3158 lappend disable_on_lock \
3159 {.vpane.lower.commarea.buttons.rescan conf -state}
3161 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3163 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3164 lappend disable_on_lock \
3165 {.vpane.lower.commarea.buttons.incall conf -state}
3167 if {![is_enabled nocommitmsg]} {
3168 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3170 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3173 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3175 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3176 lappend disable_on_lock \
3177 {.vpane.lower.commarea.buttons.commit conf -state}
3179 if {![is_enabled nocommit]} {
3180 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3181 -command do_push_anywhere
3182 pack .vpane.lower.commarea.buttons.push -side top -fill x
3185 # -- Commit Message Buffer
3187 ${NS}::frame .vpane.lower.commarea.buffer
3188 ${NS}::frame .vpane.lower.commarea.buffer.header
3189 set ui_comm .vpane.lower.commarea.buffer.t
3190 set ui_coml .vpane.lower.commarea.buffer.header.l
3192 if {![is_enabled nocommit]} {
3193 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3194 -text [mc "New Commit"] \
3195 -command do_select_commit_type \
3196 -variable selected_commit_type \
3198 lappend disable_on_lock \
3199 [list .vpane.lower.commarea.buffer.header.new conf -state]
3200 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3201 -text [mc "Amend Last Commit"] \
3202 -command do_select_commit_type \
3203 -variable selected_commit_type \
3205 lappend disable_on_lock \
3206 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3209 ${NS}::label $ui_coml \
3212 proc trace_commit_type {varname args} {
3213 global ui_coml commit_type
3214 switch -glob -- $commit_type {
3215 initial {set txt [mc "Initial Commit Message:"]}
3216 amend {set txt [mc "Amended Commit Message:"]}
3217 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3218 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3219 merge {set txt [mc "Merge Commit Message:"]}
3220 * {set txt [mc "Commit Message:"]}
3222 $ui_coml conf -text $txt
3224 trace add variable commit_type write trace_commit_type
3225 pack $ui_coml -side left -fill x
3227 if {![is_enabled nocommit]} {
3228 pack .vpane.lower.commarea.buffer.header.amend -side right
3229 pack .vpane.lower.commarea.buffer.header.new -side right
3232 text $ui_comm -background white -foreground black \
3236 -autoseparators true \
3238 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3240 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3241 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3242 -command [list $ui_comm yview]
3243 pack .vpane.lower.commarea.buffer.header -side top -fill x
3244 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3245 pack $ui_comm -side left -fill y
3246 pack .vpane.lower.commarea.buffer -side left -fill y
3248 # -- Commit Message Buffer Context Menu
3250 set ctxm .vpane.lower.commarea.buffer.ctxm
3251 menu $ctxm -tearoff 0
3254 -command {tk_textCut $ui_comm}
3257 -command {tk_textCopy $ui_comm}
3260 -command {tk_textPaste $ui_comm}
3262 -label [mc Delete] \
3263 -command {catch {$ui_comm delete sel.first sel.last}}
3266 -label [mc "Select All"] \
3267 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3269 -label [mc "Copy All"] \
3271 $ui_comm tag add sel 0.0 end
3272 tk_textCopy $ui_comm
3273 $ui_comm tag remove sel 0.0 end
3277 -label [mc "Sign Off"] \
3279 set ui_comm_ctxm $ctxm
3283 proc trace_current_diff_path {varname args} {
3284 global current_diff_path diff_actions file_states
3285 if {$current_diff_path eq {}} {
3291 set p $current_diff_path
3292 set s [mapdesc [lindex $file_states($p) 0] $p]
3294 set p [escape_path $p]
3298 .vpane.lower.diff.header.status configure -text $s
3299 .vpane.lower.diff.header.file configure -text $f
3300 .vpane.lower.diff.header.path configure -text $p
3301 foreach w $diff_actions {
3305 trace add variable current_diff_path write trace_current_diff_path
3307 gold_frame .vpane.lower.diff.header
3308 tlabel .vpane.lower.diff.header.status \
3311 -width $max_status_desc \
3314 tlabel .vpane.lower.diff.header.file \
3319 tlabel .vpane.lower.diff.header.path \
3324 pack .vpane.lower.diff.header.status -side left
3325 pack .vpane.lower.diff.header.file -side left
3326 pack .vpane.lower.diff.header.path -fill x
3327 set ctxm .vpane.lower.diff.header.ctxm
3328 menu $ctxm -tearoff 0
3336 -- $current_diff_path
3338 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3339 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3343 ${NS}::frame .vpane.lower.diff.body
3344 set ui_diff .vpane.lower.diff.body.t
3345 text $ui_diff -background white -foreground black \
3347 -width 80 -height 5 -wrap none \
3349 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3350 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3352 catch {$ui_diff configure -tabstyle wordprocessor}
3353 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3354 -command [list $ui_diff xview]
3355 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3356 -command [list $ui_diff yview]
3357 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3358 pack .vpane.lower.diff.body.sby -side right -fill y
3359 pack $ui_diff -side left -fill both -expand 1
3360 pack .vpane.lower.diff.header -side top -fill x
3361 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3363 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3364 $ui_diff tag configure clr4$n -background $c
3365 $ui_diff tag configure clri4$n -foreground $c
3366 $ui_diff tag configure clr3$n -foreground $c
3367 $ui_diff tag configure clri3$n -background $c
3369 $ui_diff tag configure clr1 -font font_diffbold
3371 $ui_diff tag conf d_info -foreground blue -font font_diffbold
3373 $ui_diff tag conf d_cr -elide true
3374 $ui_diff tag conf d_@ -font font_diffbold
3375 $ui_diff tag conf d_+ -foreground {#00a000}
3376 $ui_diff tag conf d_- -foreground red
3378 $ui_diff tag conf d_++ -foreground {#00a000}
3379 $ui_diff tag conf d_-- -foreground red
3380 $ui_diff tag conf d_+s \
3381 -foreground {#00a000} \
3382 -background {#e2effa}
3383 $ui_diff tag conf d_-s \
3385 -background {#e2effa}
3386 $ui_diff tag conf d_s+ \
3387 -foreground {#00a000} \
3389 $ui_diff tag conf d_s- \
3393 $ui_diff tag conf d< \
3394 -foreground orange \
3396 $ui_diff tag conf d= \
3397 -foreground orange \
3399 $ui_diff tag conf d> \
3400 -foreground orange \
3403 $ui_diff tag raise sel
3405 # -- Diff Body Context Menu
3408 proc create_common_diff_popup {ctxm} {
3410 -label [mc Refresh] \
3411 -command reshow_diff
3412 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3415 -command {tk_textCopy $ui_diff}
3416 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3418 -label [mc "Select All"] \
3419 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3420 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3422 -label [mc "Copy All"] \
3424 $ui_diff tag add sel 0.0 end
3425 tk_textCopy $ui_diff
3426 $ui_diff tag remove sel 0.0 end
3428 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3431 -label [mc "Decrease Font Size"] \
3432 -command {incr_font_size font_diff -1}
3433 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3435 -label [mc "Increase Font Size"] \
3436 -command {incr_font_size font_diff 1}
3437 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3441 build_encoding_menu $emenu [list force_diff_encoding]
3443 -label [mc "Encoding"] \
3445 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3447 $ctxm add command -label [mc "Options..."] \
3451 set ctxm .vpane.lower.diff.body.ctxm
3452 menu $ctxm -tearoff 0
3454 -label [mc "Apply/Reverse Hunk"] \
3455 -command {apply_hunk $cursorX $cursorY}
3456 set ui_diff_applyhunk [$ctxm index last]
3457 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3459 -label [mc "Apply/Reverse Line"] \
3460 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3461 set ui_diff_applyline [$ctxm index last]
3462 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3465 -label [mc "Show Less Context"] \
3466 -command show_less_context
3467 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3469 -label [mc "Show More Context"] \
3470 -command show_more_context
3471 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3473 create_common_diff_popup $ctxm
3475 set ctxmmg .vpane.lower.diff.body.ctxmmg
3476 menu $ctxmmg -tearoff 0
3477 $ctxmmg add command \
3478 -label [mc "Run Merge Tool"] \
3479 -command {merge_resolve_tool}
3480 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3481 $ctxmmg add separator
3482 $ctxmmg add command \
3483 -label [mc "Use Remote Version"] \
3484 -command {merge_resolve_one 3}
3485 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3486 $ctxmmg add command \
3487 -label [mc "Use Local Version"] \
3488 -command {merge_resolve_one 2}
3489 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3490 $ctxmmg add command \
3491 -label [mc "Revert To Base"] \
3492 -command {merge_resolve_one 1}
3493 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3494 $ctxmmg add separator
3495 $ctxmmg add command \
3496 -label [mc "Show Less Context"] \
3497 -command show_less_context
3498 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3499 $ctxmmg add command \
3500 -label [mc "Show More Context"] \
3501 -command show_more_context
3502 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3503 $ctxmmg add separator
3504 create_common_diff_popup $ctxmmg
3506 set ctxmsm .vpane.lower.diff.body.ctxmsm
3507 menu $ctxmsm -tearoff 0
3508 $ctxmsm add command \
3509 -label [mc "Visualize These Changes In The Submodule"] \
3510 -command {do_gitk -- true}
3511 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3512 $ctxmsm add command \
3513 -label [mc "Visualize Current Branch History In The Submodule"] \
3514 -command {do_gitk {} true}
3515 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3516 $ctxmsm add command \
3517 -label [mc "Visualize All Branch History In The Submodule"] \
3518 -command {do_gitk --all true}
3519 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3520 $ctxmsm add separator
3521 $ctxmsm add command \
3522 -label [mc "Start git gui In The Submodule"] \
3523 -command {do_git_gui}
3524 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3525 $ctxmsm add separator
3526 create_common_diff_popup $ctxmsm
3528 proc has_textconv {path} {
3529 if {[is_config_false gui.textconv]} {
3532 set filter [gitattr $path diff set]
3533 set textconv [get_config [join [list diff $filter textconv] .]]
3534 if {$filter ne {set} && $textconv ne {}} {
3541 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3542 global current_diff_path file_states
3545 if {[info exists file_states($current_diff_path)]} {
3546 set state [lindex $file_states($current_diff_path) 0]
3550 if {[string first {U} $state] >= 0} {
3551 tk_popup $ctxmmg $X $Y
3552 } elseif {$::is_submodule_diff} {
3553 tk_popup $ctxmsm $X $Y
3555 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3556 if {$::ui_index eq $::current_diff_side} {
3557 set l [mc "Unstage Hunk From Commit"]
3559 set t [mc "Unstage Lines From Commit"]
3561 set t [mc "Unstage Line From Commit"]
3564 set l [mc "Stage Hunk For Commit"]
3566 set t [mc "Stage Lines For Commit"]
3568 set t [mc "Stage Line For Commit"]
3572 || $current_diff_path eq {}
3575 || [string match {?T} $state]
3576 || [string match {T?} $state]
3577 || [has_textconv $current_diff_path]} {
3582 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3583 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3584 tk_popup $ctxm $X $Y
3587 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3591 set main_status [::status_bar::new .status]
3592 pack .status -anchor w -side bottom -fill x
3593 $main_status show [mc "Initializing..."]
3597 proc on_ttk_pane_mapped {w pane pos} {
3599 after 0 [list after idle [list $w sashpos $pane $pos]]
3601 proc on_tk_pane_mapped {w pane x y} {
3603 after 0 [list after idle [list $w sash place $pane $x $y]]
3605 proc on_application_mapped {} {
3606 global repo_config use_ttk
3608 set gm $repo_config(gui.geometry)
3611 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3612 bind .vpane.files <Map> \
3613 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3616 [list on_tk_pane_mapped %W 0 \
3618 [lindex [.vpane sash coord 0] 1]]
3619 bind .vpane.files <Map> \
3620 [list on_tk_pane_mapped %W 0 \
3621 [lindex [.vpane.files sash coord 0] 0] \
3624 wm geometry . [lindex $gm 0]
3626 if {[info exists repo_config(gui.geometry)]} {
3627 bind . <Map> [list on_application_mapped]
3628 wm geometry . [lindex $repo_config(gui.geometry) 0]
3631 # -- Load window state
3633 if {[info exists repo_config(gui.wmstate)]} {
3634 catch {wm state . $repo_config(gui.wmstate)}
3639 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3640 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3641 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3642 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3643 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3644 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3645 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3646 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3647 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3648 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3649 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3650 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3651 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3652 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3653 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3654 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3655 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3656 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3657 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3658 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3659 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3660 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3662 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3663 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3664 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3665 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3666 bind $ui_diff <$M1B-Key-v> {break}
3667 bind $ui_diff <$M1B-Key-V> {break}
3668 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3669 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3670 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3671 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3672 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3673 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3674 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3675 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3676 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3677 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3678 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3679 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3680 bind $ui_diff <Button-1> {focus %W}
3682 if {[is_enabled branch]} {
3683 bind . <$M1B-Key-n> branch_create::dialog
3684 bind . <$M1B-Key-N> branch_create::dialog
3685 bind . <$M1B-Key-o> branch_checkout::dialog
3686 bind . <$M1B-Key-O> branch_checkout::dialog
3687 bind . <$M1B-Key-m> merge::dialog
3688 bind . <$M1B-Key-M> merge::dialog
3690 if {[is_enabled transport]} {
3691 bind . <$M1B-Key-p> do_push_anywhere
3692 bind . <$M1B-Key-P> do_push_anywhere
3695 bind . <Key-F5> ui_do_rescan
3696 bind . <$M1B-Key-r> ui_do_rescan
3697 bind . <$M1B-Key-R> ui_do_rescan
3698 bind . <$M1B-Key-s> do_signoff
3699 bind . <$M1B-Key-S> do_signoff
3700 bind . <$M1B-Key-t> do_add_selection
3701 bind . <$M1B-Key-T> do_add_selection
3702 bind . <$M1B-Key-j> do_revert_selection
3703 bind . <$M1B-Key-J> do_revert_selection
3704 bind . <$M1B-Key-i> do_add_all
3705 bind . <$M1B-Key-I> do_add_all
3706 bind . <$M1B-Key-minus> {show_less_context;break}
3707 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3708 bind . <$M1B-Key-equal> {show_more_context;break}
3709 bind . <$M1B-Key-plus> {show_more_context;break}
3710 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3711 bind . <$M1B-Key-Return> do_commit
3712 foreach i [list $ui_index $ui_workdir] {
3713 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3714 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3715 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3719 set file_lists($ui_index) [list]
3720 set file_lists($ui_workdir) [list]
3722 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3723 focus -force $ui_comm
3725 # -- Warn the user about environmental problems. Cygwin's Tcl
3726 # does *not* pass its env array onto any processes it spawns.
3727 # This means that git processes get none of our environment.
3732 set msg [mc "Possible environment issues exist.
3734 The following environment variables are probably
3735 going to be ignored by any Git subprocess run
3739 foreach name [array names env] {
3740 switch -regexp -- $name {
3741 {^GIT_INDEX_FILE$} -
3742 {^GIT_OBJECT_DIRECTORY$} -
3743 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3745 {^GIT_EXTERNAL_DIFF$} -
3749 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3750 append msg " - $name\n"
3753 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3754 append msg " - $name\n"
3756 set suggest_user $name
3760 if {$ignored_env > 0} {
3762 This is due to a known issue with the
3763 Tcl binary distributed by Cygwin."]
3765 if {$suggest_user ne {}} {
3768 A good replacement for %s
3769 is placing values for the user.name and
3770 user.email settings into your personal
3776 unset ignored_env msg suggest_user name
3779 # -- Only initialize complex UI if we are going to stay running.
3781 if {[is_enabled transport]} {
3784 set n [.mbar.remote index end]
3785 populate_remotes_menu
3786 set n [expr {[.mbar.remote index end] - $n}]
3788 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3789 .mbar.remote insert $n separator
3794 if {[winfo exists $ui_comm]} {
3795 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3797 # -- If both our backup and message files exist use the
3798 # newer of the two files to initialize the buffer.
3800 if {$GITGUI_BCK_exists} {
3801 set m [gitdir GITGUI_MSG]
3802 if {[file isfile $m]} {
3803 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3804 catch {file delete [gitdir GITGUI_MSG]}
3806 $ui_comm delete 0.0 end
3808 $ui_comm edit modified false
3809 catch {file delete [gitdir GITGUI_BCK]}
3810 set GITGUI_BCK_exists 0
3816 proc backup_commit_buffer {} {
3817 global ui_comm GITGUI_BCK_exists
3819 set m [$ui_comm edit modified]
3820 if {$m || $GITGUI_BCK_exists} {
3821 set msg [string trim [$ui_comm get 0.0 end]]
3822 regsub -all -line {[ \r\t]+$} $msg {} msg
3825 if {$GITGUI_BCK_exists} {
3826 catch {file delete [gitdir GITGUI_BCK]}
3827 set GITGUI_BCK_exists 0
3831 set fd [open [gitdir GITGUI_BCK] w]
3832 puts -nonewline $fd $msg
3834 set GITGUI_BCK_exists 1
3838 $ui_comm edit modified false
3841 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3844 backup_commit_buffer
3846 # -- If the user has aspell available we can drive it
3847 # in pipe mode to spellcheck the commit message.
3849 set spell_cmd [list |]
3850 set spell_dict [get_config gui.spellingdictionary]
3851 lappend spell_cmd aspell
3852 if {$spell_dict ne {}} {
3853 lappend spell_cmd --master=$spell_dict
3855 lappend spell_cmd --mode=none
3856 lappend spell_cmd --encoding=utf-8
3857 lappend spell_cmd pipe
3858 if {$spell_dict eq {none}
3859 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3860 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3862 set ui_comm_spell [spellcheck::init \
3868 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3871 lock_index begin-read
3872 if {![winfo ismapped .]} {
3876 if {[is_enabled initialamend]} {
3882 if {[is_enabled nocommitmsg]} {
3883 $ui_comm configure -state disabled -background gray
3886 if {[is_enabled multicommit]} {
3889 if {[is_enabled retcode]} {
3890 bind . <Destroy> {+terminate_me %W}
3892 if {$picked && [is_config_true gui.autoexplore]} {
3898 # indent-tabs-mode: t