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 if { [info exists
::env
(GIT_GUI_LIB_DIR
) ] } {
53 set oguilib $
::env
(GIT_GUI_LIB_DIR
)
55 set oguilib
{@@GITGUI_LIBDIR@@
}
57 set oguirel
{@@GITGUI_RELATIVE@@
}
58 if {$oguirel eq
{1}} {
59 set oguilib
[file dirname [file normalize
$argv0]]
60 if {[file tail $oguilib] eq
{git-core
}} {
61 set oguilib
[file dirname $oguilib]
63 set oguilib
[file dirname $oguilib]
64 set oguilib
[file join $oguilib share git-gui lib
]
65 set oguimsg
[file join $oguilib msgs
]
66 } elseif
{[string match @@
* $oguirel]} {
67 set oguilib
[file join [file dirname [file normalize
$argv0]] lib
]
68 set oguimsg
[file join [file dirname [file normalize
$argv0]] po
]
70 set oguimsg
[file join $oguilib msgs
]
74 ######################################################################
76 ## enable verbose loading?
78 if {![catch
{set _verbose
$env(GITGUI_VERBOSE
)}]} {
80 rename auto_load real__auto_load
81 proc auto_load
{name args
} {
82 puts stderr
"auto_load $name"
83 return [uplevel
1 real__auto_load
$name $args]
85 rename
source real__source
87 puts stderr
"source $name"
88 uplevel
1 real__source
$name
90 if {[tk windowingsystem
] eq
"win32"} { console show
}
93 ######################################################################
95 ## Internationalization (i18n) through msgcat and gettext. See
96 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
98 package require msgcat
100 # Check for Windows 7 MUI language pack (missed by msgcat < 1.4.4)
101 if {[tk windowingsystem
] eq
"win32"
102 && [package vcompare
[package provide msgcat
] 1.4.4] < 0
104 proc _mc_update_locale
{} {
105 set key
{HKEY_CURRENT_USER\Control Panel\Desktop
}
107 package require registry
108 set uilocale
[registry get
$key "PreferredUILanguages"]
109 msgcat
::ConvertLocale
[string map
{- _
} [lindex
$uilocale 0]]
111 if {[string length
$uilocale] > 0} {
112 msgcat
::mclocale
$uilocale
119 proc _mc_trim
{fmt} {
120 set cmk
[string first @@
$fmt]
122 return [string range
$fmt 0 [expr {$cmk - 1}]]
127 proc mc
{en_fmt args
} {
128 set fmt [_mc_trim
[::msgcat
::mc
$en_fmt]]
129 if {[catch
{set msg
[eval [list format
$fmt] $args]} err
]} {
130 set msg
[eval [list format
[_mc_trim
$en_fmt]] $args]
136 return [join $args {}]
139 ::msgcat
::mcload
$oguimsg
142 ######################################################################
144 ## On Mac, bring the current Wish process window to front
146 if {[tk windowingsystem
] eq
"aqua"} {
148 exec osascript
-e [format
{
149 tell application
"System Events"
150 set frontmost of processes whose unix id is
%d to true
156 ######################################################################
160 set _appname
{Git Gui
}
169 set _shellpath
{@@SHELL_PATH@@
}
171 set _trace
[lsearch
-exact $argv --trace]
173 set argv
[lreplace
$argv $_trace $_trace]
175 if {[tk windowingsystem
] eq
"win32"} { console show
}
180 # variable for the last merged branch (useful for a default when deleting
182 set _last_merged_branch
{}
185 global _shellpath env
186 if {[string match @@
* $_shellpath]} {
187 if {[info exists env
(SHELL
)]} {
206 return [eval [list
file join $_gitdir] $args]
209 proc gitexec
{args
} {
211 if {$_gitexec eq
{}} {
212 if {[catch
{set _gitexec
[git
--exec-path]} err
]} {
213 error
"Git not installed?\n\n$err"
216 set _gitexec
[exec cygpath \
221 set _gitexec
[file normalize
$_gitexec]
227 return [eval [list
file join $_gitexec] $args]
230 proc githtmldir
{args
} {
232 if {$_githtmldir eq
{}} {
233 if {[catch
{set _githtmldir
[git
--html-path]}]} {
234 # Git not installed or option not yet supported
238 set _githtmldir
[exec cygpath \
243 set _githtmldir
[file normalize
$_githtmldir]
249 return [eval [list
file join $_githtmldir] $args]
257 if {[tk windowingsystem
] eq
{aqua
}} {
264 if {$
::tcl_platform
(platform
) eq
{windows
}} {
272 if {$_iscygwin eq
{}} {
273 if {$
::tcl_platform
(platform
) eq
{windows
}} {
274 if {[catch
{set p
[exec cygpath
--windir]} err
]} {
286 proc is_enabled
{option
} {
287 global enabled_options
288 if {[catch
{set on
$enabled_options($option)}]} {return 0}
292 proc enable_option
{option
} {
293 global enabled_options
294 set enabled_options
($option) 1
297 proc disable_option
{option
} {
298 global enabled_options
299 set enabled_options
($option) 0
302 ######################################################################
306 proc is_many_config
{name
} {
307 switch
-glob -- $name {
317 proc is_config_true
{name
} {
319 if {[catch
{set v
$repo_config($name)}]} {
322 set v
[string tolower
$v]
323 if {$v eq
{} ||
$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes} ||
$v eq
{on
}} {
330 proc is_config_false
{name
} {
332 if {[catch
{set v
$repo_config($name)}]} {
335 set v
[string tolower
$v]
336 if {$v eq
{false
} ||
$v eq
{0} ||
$v eq
{no
} ||
$v eq
{off
}} {
343 proc get_config
{name
} {
345 if {[catch
{set v
$repo_config($name)}]} {
357 if {$_isbare eq
{}} {
359 set _bare
[git rev-parse
--is-bare-repository]
361 true
{ set _isbare
1 }
362 false
{ set _isbare
0}
366 if {[is_config_true core.bare
]
367 ||
($_gitworktree eq
{}
368 && [lindex
[file split $_gitdir] end
] ne
{.git
})} {
378 ######################################################################
382 proc _trace_exec
{cmd
} {
383 if {!$
::_trace
} return
389 if {[regexp
{[ \t\r\n'"$?*]} $v]} {
397 #'" fix poor old emacs font-lock mode
399 proc _git_cmd {name} {
402 if {[catch {set v $_git_cmd_path($name)}]} {
406 --exec-path { return [list $::_git $name] }
409 set p [gitexec git-$name$::_search_exe]
410 if {[file exists $p]} {
412 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
413 # Try to determine what sort of magic will make
414 # git-$name go and do its thing, because native
415 # Tcl on Windows doesn't know it.
417 set p [gitexec git-$name]
422 switch -glob -- [lindex $s 0] {
424 #!*perl { set i perl }
425 #!*python { set i python }
426 default { error "git-
$name is not supported
: $s" }
430 if {![info exists interp]} {
431 set interp [_which $i]
434 error "git-
$name requires
$i (not
in PATH
)"
436 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
438 # Assume it is builtin to git somehow and we
439 # aren't actually able to see a file for it.
441 set v [list $::_git $name]
443 set _git_cmd_path($name) $v
448 proc _which {what args} {
449 global env _search_exe _search_path
451 if {$_search_path eq {}} {
452 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
453 set _search_path [split [exec cygpath \
459 } elseif {[is_Windows]} {
460 set gitguidir [file dirname [info script]]
461 regsub -all ";" $gitguidir "\\;" gitguidir
462 set env(PATH) "$gitguidir;$env(PATH
)"
463 set _search_path [split $env(PATH) {;}]
466 set _search_path [split $env(PATH) :]
471 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
474 set suffix $_search_exe
477 foreach p $_search_path {
478 set p [file join $p $what$suffix]
479 if {[file exists $p]} {
480 return [file normalize $p]
486 # Test a file for a hashbang to identify executable scripts on Windows.
487 proc is_shellscript {filename} {
488 if {![file exists $filename]} {return 0}
489 set f [open $filename r]
490 fconfigure $f -encoding binary
491 set magic [read $f 2]
493 return [expr {$magic eq "#!"}]
496 # Run a command connected via pipes on stdout.
497 # This is for use with textconv filters and uses sh -c "..." to allow it to
498 # contain a command with arguments. On windows we must check for shell
499 # scripts specifically otherwise just call the filter command.
500 proc open_cmd_pipe
{cmd path
} {
502 if {![file executable
[shellpath
]]} {
503 set exe
[auto_execok
[lindex
$cmd 0]]
504 if {[is_shellscript
[lindex
$exe 0]]} {
505 set run
[linsert
[auto_execok sh
] end
-c "$cmd \"\$0\"" $path]
507 set run
[concat
$exe [lrange
$cmd 1 end
] $path]
510 set run
[list
[shellpath
] -c "$cmd \"\$0\"" $path]
512 return [open |
$run r
]
515 proc _lappend_nice
{cmd_var
} {
519 if {![info exists _nice
]} {
520 set _nice
[_which nice
]
521 if {[catch
{exec $_nice git version
}]} {
523 } elseif
{[is_Windows
] && [file dirname $_nice] ne
[file dirname $
::_git
]} {
536 switch
-- [lindex
$args 0] {
547 set args
[lrange
$args 1 end
]
550 set cmdp
[_git_cmd
[lindex
$args 0]]
551 set args
[lrange
$args 1 end
]
553 _trace_exec
[concat
$opt $cmdp $args]
554 set result
[eval exec $opt $cmdp $args]
556 puts stderr
"< $result"
561 proc _open_stdout_stderr
{cmd
} {
564 set fd
[open
[concat
[list |
] $cmd] r
]
566 if { [lindex
$cmd end
] eq
{2>@
1}
567 && $err eq
{can not
find channel named
"1"}
569 # Older versions of Tcl 8.4 don't have this 2>@1 IO
570 # redirect operator. Fallback to |& cat for those.
571 # The command was not actually started, so its safe
572 # to try to start it a second time.
574 set fd
[open
[concat \
576 [lrange
$cmd 0 end-1
] \
583 fconfigure
$fd -eofchar {}
587 proc git_read
{args
} {
591 switch
-- [lindex
$args 0] {
606 set args
[lrange
$args 1 end
]
609 set cmdp
[_git_cmd
[lindex
$args 0]]
610 set args
[lrange
$args 1 end
]
612 return [_open_stdout_stderr
[concat
$opt $cmdp $args]]
615 proc git_write
{args
} {
619 switch
-- [lindex
$args 0] {
630 set args
[lrange
$args 1 end
]
633 set cmdp
[_git_cmd
[lindex
$args 0]]
634 set args
[lrange
$args 1 end
]
636 _trace_exec
[concat
$opt $cmdp $args]
637 return [open
[concat
[list |
] $opt $cmdp $args] w
]
640 proc githook_read
{hook_name args
} {
641 set pchook
[gitdir hooks
$hook_name]
644 # On Windows [file executable] might lie so we need to ask
645 # the shell if the hook is executable. Yes that's annoying.
649 if {![info exists interp
]} {
650 set interp
[_which sh
]
653 error
"hook execution requires sh (not in PATH)"
656 set scr
{if test -x "$1";then exec "$@";fi}
657 set sh_c
[list
$interp -c $scr $interp $pchook]
658 return [_open_stdout_stderr
[concat
$sh_c $args]]
661 if {[file executable
$pchook]} {
662 return [_open_stdout_stderr
[concat
[list
$pchook] $args]]
668 proc kill_file_process
{fd
} {
669 set process
[pid
$fd]
673 # Use a Cygwin-specific flag to allow killing
674 # native Windows processes
675 exec kill -f $process
682 proc gitattr
{path attr default
} {
683 if {[catch
{set r
[git check-attr
$attr -- $path]}]} {
686 set r
[join [lrange
[split $r :] 2 end
] :]
689 if {$r eq
{unspecified
}} {
696 regsub
-all ' $value "'\\''" value
700 proc load_current_branch {} {
701 global current_branch is_detached
703 set fd [open [gitdir HEAD] r]
704 if {[gets $fd ref] < 1} {
709 set pfx {ref: refs/heads/}
710 set len [string length $pfx]
711 if {[string equal -length $len $pfx $ref]} {
712 # We're on a branch. It might not exist. But
713 # HEAD looks good enough to be a branch.
715 set current_branch [string range $ref $len end]
718 # Assume this is a detached head.
720 set current_branch HEAD
725 auto_load tk_optionMenu
726 rename tk_optionMenu real__tkOptionMenu
727 proc tk_optionMenu {w varName args} {
728 set m [eval real__tkOptionMenu $w $varName $args]
729 $m configure -font font_ui
730 $w configure -font font_ui
734 proc rmsel_tag {text} {
736 -background [$text cget -background] \
737 -foreground [$text cget -foreground] \
739 $text tag conf in_sel -background lightgray
740 bind $text <Motion> break
746 bind . <Visibility> {
747 bind . <Visibility> {}
752 wm iconbitmap . -default $oguilib/git-gui.ico
753 set ::tk::AlwaysShowSelection 1
754 bind . <Control-F2> {console show}
756 # Spoof an X11 display for SSH
757 if {![info exists env(DISPLAY)]} {
758 set env(DISPLAY) :9999
762 image create photo gitlogo -width 16 -height 16
764 gitlogo put #33CC33 -to 7 0 9 2
765 gitlogo put #33CC33 -to 4 2 12 4
766 gitlogo put #33CC33 -to 7 4 9 6
767 gitlogo put #CC3333 -to 4 6 12 8
768 gitlogo put gray26 -to 4 9 6 10
769 gitlogo put gray26 -to 3 10 6 12
770 gitlogo put gray26 -to 8 9 13 11
771 gitlogo put gray26 -to 8 11 10 12
772 gitlogo put gray26 -to 11 11 13 14
773 gitlogo put gray26 -to 3 12 5 14
774 gitlogo put gray26 -to 5 13
775 gitlogo put gray26 -to 10 13
776 gitlogo put gray26 -to 4 14 12 15
777 gitlogo put gray26 -to 5 15 11 16
780 image create photo gitlogo32 -width 32 -height 32
781 gitlogo32 copy gitlogo -zoom 2 2
783 wm iconphoto . -default gitlogo gitlogo32
787 ######################################################################
793 if {[lsearch -exact [font names] TkDefaultFont] != -1} {
794 eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
795 eval [linsert [font actual TkFixedFont] 0 font create font_diff]
797 font create font_diff -family Courier -size 10
800 eval font configure font_ui [font actual [.dummy cget -font]]
805 font create font_uiitalic
806 font create font_uibold
807 font create font_diffbold
808 font create font_diffitalic
810 foreach class {Button Checkbutton Entry Label
811 Labelframe Listbox Message
812 Radiobutton Spinbox Text} {
813 option add *$class.font font_ui
816 option add *Menu.font font_ui
817 option add *Entry.borderWidth 1 startupFile
818 option add *Entry.relief sunken startupFile
819 option add *RadioButton.anchor w startupFile
823 if {[is_Windows] || [is_MacOSX]} {
824 option add *Menu.tearOff 0
835 proc bind_button3 {w cmd} {
836 bind $w <Any-Button-3> $cmd
838 # Mac OS X sends Button-2 on right click through three-button mouse,
839 # or through trackpad right-clicking (two-finger touch + click).
840 bind $w <Any-Button-2> $cmd
841 bind $w <Control-Button-1> $cmd
845 proc apply_config {} {
846 global repo_config font_descs
848 foreach option $font_descs {
849 set name [lindex $option 0]
850 set font [lindex $option 1]
853 foreach {cn cv} $repo_config(gui.$name) {
854 if {$cn eq {-weight}} {
857 font configure $font $cn $cv
860 font configure $font -weight normal
863 error_popup [strcat [mc "Invalid font specified
in %s
:" "gui.
$name"] "\n\n$err"]
865 foreach {cn cv} [font configure $font] {
866 font configure ${font}bold $cn $cv
867 font configure ${font}italic $cn $cv
869 font configure ${font}bold -weight bold
870 font configure ${font}italic -slant italic
876 if {$repo_config(gui.usettk)} {
877 set use_ttk [package vsatisfies [package provide Tk] 8.5]
880 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
886 set default_config(branch.autosetupmerge) true
887 set default_config(merge.tool) {}
888 set default_config(mergetool.keepbackup) true
889 set default_config(merge.diffstat) true
890 set default_config(merge.summary) false
891 set default_config(merge.verbosity) 2
892 set default_config(user.name) {}
893 set default_config(user.email) {}
895 set default_config(gui.encoding) [encoding system]
896 set default_config(gui.matchtrackingbranch) false
897 set default_config(gui.textconv) true
898 set default_config(gui.pruneduringfetch) false
899 set default_config(gui.trustmtime) false
900 set default_config(gui.fastcopyblame) false
901 set default_config(gui.maxrecentrepo) 10
902 set default_config(gui.copyblamethreshold) 40
903 set default_config(gui.blamehistoryctx) 7
904 set default_config(gui.diffcontext) 5
905 set default_config(gui.diffopts) {}
906 set default_config(gui.commitmsgwidth) 75
907 set default_config(gui.newbranchtemplate) {}
908 set default_config(gui.spellingdictionary) {}
909 set default_config(gui.fontui) [font configure font_ui]
910 set default_config(gui.fontdiff) [font configure font_diff]
911 # TODO: this option should be added to the git-config documentation
912 set default_config(gui.maxfilesdisplayed) 5000
913 set default_config(gui.usettk) 1
914 set default_config(gui.warndetachedcommit) 1
916 {fontui font_ui {mc "Main Font
"}}
917 {fontdiff font_diff {mc "Diff
/Console Font
"}}
919 set default_config(gui.stageuntracked) ask
920 set default_config(gui.displayuntracked) true
922 ######################################################################
926 set _git [_which git]
928 catch {wm withdraw .}
932 -title [mc "git-gui
: fatal error
"] \
933 -message [mc "Cannot
find git
in PATH.
"]
937 ######################################################################
941 if {[catch {set _git_version [git --version]} err]} {
942 catch {wm withdraw .}
946 -title [mc "git-gui
: fatal error
"] \
947 -message "Cannot determine Git version
:
951 [appname
] requires Git
1.5.0 or later.
"
954 if {![regsub {^git version } $_git_version {} _git_version]} {
955 catch {wm withdraw .}
959 -title [mc "git-gui
: fatal error
"] \
960 -message [strcat [mc "Cannot parse Git version string
:"] "\n\n$_git_version"]
964 proc get_trimmed_version {s} {
966 foreach x [split $s -._] {
967 if {[string is integer -strict $x]} {
975 set _real_git_version $_git_version
976 set _git_version [get_trimmed_version $_git_version]
978 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
979 catch {wm withdraw .}
984 -title "[appname
]: warning
" \
985 -message [mc "Git version cannot be determined.
987 %s claims it is version
'%s'.
989 %s requires
at least Git
1.5.0 or later.
991 Assume
'%s' is version
1.5.0?
992 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
993 set _git_version 1.5.0
998 unset _real_git_version
1000 proc git-version {args} {
1003 switch [llength $args] {
1005 return $_git_version
1009 set op [lindex $args 0]
1010 set vr [lindex $args 1]
1011 set cm [package vcompare $_git_version $vr]
1012 return [expr $cm $op 0]
1016 set type [lindex $args 0]
1017 set name [lindex $args 1]
1018 set parm [lindex $args 2]
1019 set body [lindex $args 3]
1021 if {($type ne {proc} && $type ne {method})} {
1022 error "Invalid arguments to git-version
"
1024 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
1025 error "Last arm of
$type $name must be default
"
1028 foreach {op vr cb} [lrange $body 0 end-2] {
1029 if {[git-version $op $vr]} {
1030 return [uplevel [list $type $name $parm $cb]]
1034 return [uplevel [list $type $name $parm [lindex $body end]]]
1038 error "git-version
>= x
"
1044 if {[git-version < 1.5]} {
1045 catch {wm withdraw .}
1049 -title [mc "git-gui
: fatal error
"] \
1050 -message "[appname
] requires Git
1.5.0 or later.
1052 You are using
[git-version
]:
1058 ######################################################################
1060 ## configure our library
1062 set idx [file join $oguilib tclIndex]
1063 if {[catch {set fd [open $idx r]} err]} {
1064 catch {wm withdraw .}
1068 -title [mc "git-gui
: fatal error
"] \
1072 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
1074 while {[gets $fd n] >= 0} {
1075 if {$n ne {} && ![string match #* $n]} {
1087 if {[lsearch -exact $loaded $p] >= 0} continue
1088 source [file join $oguilib $p]
1093 set auto_path [concat [list $oguilib] $auto_path]
1095 unset -nocomplain idx fd
1097 ######################################################################
1099 ## config file parsing
1101 git-version proc _parse_config {arr_name args} {
1108 [list git_read config] \
1110 [list --null --list]]
1111 fconfigure $fd_rc -translation binary
1112 set buf [read $fd_rc]
1115 foreach line [split $buf "\
0"] {
1116 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1117 if {[is_many_config $name]} {
1118 lappend arr($name) $value
1120 set arr($name) $value
1122 } elseif {[regexp {^([^\n]+)$} $line line name]} {
1123 # no value given, but interpreting them as
1124 # boolean will be handled as true
1133 set fd_rc [eval [list git_read config --list] $args]
1134 while {[gets $fd_rc line] >= 0} {
1135 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1136 if {[is_many_config $name]} {
1137 lappend arr($name) $value
1139 set arr($name) $value
1141 } elseif {[regexp {^([^=]+)$} $line line name]} {
1142 # no value given, but interpreting them as
1143 # boolean will be handled as true
1152 proc load_config {include_global} {
1153 global repo_config global_config system_config default_config
1155 if {$include_global} {
1156 _parse_config system_config --system
1157 _parse_config global_config --global
1159 _parse_config repo_config
1161 foreach name [array names default_config] {
1162 if {[catch {set v $system_config($name)}]} {
1163 set system_config($name) $default_config($name)
1166 foreach name [array names system_config] {
1167 if {[catch {set v $global_config($name)}]} {
1168 set global_config($name) $system_config($name)
1170 if {[catch {set v $repo_config($name)}]} {
1171 set repo_config($name) $system_config($name)
1176 ######################################################################
1178 ## feature option selection
1180 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1185 if {$subcommand eq {gui.sh}} {
1188 if {$subcommand eq {gui} && [llength $argv] > 0} {
1189 set subcommand [lindex $argv 0]
1190 set argv [lrange $argv 1 end]
1193 enable_option multicommit
1194 enable_option branch
1195 enable_option transport
1198 switch -- $subcommand {
1203 disable_option multicommit
1204 disable_option branch
1205 disable_option transport
1208 enable_option singlecommit
1209 enable_option retcode
1211 disable_option multicommit
1212 disable_option branch
1213 disable_option transport
1215 while {[llength $argv] > 0} {
1216 set a [lindex $argv 0]
1219 enable_option initialamend
1222 enable_option nocommit
1223 enable_option nocommitmsg
1226 disable_option nocommitmsg
1233 set argv [lrange $argv 1 end]
1238 ######################################################################
1240 ## execution environment
1242 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1244 # Suggest our implementation of askpass, if none is set
1245 if {![info exists env(SSH_ASKPASS)]} {
1246 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1249 ######################################################################
1255 set _gitdir $env(GIT_DIR)
1259 # beware that from the .git dir this sets _gitdir to .
1260 # and _prefix to the empty string
1261 set _gitdir [git rev-parse --git-dir]
1262 set _prefix [git rev-parse --show-prefix]
1266 choose_repository::pick
1270 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1271 # run from the .git dir itself) lest the routines to find the worktree
1273 if {$_gitdir eq ".
"} {
1277 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1278 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1280 if {![file isdirectory $_gitdir]} {
1281 catch {wm withdraw .}
1282 error_popup [strcat [mc "Git directory not found
:"] "\n\n$_gitdir"]
1285 # _gitdir exists, so try loading the config
1289 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1290 if {[package vsatisfies $_git_version 1.7.0-]} {
1291 if { [is_Cygwin] } {
1292 catch {set _gitworktree [exec cygpath --windows [git rev-parse --show-toplevel]]}
1294 set _gitworktree [git rev-parse --show-toplevel]
1297 # try to set work tree from environment, core.worktree or use
1298 # cdup to obtain a relative path to the top of the worktree. If
1299 # run from the top, the ./ prefix ensures normalize expands pwd.
1300 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1301 set _gitworktree [get_config core.worktree]
1302 if {$_gitworktree eq ""} {
1303 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1308 if {$_prefix ne {}} {
1309 if {$_gitworktree eq {}} {
1310 regsub -all {[^/]+/} $_prefix ../ cdup
1312 set cdup $_gitworktree
1314 if {[catch {cd $cdup} err]} {
1315 catch {wm withdraw .}
1316 error_popup [strcat [mc "Cannot move to top of working directory
:"] "\n\n$err"]
1319 set _gitworktree [pwd]
1321 } elseif {![is_enabled bare]} {
1323 catch {wm withdraw .}
1324 error_popup [strcat [mc "Cannot use bare repository
:"] "\n\n$_gitdir"]
1327 if {$_gitworktree eq {}} {
1328 set _gitworktree [file dirname $_gitdir]
1330 if {[catch {cd $_gitworktree} err]} {
1331 catch {wm withdraw .}
1332 error_popup [strcat [mc "No working directory
"] " $_gitworktree:\n\n$err"]
1335 set _gitworktree [pwd]
1337 set _reponame [file split [file normalize $_gitdir]]
1338 if {[lindex $_reponame end] eq {.git}} {
1339 set _reponame [lindex $_reponame end-1]
1341 set _reponame [lindex $_reponame end]
1344 set env(GIT_DIR) $_gitdir
1345 set env(GIT_WORK_TREE) $_gitworktree
1347 ######################################################################
1351 set current_diff_path {}
1352 set current_diff_side {}
1353 set diff_actions [list]
1357 set MERGE_HEAD [list]
1360 set current_branch {}
1362 set current_diff_path {}
1364 set is_submodule_diff 0
1365 set is_conflict_diff 0
1366 set selected_commit_type new
1367 set diff_empty_count 0
1369 set nullid "0000000000000000000000000000000000000000"
1370 set nullid2 "0000000000000000000000000000000000000001"
1372 ######################################################################
1380 set disable_on_lock [list]
1381 set index_lock_type none
1383 proc lock_index {type} {
1384 global index_lock_type disable_on_lock
1386 if {$index_lock_type eq {none}} {
1387 set index_lock_type $type
1388 foreach w $disable_on_lock {
1389 uplevel #0 $w disabled
1392 } elseif {$index_lock_type eq "begin-
$type"} {
1393 set index_lock_type $type
1399 proc unlock_index {} {
1400 global index_lock_type disable_on_lock
1402 set index_lock_type none
1403 foreach w $disable_on_lock {
1404 uplevel #0 $w normal
1408 ######################################################################
1412 proc repository_state {ctvar hdvar mhvar} {
1413 global current_branch
1414 upvar $ctvar ct $hdvar hd $mhvar mh
1419 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1425 set merge_head [gitdir MERGE_HEAD]
1426 if {[file exists $merge_head]} {
1428 set fd_mh [open $merge_head r]
1429 while {[gets $fd_mh line] >= 0} {
1440 global PARENT empty_tree
1442 set p [lindex $PARENT 0]
1446 if {$empty_tree eq {}} {
1447 set empty_tree [git mktree << {}]
1452 proc force_amend {} {
1453 global selected_commit_type
1454 global HEAD PARENT MERGE_HEAD commit_type
1456 repository_state newType newHEAD newMERGE_HEAD
1459 set MERGE_HEAD $newMERGE_HEAD
1460 set commit_type $newType
1462 set selected_commit_type amend
1463 do_select_commit_type
1466 proc rescan {after {honor_trustmtime 1}} {
1467 global HEAD PARENT MERGE_HEAD commit_type
1468 global ui_index ui_workdir ui_comm
1469 global rescan_active file_states
1472 if {$rescan_active > 0 || ![lock_index read]} return
1474 repository_state newType newHEAD newMERGE_HEAD
1475 if {[string match amend* $commit_type]
1476 && $newType eq {normal}
1477 && $newHEAD eq $HEAD} {
1481 set MERGE_HEAD $newMERGE_HEAD
1482 set commit_type $newType
1485 array unset file_states
1487 if {!$::GITGUI_BCK_exists &&
1488 (![$ui_comm edit modified]
1489 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1490 if {[string match amend* $commit_type]} {
1491 } elseif {[load_message GITGUI_MSG utf-8]} {
1492 } elseif {[run_prepare_commit_msg_hook]} {
1493 } elseif {[load_message MERGE_MSG]} {
1494 } elseif {[load_message SQUASH_MSG]} {
1497 $ui_comm edit modified false
1500 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1501 rescan_stage2 {} $after
1504 ui_status [mc "Refreshing
file status...
"]
1505 set fd_rf [git_read update-index \
1511 fconfigure $fd_rf -blocking 0 -translation binary
1512 fileevent $fd_rf readable \
1513 [list rescan_stage2 $fd_rf $after]
1518 set is_git_info_exclude {}
1519 proc have_info_exclude {} {
1520 global is_git_info_exclude
1522 if {$is_git_info_exclude eq {}} {
1523 if {[catch {exec test -f [gitdir info exclude]}]} {
1524 set is_git_info_exclude 0
1526 set is_git_info_exclude 1
1529 return $is_git_info_exclude
1532 proc have_info_exclude {} {
1533 return [file readable [gitdir info exclude]]
1537 proc rescan_stage2 {fd after} {
1538 global rescan_active buf_rdi buf_rdf buf_rlo
1542 if {![eof $fd]} return
1546 if {[package vsatisfies $::_git_version 1.6.3-]} {
1547 set ls_others [list --exclude-standard]
1549 set ls_others [list --exclude-per-directory=.gitignore]
1550 if {[have_info_exclude]} {
1551 lappend ls_others "--exclude-from=[gitdir info exclude
]"
1553 set user_exclude [get_config core.excludesfile]
1554 if {$user_exclude ne {} && [file readable $user_exclude]} {
1555 lappend ls_others "--exclude-from=[file normalize
$user_exclude]"
1564 ui_status [mc "Scanning
for modified files ...
"]
1565 if {[git-version >= "1.7.2"]} {
1566 set fd_di [git_read diff-index --cached --ignore-submodules=dirty -z [PARENT]]
1568 set fd_di [git_read diff-index --cached -z [PARENT]]
1570 set fd_df [git_read diff-files -z]
1572 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1573 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1575 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1576 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1578 if {[is_config_true gui.displayuntracked]} {
1579 set fd_lo [eval git_read ls-files --others -z $ls_others]
1580 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1581 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1586 proc load_message {file {encoding {}}} {
1589 set f [gitdir $file]
1590 if {[file isfile $f]} {
1591 if {[catch {set fd [open $f r]}]} {
1594 fconfigure $fd -eofchar {}
1595 if {$encoding ne {}} {
1596 fconfigure $fd -encoding $encoding
1598 set content [string trim [read $fd]]
1600 regsub -all -line {[ \r\t]+$} $content {} content
1601 $ui_comm delete 0.0 end
1602 $ui_comm insert end $content
1608 proc run_prepare_commit_msg_hook {} {
1611 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1612 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1613 # empty file but existent file.
1615 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1617 if {[file isfile [gitdir MERGE_MSG]]} {
1618 set pcm_source "merge
"
1619 set fd_mm [open [gitdir MERGE_MSG] r]
1620 puts -nonewline $fd_pcm [read $fd_mm]
1622 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1623 set pcm_source "squash
"
1624 set fd_sm [open [gitdir SQUASH_MSG] r]
1625 puts -nonewline $fd_pcm [read $fd_sm]
1633 set fd_ph [githook_read prepare-commit-msg \
1634 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1636 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1640 ui_status [mc "Calling prepare-commit-msg hook...
"]
1643 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1644 fileevent $fd_ph readable \
1645 [list prepare_commit_msg_hook_wait $fd_ph]
1650 proc prepare_commit_msg_hook_wait {fd_ph} {
1653 append pch_error [read $fd_ph]
1654 fconfigure $fd_ph -blocking 1
1656 if {[catch {close $fd_ph}]} {
1657 ui_status [mc "Commit declined by prepare-commit-msg hook.
"]
1658 hook_failed_popup prepare-commit-msg $pch_error
1659 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1662 load_message PREPARE_COMMIT_MSG
1665 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1668 fconfigure $fd_ph -blocking 0
1669 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1672 proc read_diff_index {fd after} {
1675 append buf_rdi [read $fd]
1677 set n [string length $buf_rdi]
1679 set z1 [string first "\
0" $buf_rdi $c]
1680 if {$z1 == -1} break
1682 set z2 [string first "\
0" $buf_rdi $z1]
1683 if {$z2 == -1} break
1686 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1687 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1689 [encoding convertfrom $p] \
1691 [list [lindex $i 0] [lindex $i 2]] \
1697 set buf_rdi [string range $buf_rdi $c end]
1702 rescan_done $fd buf_rdi $after
1705 proc read_diff_files {fd after} {
1708 append buf_rdf [read $fd]
1710 set n [string length $buf_rdf]
1712 set z1 [string first "\
0" $buf_rdf $c]
1713 if {$z1 == -1} break
1715 set z2 [string first "\
0" $buf_rdf $z1]
1716 if {$z2 == -1} break
1719 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1720 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1722 [encoding convertfrom $p] \
1725 [list [lindex $i 0] [lindex $i 2]]
1730 set buf_rdf [string range $buf_rdf $c end]
1735 rescan_done $fd buf_rdf $after
1738 proc read_ls_others {fd after} {
1741 append buf_rlo [read $fd]
1742 set pck [split $buf_rlo "\
0"]
1743 set buf_rlo [lindex $pck end]
1744 foreach p [lrange $pck 0 end-1] {
1745 set p [encoding convertfrom $p]
1746 if {[string index $p end] eq {/}} {
1747 set p [string range $p 0 end-1]
1751 rescan_done $fd buf_rlo $after
1754 proc rescan_done {fd buf after} {
1755 global rescan_active current_diff_path
1756 global file_states repo_config
1759 if {![eof $fd]} return
1762 if {[incr rescan_active -1] > 0} return
1767 if {$current_diff_path ne {}} { reshow_diff $after }
1768 if {$current_diff_path eq {}} { select_first_diff $after }
1771 proc prune_selection {} {
1772 global file_states selected_paths
1774 foreach path [array names selected_paths] {
1775 if {[catch {set still_here $file_states($path)}]} {
1776 unset selected_paths($path)
1781 ######################################################################
1785 proc mapicon {w state path} {
1788 if {[catch {set r $all_icons($state$w)}]} {
1789 puts "error
: no icon
for $w state
={$state} $path"
1795 proc mapdesc {state path} {
1798 if {[catch {set r $all_descs($state)}]} {
1799 puts "error
: no desc
for state
={$state} $path"
1805 proc ui_status {msg} {
1807 if {[info exists main_status]} {
1808 $main_status show $msg
1812 proc ui_ready {{test {}}} {
1814 if {[info exists main_status]} {
1815 $main_status show [mc "Ready.
"] $test
1819 proc escape_path {path} {
1820 regsub -all {\\} $path "\\\\" path
1821 regsub -all "\n" $path "\\n
" path
1825 proc short_path {path} {
1826 return [escape_path [lindex [file split $path] end]]
1830 set null_sha1 [string repeat 0 40]
1832 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1833 global file_states next_icon_id null_sha1
1835 set s0 [string index $new_state 0]
1836 set s1 [string index $new_state 1]
1838 if {[catch {set info $file_states($path)}]} {
1840 set icon n[incr next_icon_id]
1842 set state [lindex $info 0]
1843 set icon [lindex $info 1]
1844 if {$head_info eq {}} {set head_info [lindex $info 2]}
1845 if {$index_info eq {}} {set index_info [lindex $info 3]}
1848 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1849 elseif {$s0 eq {_}} {set s0 _}
1851 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1852 elseif {$s1 eq {_}} {set s1 _}
1854 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1855 set head_info [list 0 $null_sha1]
1856 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1857 && $head_info eq {}} {
1858 set head_info $index_info
1859 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1860 set index_info $head_info
1864 set file_states($path) [list $s0$s1 $icon \
1865 $head_info $index_info \
1870 proc display_file_helper {w path icon_name old_m new_m} {
1873 if {$new_m eq {_}} {
1874 set lno [lsearch -sorted -exact $file_lists($w) $path]
1876 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1878 $w conf -state normal
1879 $w delete $lno.0 [expr {$lno + 1}].0
1880 $w conf -state disabled
1882 } elseif {$old_m eq {_} && $new_m ne {_}} {
1883 lappend file_lists($w) $path
1884 set file_lists($w) [lsort -unique $file_lists($w)]
1885 set lno [lsearch -sorted -exact $file_lists($w) $path]
1887 $w conf -state normal
1888 $w image create $lno.0 \
1889 -align center -padx 5 -pady 1 \
1891 -image [mapicon $w $new_m $path]
1892 $w insert $lno.1 "[escape_path
$path]\n"
1893 $w conf -state disabled
1894 } elseif {$old_m ne $new_m} {
1895 $w conf -state normal
1896 $w image conf $icon_name -image [mapicon $w $new_m $path]
1897 $w conf -state disabled
1901 proc display_file {path state} {
1902 global file_states selected_paths
1903 global ui_index ui_workdir
1905 set old_m [merge_state $path $state]
1906 set s $file_states($path)
1907 set new_m [lindex $s 0]
1908 set icon_name [lindex $s 1]
1910 set o [string index $old_m 0]
1911 set n [string index $new_m 0]
1918 display_file_helper $ui_index $path $icon_name $o $n
1920 if {[string index $old_m 0] eq {U}} {
1923 set o [string index $old_m 1]
1925 if {[string index $new_m 0] eq {U}} {
1928 set n [string index $new_m 1]
1930 display_file_helper $ui_workdir $path $icon_name $o $n
1932 if {$new_m eq {__}} {
1933 unset file_states($path)
1934 catch {unset selected_paths($path)}
1938 proc display_all_files_helper {w path icon_name m} {
1941 lappend file_lists($w) $path
1942 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1943 $w image create end \
1944 -align center -padx 5 -pady 1 \
1946 -image [mapicon $w $m $path]
1947 $w insert end "[escape_path
$path]\n"
1951 proc display_all_files {} {
1952 global ui_index ui_workdir
1953 global file_states file_lists
1955 global files_warning
1957 $ui_index conf -state normal
1958 $ui_workdir conf -state normal
1960 $ui_index delete 0.0 end
1961 $ui_workdir delete 0.0 end
1964 set file_lists($ui_index) [list]
1965 set file_lists($ui_workdir) [list]
1967 set to_display [lsort [array names file_states]]
1968 set display_limit [get_config gui.maxfilesdisplayed]
1969 if {[llength $to_display] > $display_limit} {
1970 if {!$files_warning} {
1971 # do not repeatedly warn:
1973 info_popup [mc "Displaying only
%s of
%s files.
" \
1974 $display_limit [llength $to_display]]
1976 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1978 foreach path $to_display {
1979 set s $file_states($path)
1981 set icon_name [lindex $s 1]
1983 set s [string index $m 0]
1984 if {$s ne {U} && $s ne {_}} {
1985 display_all_files_helper $ui_index $path \
1989 if {[string index $m 0] eq {U}} {
1992 set s [string index $m 1]
1995 display_all_files_helper $ui_workdir $path \
2000 $ui_index conf -state disabled
2001 $ui_workdir conf -state disabled
2004 ######################################################################
2009 #define mask_width 14
2010 #define mask_height 15
2011 static unsigned char mask_bits[] = {
2012 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2013 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2014 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2017 image create bitmap file_plain -background white -foreground black -data {
2018 #define plain_width 14
2019 #define plain_height 15
2020 static unsigned char plain_bits[] = {
2021 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2022 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2023 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2024 } -maskdata $filemask
2026 image create bitmap file_mod -background white -foreground blue -data {
2027 #define mod_width 14
2028 #define mod_height 15
2029 static unsigned char mod_bits[] = {
2030 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2031 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2032 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2033 } -maskdata $filemask
2035 image create bitmap file_fulltick -background white -foreground "#007000" -data {
2036 #define file_fulltick_width 14
2037 #define file_fulltick_height 15
2038 static unsigned char file_fulltick_bits
[] = {
2039 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2040 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2041 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2042 } -maskdata $filemask
2044 image create bitmap file_question
-background white
-foreground black
-data {
2045 #define file_question_width 14
2046 #define file_question_height 15
2047 static unsigned char file_question_bits
[] = {
2048 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2049 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2050 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2051 } -maskdata $filemask
2053 image create bitmap file_removed
-background white
-foreground red
-data {
2054 #define file_removed_width 14
2055 #define file_removed_height 15
2056 static unsigned char file_removed_bits
[] = {
2057 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2058 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2059 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2060 } -maskdata $filemask
2062 image create bitmap file_merge
-background white
-foreground blue
-data {
2063 #define file_merge_width 14
2064 #define file_merge_height 15
2065 static unsigned char file_merge_bits
[] = {
2066 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2067 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2068 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2069 } -maskdata $filemask
2071 image create bitmap file_statechange
-background white
-foreground green
-data {
2072 #define file_statechange_width 14
2073 #define file_statechange_height 15
2074 static unsigned char file_statechange_bits
[] = {
2075 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
2076 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
2077 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2078 } -maskdata $filemask
2080 set ui_index .vpane.files.index.list
2081 set ui_workdir .vpane.files.workdir.list
2083 set all_icons
(_
$ui_index) file_plain
2084 set all_icons
(A
$ui_index) file_plain
2085 set all_icons
(M
$ui_index) file_fulltick
2086 set all_icons
(D
$ui_index) file_removed
2087 set all_icons
(U
$ui_index) file_merge
2088 set all_icons
(T
$ui_index) file_statechange
2090 set all_icons
(_
$ui_workdir) file_plain
2091 set all_icons
(M
$ui_workdir) file_mod
2092 set all_icons
(D
$ui_workdir) file_question
2093 set all_icons
(U
$ui_workdir) file_merge
2094 set all_icons
(O
$ui_workdir) file_plain
2095 set all_icons
(T
$ui_workdir) file_statechange
2097 set max_status_desc
0
2099 {__
{mc
"Unmodified"}}
2101 {_M
{mc
"Modified, not staged"}}
2102 {M_
{mc
"Staged for commit"}}
2103 {MM
{mc
"Portions staged for commit"}}
2104 {MD
{mc
"Staged for commit, missing"}}
2106 {_T
{mc
"File type changed, not staged"}}
2107 {MT
{mc
"File type changed, old type staged for commit"}}
2108 {AT
{mc
"File type changed, old type staged for commit"}}
2109 {T_
{mc
"File type changed, staged"}}
2110 {TM
{mc
"File type change staged, modification not staged"}}
2111 {TD
{mc
"File type change staged, file missing"}}
2113 {_O
{mc
"Untracked, not staged"}}
2114 {A_
{mc
"Staged for commit"}}
2115 {AM
{mc
"Portions staged for commit"}}
2116 {AD
{mc
"Staged for commit, missing"}}
2119 {D_
{mc
"Staged for removal"}}
2120 {DO
{mc
"Staged for removal, still present"}}
2122 {_U
{mc
"Requires merge resolution"}}
2123 {U_
{mc
"Requires merge resolution"}}
2124 {UU
{mc
"Requires merge resolution"}}
2125 {UM
{mc
"Requires merge resolution"}}
2126 {UD
{mc
"Requires merge resolution"}}
2127 {UT
{mc
"Requires merge resolution"}}
2129 set text
[eval [lindex
$i 1]]
2130 if {$max_status_desc < [string length
$text]} {
2131 set max_status_desc
[string length
$text]
2133 set all_descs
([lindex
$i 0]) $text
2137 ######################################################################
2141 proc scrollbar2many
{list mode args
} {
2142 foreach w
$list {eval $w $mode $args}
2145 proc many2scrollbar
{list mode sb top bottom
} {
2146 $sb set $top $bottom
2147 foreach w
$list {$w $mode moveto
$top}
2150 proc incr_font_size
{font
{amt
1}} {
2151 set sz
[font configure
$font -size]
2153 font configure
$font -size $sz
2154 font configure
${font}bold
-size $sz
2155 font configure
${font}italic
-size $sz
2158 ######################################################################
2162 set starting_gitk_msg
[mc
"Starting gitk... please wait..."]
2164 proc do_gitk
{revs
{is_submodule false
}} {
2165 global current_diff_path file_states current_diff_side ui_index
2166 global _gitdir _gitworktree
2168 # -- Always start gitk through whatever we were loaded with. This
2169 # lets us bypass using shell process on Windows systems.
2171 set exe
[_which gitk
-script]
2172 set cmd
[list
[info nameofexecutable
] $exe]
2174 error_popup
[mc
"Couldn't find gitk in PATH"]
2180 if {!$is_submodule} {
2185 cd $current_diff_path
2186 if {$revs eq
{--}} {
2187 set s
$file_states($current_diff_path)
2190 switch
-glob -- [lindex
$s 0] {
2191 M_
{ set old_sha1
[lindex
[lindex
$s 2] 1] }
2192 _M
{ set old_sha1
[lindex
[lindex
$s 3] 1] }
2194 if {$current_diff_side eq
$ui_index} {
2195 set old_sha1
[lindex
[lindex
$s 2] 1]
2196 set new_sha1
[lindex
[lindex
$s 3] 1]
2198 set old_sha1
[lindex
[lindex
$s 3] 1]
2202 set revs
$old_sha1...
$new_sha1
2204 # GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2205 # we've been using for the main repository, so unset them.
2206 # TODO we could make life easier (start up faster?) for gitk
2207 # by setting these to the appropriate values to allow gitk
2208 # to skip the heuristics to find their proper value
2210 unset env
(GIT_WORK_TREE
)
2212 eval exec $cmd $revs "--" "--" &
2214 set env
(GIT_DIR
) $_gitdir
2215 set env
(GIT_WORK_TREE
) $_gitworktree
2218 ui_status $
::starting_gitk_msg
2220 ui_ready
$starting_gitk_msg
2225 proc do_git_gui
{} {
2226 global current_diff_path
2228 # -- Always start git gui through whatever we were loaded with. This
2229 # lets us bypass using shell process on Windows systems.
2231 set exe
[list
[_which git
]]
2233 error_popup
[mc
"Couldn't find git gui in PATH"]
2236 global _gitdir _gitworktree
2238 # see note in do_gitk about unsetting these vars when
2239 # running tools in a submodule
2241 unset env
(GIT_WORK_TREE
)
2244 cd $current_diff_path
2246 eval exec $exe gui
&
2248 set env
(GIT_DIR
) $_gitdir
2249 set env
(GIT_WORK_TREE
) $_gitworktree
2252 ui_status $
::starting_gitk_msg
2254 ui_ready
$starting_gitk_msg
2259 proc do_explore
{} {
2262 if {[is_Cygwin
] ||
[is_Windows
]} {
2263 set explorer
"explorer.exe"
2264 } elseif
{[is_MacOSX
]} {
2267 # freedesktop.org-conforming system is our best shot
2268 set explorer
"xdg-open"
2270 eval exec $explorer [list
[file nativename
$_gitworktree]] &
2276 proc terminate_me
{win
} {
2278 if {$win ne
{.
}} return
2282 proc do_quit
{{rc
{1}}} {
2283 global ui_comm is_quitting repo_config commit_type
2284 global GITGUI_BCK_exists GITGUI_BCK_i
2285 global ui_comm_spell
2286 global ret_code use_ttk
2288 if {$is_quitting} return
2291 if {[winfo exists
$ui_comm]} {
2292 # -- Stash our current commit buffer.
2294 set save
[gitdir GITGUI_MSG
]
2295 if {$GITGUI_BCK_exists && ![$ui_comm edit modified
]} {
2296 file rename
-force [gitdir GITGUI_BCK
] $save
2297 set GITGUI_BCK_exists
0
2299 set msg
[string trim
[$ui_comm get
0.0 end
]]
2300 regsub
-all -line {[ \r\t]+$
} $msg {} msg
2301 if {(![string match amend
* $commit_type]
2302 ||
[$ui_comm edit modified
])
2305 set fd
[open
$save w
]
2306 fconfigure
$fd -encoding utf-8
2307 puts
-nonewline $fd $msg
2311 catch
{file delete
$save}
2315 # -- Cancel our spellchecker if its running.
2317 if {[info exists ui_comm_spell
]} {
2321 # -- Remove our editor backup, its not needed.
2323 after cancel
$GITGUI_BCK_i
2324 if {$GITGUI_BCK_exists} {
2325 catch
{file delete
[gitdir GITGUI_BCK
]}
2328 # -- Stash our current window geometry into this repository.
2330 set cfg_wmstate
[wm state .
]
2331 if {[catch
{set rc_wmstate
$repo_config(gui.wmstate
)}]} {
2334 if {$cfg_wmstate ne
$rc_wmstate} {
2335 catch
{git config gui.wmstate
$cfg_wmstate}
2337 if {$cfg_wmstate eq
{zoomed
}} {
2338 # on Windows wm geometry will lie about window
2339 # position (but not size) when window is zoomed
2340 # restore the window before querying wm geometry
2343 set cfg_geometry
[list
]
2344 lappend cfg_geometry
[wm geometry .
]
2346 lappend cfg_geometry
[.vpane sashpos
0]
2347 lappend cfg_geometry
[.vpane.files sashpos
0]
2349 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 0]
2350 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 1]
2352 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2355 if {$cfg_geometry ne
$rc_geometry} {
2356 catch
{git config gui.geometry
$cfg_geometry}
2362 # Briefly enable send again, working around Tk bug
2363 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2364 tk appname
[appname
]
2373 proc ui_do_rescan
{} {
2374 rescan
{force_first_diff ui_ready
}
2381 proc next_diff
{{after
{}}} {
2382 global next_diff_p next_diff_w next_diff_i
2383 show_diff
$next_diff_p $next_diff_w {} {} $after
2386 proc find_anchor_pos
{lst name
} {
2387 set lid
[lsearch
-sorted -exact $lst $name]
2391 foreach lname
$lst {
2392 if {$lname >= $name} break
2400 proc find_file_from
{flist idx delta path mmask
} {
2403 set len
[llength
$flist]
2404 while {$idx >= 0 && $idx < $len} {
2405 set name
[lindex
$flist $idx]
2407 if {$name ne
$path && [info exists file_states
($name)]} {
2408 set state
[lindex
$file_states($name) 0]
2410 if {$mmask eq
{} ||
[regexp
$mmask $state]} {
2421 proc find_next_diff
{w path
{lno
{}} {mmask
{}}} {
2422 global next_diff_p next_diff_w next_diff_i
2423 global file_lists ui_index ui_workdir
2425 set flist
$file_lists($w)
2427 set lno
[find_anchor_pos
$flist $path]
2432 if {$mmask ne
{} && ![regexp
{(^\^
)|
(\$$
)} $mmask]} {
2433 if {$w eq
$ui_index} {
2436 set mmask
"$mmask\$"
2440 set idx
[find_file_from
$flist $lno 1 $path $mmask]
2443 set idx
[find_file_from
$flist $lno -1 $path $mmask]
2448 set next_diff_p
[lindex
$flist $idx]
2449 set next_diff_i
[expr {$idx+1}]
2456 proc next_diff_after_action
{w path
{lno
{}} {mmask
{}}} {
2457 global current_diff_path
2459 if {$path ne
$current_diff_path} {
2461 } elseif
{[find_next_diff
$w $path $lno $mmask]} {
2464 return {reshow_diff
;}
2468 proc select_first_diff
{after
} {
2471 if {[find_next_diff
$ui_workdir {} 1 {^_?U
}] ||
2472 [find_next_diff
$ui_workdir {} 1 {[^O
]$
}]} {
2479 proc force_first_diff
{after
} {
2480 global ui_workdir current_diff_path file_states
2482 if {[info exists file_states
($current_diff_path)]} {
2483 set state
[lindex
$file_states($current_diff_path) 0]
2489 if {[string first
{U
} $state] >= 0} {
2490 # Already a conflict, do nothing
2491 } elseif
{[find_next_diff
$ui_workdir $current_diff_path {} {^_?U
}]} {
2493 } elseif
{[string index
$state 1] ne
{O
}} {
2494 # Already a diff & no conflicts, do nothing
2495 } elseif
{[find_next_diff
$ui_workdir $current_diff_path {} {[^O
]$
}]} {
2506 proc toggle_or_diff
{w x y
} {
2507 global file_states file_lists current_diff_path ui_index ui_workdir
2508 global last_clicked selected_paths
2510 set pos
[split [$w index @
$x,$y] .
]
2511 set lno
[lindex
$pos 0]
2512 set col [lindex
$pos 1]
2513 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
2519 set last_clicked
[list
$w $lno]
2520 array
unset selected_paths
2521 $ui_index tag remove in_sel
0.0 end
2522 $ui_workdir tag remove in_sel
0.0 end
2524 # Determine the state of the file
2525 if {[info exists file_states
($path)]} {
2526 set state
[lindex
$file_states($path) 0]
2531 # Restage the file, or simply show the diff
2532 if {$col == 0 && $y > 1} {
2533 # Conflicts need special handling
2534 if {[string first
{U
} $state] >= 0} {
2535 # $w must always be $ui_workdir, but...
2536 if {$w ne
$ui_workdir} { set lno
{} }
2537 merge_stage_workdir
$path $lno
2541 if {[string index
$state 1] eq
{O
}} {
2547 set after
[next_diff_after_action
$w $path $lno $mmask]
2549 if {$w eq
$ui_index} {
2551 "Unstaging [short_path $path] from commit" \
2553 [concat
$after [list ui_ready
]]
2554 } elseif
{$w eq
$ui_workdir} {
2556 "Adding [short_path $path]" \
2558 [concat
$after [list ui_ready
]]
2561 set selected_paths
($path) 1
2562 show_diff
$path $w $lno
2566 proc add_one_to_selection
{w x y
} {
2567 global file_lists last_clicked selected_paths
2569 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
2570 set path
[lindex
$file_lists($w) [expr {$lno - 1}]]
2576 if {$last_clicked ne
{}
2577 && [lindex
$last_clicked 0] ne
$w} {
2578 array
unset selected_paths
2579 [lindex
$last_clicked 0] tag remove in_sel
0.0 end
2582 set last_clicked
[list
$w $lno]
2583 if {[catch
{set in_sel
$selected_paths($path)}]} {
2587 unset selected_paths
($path)
2588 $w tag remove in_sel
$lno.0 [expr {$lno + 1}].0
2590 set selected_paths
($path) 1
2591 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
2595 proc add_range_to_selection
{w x y
} {
2596 global file_lists last_clicked selected_paths
2598 if {[lindex
$last_clicked 0] ne
$w} {
2599 toggle_or_diff
$w $x $y
2603 set lno
[lindex
[split [$w index @
$x,$y] .
] 0]
2604 set lc
[lindex
$last_clicked 1]
2613 foreach path
[lrange
$file_lists($w) \
2614 [expr {$begin - 1}] \
2615 [expr {$end - 1}]] {
2616 set selected_paths
($path) 1
2618 $w tag add in_sel
$begin.0 [expr {$end + 1}].0
2621 proc show_more_context
{} {
2623 if {$repo_config(gui.diffcontext
) < 99} {
2624 incr repo_config
(gui.diffcontext
)
2629 proc show_less_context
{} {
2631 if {$repo_config(gui.diffcontext
) > 1} {
2632 incr repo_config
(gui.diffcontext
) -1
2637 ######################################################################
2645 menu .mbar
-tearoff 0
2647 # -- Apple Menu (Mac OS X only)
2649 .mbar add cascade
-label Apple
-menu .mbar.apple
2652 .mbar add cascade
-label [mc Repository
] -menu .mbar.repository
2653 .mbar add cascade
-label [mc Edit
] -menu .mbar.edit
2654 if {[is_enabled branch
]} {
2655 .mbar add cascade
-label [mc Branch
] -menu .mbar.branch
2657 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
2658 .mbar add cascade
-label [mc Commit@@noun
] -menu .mbar.commit
2660 if {[is_enabled transport
]} {
2661 .mbar add cascade
-label [mc Merge
] -menu .mbar.merge
2662 .mbar add cascade
-label [mc Remote
] -menu .mbar.remote
2664 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
2665 .mbar add cascade
-label [mc Tools
] -menu .mbar.tools
2668 # -- Repository Menu
2670 menu .mbar.repository
2673 .mbar.repository add
command \
2674 -label [mc
"Explore Working Copy"] \
2675 -command {do_explore
}
2679 .mbar.repository add
command \
2680 -label [mc
"Git Bash"] \
2681 -command {eval exec [auto_execok start
] \
2682 [list
"Git Bash" bash
--login -l &]}
2685 if {[is_Windows
] ||
![is_bare
]} {
2686 .mbar.repository add separator
2689 .mbar.repository add
command \
2690 -label [mc
"Browse Current Branch's Files"] \
2691 -command {browser
::new
$current_branch}
2692 set ui_browse_current
[.mbar.repository index last
]
2693 .mbar.repository add
command \
2694 -label [mc
"Browse Branch Files..."] \
2695 -command browser_open
::dialog
2696 .mbar.repository add separator
2698 .mbar.repository add
command \
2699 -label [mc
"Visualize Current Branch's History"] \
2700 -command {do_gitk
$current_branch}
2701 set ui_visualize_current
[.mbar.repository index last
]
2702 .mbar.repository add
command \
2703 -label [mc
"Visualize All Branch History"] \
2704 -command {do_gitk
--all}
2705 .mbar.repository add separator
2707 proc current_branch_write
{args
} {
2708 global current_branch
2709 .mbar.repository entryconf $
::ui_browse_current \
2710 -label [mc
"Browse %s's Files" $current_branch]
2711 .mbar.repository entryconf $
::ui_visualize_current \
2712 -label [mc
"Visualize %s's History" $current_branch]
2714 trace add variable current_branch
write current_branch_write
2716 if {[is_enabled multicommit
]} {
2717 .mbar.repository add
command -label [mc
"Database Statistics"] \
2720 .mbar.repository add
command -label [mc
"Compress Database"] \
2723 .mbar.repository add
command -label [mc
"Verify Database"] \
2724 -command do_fsck_objects
2726 .mbar.repository add separator
2729 .mbar.repository add
command \
2730 -label [mc
"Create Desktop Icon"] \
2731 -command do_cygwin_shortcut
2732 } elseif
{[is_Windows
]} {
2733 .mbar.repository add
command \
2734 -label [mc
"Create Desktop Icon"] \
2735 -command do_windows_shortcut
2736 } elseif
{[is_MacOSX
]} {
2737 .mbar.repository add
command \
2738 -label [mc
"Create Desktop Icon"] \
2739 -command do_macosx_app
2744 proc
::tk
::mac
::Quit
{args
} { do_quit
}
2746 .mbar.repository add
command -label [mc Quit
] \
2754 .mbar.edit add
command -label [mc Undo
] \
2755 -command {catch
{[focus
] edit undo
}} \
2757 .mbar.edit add
command -label [mc Redo
] \
2758 -command {catch
{[focus
] edit redo
}} \
2760 .mbar.edit add separator
2761 .mbar.edit add
command -label [mc Cut
] \
2762 -command {catch
{tk_textCut
[focus
]}} \
2764 .mbar.edit add
command -label [mc Copy
] \
2765 -command {catch
{tk_textCopy
[focus
]}} \
2767 .mbar.edit add
command -label [mc Paste
] \
2768 -command {catch
{tk_textPaste
[focus
]; [focus
] see insert
}} \
2770 .mbar.edit add
command -label [mc Delete
] \
2771 -command {catch
{[focus
] delete sel.first sel.last
}} \
2773 .mbar.edit add separator
2774 .mbar.edit add
command -label [mc
"Select All"] \
2775 -command {catch
{[focus
] tag add sel
0.0 end
}} \
2780 if {[is_enabled branch
]} {
2783 .mbar.branch add
command -label [mc
"Create..."] \
2784 -command branch_create
::dialog \
2786 lappend disable_on_lock
[list .mbar.branch entryconf \
2787 [.mbar.branch index last
] -state]
2789 .mbar.branch add
command -label [mc
"Checkout..."] \
2790 -command branch_checkout
::dialog \
2792 lappend disable_on_lock
[list .mbar.branch entryconf \
2793 [.mbar.branch index last
] -state]
2795 .mbar.branch add
command -label [mc
"Rename..."] \
2796 -command branch_rename
::dialog
2797 lappend disable_on_lock
[list .mbar.branch entryconf \
2798 [.mbar.branch index last
] -state]
2800 .mbar.branch add
command -label [mc
"Delete..."] \
2801 -command branch_delete
::dialog
2802 lappend disable_on_lock
[list .mbar.branch entryconf \
2803 [.mbar.branch index last
] -state]
2805 .mbar.branch add
command -label [mc
"Reset..."] \
2806 -command merge
::reset_hard
2807 lappend disable_on_lock
[list .mbar.branch entryconf \
2808 [.mbar.branch index last
] -state]
2813 proc commit_btn_caption
{} {
2814 if {[is_enabled nocommit
]} {
2817 return [mc Commit@@verb
]
2821 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
2824 if {![is_enabled nocommit
]} {
2825 .mbar.commit add radiobutton \
2826 -label [mc
"New Commit"] \
2827 -command do_select_commit_type \
2828 -variable selected_commit_type \
2830 lappend disable_on_lock \
2831 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2833 .mbar.commit add radiobutton \
2834 -label [mc
"Amend Last Commit"] \
2835 -command do_select_commit_type \
2836 -variable selected_commit_type \
2838 lappend disable_on_lock \
2839 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2841 .mbar.commit add separator
2844 .mbar.commit add
command -label [mc Rescan
] \
2845 -command ui_do_rescan \
2847 lappend disable_on_lock \
2848 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2850 .mbar.commit add
command -label [mc
"Stage To Commit"] \
2851 -command do_add_selection \
2853 lappend disable_on_lock \
2854 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2856 .mbar.commit add
command -label [mc
"Stage Changed Files To Commit"] \
2857 -command do_add_all \
2859 lappend disable_on_lock \
2860 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2862 .mbar.commit add
command -label [mc
"Unstage From Commit"] \
2863 -command do_unstage_selection \
2865 lappend disable_on_lock \
2866 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2868 .mbar.commit add
command -label [mc
"Revert Changes"] \
2869 -command do_revert_selection \
2871 lappend disable_on_lock \
2872 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2874 .mbar.commit add separator
2876 .mbar.commit add
command -label [mc
"Show Less Context"] \
2877 -command show_less_context \
2878 -accelerator $M1T-\
-
2880 .mbar.commit add
command -label [mc
"Show More Context"] \
2881 -command show_more_context \
2884 .mbar.commit add separator
2886 if {![is_enabled nocommitmsg
]} {
2887 .mbar.commit add
command -label [mc
"Sign Off"] \
2888 -command do_signoff \
2892 .mbar.commit add
command -label [commit_btn_caption
] \
2893 -command do_commit \
2894 -accelerator $M1T-Return
2895 lappend disable_on_lock \
2896 [list .mbar.commit entryconf
[.mbar.commit index last
] -state]
2901 if {[is_enabled branch
]} {
2903 .mbar.merge add
command -label [mc
"Local Merge..."] \
2904 -command merge
::dialog \
2906 lappend disable_on_lock \
2907 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
2908 .mbar.merge add
command -label [mc
"Abort Merge..."] \
2909 -command merge
::reset_hard
2910 lappend disable_on_lock \
2911 [list .mbar.merge entryconf
[.mbar.merge index last
] -state]
2916 if {[is_enabled transport
]} {
2919 .mbar.remote add
command \
2920 -label [mc
"Add..."] \
2921 -command remote_add
::dialog \
2923 .mbar.remote add
command \
2924 -label [mc
"Push..."] \
2925 -command do_push_anywhere \
2927 .mbar.remote add
command \
2928 -label [mc
"Delete Branch..."] \
2929 -command remote_branch_delete
::dialog
2933 proc
::tk
::mac
::ShowPreferences
{} {do_options
}
2937 .mbar.edit add separator
2938 .mbar.edit add
command -label [mc
"Options..."] \
2944 if {[is_enabled multicommit
] ||
[is_enabled singlecommit
]} {
2945 set tools_menubar .mbar.tools
2947 $tools_menubar add separator
2948 $tools_menubar add
command -label [mc
"Add..."] -command tools_add
::dialog
2949 $tools_menubar add
command -label [mc
"Remove..."] -command tools_remove
::dialog
2951 if {[array names repo_config guitool.
*.cmd
] ne
{}} {
2958 .mbar add cascade
-label [mc Help
] -menu .mbar.
help
2962 .mbar.apple add
command -label [mc
"About %s" [appname
]] \
2964 .mbar.apple add separator
2966 .mbar.
help add
command -label [mc
"About %s" [appname
]] \
2969 . configure
-menu .mbar
2971 set doc_path
[githtmldir
]
2972 if {$doc_path ne
{}} {
2973 set doc_path
[file join $doc_path index.html
]
2976 set doc_path
[exec cygpath
--mixed $doc_path]
2980 if {[file isfile
$doc_path]} {
2981 set doc_url
"file:$doc_path"
2983 set doc_url
{http
://www.kernel.org
/pub
/software
/scm
/git
/docs
/}
2986 proc start_browser
{url
} {
2987 git
"web--browse" $url
2990 .mbar.
help add
command -label [mc
"Online Documentation"] \
2991 -command [list start_browser
$doc_url]
2993 .mbar.
help add
command -label [mc
"Show SSH Key"] \
2996 unset doc_path doc_url
2998 # -- Standard bindings
3000 wm protocol . WM_DELETE_WINDOW do_quit
3001 bind all
<$M1B-Key-q> do_quit
3002 bind all
<$M1B-Key-Q> do_quit
3003 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
3004 bind all
<$M1B-Key-W> {destroy
[winfo toplevel
%W
]}
3006 set subcommand_args
{}
3008 set s
"usage: $::argv0 $::subcommand $::subcommand_args"
3009 if {[tk windowingsystem
] eq
"win32"} {
3011 tk_messageBox
-icon info
-message $s \
3019 proc normalize_relpath
{path
} {
3021 foreach item
[file split $path] {
3022 if {$item eq
{.
}} continue
3023 if {$item eq
{..
} && [llength
$elements] > 0
3024 && [lindex
$elements end
] ne
{..
}} {
3025 set elements
[lrange
$elements 0 end-1
]
3028 lappend elements
$item
3030 return [eval file join $elements]
3033 # -- Not a normal commit type invocation? Do that instead!
3035 switch
-- $subcommand {
3038 if {$subcommand eq
"blame"} {
3039 set subcommand_args
{[--line=<num
>] rev? path
}
3041 set subcommand_args
{rev? path
}
3043 if {$argv eq
{}} usage
3049 set p
[file join $_prefix $a]
3051 if {$is_path ||
[file exists
$p]} {
3052 if {$path ne
{}} usage
3053 set path
[normalize_relpath
$p]
3055 } elseif
{$a eq
{--}} {
3057 if {$head ne
{}} usage
3062 } elseif
{[regexp
{^
--line=(\d
+)$
} $a a lnum
]} {
3063 if {$jump_spec ne
{} ||
$head ne
{}} usage
3064 set jump_spec
[list
$lnum]
3065 } elseif
{$head eq
{}} {
3066 if {$head ne
{}} usage
3075 if {$head ne
{} && $path eq
{}} {
3076 if {[string index
$head 0] eq
{/}} {
3077 set path
[normalize_relpath
$head]
3080 set path
[normalize_relpath
$_prefix$head]
3088 if {[regexp
{^
[0-9a-f]{1,39}$
} $head]} {
3090 set head [git rev-parse
--verify $head]
3092 if {[tk windowingsystem
] eq
"win32"} {
3093 tk_messageBox
-icon error
-title [mc Error
] -message $err
3100 set current_branch
$head
3104 switch
-- $subcommand {
3106 if {$jump_spec ne
{}} usage
3108 if {$path ne
{} && [file isdirectory
$path]} {
3109 set head $current_branch
3115 browser
::new
$head $path
3118 if {$head eq
{} && ![file exists
$path]} {
3119 catch
{wm withdraw .
}
3123 -title [mc
"git-gui: fatal error"] \
3124 -message [mc
"fatal: cannot stat path %s: No such file or directory" $path]
3127 blame
::new
$head $path $jump_spec
3134 if {[llength
$argv] != 0} {
3137 # fall through to setup UI for commits
3140 set err
"usage: $argv0 \[{blame|browser|citool}\]"
3141 if {[tk windowingsystem
] eq
"win32"} {
3143 tk_messageBox
-icon error
-message $err \
3154 ${NS}::frame .branch
3155 if {!$use_ttk} {.branch configure
-borderwidth 1 -relief sunken
}
3156 ${NS}::label .branch.l1 \
3157 -text [mc
"Current Branch:"] \
3160 ${NS}::label .branch.cb \
3161 -textvariable current_branch \
3164 pack .branch.l1
-side left
3165 pack .branch.cb
-side left
-fill x
3166 pack .branch
-side top
-fill x
3168 # -- Main Window Layout
3170 ${NS}::panedwindow .vpane
-orient horizontal
3171 ${NS}::panedwindow .vpane.files
-orient vertical
3173 .vpane add .vpane.files
3175 .vpane add .vpane.files
-sticky nsew
-height 100 -width 200
3177 pack .vpane
-anchor n
-side top
-fill both
-expand 1
3179 # -- Index File List
3181 ${NS}::frame .vpane.files.index
-height 100 -width 200
3182 tlabel .vpane.files.index.title \
3183 -text [mc
"Staged Changes (Will Commit)"] \
3184 -background lightgreen
-foreground black
3185 text
$ui_index -background white
-foreground black \
3187 -width 20 -height 10 \
3189 -cursor $cursor_ptr \
3190 -xscrollcommand {.vpane.files.index.sx
set} \
3191 -yscrollcommand {.vpane.files.index.sy
set} \
3193 ${NS}::scrollbar .vpane.files.index.sx
-orient h
-command [list
$ui_index xview
]
3194 ${NS}::scrollbar .vpane.files.index.sy
-orient v
-command [list
$ui_index yview
]
3195 pack .vpane.files.index.title
-side top
-fill x
3196 pack .vpane.files.index.sx
-side bottom
-fill x
3197 pack .vpane.files.index.sy
-side right
-fill y
3198 pack
$ui_index -side left
-fill both
-expand 1
3200 # -- Working Directory File List
3202 ${NS}::frame .vpane.files.workdir
-height 100 -width 200
3203 tlabel .vpane.files.workdir.title
-text [mc
"Unstaged Changes"] \
3204 -background lightsalmon
-foreground black
3205 text
$ui_workdir -background white
-foreground black \
3207 -width 20 -height 10 \
3209 -cursor $cursor_ptr \
3210 -xscrollcommand {.vpane.files.workdir.sx
set} \
3211 -yscrollcommand {.vpane.files.workdir.sy
set} \
3213 ${NS}::scrollbar .vpane.files.workdir.sx
-orient h
-command [list
$ui_workdir xview
]
3214 ${NS}::scrollbar .vpane.files.workdir.sy
-orient v
-command [list
$ui_workdir yview
]
3215 pack .vpane.files.workdir.title
-side top
-fill x
3216 pack .vpane.files.workdir.sx
-side bottom
-fill x
3217 pack .vpane.files.workdir.sy
-side right
-fill y
3218 pack
$ui_workdir -side left
-fill both
-expand 1
3220 .vpane.files add .vpane.files.workdir
3221 .vpane.files add .vpane.files.index
3223 .vpane.files paneconfigure .vpane.files.workdir
-sticky news
3224 .vpane.files paneconfigure .vpane.files.index
-sticky news
3227 foreach i
[list
$ui_index $ui_workdir] {
3229 $i tag conf in_diff
-background [$i tag cget in_sel
-background]
3233 # -- Diff and Commit Area
3236 ${NS}::panedwindow .vpane.lower
-orient vertical
3237 ${NS}::frame .vpane.lower.commarea
3238 ${NS}::frame .vpane.lower.
diff -relief sunken
-borderwidth 1 -height 500
3239 .vpane.lower add .vpane.lower.
diff
3240 .vpane.lower add .vpane.lower.commarea
3241 .vpane add .vpane.lower
3243 .vpane.lower pane .vpane.lower.
diff -weight 1
3244 .vpane.lower pane .vpane.lower.commarea
-weight 0
3246 .vpane.lower paneconfigure .vpane.lower.
diff -stretch always
3247 .vpane.lower paneconfigure .vpane.lower.commarea
-stretch never
3250 frame .vpane.lower
-height 300 -width 400
3251 frame .vpane.lower.commarea
3252 frame .vpane.lower.
diff -relief sunken
-borderwidth 1
3253 pack .vpane.lower.
diff -fill both
-expand 1
3254 pack .vpane.lower.commarea
-side bottom
-fill x
3255 .vpane add .vpane.lower
3256 .vpane paneconfigure .vpane.lower
-sticky nsew
3259 # -- Commit Area Buttons
3261 ${NS}::frame .vpane.lower.commarea.buttons
3262 ${NS}::label .vpane.lower.commarea.buttons.l
-text {} \
3265 pack .vpane.lower.commarea.buttons.l
-side top
-fill x
3266 pack .vpane.lower.commarea.buttons
-side left
-fill y
3268 ${NS}::button .vpane.lower.commarea.buttons.rescan
-text [mc Rescan
] \
3269 -command ui_do_rescan
3270 pack .vpane.lower.commarea.buttons.rescan
-side top
-fill x
3271 lappend disable_on_lock \
3272 {.vpane.lower.commarea.buttons.rescan conf
-state}
3274 ${NS}::button .vpane.lower.commarea.buttons.incall
-text [mc
"Stage Changed"] \
3276 pack .vpane.lower.commarea.buttons.incall
-side top
-fill x
3277 lappend disable_on_lock \
3278 {.vpane.lower.commarea.buttons.incall conf
-state}
3280 if {![is_enabled nocommitmsg
]} {
3281 ${NS}::button .vpane.lower.commarea.buttons.signoff
-text [mc
"Sign Off"] \
3283 pack .vpane.lower.commarea.buttons.signoff
-side top
-fill x
3286 ${NS}::button .vpane.lower.commarea.buttons.commit
-text [commit_btn_caption
] \
3288 pack .vpane.lower.commarea.buttons.commit
-side top
-fill x
3289 lappend disable_on_lock \
3290 {.vpane.lower.commarea.buttons.commit conf
-state}
3292 if {![is_enabled nocommit
]} {
3293 ${NS}::button .vpane.lower.commarea.buttons.push
-text [mc Push
] \
3294 -command do_push_anywhere
3295 pack .vpane.lower.commarea.buttons.push
-side top
-fill x
3298 # -- Commit Message Buffer
3300 ${NS}::frame .vpane.lower.commarea.buffer
3301 ${NS}::frame .vpane.lower.commarea.buffer.header
3302 set ui_comm .vpane.lower.commarea.buffer.t
3303 set ui_coml .vpane.lower.commarea.buffer.header.l
3305 if {![is_enabled nocommit
]} {
3306 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3307 -text [mc
"New Commit"] \
3308 -command do_select_commit_type \
3309 -variable selected_commit_type \
3311 lappend disable_on_lock \
3312 [list .vpane.lower.commarea.buffer.header.new conf
-state]
3313 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3314 -text [mc
"Amend Last Commit"] \
3315 -command do_select_commit_type \
3316 -variable selected_commit_type \
3318 lappend disable_on_lock \
3319 [list .vpane.lower.commarea.buffer.header.amend conf
-state]
3322 ${NS}::label
$ui_coml \
3325 proc trace_commit_type
{varname args
} {
3326 global ui_coml commit_type
3327 switch
-glob -- $commit_type {
3328 initial
{set txt
[mc
"Initial Commit Message:"]}
3329 amend
{set txt
[mc
"Amended Commit Message:"]}
3330 amend-initial
{set txt
[mc
"Amended Initial Commit Message:"]}
3331 amend-merge
{set txt
[mc
"Amended Merge Commit Message:"]}
3332 merge
{set txt
[mc
"Merge Commit Message:"]}
3333 * {set txt
[mc
"Commit Message:"]}
3335 $ui_coml conf
-text $txt
3337 trace add variable commit_type
write trace_commit_type
3338 pack
$ui_coml -side left
-fill x
3340 if {![is_enabled nocommit
]} {
3341 pack .vpane.lower.commarea.buffer.header.amend
-side right
3342 pack .vpane.lower.commarea.buffer.header.new
-side right
3345 text
$ui_comm -background white
-foreground black \
3349 -autoseparators true \
3351 -width $repo_config(gui.commitmsgwidth
) -height 9 -wrap none \
3353 -yscrollcommand {.vpane.lower.commarea.buffer.sby
set}
3354 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3355 -command [list
$ui_comm yview
]
3356 pack .vpane.lower.commarea.buffer.header
-side top
-fill x
3357 pack .vpane.lower.commarea.buffer.sby
-side right
-fill y
3358 pack
$ui_comm -side left
-fill y
3359 pack .vpane.lower.commarea.buffer
-side left
-fill y
3361 # -- Commit Message Buffer Context Menu
3363 set ctxm .vpane.lower.commarea.buffer.ctxm
3364 menu
$ctxm -tearoff 0
3367 -command {tk_textCut
$ui_comm}
3370 -command {tk_textCopy
$ui_comm}
3373 -command {tk_textPaste
$ui_comm}
3375 -label [mc Delete
] \
3376 -command {catch
{$ui_comm delete sel.first sel.last
}}
3379 -label [mc
"Select All"] \
3380 -command {focus
$ui_comm;$ui_comm tag add sel
0.0 end
}
3382 -label [mc
"Copy All"] \
3384 $ui_comm tag add sel
0.0 end
3385 tk_textCopy
$ui_comm
3386 $ui_comm tag remove sel
0.0 end
3390 -label [mc
"Sign Off"] \
3392 set ui_comm_ctxm
$ctxm
3396 proc trace_current_diff_path
{varname args
} {
3397 global current_diff_path diff_actions file_states
3398 if {$current_diff_path eq
{}} {
3404 set p
$current_diff_path
3405 set s
[mapdesc
[lindex
$file_states($p) 0] $p]
3407 set p
[escape_path
$p]
3411 .vpane.lower.
diff.header.status configure
-text $s
3412 .vpane.lower.
diff.header.
file configure
-text $f
3413 .vpane.lower.
diff.header.path configure
-text $p
3414 foreach w
$diff_actions {
3418 trace add variable current_diff_path
write trace_current_diff_path
3420 gold_frame .vpane.lower.
diff.header
3421 tlabel .vpane.lower.
diff.header.status \
3424 -width $max_status_desc \
3427 tlabel .vpane.lower.
diff.header.
file \
3432 tlabel .vpane.lower.
diff.header.path \
3437 pack .vpane.lower.
diff.header.status
-side left
3438 pack .vpane.lower.
diff.header.
file -side left
3439 pack .vpane.lower.
diff.header.path
-fill x
3440 set ctxm .vpane.lower.
diff.header.ctxm
3441 menu
$ctxm -tearoff 0
3449 -- $current_diff_path
3451 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3452 bind_button3 .vpane.lower.
diff.header.path
"tk_popup $ctxm %X %Y"
3456 ${NS}::frame .vpane.lower.
diff.body
3457 set ui_diff .vpane.lower.
diff.body.t
3458 text
$ui_diff -background white
-foreground black \
3460 -width 80 -height 5 -wrap none \
3462 -xscrollcommand {.vpane.lower.
diff.body.sbx
set} \
3463 -yscrollcommand {.vpane.lower.
diff.body.sby
set} \
3465 catch
{$ui_diff configure
-tabstyle wordprocessor
}
3466 ${NS}::scrollbar .vpane.lower.
diff.body.sbx
-orient horizontal \
3467 -command [list
$ui_diff xview
]
3468 ${NS}::scrollbar .vpane.lower.
diff.body.sby
-orient vertical \
3469 -command [list
$ui_diff yview
]
3470 pack .vpane.lower.
diff.body.sbx
-side bottom
-fill x
3471 pack .vpane.lower.
diff.body.sby
-side right
-fill y
3472 pack
$ui_diff -side left
-fill both
-expand 1
3473 pack .vpane.lower.
diff.header
-side top
-fill x
3474 pack .vpane.lower.
diff.body
-side bottom
-fill both
-expand 1
3476 foreach
{n c
} {0 black
1 red4
2 green4
3 yellow4
4 blue4
5 magenta4
6 cyan4
7 grey60
} {
3477 $ui_diff tag configure clr4
$n -background $c
3478 $ui_diff tag configure clri4
$n -foreground $c
3479 $ui_diff tag configure clr3
$n -foreground $c
3480 $ui_diff tag configure clri3
$n -background $c
3482 $ui_diff tag configure clr1
-font font_diffbold
3483 $ui_diff tag configure clr4
-underline 1
3485 $ui_diff tag conf d_info
-foreground blue
-font font_diffbold
3487 $ui_diff tag conf d_cr
-elide true
3488 $ui_diff tag conf d_@
-font font_diffbold
3489 $ui_diff tag conf d_
+ -foreground {#00a000}
3490 $ui_diff tag conf d_-
-foreground red
3492 $ui_diff tag conf d_
++ -foreground {#00a000}
3493 $ui_diff tag conf d_--
-foreground red
3494 $ui_diff tag conf d_
+s \
3495 -foreground {#00a000} \
3496 -background {#e2effa}
3497 $ui_diff tag conf d_-s \
3499 -background {#e2effa}
3500 $ui_diff tag conf d_s
+ \
3501 -foreground {#00a000} \
3503 $ui_diff tag conf d_s- \
3507 $ui_diff tag conf d
< \
3508 -foreground orange \
3510 $ui_diff tag conf d
= \
3511 -foreground orange \
3513 $ui_diff tag conf d
> \
3514 -foreground orange \
3517 $ui_diff tag raise sel
3519 # -- Diff Body Context Menu
3522 proc create_common_diff_popup
{ctxm
} {
3524 -label [mc Refresh
] \
3525 -command reshow_diff
3526 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3529 -command {tk_textCopy
$ui_diff}
3530 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3532 -label [mc
"Select All"] \
3533 -command {focus
$ui_diff;$ui_diff tag add sel
0.0 end
}
3534 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3536 -label [mc
"Copy All"] \
3538 $ui_diff tag add sel
0.0 end
3539 tk_textCopy
$ui_diff
3540 $ui_diff tag remove sel
0.0 end
3542 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3545 -label [mc
"Decrease Font Size"] \
3546 -command {incr_font_size font_diff
-1}
3547 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3549 -label [mc
"Increase Font Size"] \
3550 -command {incr_font_size font_diff
1}
3551 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3555 build_encoding_menu
$emenu [list force_diff_encoding
]
3557 -label [mc
"Encoding"] \
3559 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3561 $ctxm add
command -label [mc
"Options..."] \
3565 set ctxm .vpane.lower.
diff.body.ctxm
3566 menu
$ctxm -tearoff 0
3568 -label [mc
"Apply/Reverse Hunk"] \
3569 -command {apply_hunk
$cursorX $cursorY}
3570 set ui_diff_applyhunk
[$ctxm index last
]
3571 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyhunk -state]
3573 -label [mc
"Apply/Reverse Line"] \
3574 -command {apply_range_or_line
$cursorX $cursorY; do_rescan
}
3575 set ui_diff_applyline
[$ctxm index last
]
3576 lappend diff_actions
[list
$ctxm entryconf
$ui_diff_applyline -state]
3579 -label [mc
"Show Less Context"] \
3580 -command show_less_context
3581 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3583 -label [mc
"Show More Context"] \
3584 -command show_more_context
3585 lappend diff_actions
[list
$ctxm entryconf
[$ctxm index last
] -state]
3587 create_common_diff_popup
$ctxm
3589 set ctxmmg .vpane.lower.
diff.body.ctxmmg
3590 menu
$ctxmmg -tearoff 0
3591 $ctxmmg add
command \
3592 -label [mc
"Run Merge Tool"] \
3593 -command {merge_resolve_tool
}
3594 lappend diff_actions
[list
$ctxmmg entryconf
[$ctxmmg index last
] -state]
3595 $ctxmmg add separator
3596 $ctxmmg add
command \
3597 -label [mc
"Use Remote Version"] \
3598 -command {merge_resolve_one
3}
3599 lappend diff_actions
[list
$ctxmmg entryconf
[$ctxmmg index last
] -state]
3600 $ctxmmg add
command \
3601 -label [mc
"Use Local Version"] \
3602 -command {merge_resolve_one
2}
3603 lappend diff_actions
[list
$ctxmmg entryconf
[$ctxmmg index last
] -state]
3604 $ctxmmg add
command \
3605 -label [mc
"Revert To Base"] \
3606 -command {merge_resolve_one
1}
3607 lappend diff_actions
[list
$ctxmmg entryconf
[$ctxmmg index last
] -state]
3608 $ctxmmg add separator
3609 $ctxmmg add
command \
3610 -label [mc
"Show Less Context"] \
3611 -command show_less_context
3612 lappend diff_actions
[list
$ctxmmg entryconf
[$ctxmmg index last
] -state]
3613 $ctxmmg add
command \
3614 -label [mc
"Show More Context"] \
3615 -command show_more_context
3616 lappend diff_actions
[list
$ctxmmg entryconf
[$ctxmmg index last
] -state]
3617 $ctxmmg add separator
3618 create_common_diff_popup
$ctxmmg
3620 set ctxmsm .vpane.lower.
diff.body.ctxmsm
3621 menu
$ctxmsm -tearoff 0
3622 $ctxmsm add
command \
3623 -label [mc
"Visualize These Changes In The Submodule"] \
3624 -command {do_gitk
-- true
}
3625 lappend diff_actions
[list
$ctxmsm entryconf
[$ctxmsm index last
] -state]
3626 $ctxmsm add
command \
3627 -label [mc
"Visualize Current Branch History In The Submodule"] \
3628 -command {do_gitk
{} true
}
3629 lappend diff_actions
[list
$ctxmsm entryconf
[$ctxmsm index last
] -state]
3630 $ctxmsm add
command \
3631 -label [mc
"Visualize All Branch History In The Submodule"] \
3632 -command {do_gitk
--all true
}
3633 lappend diff_actions
[list
$ctxmsm entryconf
[$ctxmsm index last
] -state]
3634 $ctxmsm add separator
3635 $ctxmsm add
command \
3636 -label [mc
"Start git gui In The Submodule"] \
3637 -command {do_git_gui
}
3638 lappend diff_actions
[list
$ctxmsm entryconf
[$ctxmsm index last
] -state]
3639 $ctxmsm add separator
3640 create_common_diff_popup
$ctxmsm
3642 proc has_textconv
{path
} {
3643 if {[is_config_false gui.textconv
]} {
3646 set filter
[gitattr
$path diff set]
3647 set textconv
[get_config
[join [list
diff $filter textconv
] .
]]
3648 if {$filter ne
{set} && $textconv ne
{}} {
3655 proc popup_diff_menu
{ctxm ctxmmg ctxmsm x y X Y
} {
3656 global current_diff_path file_states
3659 if {[info exists file_states
($current_diff_path)]} {
3660 set state
[lindex
$file_states($current_diff_path) 0]
3664 if {[string first
{U
} $state] >= 0} {
3665 tk_popup
$ctxmmg $X $Y
3666 } elseif
{$
::is_submodule_diff
} {
3667 tk_popup
$ctxmsm $X $Y
3669 set has_range
[expr {[$
::ui_diff tag nextrange sel
0.0] != {}}]
3670 if {$
::ui_index eq $
::current_diff_side
} {
3671 set l
[mc
"Unstage Hunk From Commit"]
3673 set t
[mc
"Unstage Lines From Commit"]
3675 set t
[mc
"Unstage Line From Commit"]
3678 set l
[mc
"Stage Hunk For Commit"]
3680 set t
[mc
"Stage Lines For Commit"]
3682 set t
[mc
"Stage Line For Commit"]
3686 ||
$current_diff_path eq
{}
3689 ||
[string match
{?T
} $state]
3690 ||
[string match
{T?
} $state]
3691 ||
[has_textconv
$current_diff_path]} {
3696 $ctxm entryconf $
::ui_diff_applyhunk
-state $s -label $l
3697 $ctxm entryconf $
::ui_diff_applyline
-state $s -label $t
3698 tk_popup
$ctxm $X $Y
3701 bind_button3
$ui_diff [list popup_diff_menu
$ctxm $ctxmmg $ctxmsm %x
%y
%X
%Y
]
3705 set main_status
[::status_bar
::new .status
]
3706 pack .status
-anchor w
-side bottom
-fill x
3707 $main_status show
[mc
"Initializing..."]
3711 proc on_ttk_pane_mapped
{w pane pos
} {
3713 after
0 [list after idle
[list
$w sashpos
$pane $pos]]
3715 proc on_tk_pane_mapped
{w pane x y
} {
3717 after
0 [list after idle
[list
$w sash place
$pane $x $y]]
3719 proc on_application_mapped
{} {
3720 global repo_config use_ttk
3722 set gm
$repo_config(gui.geometry
)
3725 [list on_ttk_pane_mapped
%W
0 [lindex
$gm 1]]
3726 bind .vpane.files
<Map
> \
3727 [list on_ttk_pane_mapped
%W
0 [lindex
$gm 2]]
3730 [list on_tk_pane_mapped
%W
0 \
3732 [lindex
[.vpane sash coord
0] 1]]
3733 bind .vpane.files
<Map
> \
3734 [list on_tk_pane_mapped
%W
0 \
3735 [lindex
[.vpane.files sash coord
0] 0] \
3738 wm geometry .
[lindex
$gm 0]
3740 if {[info exists repo_config
(gui.geometry
)]} {
3741 bind .
<Map
> [list on_application_mapped
]
3742 wm geometry .
[lindex
$repo_config(gui.geometry
) 0]
3745 # -- Load window state
3747 if {[info exists repo_config
(gui.wmstate
)]} {
3748 catch
{wm state .
$repo_config(gui.wmstate
)}
3753 bind $ui_comm <$M1B-Key-Return> {do_commit
;break}
3754 bind $ui_comm <$M1B-Key-t> {do_add_selection
;break}
3755 bind $ui_comm <$M1B-Key-T> {do_add_selection
;break}
3756 bind $ui_comm <$M1B-Key-u> {do_unstage_selection
;break}
3757 bind $ui_comm <$M1B-Key-U> {do_unstage_selection
;break}
3758 bind $ui_comm <$M1B-Key-j> {do_revert_selection
;break}
3759 bind $ui_comm <$M1B-Key-J> {do_revert_selection
;break}
3760 bind $ui_comm <$M1B-Key-i> {do_add_all
;break}
3761 bind $ui_comm <$M1B-Key-I> {do_add_all
;break}
3762 bind $ui_comm <$M1B-Key-x> {tk_textCut
%W
;break}
3763 bind $ui_comm <$M1B-Key-X> {tk_textCut
%W
;break}
3764 bind $ui_comm <$M1B-Key-c> {tk_textCopy
%W
;break}
3765 bind $ui_comm <$M1B-Key-C> {tk_textCopy
%W
;break}
3766 bind $ui_comm <$M1B-Key-v> {tk_textPaste
%W
; %W see insert
; break}
3767 bind $ui_comm <$M1B-Key-V> {tk_textPaste
%W
; %W see insert
; break}
3768 bind $ui_comm <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
3769 bind $ui_comm <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
3770 bind $ui_comm <$M1B-Key-minus> {show_less_context
;break}
3771 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context
;break}
3772 bind $ui_comm <$M1B-Key-equal> {show_more_context
;break}
3773 bind $ui_comm <$M1B-Key-plus> {show_more_context
;break}
3774 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context
;break}
3776 bind $ui_diff <$M1B-Key-x> {tk_textCopy
%W
;break}
3777 bind $ui_diff <$M1B-Key-X> {tk_textCopy
%W
;break}
3778 bind $ui_diff <$M1B-Key-c> {tk_textCopy
%W
;break}
3779 bind $ui_diff <$M1B-Key-C> {tk_textCopy
%W
;break}
3780 bind $ui_diff <$M1B-Key-v> {break}
3781 bind $ui_diff <$M1B-Key-V> {break}
3782 bind $ui_diff <$M1B-Key-a> {%W tag add sel
0.0 end
;break}
3783 bind $ui_diff <$M1B-Key-A> {%W tag add sel
0.0 end
;break}
3784 bind $ui_diff <$M1B-Key-j> {do_revert_selection
;break}
3785 bind $ui_diff <$M1B-Key-J> {do_revert_selection
;break}
3786 bind $ui_diff <Key-Up
> {catch
{%W yview scroll
-1 units
};break}
3787 bind $ui_diff <Key-Down
> {catch
{%W yview scroll
1 units
};break}
3788 bind $ui_diff <Key-Left
> {catch
{%W xview scroll
-1 units
};break}
3789 bind $ui_diff <Key-Right
> {catch
{%W xview scroll
1 units
};break}
3790 bind $ui_diff <Key-k
> {catch
{%W yview scroll
-1 units
};break}
3791 bind $ui_diff <Key-j
> {catch
{%W yview scroll
1 units
};break}
3792 bind $ui_diff <Key-h
> {catch
{%W xview scroll
-1 units
};break}
3793 bind $ui_diff <Key-l
> {catch
{%W xview scroll
1 units
};break}
3794 bind $ui_diff <Control-Key-b
> {catch
{%W yview scroll
-1 pages
};break}
3795 bind $ui_diff <Control-Key-f
> {catch
{%W yview scroll
1 pages
};break}
3796 bind $ui_diff <Button-1
> {focus
%W
}
3798 if {[is_enabled branch
]} {
3799 bind .
<$M1B-Key-n> branch_create
::dialog
3800 bind .
<$M1B-Key-N> branch_create
::dialog
3801 bind .
<$M1B-Key-o> branch_checkout
::dialog
3802 bind .
<$M1B-Key-O> branch_checkout
::dialog
3803 bind .
<$M1B-Key-m> merge
::dialog
3804 bind .
<$M1B-Key-M> merge
::dialog
3806 if {[is_enabled transport
]} {
3807 bind .
<$M1B-Key-p> do_push_anywhere
3808 bind .
<$M1B-Key-P> do_push_anywhere
3811 bind .
<Key-F5
> ui_do_rescan
3812 bind .
<$M1B-Key-r> ui_do_rescan
3813 bind .
<$M1B-Key-R> ui_do_rescan
3814 bind .
<$M1B-Key-s> do_signoff
3815 bind .
<$M1B-Key-S> do_signoff
3816 bind .
<$M1B-Key-t> do_add_selection
3817 bind .
<$M1B-Key-T> do_add_selection
3818 bind .
<$M1B-Key-u> do_unstage_selection
3819 bind .
<$M1B-Key-U> do_unstage_selection
3820 bind .
<$M1B-Key-j> do_revert_selection
3821 bind .
<$M1B-Key-J> do_revert_selection
3822 bind .
<$M1B-Key-i> do_add_all
3823 bind .
<$M1B-Key-I> do_add_all
3824 bind .
<$M1B-Key-minus> {show_less_context
;break}
3825 bind .
<$M1B-Key-KP_Subtract> {show_less_context
;break}
3826 bind .
<$M1B-Key-equal> {show_more_context
;break}
3827 bind .
<$M1B-Key-plus> {show_more_context
;break}
3828 bind .
<$M1B-Key-KP_Add> {show_more_context
;break}
3829 bind .
<$M1B-Key-Return> do_commit
3830 foreach i
[list
$ui_index $ui_workdir] {
3831 bind $i <Button-1
> "toggle_or_diff $i %x %y; break"
3832 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3833 bind $i <Shift-Button-1
> "add_range_to_selection $i %x %y; break"
3837 set file_lists
($ui_index) [list
]
3838 set file_lists
($ui_workdir) [list
]
3840 wm title .
"[appname] ([reponame]) [file normalize $_gitworktree]"
3841 focus
-force $ui_comm
3843 # -- Warn the user about environmental problems. Cygwin's Tcl
3844 # does *not* pass its env array onto any processes it spawns.
3845 # This means that git processes get none of our environment.
3850 set msg
[mc
"Possible environment issues exist.
3852 The following environment variables are probably
3853 going to be ignored by any Git subprocess run
3857 foreach name
[array names env
] {
3858 switch
-regexp -- $name {
3859 {^GIT_INDEX_FILE$
} -
3860 {^GIT_OBJECT_DIRECTORY$
} -
3861 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$
} -
3863 {^GIT_EXTERNAL_DIFF$
} -
3867 {^GIT_
(AUTHOR|COMMITTER
)_DATE$
} {
3868 append msg
" - $name\n"
3871 {^GIT_
(AUTHOR|COMMITTER
)_
(NAME|EMAIL
)$
} {
3872 append msg
" - $name\n"
3874 set suggest_user
$name
3878 if {$ignored_env > 0} {
3880 This is due to a known issue with the
3881 Tcl binary distributed by Cygwin."]
3883 if {$suggest_user ne
{}} {
3886 A good replacement for %s
3887 is placing values for the user.name and
3888 user.email settings into your personal
3894 unset ignored_env msg suggest_user name
3897 # -- Only initialize complex UI if we are going to stay running.
3899 if {[is_enabled transport
]} {
3902 set n
[.mbar.remote index end
]
3903 populate_remotes_menu
3904 set n
[expr {[.mbar.remote index end
] - $n}]
3906 if {[.mbar.remote
type 0] eq
"tearoff"} { incr n
}
3907 .mbar.remote insert
$n separator
3912 if {[winfo exists
$ui_comm]} {
3913 set GITGUI_BCK_exists
[load_message GITGUI_BCK utf-8
]
3915 # -- If both our backup and message files exist use the
3916 # newer of the two files to initialize the buffer.
3918 if {$GITGUI_BCK_exists} {
3919 set m
[gitdir GITGUI_MSG
]
3920 if {[file isfile
$m]} {
3921 if {[file mtime
[gitdir GITGUI_BCK
]] > [file mtime
$m]} {
3922 catch
{file delete
[gitdir GITGUI_MSG
]}
3924 $ui_comm delete
0.0 end
3926 $ui_comm edit modified false
3927 catch
{file delete
[gitdir GITGUI_BCK
]}
3928 set GITGUI_BCK_exists
0
3934 proc backup_commit_buffer
{} {
3935 global ui_comm GITGUI_BCK_exists
3937 set m
[$ui_comm edit modified
]
3938 if {$m ||
$GITGUI_BCK_exists} {
3939 set msg
[string trim
[$ui_comm get
0.0 end
]]
3940 regsub
-all -line {[ \r\t]+$
} $msg {} msg
3943 if {$GITGUI_BCK_exists} {
3944 catch
{file delete
[gitdir GITGUI_BCK
]}
3945 set GITGUI_BCK_exists
0
3949 set fd
[open
[gitdir GITGUI_BCK
] w
]
3950 fconfigure
$fd -encoding utf-8
3951 puts
-nonewline $fd $msg
3953 set GITGUI_BCK_exists
1
3957 $ui_comm edit modified false
3960 set ::GITGUI_BCK_i
[after
2000 backup_commit_buffer
]
3963 backup_commit_buffer
3965 # -- If the user has aspell available we can drive it
3966 # in pipe mode to spellcheck the commit message.
3968 set spell_cmd
[list |
]
3969 set spell_dict
[get_config gui.spellingdictionary
]
3970 lappend spell_cmd aspell
3971 if {$spell_dict ne
{}} {
3972 lappend spell_cmd
--master=$spell_dict
3974 lappend spell_cmd
--mode=none
3975 lappend spell_cmd
--encoding=utf-8
3976 lappend spell_cmd pipe
3977 if {$spell_dict eq
{none
}
3978 ||
[catch
{set spell_fd
[open
$spell_cmd r
+]} spell_err
]} {
3979 bind_button3
$ui_comm [list tk_popup
$ui_comm_ctxm %X
%Y
]
3981 set ui_comm_spell
[spellcheck
::init \
3987 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3990 lock_index begin-read
3991 if {![winfo ismapped .
]} {
3995 if {[is_enabled initialamend
]} {
4001 if {[is_enabled nocommitmsg
]} {
4002 $ui_comm configure
-state disabled
-background gray
4005 if {[is_enabled multicommit
] && ![is_config_false gui.gcwarning
]} {
4008 if {[is_enabled retcode
]} {
4009 bind .
<Destroy
> {+terminate_me
%W
}
4011 if {$picked && [is_config_true gui.autoexplore
]} {
4017 # indent-tabs-mode: t