2 # Tcl ignores the next line -*- tcl -*- \
5 set appvers {@@GIT_VERSION@@}
7 Copyright © 2006, 2007 Shawn Pearce, Paul Mackerras.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
23 ######################################################################
27 set _appname [lindex [file split $argv0] end]
41 return [eval [concat [list file join $_gitdir] $args]]
49 ######################################################################
53 proc is_many_config {name} {
54 switch -glob -- $name {
63 proc load_config {include_global} {
64 global repo_config global_config default_config
66 array unset global_config
67 if {$include_global} {
69 set fd_rc [open "| git repo-config --global --list" r]
70 while {[gets $fd_rc line] >= 0} {
71 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
72 if {[is_many_config $name]} {
73 lappend global_config($name) $value
75 set global_config($name) $value
83 array unset repo_config
85 set fd_rc [open "| git repo-config --list" r]
86 while {[gets $fd_rc line] >= 0} {
87 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
88 if {[is_many_config $name]} {
89 lappend repo_config($name) $value
91 set repo_config($name) $value
98 foreach name [array names default_config] {
99 if {[catch {set v $global_config($name)}]} {
100 set global_config($name) $default_config($name)
102 if {[catch {set v $repo_config($name)}]} {
103 set repo_config($name) $default_config($name)
108 proc save_config {} {
109 global default_config font_descs
110 global repo_config global_config
111 global repo_config_new global_config_new
113 foreach option $font_descs {
114 set name [lindex $option 0]
115 set font [lindex $option 1]
116 font configure $font \
117 -family $global_config_new(gui.$font^^family) \
118 -size $global_config_new(gui.$font^^size)
119 font configure ${font}bold \
120 -family $global_config_new(gui.$font^^family) \
121 -size $global_config_new(gui.$font^^size)
122 set global_config_new(gui.$name) [font configure $font]
123 unset global_config_new(gui.$font^^family)
124 unset global_config_new(gui.$font^^size)
127 foreach name [array names default_config] {
128 set value $global_config_new($name)
129 if {$value ne $global_config($name)} {
130 if {$value eq $default_config($name)} {
131 catch {exec git repo-config --global --unset $name}
133 regsub -all "\[{}\]" $value {"} value
134 exec git repo-config --global $name $value
136 set global_config($name) $value
137 if {$value eq $repo_config($name)} {
138 catch {exec git repo-config --unset $name}
139 set repo_config($name) $value
144 foreach name [array names default_config] {
145 set value $repo_config_new($name)
146 if {$value ne $repo_config($name)} {
147 if {$value eq $global_config($name)} {
148 catch {exec git repo-config --unset $name}
150 regsub -all "\[{}\]" $value {"} value
151 exec git repo-config $name $value
153 set repo_config($name) $value
158 proc error_popup {msg} {
160 if {[reponame] ne {}} {
161 append title " ([reponame])"
163 set cmd [list tk_messageBox \
166 -title "$title: error" \
168 if {[winfo ismapped .]} {
169 lappend cmd -parent .
174 proc warn_popup {msg} {
176 if {[reponame] ne {}} {
177 append title " ([reponame])"
179 set cmd [list tk_messageBox \
182 -title "$title: warning" \
184 if {[winfo ismapped .]} {
185 lappend cmd -parent .
190 proc info_popup {msg} {
192 if {[reponame] ne {}} {
193 append title " ([reponame])"
203 proc ask_popup {msg} {
205 if {[reponame] ne {}} {
206 append title " ([reponame])"
208 return [tk_messageBox \
216 ######################################################################
220 if { [catch {set _gitdir $env(GIT_DIR)}]
221 && [catch {set _gitdir [exec git rev-parse --git-dir]} err]} {
222 catch {wm withdraw .}
223 error_popup "Cannot find the git directory:\n\n$err"
226 if {![file isdirectory $_gitdir]} {
227 catch {wm withdraw .}
228 error_popup "Git directory not found:\n\n$_gitdir"
231 if {[lindex [file split $_gitdir] end] ne {.git}} {
232 catch {wm withdraw .}
233 error_popup "Cannot use funny .git directory:\n\n$gitdir"
236 if {[catch {cd [file dirname $_gitdir]} err]} {
237 catch {wm withdraw .}
238 error_popup "No working directory [file dirname $_gitdir]:\n\n$err"
241 set _reponame [lindex [file split \
242 [file normalize [file dirname $_gitdir]]] \
246 if {[appname] eq {git-citool}} {
250 ######################################################################
258 set disable_on_lock [list]
259 set index_lock_type none
261 proc lock_index {type} {
262 global index_lock_type disable_on_lock
264 if {$index_lock_type eq {none}} {
265 set index_lock_type $type
266 foreach w $disable_on_lock {
267 uplevel #0 $w disabled
270 } elseif {$index_lock_type eq "begin-$type"} {
271 set index_lock_type $type
277 proc unlock_index {} {
278 global index_lock_type disable_on_lock
280 set index_lock_type none
281 foreach w $disable_on_lock {
286 ######################################################################
290 proc repository_state {ctvar hdvar mhvar} {
291 global current_branch
292 upvar $ctvar ct $hdvar hd $mhvar mh
296 if {[catch {set current_branch [exec git symbolic-ref HEAD]}]} {
297 set current_branch {}
299 regsub ^refs/((heads|tags|remotes)/)? \
305 if {[catch {set hd [exec git rev-parse --verify HEAD]}]} {
311 set merge_head [gitdir MERGE_HEAD]
312 if {[file exists $merge_head]} {
314 set fd_mh [open $merge_head r]
315 while {[gets $fd_mh line] >= 0} {
326 global PARENT empty_tree
328 set p [lindex $PARENT 0]
332 if {$empty_tree eq {}} {
333 set empty_tree [exec git mktree << {}]
338 proc rescan {after} {
339 global HEAD PARENT MERGE_HEAD commit_type
340 global ui_index ui_workdir ui_status_value ui_comm
341 global rescan_active file_states
344 if {$rescan_active > 0 || ![lock_index read]} return
346 repository_state newType newHEAD newMERGE_HEAD
347 if {[string match amend* $commit_type]
348 && $newType eq {normal}
349 && $newHEAD eq $HEAD} {
353 set MERGE_HEAD $newMERGE_HEAD
354 set commit_type $newType
357 array unset file_states
359 if {![$ui_comm edit modified]
360 || [string trim [$ui_comm get 0.0 end]] eq {}} {
361 if {[load_message GITGUI_MSG]} {
362 } elseif {[load_message MERGE_MSG]} {
363 } elseif {[load_message SQUASH_MSG]} {
366 $ui_comm edit modified false
369 if {$repo_config(gui.trustmtime) eq {true}} {
370 rescan_stage2 {} $after
373 set ui_status_value {Refreshing file status...}
374 set cmd [list git update-index]
376 lappend cmd --unmerged
377 lappend cmd --ignore-missing
378 lappend cmd --refresh
379 set fd_rf [open "| $cmd" r]
380 fconfigure $fd_rf -blocking 0 -translation binary
381 fileevent $fd_rf readable \
382 [list rescan_stage2 $fd_rf $after]
386 proc rescan_stage2 {fd after} {
387 global ui_status_value
388 global rescan_active buf_rdi buf_rdf buf_rlo
392 if {![eof $fd]} return
396 set ls_others [list | git ls-files --others -z \
397 --exclude-per-directory=.gitignore]
398 set info_exclude [gitdir info exclude]
399 if {[file readable $info_exclude]} {
400 lappend ls_others "--exclude-from=$info_exclude"
408 set ui_status_value {Scanning for modified files ...}
409 set fd_di [open "| git diff-index --cached -z [PARENT]" r]
410 set fd_df [open "| git diff-files -z" r]
411 set fd_lo [open $ls_others r]
413 fconfigure $fd_di -blocking 0 -translation binary
414 fconfigure $fd_df -blocking 0 -translation binary
415 fconfigure $fd_lo -blocking 0 -translation binary
416 fileevent $fd_di readable [list read_diff_index $fd_di $after]
417 fileevent $fd_df readable [list read_diff_files $fd_df $after]
418 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
421 proc load_message {file} {
425 if {[file isfile $f]} {
426 if {[catch {set fd [open $f r]}]} {
429 set content [string trim [read $fd]]
431 $ui_comm delete 0.0 end
432 $ui_comm insert end $content
438 proc read_diff_index {fd after} {
441 append buf_rdi [read $fd]
443 set n [string length $buf_rdi]
445 set z1 [string first "\0" $buf_rdi $c]
448 set z2 [string first "\0" $buf_rdi $z1]
452 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
454 [string range $buf_rdi $z1 [expr {$z2 - 1}]] \
456 [list [lindex $i 0] [lindex $i 2]] \
462 set buf_rdi [string range $buf_rdi $c end]
467 rescan_done $fd buf_rdi $after
470 proc read_diff_files {fd after} {
473 append buf_rdf [read $fd]
475 set n [string length $buf_rdf]
477 set z1 [string first "\0" $buf_rdf $c]
480 set z2 [string first "\0" $buf_rdf $z1]
484 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
486 [string range $buf_rdf $z1 [expr {$z2 - 1}]] \
489 [list [lindex $i 0] [lindex $i 2]]
494 set buf_rdf [string range $buf_rdf $c end]
499 rescan_done $fd buf_rdf $after
502 proc read_ls_others {fd after} {
505 append buf_rlo [read $fd]
506 set pck [split $buf_rlo "\0"]
507 set buf_rlo [lindex $pck end]
508 foreach p [lrange $pck 0 end-1] {
511 rescan_done $fd buf_rlo $after
514 proc rescan_done {fd buf after} {
516 global file_states repo_config
519 if {![eof $fd]} return
522 if {[incr rescan_active -1] > 0} return
531 proc prune_selection {} {
532 global file_states selected_paths
534 foreach path [array names selected_paths] {
535 if {[catch {set still_here $file_states($path)}]} {
536 unset selected_paths($path)
541 ######################################################################
546 global ui_diff current_diff_path ui_index ui_workdir
548 $ui_diff conf -state normal
549 $ui_diff delete 0.0 end
550 $ui_diff conf -state disabled
552 set current_diff_path {}
554 $ui_index tag remove in_diff 0.0 end
555 $ui_workdir tag remove in_diff 0.0 end
558 proc reshow_diff {} {
559 global ui_status_value file_states
560 global current_diff_path current_diff_side
562 if {$current_diff_path eq {}
563 || [catch {set s $file_states($current_diff_path)}]} {
566 show_diff $current_diff_path $current_diff_side
570 proc handle_empty_diff {} {
571 global current_diff_path file_states file_lists
573 set path $current_diff_path
574 set s $file_states($path)
575 if {[lindex $s 0] ne {_M}} return
577 info_popup "No differences detected.
579 [short_path $path] has no changes.
581 The modification date of this file was updated
582 by another application and you currently have
583 the Trust File Modification Timestamps option
584 enabled, so Git did not automatically detect
585 that there are no content differences in this
588 This file will now be removed from the modified
589 files list, to prevent possible confusion.
591 if {[catch {exec git update-index -- $path} err]} {
592 error_popup "Failed to refresh index:\n\n$err"
596 display_file $path __
599 proc show_diff {path w {lno {}}} {
600 global file_states file_lists
601 global is_3way_diff diff_active repo_config
602 global ui_diff ui_status_value ui_index ui_workdir
603 global current_diff_path current_diff_side
605 if {$diff_active || ![lock_index read]} return
608 if {$w eq {} || $lno == {}} {
609 foreach w [array names file_lists] {
610 set lno [lsearch -sorted $file_lists($w) $path]
617 if {$w ne {} && $lno >= 1} {
618 $w tag add in_diff $lno.0 [expr {$lno + 1}].0
621 set s $file_states($path)
625 set current_diff_path $path
626 set current_diff_side $w
627 set ui_status_value "Loading diff of [escape_path $path]..."
629 # - Git won't give us the diff, there's nothing to compare to!
633 set fd [open $path r]
634 set content [read $fd]
639 set ui_status_value "Unable to display [escape_path $path]"
640 error_popup "Error loading file:\n\n$err"
643 $ui_diff conf -state normal
644 $ui_diff insert end $content
645 $ui_diff conf -state disabled
648 set ui_status_value {Ready.}
653 if {$w eq $ui_index} {
654 lappend cmd diff-index
656 } elseif {$w eq $ui_workdir} {
657 if {[string index $m 0] eq {U}} {
660 lappend cmd diff-files
665 lappend cmd --no-color
666 if {$repo_config(gui.diffcontext) > 0} {
667 lappend cmd "-U$repo_config(gui.diffcontext)"
669 if {$w eq $ui_index} {
675 if {[catch {set fd [open $cmd r]} err]} {
678 set ui_status_value "Unable to display [escape_path $path]"
679 error_popup "Error loading diff:\n\n$err"
683 fconfigure $fd -blocking 0 -translation auto
684 fileevent $fd readable [list read_diff $fd]
687 proc read_diff {fd} {
688 global ui_diff ui_status_value is_3way_diff diff_active
691 $ui_diff conf -state normal
692 while {[gets $fd line] >= 0} {
693 # -- Cleanup uninteresting diff header lines.
695 if {[string match {diff --git *} $line]} continue
696 if {[string match {diff --cc *} $line]} continue
697 if {[string match {diff --combined *} $line]} continue
698 if {[string match {--- *} $line]} continue
699 if {[string match {+++ *} $line]} continue
700 if {$line eq {deleted file mode 120000}} {
701 set line "deleted symlink"
704 # -- Automatically detect if this is a 3 way diff.
706 if {[string match {@@@ *} $line]} {set is_3way_diff 1}
708 if {[string match {index *} $line]} {
710 } elseif {$is_3way_diff} {
711 set op [string range $line 0 1]
721 if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} {
722 set line [string replace $line 0 1 { }]
729 puts "error: Unhandled 3 way diff marker: {$op}"
734 set op [string index $line 0]
740 if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
741 set line [string replace $line 0 0 { }]
748 puts "error: Unhandled 2 way diff marker: {$op}"
753 $ui_diff insert end $line $tags
754 $ui_diff insert end "\n" $tags
756 $ui_diff conf -state disabled
762 set ui_status_value {Ready.}
764 if {$repo_config(gui.trustmtime) eq {true}
765 && [$ui_diff index end] eq {2.0}} {
771 ######################################################################
775 proc load_last_commit {} {
776 global HEAD PARENT MERGE_HEAD commit_type ui_comm
778 if {[llength $PARENT] == 0} {
779 error_popup {There is nothing to amend.
781 You are about to create the initial commit.
782 There is no commit before this to amend.
787 repository_state curType curHEAD curMERGE_HEAD
788 if {$curType eq {merge}} {
789 error_popup {Cannot amend while merging.
791 You are currently in the middle of a merge that
792 has not been fully completed. You cannot amend
793 the prior commit unless you first abort the
794 current merge activity.
802 set fd [open "| git cat-file commit $curHEAD" r]
803 while {[gets $fd line] > 0} {
804 if {[string match {parent *} $line]} {
805 lappend parents [string range $line 7 end]
808 set msg [string trim [read $fd]]
811 error_popup "Error loading commit data for amend:\n\n$err"
817 set MERGE_HEAD [list]
818 switch -- [llength $parents] {
819 0 {set commit_type amend-initial}
820 1 {set commit_type amend}
821 default {set commit_type amend-merge}
824 $ui_comm delete 0.0 end
825 $ui_comm insert end $msg
827 $ui_comm edit modified false
828 rescan {set ui_status_value {Ready.}}
831 proc create_new_commit {} {
832 global commit_type ui_comm
834 set commit_type normal
835 $ui_comm delete 0.0 end
837 $ui_comm edit modified false
838 rescan {set ui_status_value {Ready.}}
841 set GIT_COMMITTER_IDENT {}
843 proc committer_ident {} {
844 global GIT_COMMITTER_IDENT
846 if {$GIT_COMMITTER_IDENT eq {}} {
847 if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
848 error_popup "Unable to obtain your identity:\n\n$err"
851 if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
852 $me me GIT_COMMITTER_IDENT]} {
853 error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
858 return $GIT_COMMITTER_IDENT
861 proc commit_tree {} {
862 global HEAD commit_type file_states ui_comm repo_config
863 global ui_status_value pch_error
865 if {![lock_index update]} return
866 if {[committer_ident] eq {}} return
868 # -- Our in memory state should match the repository.
870 repository_state curType curHEAD curMERGE_HEAD
871 if {[string match amend* $commit_type]
872 && $curType eq {normal}
873 && $curHEAD eq $HEAD} {
874 } elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {
875 info_popup {Last scanned state does not match repository state.
877 Another Git program has modified this repository
878 since the last scan. A rescan must be performed
879 before another commit can be created.
881 The rescan will be automatically started now.
884 rescan {set ui_status_value {Ready.}}
888 # -- At least one file should differ in the index.
891 foreach path [array names file_states] {
892 switch -glob -- [lindex $file_states($path) 0] {
896 M? {set files_ready 1; break}
898 error_popup "Unmerged files cannot be committed.
900 File [short_path $path] has merge conflicts.
901 You must resolve them and include the file before committing.
907 error_popup "Unknown file state [lindex $s 0] detected.
909 File [short_path $path] cannot be committed by this program.
915 error_popup {No included files to commit.
917 You must include at least 1 file before you can commit.
923 # -- A message is required.
925 set msg [string trim [$ui_comm get 1.0 end]]
927 error_popup {Please supply a commit message.
929 A good commit message has the following format:
931 - First line: Describe in one sentance what you did.
933 - Remaining lines: Describe why this change is good.
939 # -- Run the pre-commit hook.
941 set pchook [gitdir hooks pre-commit]
943 # On Cygwin [file executable] might lie so we need to ask
944 # the shell if the hook is executable. Yes that's annoying.
946 if {[is_Windows] && [file isfile $pchook]} {
947 set pchook [list sh -c [concat \
948 "if test -x \"$pchook\";" \
949 "then exec \"$pchook\" 2>&1;" \
951 } elseif {[file executable $pchook]} {
952 set pchook [list $pchook |& cat]
954 commit_writetree $curHEAD $msg
958 set ui_status_value {Calling pre-commit hook...}
960 set fd_ph [open "| $pchook" r]
961 fconfigure $fd_ph -blocking 0 -translation binary
962 fileevent $fd_ph readable \
963 [list commit_prehook_wait $fd_ph $curHEAD $msg]
966 proc commit_prehook_wait {fd_ph curHEAD msg} {
967 global pch_error ui_status_value
969 append pch_error [read $fd_ph]
970 fconfigure $fd_ph -blocking 1
972 if {[catch {close $fd_ph}]} {
973 set ui_status_value {Commit declined by pre-commit hook.}
974 hook_failed_popup pre-commit $pch_error
977 commit_writetree $curHEAD $msg
982 fconfigure $fd_ph -blocking 0
985 proc commit_writetree {curHEAD msg} {
986 global ui_status_value
988 set ui_status_value {Committing changes...}
989 set fd_wt [open "| git write-tree" r]
990 fileevent $fd_wt readable \
991 [list commit_committree $fd_wt $curHEAD $msg]
994 proc commit_committree {fd_wt curHEAD msg} {
995 global HEAD PARENT MERGE_HEAD commit_type
997 global ui_status_value ui_comm selected_commit_type
998 global file_states selected_paths rescan_active
1001 if {$tree_id eq {} || [catch {close $fd_wt} err]} {
1002 error_popup "write-tree failed:\n\n$err"
1003 set ui_status_value {Commit failed.}
1008 # -- Create the commit.
1010 set cmd [list git commit-tree $tree_id]
1011 set parents [concat $PARENT $MERGE_HEAD]
1012 if {[llength $parents] > 0} {
1013 foreach p $parents {
1017 # git commit-tree writes to stderr during initial commit.
1018 lappend cmd 2>/dev/null
1021 if {[catch {set cmt_id [eval exec $cmd]} err]} {
1022 error_popup "commit-tree failed:\n\n$err"
1023 set ui_status_value {Commit failed.}
1028 # -- Update the HEAD ref.
1031 if {$commit_type ne {normal}} {
1032 append reflogm " ($commit_type)"
1034 set i [string first "\n" $msg]
1036 append reflogm {: } [string range $msg 0 [expr {$i - 1}]]
1038 append reflogm {: } $msg
1040 set cmd [list git update-ref -m $reflogm HEAD $cmt_id $curHEAD]
1041 if {[catch {eval exec $cmd} err]} {
1042 error_popup "update-ref failed:\n\n$err"
1043 set ui_status_value {Commit failed.}
1048 # -- Cleanup after ourselves.
1050 catch {file delete [gitdir MERGE_HEAD]}
1051 catch {file delete [gitdir MERGE_MSG]}
1052 catch {file delete [gitdir SQUASH_MSG]}
1053 catch {file delete [gitdir GITGUI_MSG]}
1055 # -- Let rerere do its thing.
1057 if {[file isdirectory [gitdir rr-cache]]} {
1058 catch {exec git rerere}
1061 # -- Run the post-commit hook.
1063 set pchook [gitdir hooks post-commit]
1064 if {[is_Windows] && [file isfile $pchook]} {
1065 set pchook [list sh -c [concat \
1066 "if test -x \"$pchook\";" \
1067 "then exec \"$pchook\";" \
1069 } elseif {![file executable $pchook]} {
1072 if {$pchook ne {}} {
1073 catch {exec $pchook &}
1076 $ui_comm delete 0.0 end
1078 $ui_comm edit modified false
1080 if {$single_commit} do_quit
1082 # -- Update in memory status
1084 set selected_commit_type new
1085 set commit_type normal
1088 set MERGE_HEAD [list]
1090 foreach path [array names file_states] {
1091 set s $file_states($path)
1093 switch -glob -- $m {
1101 unset file_states($path)
1102 catch {unset selected_paths($path)}
1105 set file_states($path) [list _O [lindex $s 1] {} {}]
1111 set file_states($path) [list \
1112 _[string index $m 1] \
1123 set ui_status_value \
1124 "Changes committed as [string range $cmt_id 0 7]."
1127 ######################################################################
1131 proc fetch_from {remote} {
1132 set w [new_console "fetch $remote" \
1133 "Fetching new changes from $remote"]
1134 set cmd [list git fetch]
1136 console_exec $w $cmd
1139 proc pull_remote {remote branch} {
1140 global HEAD commit_type file_states repo_config
1142 if {![lock_index update]} return
1144 # -- Our in memory state should match the repository.
1146 repository_state curType curHEAD curMERGE_HEAD
1147 if {$commit_type ne $curType || $HEAD ne $curHEAD} {
1148 info_popup {Last scanned state does not match repository state.
1150 Another Git program has modified this repository
1151 since the last scan. A rescan must be performed
1152 before a pull operation can be started.
1154 The rescan will be automatically started now.
1157 rescan {set ui_status_value {Ready.}}
1161 # -- No differences should exist before a pull.
1163 if {[array size file_states] != 0} {
1164 error_popup {Uncommitted but modified files are present.
1166 You should not perform a pull with unmodified
1167 files in your working directory as Git will be
1168 unable to recover from an incorrect merge.
1170 You should commit or revert all changes before
1171 starting a pull operation.
1177 set w [new_console "pull $remote $branch" \
1178 "Pulling new changes from branch $branch in $remote"]
1179 set cmd [list git pull]
1180 if {$repo_config(gui.pullsummary) eq {false}} {
1181 lappend cmd --no-summary
1185 console_exec $w $cmd [list post_pull_remote $remote $branch]
1188 proc post_pull_remote {remote branch success} {
1189 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1190 global ui_status_value
1194 repository_state commit_type HEAD MERGE_HEAD
1196 set selected_commit_type new
1197 set ui_status_value "Pulling $branch from $remote complete."
1199 rescan [list set ui_status_value \
1200 "Conflicts detected while pulling $branch from $remote."]
1204 proc push_to {remote} {
1205 set w [new_console "push $remote" \
1206 "Pushing changes to $remote"]
1207 set cmd [list git push]
1209 console_exec $w $cmd
1212 ######################################################################
1216 proc mapicon {w state path} {
1219 if {[catch {set r $all_icons($state$w)}]} {
1220 puts "error: no icon for $w state={$state} $path"
1226 proc mapdesc {state path} {
1229 if {[catch {set r $all_descs($state)}]} {
1230 puts "error: no desc for state={$state} $path"
1236 proc escape_path {path} {
1237 regsub -all "\n" $path "\\n" path
1241 proc short_path {path} {
1242 return [escape_path [lindex [file split $path] end]]
1246 set null_sha1 [string repeat 0 40]
1248 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1249 global file_states next_icon_id null_sha1
1251 set s0 [string index $new_state 0]
1252 set s1 [string index $new_state 1]
1254 if {[catch {set info $file_states($path)}]} {
1256 set icon n[incr next_icon_id]
1258 set state [lindex $info 0]
1259 set icon [lindex $info 1]
1260 if {$head_info eq {}} {set head_info [lindex $info 2]}
1261 if {$index_info eq {}} {set index_info [lindex $info 3]}
1264 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1265 elseif {$s0 eq {_}} {set s0 _}
1267 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1268 elseif {$s1 eq {_}} {set s1 _}
1270 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1271 set head_info [list 0 $null_sha1]
1272 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1273 && $head_info eq {}} {
1274 set head_info $index_info
1277 set file_states($path) [list $s0$s1 $icon \
1278 $head_info $index_info \
1283 proc display_file_helper {w path icon_name old_m new_m} {
1286 if {$new_m eq {_}} {
1287 set lno [lsearch -sorted $file_lists($w) $path]
1289 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1291 $w conf -state normal
1292 $w delete $lno.0 [expr {$lno + 1}].0
1293 $w conf -state disabled
1295 } elseif {$old_m eq {_} && $new_m ne {_}} {
1296 lappend file_lists($w) $path
1297 set file_lists($w) [lsort -unique $file_lists($w)]
1298 set lno [lsearch -sorted $file_lists($w) $path]
1300 $w conf -state normal
1301 $w image create $lno.0 \
1302 -align center -padx 5 -pady 1 \
1304 -image [mapicon $w $new_m $path]
1305 $w insert $lno.1 "[escape_path $path]\n"
1306 $w conf -state disabled
1307 } elseif {$old_m ne $new_m} {
1308 $w conf -state normal
1309 $w image conf $icon_name -image [mapicon $w $new_m $path]
1310 $w conf -state disabled
1314 proc display_file {path state} {
1315 global file_states selected_paths
1316 global ui_index ui_workdir
1318 set old_m [merge_state $path $state]
1319 set s $file_states($path)
1320 set new_m [lindex $s 0]
1321 set icon_name [lindex $s 1]
1323 set s [string index $new_m 0]
1327 display_file_helper $ui_index $path $icon_name \
1328 [string index $old_m 0] $s
1330 if {[string index $new_m 0] eq {U}} {
1333 set s [string index $new_m 1]
1335 display_file_helper $ui_workdir $path $icon_name \
1336 [string index $old_m 1] $s
1338 if {$new_m eq {__}} {
1339 unset file_states($path)
1340 catch {unset selected_paths($path)}
1344 proc display_all_files_helper {w path icon_name m} {
1347 lappend file_lists($w) $path
1348 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1349 $w image create end \
1350 -align center -padx 5 -pady 1 \
1352 -image [mapicon $w $m $path]
1353 $w insert end "[escape_path $path]\n"
1356 proc display_all_files {} {
1357 global ui_index ui_workdir
1358 global file_states file_lists
1361 $ui_index conf -state normal
1362 $ui_workdir conf -state normal
1364 $ui_index delete 0.0 end
1365 $ui_workdir delete 0.0 end
1368 set file_lists($ui_index) [list]
1369 set file_lists($ui_workdir) [list]
1371 foreach path [lsort [array names file_states]] {
1372 set s $file_states($path)
1374 set icon_name [lindex $s 1]
1376 set s [string index $m 0]
1377 if {$s ne {U} && $s ne {_}} {
1378 display_all_files_helper $ui_index $path \
1382 if {[string index $m 0] eq {U}} {
1385 set s [string index $m 1]
1388 display_all_files_helper $ui_workdir $path \
1393 $ui_index conf -state disabled
1394 $ui_workdir conf -state disabled
1397 proc update_indexinfo {msg pathList after} {
1398 global update_index_cp ui_status_value
1400 if {![lock_index update]} return
1402 set update_index_cp 0
1403 set pathList [lsort $pathList]
1404 set totalCnt [llength $pathList]
1405 set batch [expr {int($totalCnt * .01) + 1}]
1406 if {$batch > 25} {set batch 25}
1408 set ui_status_value [format \
1409 "$msg... %i/%i files (%.2f%%)" \
1413 set fd [open "| git update-index -z --index-info" w]
1419 fileevent $fd writable [list \
1420 write_update_indexinfo \
1430 proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
1431 global update_index_cp ui_status_value
1432 global file_states current_diff_path
1434 if {$update_index_cp >= $totalCnt} {
1441 for {set i $batch} \
1442 {$update_index_cp < $totalCnt && $i > 0} \
1444 set path [lindex $pathList $update_index_cp]
1445 incr update_index_cp
1447 set s $file_states($path)
1448 switch -glob -- [lindex $s 0] {
1455 set info [lindex $s 2]
1456 if {$info eq {}} continue
1458 puts -nonewline $fd "$info\t$path\0"
1459 display_file $path $new
1462 set ui_status_value [format \
1463 "$msg... %i/%i files (%.2f%%)" \
1466 [expr {100.0 * $update_index_cp / $totalCnt}]]
1469 proc update_index {msg pathList after} {
1470 global update_index_cp ui_status_value
1472 if {![lock_index update]} return
1474 set update_index_cp 0
1475 set pathList [lsort $pathList]
1476 set totalCnt [llength $pathList]
1477 set batch [expr {int($totalCnt * .01) + 1}]
1478 if {$batch > 25} {set batch 25}
1480 set ui_status_value [format \
1481 "$msg... %i/%i files (%.2f%%)" \
1485 set fd [open "| git update-index --add --remove -z --stdin" w]
1491 fileevent $fd writable [list \
1492 write_update_index \
1502 proc write_update_index {fd pathList totalCnt batch msg after} {
1503 global update_index_cp ui_status_value
1504 global file_states current_diff_path
1506 if {$update_index_cp >= $totalCnt} {
1513 for {set i $batch} \
1514 {$update_index_cp < $totalCnt && $i > 0} \
1516 set path [lindex $pathList $update_index_cp]
1517 incr update_index_cp
1519 switch -glob -- [lindex $file_states($path) 0] {
1525 if {[file exists $path]} {
1534 puts -nonewline $fd "$path\0"
1535 display_file $path $new
1538 set ui_status_value [format \
1539 "$msg... %i/%i files (%.2f%%)" \
1542 [expr {100.0 * $update_index_cp / $totalCnt}]]
1545 proc checkout_index {msg pathList after} {
1546 global update_index_cp ui_status_value
1548 if {![lock_index update]} return
1550 set update_index_cp 0
1551 set pathList [lsort $pathList]
1552 set totalCnt [llength $pathList]
1553 set batch [expr {int($totalCnt * .01) + 1}]
1554 if {$batch > 25} {set batch 25}
1556 set ui_status_value [format \
1557 "$msg... %i/%i files (%.2f%%)" \
1561 set cmd [list git checkout-index]
1567 set fd [open "| $cmd " w]
1573 fileevent $fd writable [list \
1574 write_checkout_index \
1584 proc write_checkout_index {fd pathList totalCnt batch msg after} {
1585 global update_index_cp ui_status_value
1586 global file_states current_diff_path
1588 if {$update_index_cp >= $totalCnt} {
1595 for {set i $batch} \
1596 {$update_index_cp < $totalCnt && $i > 0} \
1598 set path [lindex $pathList $update_index_cp]
1599 incr update_index_cp
1600 switch -glob -- [lindex $file_states($path) 0] {
1604 puts -nonewline $fd "$path\0"
1605 display_file $path ?_
1610 set ui_status_value [format \
1611 "$msg... %i/%i files (%.2f%%)" \
1614 [expr {100.0 * $update_index_cp / $totalCnt}]]
1617 ######################################################################
1619 ## branch management
1621 proc load_all_heads {} {
1622 global all_heads tracking_branches
1624 set all_heads [list]
1625 set cmd [list git for-each-ref]
1626 lappend cmd --format=%(refname)
1627 lappend cmd refs/heads
1628 set fd [open "| $cmd" r]
1629 while {[gets $fd line] > 0} {
1630 if {![catch {set info $tracking_branches($line)}]} continue
1631 if {![regsub ^refs/heads/ $line {} name]} continue
1632 lappend all_heads $name
1636 set all_heads [lsort $all_heads]
1639 proc populate_branch_menu {} {
1640 global all_heads disable_on_lock
1643 set last [$m index last]
1644 for {set i 0} {$i <= $last} {incr i} {
1645 if {[$m type $i] eq {separator}} {
1648 foreach a $disable_on_lock {
1649 if {[lindex $a 0] ne $m || [lindex $a 2] < $i} {
1653 set disable_on_lock $new_dol
1659 foreach b $all_heads {
1660 $m add radiobutton \
1662 -command [list switch_branch $b] \
1663 -variable current_branch \
1666 lappend disable_on_lock \
1667 [list $m entryconf [$m index last] -state]
1671 proc do_create_branch_action {w} {
1672 global all_heads null_sha1
1673 global create_branch_checkout create_branch_revtype
1674 global create_branch_head create_branch_trackinghead
1676 set newbranch [string trim [$w.name.t get 0.0 end]]
1677 if {![catch {exec git show-ref --verify -- "refs/heads/$newbranch"}]} {
1681 -title [wm title $w] \
1683 -message "Branch '$newbranch' already exists."
1687 if {[catch {exec git check-ref-format "heads/$newbranch"}]} {
1691 -title [wm title $w] \
1693 -message "We do not like '$newbranch' as a branch name."
1699 switch -- $create_branch_revtype {
1700 head {set rev $create_branch_head}
1701 tracking {set rev $create_branch_trackinghead}
1702 expression {set rev [string trim [$w.from.exp.t get 0.0 end]]}
1704 if {[catch {set cmt [exec git rev-parse --verify "${rev}^0"]}]} {
1708 -title [wm title $w] \
1710 -message "Invalid starting revision: $rev"
1713 set cmd [list git update-ref]
1715 lappend cmd "branch: Created from $rev"
1716 lappend cmd "refs/heads/$newbranch"
1718 lappend cmd $null_sha1
1719 if {[catch {eval exec $cmd} err]} {
1723 -title [wm title $w] \
1725 -message "Failed to create '$newbranch'.\n\n$err"
1729 lappend all_heads $newbranch
1730 set all_heads [lsort $all_heads]
1731 populate_branch_menu
1733 if {$create_branch_checkout} {
1734 switch_branch $newbranch
1738 proc do_create_branch {} {
1739 global all_heads current_branch tracking_branches
1740 global create_branch_checkout create_branch_revtype
1741 global create_branch_head create_branch_trackinghead
1743 set create_branch_checkout 1
1744 set create_branch_revtype head
1745 set create_branch_head $current_branch
1746 set create_branch_trackinghead {}
1748 set w .branch_editor
1750 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
1752 label $w.header -text {Create New Branch} \
1754 pack $w.header -side top -fill x
1757 button $w.buttons.create -text Create \
1760 -command [list do_create_branch_action $w]
1761 pack $w.buttons.create -side right
1762 button $w.buttons.cancel -text {Cancel} \
1764 -command [list destroy $w]
1765 pack $w.buttons.cancel -side right -padx 5
1766 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
1768 labelframe $w.name \
1769 -text {Branch Description} \
1771 label $w.name.l -text {Name:} -font font_ui
1778 bind $w.name.t <Shift-Key-Tab> "focus $w.postActions.checkout;break"
1779 bind $w.name.t <Key-Tab> "focus $w.from.exp.t;break"
1780 bind $w.name.t <Key-Return> "do_create_branch_action $w;break"
1781 bind $w.name.t <Key> {
1782 if {{%K} ne {BackSpace}
1785 && {%K} ne {Return}} {
1787 if {[string first %A {~^:?*[}] >= 0} break
1790 pack $w.name.l -side left -padx 5
1791 pack $w.name.t -side left -fill x -expand 1
1792 pack $w.name -anchor nw -fill x -pady 5 -padx 5
1794 set all_trackings [list]
1795 foreach b [array names tracking_branches] {
1796 regsub ^refs/(heads|remotes)/ $b {} b
1797 lappend all_trackings $b
1799 set all_trackings [lsort -unique $all_trackings]
1800 if {$all_trackings ne {}} {
1801 set create_branch_trackinghead [lindex $all_trackings 0]
1804 labelframe $w.from \
1805 -text {Starting Revision} \
1808 radiobutton $w.from.head.r \
1809 -text {Local Branch:} \
1811 -variable create_branch_revtype \
1813 eval tk_optionMenu $w.from.head.m create_branch_head $all_heads
1814 pack $w.from.head.r -side left
1815 pack $w.from.head.m -side left
1816 frame $w.from.tracking
1817 radiobutton $w.from.tracking.r \
1818 -text {Tracking Branch:} \
1820 -variable create_branch_revtype \
1822 eval tk_optionMenu $w.from.tracking.m \
1823 create_branch_trackinghead \
1825 pack $w.from.tracking.r -side left
1826 pack $w.from.tracking.m -side left
1828 radiobutton $w.from.exp.r \
1829 -text {Revision Expression:} \
1831 -variable create_branch_revtype \
1833 text $w.from.exp.t \
1839 bind $w.from.exp.t <Shift-Key-Tab> "focus $w.name.t;break"
1840 bind $w.from.exp.t <Key-Tab> "focus $w.postActions.checkout;break"
1841 bind $w.from.exp.t <Key-Return> "do_create_branch_action $w;break"
1842 pack $w.from.exp.r -side left
1843 pack $w.from.exp.t -side left -fill x -expand 1
1844 pack $w.from.head -padx 5 -fill x -expand 1
1845 pack $w.from.tracking -padx 5 -fill x -expand 1
1846 pack $w.from.exp -padx 5 -fill x -expand 1
1847 pack $w.from -anchor nw -fill x -pady 5 -padx 5
1849 labelframe $w.postActions \
1850 -text {Post Creation Actions} \
1852 checkbutton $w.postActions.checkout \
1853 -text {Checkout after creation} \
1854 -variable create_branch_checkout \
1856 pack $w.postActions.checkout -anchor nw
1857 pack $w.postActions -anchor nw -fill x -pady 5 -padx 5
1859 bind $w <Visibility> "grab $w; focus $w.name.t"
1860 bind $w <Key-Escape> "destroy $w"
1861 bind $w <Key-Return> "do_create_branch_action $w;break"
1862 wm title $w "[appname] ([reponame]): Create Branch"
1866 proc do_delete_branch_action {w} {
1868 global delete_branch_checkhead delete_branch_head
1870 set to_delete [list]
1871 set not_merged [list]
1872 foreach i [$w.list.l curselection] {
1873 set b [$w.list.l get $i]
1874 if {[catch {set o [exec git rev-parse --verify $b]}]} continue
1875 if {$delete_branch_checkhead} {
1876 if {$b eq $delete_branch_head} continue
1877 if {[catch {set m [exec git merge-base $o $delete_branch_head]}]} continue
1879 lappend not_merged $b
1883 lappend to_delete [list $b $o]
1885 if {$not_merged ne {}} {
1886 set msg "The following branches are not completely merged into $delete_branch_head:
1888 - [join $not_merged "\n - "]"
1892 -title [wm title $w] \
1896 if {$to_delete eq {}} return
1897 if {!$delete_branch_checkhead} {
1898 set msg {Recovering deleted branches is difficult.
1900 Delete the selected branches?}
1901 if {[tk_messageBox \
1904 -title [wm title $w] \
1906 -message $msg] ne yes} {
1912 foreach i $to_delete {
1915 if {[catch {exec git update-ref -d "refs/heads/$b" $o} err]} {
1916 append failed " - $b: $err\n"
1918 set x [lsearch -sorted $all_heads $b]
1920 set all_heads [lreplace $all_heads $x $x]
1925 if {$failed ne {}} {
1929 -title [wm title $w] \
1931 -message "Failed to delete branches:\n$failed"
1934 set all_heads [lsort $all_heads]
1935 populate_branch_menu
1939 proc do_delete_branch {} {
1940 global all_heads tracking_branches current_branch
1941 global delete_branch_checkhead delete_branch_head
1943 set delete_branch_checkhead 1
1944 set delete_branch_head $current_branch
1946 set w .branch_editor
1948 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
1950 label $w.header -text {Delete Local Branch} \
1952 pack $w.header -side top -fill x
1955 button $w.buttons.create -text Delete \
1957 -command [list do_delete_branch_action $w]
1958 pack $w.buttons.create -side right
1959 button $w.buttons.cancel -text {Cancel} \
1961 -command [list destroy $w]
1962 pack $w.buttons.cancel -side right -padx 5
1963 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
1965 labelframe $w.list \
1966 -text {Local Branches} \
1971 -selectmode extended \
1973 foreach h $all_heads {
1974 if {$h ne $current_branch} {
1975 $w.list.l insert end $h
1978 pack $w.list.l -fill both -pady 5 -padx 5
1979 pack $w.list -fill both -pady 5 -padx 5
1981 set all_trackings [list]
1982 foreach b [array names tracking_branches] {
1983 regsub ^refs/(heads|remotes)/ $b {} b
1984 lappend all_trackings $b
1987 labelframe $w.validate \
1988 -text {Only Delete If} \
1990 frame $w.validate.head
1991 checkbutton $w.validate.head.r \
1992 -text {Already Merged Into:} \
1993 -variable delete_branch_checkhead \
1995 eval tk_optionMenu $w.validate.head.m delete_branch_head \
1997 [lsort -unique $all_trackings]
1998 pack $w.validate.head.r -side left
1999 pack $w.validate.head.m -side left
2000 pack $w.validate.head -padx 5 -fill x -expand 1
2001 pack $w.validate -anchor nw -fill x -pady 5 -padx 5
2003 bind $w <Visibility> "grab $w; focus $w"
2004 bind $w <Key-Escape> "destroy $w"
2005 wm title $w "[appname] ([reponame]): Delete Branch"
2009 proc switch_branch {b} {
2010 global HEAD commit_type file_states current_branch
2011 global selected_commit_type ui_comm
2013 if {![lock_index switch]} return
2015 # -- Backup the selected branch (repository_state resets it)
2017 set new_branch $current_branch
2019 # -- Our in memory state should match the repository.
2021 repository_state curType curHEAD curMERGE_HEAD
2022 if {[string match amend* $commit_type]
2023 && $curType eq {normal}
2024 && $curHEAD eq $HEAD} {
2025 } elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {
2026 info_popup {Last scanned state does not match repository state.
2028 Another Git program has modified this repository
2029 since the last scan. A rescan must be performed
2030 before the current branch can be changed.
2032 The rescan will be automatically started now.
2035 rescan {set ui_status_value {Ready.}}
2039 # -- Toss the message buffer if we are in amend mode.
2041 if {[string match amend* $curType]} {
2042 $ui_comm delete 0.0 end
2044 $ui_comm edit modified false
2047 set selected_commit_type new
2048 set current_branch $new_branch
2051 error "NOT FINISHED"
2054 ######################################################################
2056 ## remote management
2058 proc load_all_remotes {} {
2060 global all_remotes tracking_branches
2062 set all_remotes [list]
2063 array unset tracking_branches
2065 set rm_dir [gitdir remotes]
2066 if {[file isdirectory $rm_dir]} {
2067 set all_remotes [glob \
2071 -directory $rm_dir *]
2073 foreach name $all_remotes {
2075 set fd [open [file join $rm_dir $name] r]
2076 while {[gets $fd line] >= 0} {
2077 if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
2078 $line line src dst]} continue
2079 if {![regexp ^refs/ $dst]} {
2080 set dst "refs/heads/$dst"
2082 set tracking_branches($dst) [list $name $src]
2089 foreach line [array names repo_config remote.*.url] {
2090 if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
2091 lappend all_remotes $name
2093 if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
2097 if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
2098 if {![regexp ^refs/ $dst]} {
2099 set dst "refs/heads/$dst"
2101 set tracking_branches($dst) [list $name $src]
2105 set all_remotes [lsort -unique $all_remotes]
2108 proc populate_fetch_menu {m} {
2109 global all_remotes repo_config
2111 foreach r $all_remotes {
2113 if {![catch {set a $repo_config(remote.$r.url)}]} {
2114 if {![catch {set a $repo_config(remote.$r.fetch)}]} {
2119 set fd [open [gitdir remotes $r] r]
2120 while {[gets $fd n] >= 0} {
2121 if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
2132 -label "Fetch from $r..." \
2133 -command [list fetch_from $r] \
2139 proc populate_push_menu {m} {
2140 global all_remotes repo_config
2142 foreach r $all_remotes {
2144 if {![catch {set a $repo_config(remote.$r.url)}]} {
2145 if {![catch {set a $repo_config(remote.$r.push)}]} {
2150 set fd [open [gitdir remotes $r] r]
2151 while {[gets $fd n] >= 0} {
2152 if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
2163 -label "Push to $r..." \
2164 -command [list push_to $r] \
2170 proc populate_pull_menu {m} {
2171 global repo_config all_remotes disable_on_lock
2173 foreach remote $all_remotes {
2175 if {[array get repo_config remote.$remote.url] ne {}} {
2176 if {[array get repo_config remote.$remote.fetch] ne {}} {
2177 foreach line $repo_config(remote.$remote.fetch) {
2178 if {[regexp {^([^:]+):} $line line rb]} {
2185 set fd [open [gitdir remotes $remote] r]
2186 while {[gets $fd line] >= 0} {
2187 if {[regexp {^Pull:[ \t]*([^:]+):} $line line rb]} {
2195 foreach rb $rb_list {
2196 regsub ^refs/heads/ $rb {} rb_short
2198 -label "Branch $rb_short from $remote..." \
2199 -command [list pull_remote $remote $rb] \
2201 lappend disable_on_lock \
2202 [list $m entryconf [$m index last] -state]
2207 ######################################################################
2212 #define mask_width 14
2213 #define mask_height 15
2214 static unsigned char mask_bits[] = {
2215 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2216 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2217 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2220 image create bitmap file_plain -background white -foreground black -data {
2221 #define plain_width 14
2222 #define plain_height 15
2223 static unsigned char plain_bits[] = {
2224 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2225 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2226 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2227 } -maskdata $filemask
2229 image create bitmap file_mod -background white -foreground blue -data {
2230 #define mod_width 14
2231 #define mod_height 15
2232 static unsigned char mod_bits[] = {
2233 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2234 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2235 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2236 } -maskdata $filemask
2238 image create bitmap file_fulltick -background white -foreground "#007000" -data {
2239 #define file_fulltick_width 14
2240 #define file_fulltick_height 15
2241 static unsigned char file_fulltick_bits[] = {
2242 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2243 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2244 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2245 } -maskdata $filemask
2247 image create bitmap file_parttick -background white -foreground "#005050" -data {
2248 #define parttick_width 14
2249 #define parttick_height 15
2250 static unsigned char parttick_bits[] = {
2251 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2252 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2253 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2254 } -maskdata $filemask
2256 image create bitmap file_question -background white -foreground black -data {
2257 #define file_question_width 14
2258 #define file_question_height 15
2259 static unsigned char file_question_bits[] = {
2260 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2261 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2262 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2263 } -maskdata $filemask
2265 image create bitmap file_removed -background white -foreground red -data {
2266 #define file_removed_width 14
2267 #define file_removed_height 15
2268 static unsigned char file_removed_bits[] = {
2269 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2270 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2271 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2272 } -maskdata $filemask
2274 image create bitmap file_merge -background white -foreground blue -data {
2275 #define file_merge_width 14
2276 #define file_merge_height 15
2277 static unsigned char file_merge_bits[] = {
2278 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2279 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2280 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2281 } -maskdata $filemask
2283 set ui_index .vpane.files.index.list
2284 set ui_workdir .vpane.files.workdir.list
2286 set all_icons(_$ui_index) file_plain
2287 set all_icons(A$ui_index) file_fulltick
2288 set all_icons(M$ui_index) file_fulltick
2289 set all_icons(D$ui_index) file_removed
2290 set all_icons(U$ui_index) file_merge
2292 set all_icons(_$ui_workdir) file_plain
2293 set all_icons(M$ui_workdir) file_mod
2294 set all_icons(D$ui_workdir) file_question
2295 set all_icons(U$ui_workdir) file_merge
2296 set all_icons(O$ui_workdir) file_plain
2298 set max_status_desc 0
2302 {_M "Modified, not staged"}
2303 {M_ "Staged for commit"}
2304 {MM "Portions staged for commit"}
2305 {MD "Staged for commit, missing"}
2307 {_O "Untracked, not staged"}
2308 {A_ "Staged for commit"}
2309 {AM "Portions staged for commit"}
2310 {AD "Staged for commit, missing"}
2313 {D_ "Staged for removal"}
2314 {DO "Staged for removal, still present"}
2316 {U_ "Requires merge resolution"}
2317 {UU "Requires merge resolution"}
2318 {UM "Requires merge resolution"}
2319 {UD "Requires merge resolution"}
2321 if {$max_status_desc < [string length [lindex $i 1]]} {
2322 set max_status_desc [string length [lindex $i 1]]
2324 set all_descs([lindex $i 0]) [lindex $i 1]
2328 ######################################################################
2333 global tcl_platform tk_library
2334 if {[tk windowingsystem] eq {aqua}} {
2340 proc is_Windows {} {
2342 if {$tcl_platform(platform) eq {windows}} {
2348 proc bind_button3 {w cmd} {
2349 bind $w <Any-Button-3> $cmd
2351 bind $w <Control-Button-1> $cmd
2355 proc incr_font_size {font {amt 1}} {
2356 set sz [font configure $font -size]
2358 font configure $font -size $sz
2359 font configure ${font}bold -size $sz
2362 proc hook_failed_popup {hook msg} {
2367 label $w.m.l1 -text "$hook hook failed:" \
2372 -background white -borderwidth 1 \
2374 -width 80 -height 10 \
2376 -yscrollcommand [list $w.m.sby set]
2378 -text {You must correct the above errors before committing.} \
2382 scrollbar $w.m.sby -command [list $w.m.t yview]
2383 pack $w.m.l1 -side top -fill x
2384 pack $w.m.l2 -side bottom -fill x
2385 pack $w.m.sby -side right -fill y
2386 pack $w.m.t -side left -fill both -expand 1
2387 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
2389 $w.m.t insert 1.0 $msg
2390 $w.m.t conf -state disabled
2392 button $w.ok -text OK \
2395 -command "destroy $w"
2396 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
2398 bind $w <Visibility> "grab $w; focus $w"
2399 bind $w <Key-Return> "destroy $w"
2400 wm title $w "[appname] ([reponame]): error"
2404 set next_console_id 0
2406 proc new_console {short_title long_title} {
2407 global next_console_id console_data
2408 set w .console[incr next_console_id]
2409 set console_data($w) [list $short_title $long_title]
2410 return [console_init $w]
2413 proc console_init {w} {
2414 global console_cr console_data M1B
2416 set console_cr($w) 1.0
2419 label $w.m.l1 -text "[lindex $console_data($w) 1]:" \
2424 -background white -borderwidth 1 \
2426 -width 80 -height 10 \
2429 -yscrollcommand [list $w.m.sby set]
2430 label $w.m.s -text {Working... please wait...} \
2434 scrollbar $w.m.sby -command [list $w.m.t yview]
2435 pack $w.m.l1 -side top -fill x
2436 pack $w.m.s -side bottom -fill x
2437 pack $w.m.sby -side right -fill y
2438 pack $w.m.t -side left -fill both -expand 1
2439 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
2441 menu $w.ctxm -tearoff 0
2442 $w.ctxm add command -label "Copy" \
2444 -command "tk_textCopy $w.m.t"
2445 $w.ctxm add command -label "Select All" \
2447 -command "$w.m.t tag add sel 0.0 end"
2448 $w.ctxm add command -label "Copy All" \
2451 $w.m.t tag add sel 0.0 end
2453 $w.m.t tag remove sel 0.0 end
2456 button $w.ok -text {Close} \
2459 -command "destroy $w"
2460 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
2462 bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
2463 bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2464 bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2465 bind $w <Visibility> "focus $w"
2466 wm title $w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2470 proc console_exec {w cmd {after {}}} {
2471 # -- Windows tosses the enviroment when we exec our child.
2472 # But most users need that so we have to relogin. :-(
2475 set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
2478 # -- Tcl won't let us redirect both stdout and stderr to
2479 # the same pipe. So pass it through cat...
2481 set cmd [concat | $cmd |& cat]
2483 set fd_f [open $cmd r]
2484 fconfigure $fd_f -blocking 0 -translation binary
2485 fileevent $fd_f readable [list console_read $w $fd_f $after]
2488 proc console_read {w fd after} {
2489 global console_cr console_data
2493 if {![winfo exists $w]} {console_init $w}
2494 $w.m.t conf -state normal
2496 set n [string length $buf]
2498 set cr [string first "\r" $buf $c]
2499 set lf [string first "\n" $buf $c]
2500 if {$cr < 0} {set cr [expr {$n + 1}]}
2501 if {$lf < 0} {set lf [expr {$n + 1}]}
2504 $w.m.t insert end [string range $buf $c $lf]
2505 set console_cr($w) [$w.m.t index {end -1c}]
2509 $w.m.t delete $console_cr($w) end
2510 $w.m.t insert end "\n"
2511 $w.m.t insert end [string range $buf $c $cr]
2516 $w.m.t conf -state disabled
2520 fconfigure $fd -blocking 1
2522 if {[catch {close $fd}]} {
2523 if {![winfo exists $w]} {console_init $w}
2524 $w.m.s conf -background red -text {Error: Command Failed}
2525 $w.ok conf -state normal
2527 } elseif {[winfo exists $w]} {
2528 $w.m.s conf -background green -text {Success}
2529 $w.ok conf -state normal
2532 array unset console_cr $w
2533 array unset console_data $w
2535 uplevel #0 $after $ok
2539 fconfigure $fd -blocking 0
2542 ######################################################################
2546 set starting_gitk_msg {Starting gitk... please wait...}
2548 proc do_gitk {revs} {
2549 global ui_status_value starting_gitk_msg
2557 set cmd "sh -c \"exec $cmd\""
2561 if {[catch {eval exec $cmd} err]} {
2562 error_popup "Failed to start gitk:\n\n$err"
2564 set ui_status_value $starting_gitk_msg
2566 if {$ui_status_value eq $starting_gitk_msg} {
2567 set ui_status_value {Ready.}
2574 set w [new_console {gc} {Compressing the object database}]
2575 console_exec $w {git gc}
2578 proc do_fsck_objects {} {
2579 set w [new_console {fsck-objects} \
2580 {Verifying the object database with fsck-objects}]
2581 set cmd [list git fsck-objects]
2584 lappend cmd --strict
2585 console_exec $w $cmd
2591 global ui_comm is_quitting repo_config commit_type
2593 if {$is_quitting} return
2596 # -- Stash our current commit buffer.
2598 set save [gitdir GITGUI_MSG]
2599 set msg [string trim [$ui_comm get 0.0 end]]
2600 if {![string match amend* $commit_type]
2601 && [$ui_comm edit modified]
2604 set fd [open $save w]
2605 puts $fd [string trim [$ui_comm get 0.0 end]]
2609 catch {file delete $save}
2612 # -- Stash our current window geometry into this repository.
2614 set cfg_geometry [list]
2615 lappend cfg_geometry [wm geometry .]
2616 lappend cfg_geometry [lindex [.vpane sash coord 0] 1]
2617 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 0]
2618 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2621 if {$cfg_geometry ne $rc_geometry} {
2622 catch {exec git repo-config gui.geometry $cfg_geometry}
2629 rescan {set ui_status_value {Ready.}}
2632 proc unstage_helper {txt paths} {
2633 global file_states current_diff_path
2635 if {![lock_index begin-update]} return
2639 foreach path $paths {
2640 switch -glob -- [lindex $file_states($path) 0] {
2644 lappend pathList $path
2645 if {$path eq $current_diff_path} {
2646 set after {reshow_diff;}
2651 if {$pathList eq {}} {
2657 [concat $after {set ui_status_value {Ready.}}]
2661 proc do_unstage_selection {} {
2662 global current_diff_path selected_paths
2664 if {[array size selected_paths] > 0} {
2666 {Unstaging selected files from commit} \
2667 [array names selected_paths]
2668 } elseif {$current_diff_path ne {}} {
2670 "Unstaging [short_path $current_diff_path] from commit" \
2671 [list $current_diff_path]
2675 proc add_helper {txt paths} {
2676 global file_states current_diff_path
2678 if {![lock_index begin-update]} return
2682 foreach path $paths {
2683 switch -glob -- [lindex $file_states($path) 0] {
2688 lappend pathList $path
2689 if {$path eq $current_diff_path} {
2690 set after {reshow_diff;}
2695 if {$pathList eq {}} {
2701 [concat $after {set ui_status_value {Ready to commit.}}]
2705 proc do_add_selection {} {
2706 global current_diff_path selected_paths
2708 if {[array size selected_paths] > 0} {
2710 {Adding selected files} \
2711 [array names selected_paths]
2712 } elseif {$current_diff_path ne {}} {
2714 "Adding [short_path $current_diff_path]" \
2715 [list $current_diff_path]
2719 proc do_add_all {} {
2723 foreach path [array names file_states] {
2724 switch -glob -- [lindex $file_states($path) 0] {
2727 ?D {lappend paths $path}
2730 add_helper {Adding all changed files} $paths
2733 proc revert_helper {txt paths} {
2734 global file_states current_diff_path
2736 if {![lock_index begin-update]} return
2740 foreach path $paths {
2741 switch -glob -- [lindex $file_states($path) 0] {
2745 lappend pathList $path
2746 if {$path eq $current_diff_path} {
2747 set after {reshow_diff;}
2753 set n [llength $pathList]
2757 } elseif {$n == 1} {
2758 set s "[short_path [lindex $pathList]]"
2760 set s "these $n files"
2763 set reply [tk_dialog \
2765 "[appname] ([reponame])" \
2766 "Revert changes in $s?
2768 Any unadded changes will be permanently lost by the revert." \
2778 [concat $after {set ui_status_value {Ready.}}]
2784 proc do_revert_selection {} {
2785 global current_diff_path selected_paths
2787 if {[array size selected_paths] > 0} {
2789 {Reverting selected files} \
2790 [array names selected_paths]
2791 } elseif {$current_diff_path ne {}} {
2793 "Reverting [short_path $current_diff_path]" \
2794 [list $current_diff_path]
2798 proc do_signoff {} {
2801 set me [committer_ident]
2802 if {$me eq {}} return
2804 set sob "Signed-off-by: $me"
2805 set last [$ui_comm get {end -1c linestart} {end -1c}]
2806 if {$last ne $sob} {
2807 $ui_comm edit separator
2809 && ![regexp {^[A-Z][A-Za-z]*-[A-Za-z-]+: *} $last]} {
2810 $ui_comm insert end "\n"
2812 $ui_comm insert end "\n$sob"
2813 $ui_comm edit separator
2818 proc do_select_commit_type {} {
2819 global commit_type selected_commit_type
2821 if {$selected_commit_type eq {new}
2822 && [string match amend* $commit_type]} {
2824 } elseif {$selected_commit_type eq {amend}
2825 && ![string match amend* $commit_type]} {
2828 # The amend request was rejected...
2830 if {![string match amend* $commit_type]} {
2831 set selected_commit_type new
2841 global appvers copyright
2842 global tcl_patchLevel tk_patchLevel
2846 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2848 label $w.header -text "About [appname]" \
2850 pack $w.header -side top -fill x
2853 button $w.buttons.close -text {Close} \
2855 -command [list destroy $w]
2856 pack $w.buttons.close -side right
2857 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2860 -text "[appname] - a commit creation tool for Git.
2868 pack $w.desc -side top -fill x -padx 5 -pady 5
2871 append v "[appname] version $appvers\n"
2872 append v "[exec git version]\n"
2874 if {$tcl_patchLevel eq $tk_patchLevel} {
2875 append v "Tcl/Tk version $tcl_patchLevel"
2877 append v "Tcl version $tcl_patchLevel"
2878 append v ", Tk version $tk_patchLevel"
2889 pack $w.vers -side top -fill x -padx 5 -pady 5
2891 menu $w.ctxm -tearoff 0
2892 $w.ctxm add command \
2897 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
2900 bind $w <Visibility> "grab $w; focus $w"
2901 bind $w <Key-Escape> "destroy $w"
2902 bind_button3 $w.vers "tk_popup $w.ctxm %X %Y; grab $w; focus $w"
2903 wm title $w "About [appname]"
2907 proc do_options {} {
2908 global repo_config global_config font_descs
2909 global repo_config_new global_config_new
2911 array unset repo_config_new
2912 array unset global_config_new
2913 foreach name [array names repo_config] {
2914 set repo_config_new($name) $repo_config($name)
2917 foreach name [array names repo_config] {
2919 gui.diffcontext {continue}
2921 set repo_config_new($name) $repo_config($name)
2923 foreach name [array names global_config] {
2924 set global_config_new($name) $global_config($name)
2927 set w .options_editor
2929 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2931 label $w.header -text "[appname] Options" \
2933 pack $w.header -side top -fill x
2936 button $w.buttons.restore -text {Restore Defaults} \
2938 -command do_restore_defaults
2939 pack $w.buttons.restore -side left
2940 button $w.buttons.save -text Save \
2942 -command [list do_save_config $w]
2943 pack $w.buttons.save -side right
2944 button $w.buttons.cancel -text {Cancel} \
2946 -command [list destroy $w]
2947 pack $w.buttons.cancel -side right -padx 5
2948 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2950 labelframe $w.repo -text "[reponame] Repository" \
2952 -relief raised -borderwidth 2
2953 labelframe $w.global -text {Global (All Repositories)} \
2955 -relief raised -borderwidth 2
2956 pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
2957 pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
2960 {b pullsummary {Show Pull Summary}}
2961 {b trustmtime {Trust File Modification Timestamps}}
2962 {i diffcontext {Number of Diff Context Lines}}
2964 set type [lindex $option 0]
2965 set name [lindex $option 1]
2966 set text [lindex $option 2]
2967 foreach f {repo global} {
2970 checkbutton $w.$f.$name -text $text \
2971 -variable ${f}_config_new(gui.$name) \
2975 pack $w.$f.$name -side top -anchor w
2979 label $w.$f.$name.l -text "$text:" -font font_ui
2980 pack $w.$f.$name.l -side left -anchor w -fill x
2981 spinbox $w.$f.$name.v \
2982 -textvariable ${f}_config_new(gui.$name) \
2983 -from 1 -to 99 -increment 1 \
2986 pack $w.$f.$name.v -side right -anchor e
2987 pack $w.$f.$name -side top -anchor w -fill x
2993 set all_fonts [lsort [font families]]
2994 foreach option $font_descs {
2995 set name [lindex $option 0]
2996 set font [lindex $option 1]
2997 set text [lindex $option 2]
2999 set global_config_new(gui.$font^^family) \
3000 [font configure $font -family]
3001 set global_config_new(gui.$font^^size) \
3002 [font configure $font -size]
3004 frame $w.global.$name
3005 label $w.global.$name.l -text "$text:" -font font_ui
3006 pack $w.global.$name.l -side left -anchor w -fill x
3007 eval tk_optionMenu $w.global.$name.family \
3008 global_config_new(gui.$font^^family) \
3010 spinbox $w.global.$name.size \
3011 -textvariable global_config_new(gui.$font^^size) \
3012 -from 2 -to 80 -increment 1 \
3015 pack $w.global.$name.size -side right -anchor e
3016 pack $w.global.$name.family -side right -anchor e
3017 pack $w.global.$name -side top -anchor w -fill x
3020 bind $w <Visibility> "grab $w; focus $w"
3021 bind $w <Key-Escape> "destroy $w"
3022 wm title $w "[appname] ([reponame]): Options"
3026 proc do_restore_defaults {} {
3027 global font_descs default_config repo_config
3028 global repo_config_new global_config_new
3030 foreach name [array names default_config] {
3031 set repo_config_new($name) $default_config($name)
3032 set global_config_new($name) $default_config($name)
3035 foreach option $font_descs {
3036 set name [lindex $option 0]
3037 set repo_config(gui.$name) $default_config(gui.$name)
3041 foreach option $font_descs {
3042 set name [lindex $option 0]
3043 set font [lindex $option 1]
3044 set global_config_new(gui.$font^^family) \
3045 [font configure $font -family]
3046 set global_config_new(gui.$font^^size) \
3047 [font configure $font -size]
3051 proc do_save_config {w} {
3052 if {[catch {save_config} err]} {
3053 error_popup "Failed to completely save options:\n\n$err"
3059 proc do_windows_shortcut {} {
3063 set desktop [exec cygpath \
3071 set fn [tk_getSaveFile \
3073 -title "[appname] ([reponame]): Create Desktop Icon" \
3074 -initialdir $desktop \
3075 -initialfile "Git [reponame].bat"]
3079 set sh [exec cygpath \
3083 set me [exec cygpath \
3087 set gd [exec cygpath \
3091 set gw [exec cygpath \
3094 [file dirname [gitdir]]]
3095 regsub -all ' $me "'\\''" me
3096 regsub -all ' $gd "'\\''" gd
3097 puts $fd "@ECHO Entering $gw"
3098 puts $fd "@ECHO Starting git-gui... please wait..."
3099 puts -nonewline $fd "@\"$sh\" --login -c \""
3100 puts -nonewline $fd "GIT_DIR='$gd'"
3101 puts -nonewline $fd " '$me'"
3105 error_popup "Cannot write script:\n\n$err"
3110 proc do_macosx_app {} {
3113 set fn [tk_getSaveFile \
3115 -title "[appname] ([reponame]): Create Desktop Icon" \
3116 -initialdir [file join $env(HOME) Desktop] \
3117 -initialfile "Git [reponame].app"]
3120 set Contents [file join $fn Contents]
3121 set MacOS [file join $Contents MacOS]
3122 set exe [file join $MacOS git-gui]
3126 set fd [open [file join $Contents Info.plist] w]
3127 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3128 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3129 <plist version="1.0">
3131 <key>CFBundleDevelopmentRegion</key>
3132 <string>English</string>
3133 <key>CFBundleExecutable</key>
3134 <string>git-gui</string>
3135 <key>CFBundleIdentifier</key>
3136 <string>org.spearce.git-gui</string>
3137 <key>CFBundleInfoDictionaryVersion</key>
3138 <string>6.0</string>
3139 <key>CFBundlePackageType</key>
3140 <string>APPL</string>
3141 <key>CFBundleSignature</key>
3142 <string>????</string>
3143 <key>CFBundleVersion</key>
3144 <string>1.0</string>
3145 <key>NSPrincipalClass</key>
3146 <string>NSApplication</string>
3151 set fd [open $exe w]
3152 set gd [file normalize [gitdir]]
3153 set ep [file normalize [exec git --exec-path]]
3154 regsub -all ' $gd "'\\''" gd
3155 regsub -all ' $ep "'\\''" ep
3156 puts $fd "#!/bin/sh"
3157 foreach name [array names env] {
3158 if {[string match GIT_* $name]} {
3159 regsub -all ' $env($name) "'\\''" v
3160 puts $fd "export $name='$v'"
3163 puts $fd "export PATH='$ep':\$PATH"
3164 puts $fd "export GIT_DIR='$gd'"
3165 puts $fd "exec [file normalize $argv0]"
3168 file attributes $exe -permissions u+x,g+x,o+x
3170 error_popup "Cannot write icon:\n\n$err"
3175 proc toggle_or_diff {w x y} {
3176 global file_states file_lists current_diff_path ui_index ui_workdir
3177 global last_clicked selected_paths
3179 set pos [split [$w index @$x,$y] .]
3180 set lno [lindex $pos 0]
3181 set col [lindex $pos 1]
3182 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3188 set last_clicked [list $w $lno]
3189 array unset selected_paths
3190 $ui_index tag remove in_sel 0.0 end
3191 $ui_workdir tag remove in_sel 0.0 end
3194 if {$current_diff_path eq $path} {
3195 set after {reshow_diff;}
3199 if {$w eq $ui_index} {
3201 "Unstaging [short_path $path] from commit" \
3203 [concat $after {set ui_status_value {Ready.}}]
3204 } elseif {$w eq $ui_workdir} {
3206 "Adding [short_path $path]" \
3208 [concat $after {set ui_status_value {Ready.}}]
3211 show_diff $path $w $lno
3215 proc add_one_to_selection {w x y} {
3216 global file_lists last_clicked selected_paths
3218 set lno [lindex [split [$w index @$x,$y] .] 0]
3219 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3225 if {$last_clicked ne {}
3226 && [lindex $last_clicked 0] ne $w} {
3227 array unset selected_paths
3228 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3231 set last_clicked [list $w $lno]
3232 if {[catch {set in_sel $selected_paths($path)}]} {
3236 unset selected_paths($path)
3237 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3239 set selected_paths($path) 1
3240 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3244 proc add_range_to_selection {w x y} {
3245 global file_lists last_clicked selected_paths
3247 if {[lindex $last_clicked 0] ne $w} {
3248 toggle_or_diff $w $x $y
3252 set lno [lindex [split [$w index @$x,$y] .] 0]
3253 set lc [lindex $last_clicked 1]
3262 foreach path [lrange $file_lists($w) \
3263 [expr {$begin - 1}] \
3264 [expr {$end - 1}]] {
3265 set selected_paths($path) 1
3267 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3270 ######################################################################
3274 set cursor_ptr arrow
3275 font create font_diff -family Courier -size 10
3279 eval font configure font_ui [font actual [.dummy cget -font]]
3283 font create font_uibold
3284 font create font_diffbold
3289 } elseif {[is_MacOSX]} {
3297 proc apply_config {} {
3298 global repo_config font_descs
3300 foreach option $font_descs {
3301 set name [lindex $option 0]
3302 set font [lindex $option 1]
3304 foreach {cn cv} $repo_config(gui.$name) {
3305 font configure $font $cn $cv
3308 error_popup "Invalid font specified in gui.$name:\n\n$err"
3310 foreach {cn cv} [font configure $font] {
3311 font configure ${font}bold $cn $cv
3313 font configure ${font}bold -weight bold
3317 set default_config(gui.trustmtime) false
3318 set default_config(gui.pullsummary) true
3319 set default_config(gui.diffcontext) 5
3320 set default_config(gui.fontui) [font configure font_ui]
3321 set default_config(gui.fontdiff) [font configure font_diff]
3323 {fontui font_ui {Main Font}}
3324 {fontdiff font_diff {Diff/Console Font}}
3329 ######################################################################
3335 menu .mbar -tearoff 0
3336 .mbar add cascade -label Repository -menu .mbar.repository
3337 .mbar add cascade -label Edit -menu .mbar.edit
3338 if {!$single_commit} {
3339 .mbar add cascade -label Branch -menu .mbar.branch
3341 .mbar add cascade -label Commit -menu .mbar.commit
3342 if {!$single_commit} {
3343 .mbar add cascade -label Fetch -menu .mbar.fetch
3344 .mbar add cascade -label Pull -menu .mbar.pull
3345 .mbar add cascade -label Push -menu .mbar.push
3347 . configure -menu .mbar
3349 # -- Repository Menu
3351 menu .mbar.repository
3352 .mbar.repository add command \
3353 -label {Visualize Current Branch} \
3354 -command {do_gitk {}} \
3357 .mbar.repository add command \
3358 -label {Visualize All Branches} \
3359 -command {do_gitk {--all}} \
3362 .mbar.repository add separator
3364 if {!$single_commit} {
3365 .mbar.repository add command -label {Compress Database} \
3369 .mbar.repository add command -label {Verify Database} \
3370 -command do_fsck_objects \
3373 .mbar.repository add separator
3376 .mbar.repository add command \
3377 -label {Create Desktop Icon} \
3378 -command do_windows_shortcut \
3380 } elseif {[is_MacOSX]} {
3381 .mbar.repository add command \
3382 -label {Create Desktop Icon} \
3383 -command do_macosx_app \
3388 .mbar.repository add command -label Quit \
3390 -accelerator $M1T-Q \
3396 .mbar.edit add command -label Undo \
3397 -command {catch {[focus] edit undo}} \
3398 -accelerator $M1T-Z \
3400 .mbar.edit add command -label Redo \
3401 -command {catch {[focus] edit redo}} \
3402 -accelerator $M1T-Y \
3404 .mbar.edit add separator
3405 .mbar.edit add command -label Cut \
3406 -command {catch {tk_textCut [focus]}} \
3407 -accelerator $M1T-X \
3409 .mbar.edit add command -label Copy \
3410 -command {catch {tk_textCopy [focus]}} \
3411 -accelerator $M1T-C \
3413 .mbar.edit add command -label Paste \
3414 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3415 -accelerator $M1T-V \
3417 .mbar.edit add command -label Delete \
3418 -command {catch {[focus] delete sel.first sel.last}} \
3421 .mbar.edit add separator
3422 .mbar.edit add command -label {Select All} \
3423 -command {catch {[focus] tag add sel 0.0 end}} \
3424 -accelerator $M1T-A \
3429 if {!$single_commit} {
3432 .mbar.branch add command -label {Create...} \
3433 -command do_create_branch \
3434 -accelerator $M1T-N \
3436 lappend disable_on_lock [list .mbar.branch entryconf \
3437 [.mbar.branch index last] -state]
3439 .mbar.branch add command -label {Delete...} \
3440 -command do_delete_branch \
3442 lappend disable_on_lock [list .mbar.branch entryconf \
3443 [.mbar.branch index last] -state]
3450 .mbar.commit add radiobutton \
3451 -label {New Commit} \
3452 -command do_select_commit_type \
3453 -variable selected_commit_type \
3456 lappend disable_on_lock \
3457 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3459 .mbar.commit add radiobutton \
3460 -label {Amend Last Commit} \
3461 -command do_select_commit_type \
3462 -variable selected_commit_type \
3465 lappend disable_on_lock \
3466 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3468 .mbar.commit add separator
3470 .mbar.commit add command -label Rescan \
3471 -command do_rescan \
3474 lappend disable_on_lock \
3475 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3477 .mbar.commit add command -label {Add To Commit} \
3478 -command do_add_selection \
3480 lappend disable_on_lock \
3481 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3483 .mbar.commit add command -label {Add All To Commit} \
3484 -command do_add_all \
3485 -accelerator $M1T-I \
3487 lappend disable_on_lock \
3488 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3490 .mbar.commit add command -label {Unstage From Commit} \
3491 -command do_unstage_selection \
3493 lappend disable_on_lock \
3494 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3496 .mbar.commit add command -label {Revert Changes} \
3497 -command do_revert_selection \
3499 lappend disable_on_lock \
3500 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3502 .mbar.commit add separator
3504 .mbar.commit add command -label {Sign Off} \
3505 -command do_signoff \
3506 -accelerator $M1T-S \
3509 .mbar.commit add command -label Commit \
3510 -command do_commit \
3511 -accelerator $M1T-Return \
3513 lappend disable_on_lock \
3514 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3516 # -- Transport menus
3518 if {!$single_commit} {
3525 # -- Apple Menu (Mac OS X only)
3527 .mbar add cascade -label Apple -menu .mbar.apple
3530 .mbar.apple add command -label "About [appname]" \
3533 .mbar.apple add command -label "[appname] Options..." \
3534 -command do_options \
3539 .mbar.edit add separator
3540 .mbar.edit add command -label {Options...} \
3541 -command do_options \
3546 if {[file exists /usr/local/miga/lib/gui-miga]
3547 && [file exists .pvcsrc]} {
3549 global ui_status_value
3550 if {![lock_index update]} return
3551 set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
3552 set miga_fd [open "|$cmd" r]
3553 fconfigure $miga_fd -blocking 0
3554 fileevent $miga_fd readable [list miga_done $miga_fd]
3555 set ui_status_value {Running miga...}
3557 proc miga_done {fd} {
3562 rescan [list set ui_status_value {Ready.}]
3565 .mbar add cascade -label Tools -menu .mbar.tools
3567 .mbar.tools add command -label "Migrate" \
3570 lappend disable_on_lock \
3571 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3576 .mbar add cascade -label Help -menu .mbar.help
3579 .mbar.help add command -label "About [appname]" \
3591 -text {Current Branch:} \
3596 -textvariable current_branch \
3600 pack .branch.l1 -side left
3601 pack .branch.cb -side left -fill x
3602 pack .branch -side top -fill x
3604 # -- Main Window Layout
3606 panedwindow .vpane -orient vertical
3607 panedwindow .vpane.files -orient horizontal
3608 .vpane add .vpane.files -sticky nsew -height 100 -width 400
3609 pack .vpane -anchor n -side top -fill both -expand 1
3611 # -- Index File List
3613 frame .vpane.files.index -height 100 -width 400
3614 label .vpane.files.index.title -text {Changes To Be Committed} \
3617 text $ui_index -background white -borderwidth 0 \
3618 -width 40 -height 10 \
3620 -cursor $cursor_ptr \
3621 -yscrollcommand {.vpane.files.index.sb set} \
3623 scrollbar .vpane.files.index.sb -command [list $ui_index yview]
3624 pack .vpane.files.index.title -side top -fill x
3625 pack .vpane.files.index.sb -side right -fill y
3626 pack $ui_index -side left -fill both -expand 1
3627 .vpane.files add .vpane.files.index -sticky nsew
3629 # -- Working Directory File List
3631 frame .vpane.files.workdir -height 100 -width 100
3632 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3635 text $ui_workdir -background white -borderwidth 0 \
3636 -width 40 -height 10 \
3638 -cursor $cursor_ptr \
3639 -yscrollcommand {.vpane.files.workdir.sb set} \
3641 scrollbar .vpane.files.workdir.sb -command [list $ui_workdir yview]
3642 pack .vpane.files.workdir.title -side top -fill x
3643 pack .vpane.files.workdir.sb -side right -fill y
3644 pack $ui_workdir -side left -fill both -expand 1
3645 .vpane.files add .vpane.files.workdir -sticky nsew
3647 foreach i [list $ui_index $ui_workdir] {
3648 $i tag conf in_diff -font font_uibold
3649 $i tag conf in_sel \
3650 -background [$i cget -foreground] \
3651 -foreground [$i cget -background]
3655 # -- Diff and Commit Area
3657 frame .vpane.lower -height 300 -width 400
3658 frame .vpane.lower.commarea
3659 frame .vpane.lower.diff -relief sunken -borderwidth 1
3660 pack .vpane.lower.commarea -side top -fill x
3661 pack .vpane.lower.diff -side bottom -fill both -expand 1
3662 .vpane add .vpane.lower -stick nsew
3664 # -- Commit Area Buttons
3666 frame .vpane.lower.commarea.buttons
3667 label .vpane.lower.commarea.buttons.l -text {} \
3671 pack .vpane.lower.commarea.buttons.l -side top -fill x
3672 pack .vpane.lower.commarea.buttons -side left -fill y
3674 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3675 -command do_rescan \
3677 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3678 lappend disable_on_lock \
3679 {.vpane.lower.commarea.buttons.rescan conf -state}
3681 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3682 -command do_add_all \
3684 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3685 lappend disable_on_lock \
3686 {.vpane.lower.commarea.buttons.incall conf -state}
3688 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3689 -command do_signoff \
3691 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3693 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3694 -command do_commit \
3696 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3697 lappend disable_on_lock \
3698 {.vpane.lower.commarea.buttons.commit conf -state}
3700 # -- Commit Message Buffer
3702 frame .vpane.lower.commarea.buffer
3703 frame .vpane.lower.commarea.buffer.header
3704 set ui_comm .vpane.lower.commarea.buffer.t
3705 set ui_coml .vpane.lower.commarea.buffer.header.l
3706 radiobutton .vpane.lower.commarea.buffer.header.new \
3707 -text {New Commit} \
3708 -command do_select_commit_type \
3709 -variable selected_commit_type \
3712 lappend disable_on_lock \
3713 [list .vpane.lower.commarea.buffer.header.new conf -state]
3714 radiobutton .vpane.lower.commarea.buffer.header.amend \
3715 -text {Amend Last Commit} \
3716 -command do_select_commit_type \
3717 -variable selected_commit_type \
3720 lappend disable_on_lock \
3721 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3726 proc trace_commit_type {varname args} {
3727 global ui_coml commit_type
3728 switch -glob -- $commit_type {
3729 initial {set txt {Initial Commit Message:}}
3730 amend {set txt {Amended Commit Message:}}
3731 amend-initial {set txt {Amended Initial Commit Message:}}
3732 amend-merge {set txt {Amended Merge Commit Message:}}
3733 merge {set txt {Merge Commit Message:}}
3734 * {set txt {Commit Message:}}
3736 $ui_coml conf -text $txt
3738 trace add variable commit_type write trace_commit_type
3739 pack $ui_coml -side left -fill x
3740 pack .vpane.lower.commarea.buffer.header.amend -side right
3741 pack .vpane.lower.commarea.buffer.header.new -side right
3743 text $ui_comm -background white -borderwidth 1 \
3746 -autoseparators true \
3748 -width 75 -height 9 -wrap none \
3750 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3751 scrollbar .vpane.lower.commarea.buffer.sby \
3752 -command [list $ui_comm yview]
3753 pack .vpane.lower.commarea.buffer.header -side top -fill x
3754 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3755 pack $ui_comm -side left -fill y
3756 pack .vpane.lower.commarea.buffer -side left -fill y
3758 # -- Commit Message Buffer Context Menu
3760 set ctxm .vpane.lower.commarea.buffer.ctxm
3761 menu $ctxm -tearoff 0
3765 -command {tk_textCut $ui_comm}
3769 -command {tk_textCopy $ui_comm}
3773 -command {tk_textPaste $ui_comm}
3777 -command {$ui_comm delete sel.first sel.last}
3780 -label {Select All} \
3782 -command {$ui_comm tag add sel 0.0 end}
3787 $ui_comm tag add sel 0.0 end
3788 tk_textCopy $ui_comm
3789 $ui_comm tag remove sel 0.0 end
3796 bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
3800 set current_diff_path {}
3801 set diff_actions [list]
3802 proc trace_current_diff_path {varname args} {
3803 global current_diff_path diff_actions file_states
3804 if {$current_diff_path eq {}} {
3810 set p $current_diff_path
3811 set s [mapdesc [lindex $file_states($p) 0] $p]
3813 set p [escape_path $p]
3817 .vpane.lower.diff.header.status configure -text $s
3818 .vpane.lower.diff.header.file configure -text $f
3819 .vpane.lower.diff.header.path configure -text $p
3820 foreach w $diff_actions {
3824 trace add variable current_diff_path write trace_current_diff_path
3826 frame .vpane.lower.diff.header -background orange
3827 label .vpane.lower.diff.header.status \
3828 -background orange \
3829 -width $max_status_desc \
3833 label .vpane.lower.diff.header.file \
3834 -background orange \
3838 label .vpane.lower.diff.header.path \
3839 -background orange \
3843 pack .vpane.lower.diff.header.status -side left
3844 pack .vpane.lower.diff.header.file -side left
3845 pack .vpane.lower.diff.header.path -fill x
3846 set ctxm .vpane.lower.diff.header.ctxm
3847 menu $ctxm -tearoff 0
3856 -- $current_diff_path
3858 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3859 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3863 frame .vpane.lower.diff.body
3864 set ui_diff .vpane.lower.diff.body.t
3865 text $ui_diff -background white -borderwidth 0 \
3866 -width 80 -height 15 -wrap none \
3868 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3869 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3871 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3872 -command [list $ui_diff xview]
3873 scrollbar .vpane.lower.diff.body.sby -orient vertical \
3874 -command [list $ui_diff yview]
3875 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3876 pack .vpane.lower.diff.body.sby -side right -fill y
3877 pack $ui_diff -side left -fill both -expand 1
3878 pack .vpane.lower.diff.header -side top -fill x
3879 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3881 $ui_diff tag conf d_@ -font font_diffbold
3882 $ui_diff tag conf d_+ -foreground blue
3883 $ui_diff tag conf d_- -foreground red
3885 $ui_diff tag conf d_++ -foreground blue
3886 $ui_diff tag conf d_-- -foreground red
3887 $ui_diff tag conf d_+s \
3890 $ui_diff tag conf d_-s \
3893 $ui_diff tag conf d_s+ \
3895 -background {light goldenrod yellow}
3896 $ui_diff tag conf d_s- \
3898 -background {light goldenrod yellow}
3900 $ui_diff tag conf d<<<<<<< \
3901 -foreground orange \
3903 $ui_diff tag conf d======= \
3904 -foreground orange \
3906 $ui_diff tag conf d>>>>>>> \
3907 -foreground orange \
3910 # -- Diff Body Context Menu
3912 set ctxm .vpane.lower.diff.body.ctxm
3913 menu $ctxm -tearoff 0
3917 -command {tk_textCopy $ui_diff}
3918 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3920 -label {Select All} \
3922 -command {$ui_diff tag add sel 0.0 end}
3923 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3928 $ui_diff tag add sel 0.0 end
3929 tk_textCopy $ui_diff
3930 $ui_diff tag remove sel 0.0 end
3932 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3935 -label {Decrease Font Size} \
3937 -command {incr_font_size font_diff -1}
3938 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3940 -label {Increase Font Size} \
3942 -command {incr_font_size font_diff 1}
3943 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3946 -label {Show Less Context} \
3948 -command {if {$repo_config(gui.diffcontext) >= 2} {
3949 incr repo_config(gui.diffcontext) -1
3952 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3954 -label {Show More Context} \
3957 incr repo_config(gui.diffcontext)
3960 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3962 $ctxm add command -label {Options...} \
3965 bind_button3 $ui_diff "tk_popup $ctxm %X %Y"
3969 set ui_status_value {Initializing...}
3970 label .status -textvariable ui_status_value \
3976 pack .status -anchor w -side bottom -fill x
3981 set gm $repo_config(gui.geometry)
3982 wm geometry . [lindex $gm 0]
3983 .vpane sash place 0 \
3984 [lindex [.vpane sash coord 0] 0] \
3986 .vpane.files sash place 0 \
3988 [lindex [.vpane.files sash coord 0] 1]
3994 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3995 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3996 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3997 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3998 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3999 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4000 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4001 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4002 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4003 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4004 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4006 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4007 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4008 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4009 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4010 bind $ui_diff <$M1B-Key-v> {break}
4011 bind $ui_diff <$M1B-Key-V> {break}
4012 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4013 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4014 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4015 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4016 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4017 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4019 if {!$single_commit} {
4020 bind . <$M1B-Key-n> do_create_branch
4021 bind . <$M1B-Key-N> do_create_branch
4024 bind . <Destroy> do_quit
4025 bind all <Key-F5> do_rescan
4026 bind all <$M1B-Key-r> do_rescan
4027 bind all <$M1B-Key-R> do_rescan
4028 bind . <$M1B-Key-s> do_signoff
4029 bind . <$M1B-Key-S> do_signoff
4030 bind . <$M1B-Key-i> do_add_all
4031 bind . <$M1B-Key-I> do_add_all
4032 bind . <$M1B-Key-Return> do_commit
4033 bind all <$M1B-Key-q> do_quit
4034 bind all <$M1B-Key-Q> do_quit
4035 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4036 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4037 foreach i [list $ui_index $ui_workdir] {
4038 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
4039 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
4040 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
4044 set file_lists($ui_index) [list]
4045 set file_lists($ui_workdir) [list]
4049 set MERGE_HEAD [list]
4052 set current_branch {}
4053 set current_diff_path {}
4054 set selected_commit_type new
4056 wm title . "[appname] ([file normalize [file dirname [gitdir]]])"
4057 focus -force $ui_comm
4059 # -- Warn the user about environmental problems. Cygwin's Tcl
4060 # does *not* pass its env array onto any processes it spawns.
4061 # This means that git processes get none of our environment.
4066 set msg "Possible environment issues exist.
4068 The following environment variables are probably
4069 going to be ignored by any Git subprocess run
4073 foreach name [array names env] {
4074 switch -regexp -- $name {
4075 {^GIT_INDEX_FILE$} -
4076 {^GIT_OBJECT_DIRECTORY$} -
4077 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4079 {^GIT_EXTERNAL_DIFF$} -
4083 {^GIT_CONFIG_LOCAL$} -
4084 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4085 append msg " - $name\n"
4088 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4089 append msg " - $name\n"
4091 set suggest_user $name
4095 if {$ignored_env > 0} {
4097 This is due to a known issue with the
4098 Tcl binary distributed by Cygwin."
4100 if {$suggest_user ne {}} {
4103 A good replacement for $suggest_user
4104 is placing values for the user.name and
4105 user.email settings into your personal
4111 unset ignored_env msg suggest_user name
4114 # -- Only initialize complex UI if we are going to stay running.
4116 if {!$single_commit} {
4120 populate_branch_menu
4121 populate_fetch_menu .mbar.fetch
4122 populate_pull_menu .mbar.pull
4123 populate_push_menu .mbar.push
4126 # -- Only suggest a gc run if we are going to stay running.
4128 if {!$single_commit} {
4129 set object_limit 2000
4130 if {[is_Windows]} {set object_limit 200}
4131 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4132 if {$objects_current >= $object_limit} {
4134 "This repository currently has $objects_current loose objects.
4136 To maintain optimal performance it is strongly
4137 recommended that you compress the database
4138 when more than $object_limit loose objects exist.
4140 Compress the database now?"] eq yes} {
4144 unset object_limit _junk objects_current
4147 lock_index begin-read