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 ui_index ui_workdir
548 $ui_diff conf
-state normal
549 $ui_diff delete
0.0 end
550 $ui_diff conf
-state disabled
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 current_diff ui_status_value file_states
561 if {$current_diff eq
{}
562 ||
[catch
{set s
$file_states($current_diff)}]} {
565 show_diff
$current_diff
569 proc handle_empty_diff
{} {
570 global current_diff file_states file_lists
572 set path
$current_diff
573 set s
$file_states($path)
574 if {[lindex
$s 0] ne
{_M
}} return
576 info_popup
"No differences detected.
578 [short_path $path] has no changes.
580 The modification date of this file was updated
581 by another application and you currently have
582 the Trust File Modification Timestamps option
583 enabled, so Git did not automatically detect
584 that there are no content differences in this
587 This file will now be removed from the modified
588 files list, to prevent possible confusion.
590 if {[catch
{exec git update-index
-- $path} err
]} {
591 error_popup
"Failed to refresh index:\n\n$err"
595 display_file
$path __
598 proc show_diff
{path
{w
{}} {lno
{}}} {
599 global file_states file_lists
600 global is_3way_diff diff_active repo_config
601 global ui_diff current_diff ui_status_value
603 if {$diff_active ||
![lock_index
read]} return
606 if {$w eq
{} ||
$lno == {}} {
607 foreach w
[array names file_lists
] {
608 set lno
[lsearch
-sorted $file_lists($w) $path]
615 if {$w ne
{} && $lno >= 1} {
616 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
619 set s
$file_states($path)
623 set current_diff
$path
624 set ui_status_value
"Loading diff of [escape_path $path]..."
626 set cmd
[list | git diff-index
]
627 lappend cmd
--no-color
628 if {$repo_config(gui.diffcontext
) > 0} {
629 lappend cmd
"-U$repo_config(gui.diffcontext)"
639 set fd
[open
$path r
]
640 set content
[read $fd]
645 set ui_status_value
"Unable to display [escape_path $path]"
646 error_popup
"Error loading file:\n\n$err"
649 $ui_diff conf
-state normal
650 $ui_diff insert end
$content
651 $ui_diff conf
-state disabled
654 set ui_status_value
{Ready.
}
663 if {[catch
{set fd
[open
$cmd r
]} err
]} {
666 set ui_status_value
"Unable to display [escape_path $path]"
667 error_popup
"Error loading diff:\n\n$err"
671 fconfigure
$fd -blocking 0 -translation auto
672 fileevent
$fd readable
[list read_diff
$fd]
675 proc read_diff
{fd
} {
676 global ui_diff ui_status_value is_3way_diff diff_active
679 $ui_diff conf
-state normal
680 while {[gets
$fd line
] >= 0} {
681 # -- Cleanup uninteresting diff header lines.
683 if {[string match
{diff --git *} $line]} continue
684 if {[string match
{diff --combined *} $line]} continue
685 if {[string match
{--- *} $line]} continue
686 if {[string match
{+++ *} $line]} continue
687 if {$line eq
{deleted
file mode
120000}} {
688 set line
"deleted symlink"
691 # -- Automatically detect if this is a 3 way diff.
693 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
695 # -- Reformat a 3 way diff, 'cause its too weird.
698 set op
[string range
$line 0 1]
701 {++} {set tags d_
+ ; set op
{ +}}
702 {--} {set tags d_-
; set op
{ -}}
703 { +} {set tags d_
++; set op
{++}}
704 { -} {set tags d_--
; set op
{--}}
705 {+ } {set tags d_-
+; set op
{-+}}
706 {- } {set tags d_
+-; set op
{+-}}
707 default
{set tags
{}}
709 set line
[string replace
$line 0 1 $op]
711 switch
-- [string index
$line 0] {
715 default
{set tags
{}}
718 $ui_diff insert end
$line $tags
719 $ui_diff insert end
"\n" $tags
721 $ui_diff conf
-state disabled
727 set ui_status_value
{Ready.
}
729 if {$repo_config(gui.trustmtime
) eq
{true
}
730 && [$ui_diff index end
] eq
{2.0}} {
736 ######################################################################
740 proc load_last_commit
{} {
741 global HEAD PARENT MERGE_HEAD commit_type ui_comm
743 if {[llength
$PARENT] == 0} {
744 error_popup
{There is nothing to amend.
746 You are about to create the initial commit.
747 There is no commit before this to amend.
752 repository_state curType curHEAD curMERGE_HEAD
753 if {$curType eq
{merge
}} {
754 error_popup
{Cannot amend
while merging.
756 You are currently
in the middle of a merge that
757 has not been fully completed. You cannot amend
758 the prior commit unless you first abort the
759 current merge activity.
767 set fd
[open
"| git cat-file commit $curHEAD" r
]
768 while {[gets
$fd line
] > 0} {
769 if {[string match
{parent
*} $line]} {
770 lappend parents
[string range
$line 7 end
]
773 set msg
[string trim
[read $fd]]
776 error_popup
"Error loading commit data for amend:\n\n$err"
782 set MERGE_HEAD
[list
]
783 switch
-- [llength
$parents] {
784 0 {set commit_type amend-initial
}
785 1 {set commit_type amend
}
786 default
{set commit_type amend-merge
}
789 $ui_comm delete
0.0 end
790 $ui_comm insert end
$msg
792 $ui_comm edit modified false
793 rescan
{set ui_status_value
{Ready.
}}
796 proc create_new_commit
{} {
797 global commit_type ui_comm
799 set commit_type normal
800 $ui_comm delete
0.0 end
802 $ui_comm edit modified false
803 rescan
{set ui_status_value
{Ready.
}}
806 set GIT_COMMITTER_IDENT
{}
808 proc committer_ident
{} {
809 global GIT_COMMITTER_IDENT
811 if {$GIT_COMMITTER_IDENT eq
{}} {
812 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
813 error_popup
"Unable to obtain your identity:\n\n$err"
816 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
817 $me me GIT_COMMITTER_IDENT
]} {
818 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
823 return $GIT_COMMITTER_IDENT
826 proc commit_tree
{} {
827 global HEAD commit_type file_states ui_comm repo_config
828 global ui_status_value pch_error
830 if {![lock_index update
]} return
831 if {[committer_ident
] eq
{}} return
833 # -- Our in memory state should match the repository.
835 repository_state curType curHEAD curMERGE_HEAD
836 if {[string match amend
* $commit_type]
837 && $curType eq
{normal
}
838 && $curHEAD eq
$HEAD} {
839 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
840 info_popup
{Last scanned state does not match repository state.
842 Another Git program has modified this repository
843 since the last scan. A rescan must be performed
844 before another commit can be created.
846 The rescan will be automatically started now.
849 rescan
{set ui_status_value
{Ready.
}}
853 # -- At least one file should differ in the index.
856 foreach path
[array names file_states
] {
857 switch
-glob -- [lindex
$file_states($path) 0] {
861 M?
{set files_ready
1; break}
863 error_popup
"Unmerged files cannot be committed.
865 File [short_path $path] has merge conflicts.
866 You must resolve them and include the file before committing.
872 error_popup
"Unknown file state [lindex $s 0] detected.
874 File [short_path $path] cannot be committed by this program.
880 error_popup
{No included files to commit.
882 You must include
at least
1 file before you can commit.
888 # -- A message is required.
890 set msg
[string trim
[$ui_comm get
1.0 end
]]
892 error_popup
{Please supply a commit message.
894 A good commit message has the following format
:
896 - First line
: Describe
in one sentance what you did.
898 - Remaining lines
: Describe why this change is good.
904 # -- Run the pre-commit hook.
906 set pchook
[gitdir hooks pre-commit
]
908 # On Cygwin [file executable] might lie so we need to ask
909 # the shell if the hook is executable. Yes that's annoying.
911 if {[is_Windows
] && [file isfile
$pchook]} {
912 set pchook
[list sh
-c [concat \
913 "if test -x \"$pchook\";" \
914 "then exec \"$pchook\" 2>&1;" \
916 } elseif
{[file executable
$pchook]} {
917 set pchook
[list
$pchook |
& cat]
919 commit_writetree
$curHEAD $msg
923 set ui_status_value
{Calling pre-commit hook...
}
925 set fd_ph
[open
"| $pchook" r
]
926 fconfigure
$fd_ph -blocking 0 -translation binary
927 fileevent
$fd_ph readable \
928 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
931 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
932 global pch_error ui_status_value
934 append pch_error
[read $fd_ph]
935 fconfigure
$fd_ph -blocking 1
937 if {[catch
{close
$fd_ph}]} {
938 set ui_status_value
{Commit declined by pre-commit hook.
}
939 hook_failed_popup pre-commit
$pch_error
942 commit_writetree
$curHEAD $msg
947 fconfigure
$fd_ph -blocking 0
950 proc commit_writetree
{curHEAD msg
} {
951 global ui_status_value
953 set ui_status_value
{Committing changes...
}
954 set fd_wt
[open
"| git write-tree" r
]
955 fileevent
$fd_wt readable \
956 [list commit_committree
$fd_wt $curHEAD $msg]
959 proc commit_committree
{fd_wt curHEAD msg
} {
960 global HEAD PARENT MERGE_HEAD commit_type
962 global ui_status_value ui_comm selected_commit_type
963 global file_states selected_paths rescan_active
966 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
967 error_popup
"write-tree failed:\n\n$err"
968 set ui_status_value
{Commit failed.
}
973 # -- Create the commit.
975 set cmd
[list git commit-tree
$tree_id]
976 set parents
[concat
$PARENT $MERGE_HEAD]
977 if {[llength
$parents] > 0} {
982 # git commit-tree writes to stderr during initial commit.
983 lappend cmd
2>/dev
/null
986 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
987 error_popup
"commit-tree failed:\n\n$err"
988 set ui_status_value
{Commit failed.
}
993 # -- Update the HEAD ref.
996 if {$commit_type ne
{normal
}} {
997 append reflogm
" ($commit_type)"
999 set i
[string first
"\n" $msg]
1001 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1003 append reflogm
{: } $msg
1005 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1006 if {[catch
{eval exec $cmd} err
]} {
1007 error_popup
"update-ref failed:\n\n$err"
1008 set ui_status_value
{Commit failed.
}
1013 # -- Cleanup after ourselves.
1015 catch
{file delete
[gitdir MERGE_HEAD
]}
1016 catch
{file delete
[gitdir MERGE_MSG
]}
1017 catch
{file delete
[gitdir SQUASH_MSG
]}
1018 catch
{file delete
[gitdir GITGUI_MSG
]}
1020 # -- Let rerere do its thing.
1022 if {[file isdirectory
[gitdir rr-cache
]]} {
1023 catch
{exec git rerere
}
1026 # -- Run the post-commit hook.
1028 set pchook
[gitdir hooks post-commit
]
1029 if {[is_Windows
] && [file isfile
$pchook]} {
1030 set pchook
[list sh
-c [concat \
1031 "if test -x \"$pchook\";" \
1032 "then exec \"$pchook\";" \
1034 } elseif
{![file executable
$pchook]} {
1037 if {$pchook ne
{}} {
1038 catch
{exec $pchook &}
1041 $ui_comm delete
0.0 end
1043 $ui_comm edit modified false
1045 if {$single_commit} do_quit
1047 # -- Update in memory status
1049 set selected_commit_type new
1050 set commit_type normal
1053 set MERGE_HEAD
[list
]
1055 foreach path
[array names file_states
] {
1056 set s
$file_states($path)
1058 switch
-glob -- $m {
1066 unset file_states
($path)
1067 catch
{unset selected_paths
($path)}
1070 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1076 set file_states
($path) [list \
1077 _
[string index
$m 1] \
1088 set ui_status_value \
1089 "Changes committed as [string range $cmt_id 0 7]."
1092 ######################################################################
1096 proc fetch_from
{remote
} {
1097 set w
[new_console
"fetch $remote" \
1098 "Fetching new changes from $remote"]
1099 set cmd
[list git fetch
]
1101 console_exec
$w $cmd
1104 proc pull_remote
{remote branch
} {
1105 global HEAD commit_type file_states repo_config
1107 if {![lock_index update
]} return
1109 # -- Our in memory state should match the repository.
1111 repository_state curType curHEAD curMERGE_HEAD
1112 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1113 info_popup
{Last scanned state does not match repository state.
1115 Another Git program has modified this repository
1116 since the last scan. A rescan must be performed
1117 before a pull operation can be started.
1119 The rescan will be automatically started now.
1122 rescan
{set ui_status_value
{Ready.
}}
1126 # -- No differences should exist before a pull.
1128 if {[array size file_states
] != 0} {
1129 error_popup
{Uncommitted but modified files are present.
1131 You should not perform a pull with unmodified
1132 files
in your working directory as Git will be
1133 unable to recover from an incorrect merge.
1135 You should commit or revert all changes before
1136 starting a pull operation.
1142 set w
[new_console
"pull $remote $branch" \
1143 "Pulling new changes from branch $branch in $remote"]
1144 set cmd
[list git pull
]
1145 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1146 lappend cmd
--no-summary
1150 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1153 proc post_pull_remote
{remote branch success
} {
1154 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1155 global ui_status_value
1159 repository_state commit_type HEAD MERGE_HEAD
1161 set selected_commit_type new
1162 set ui_status_value
"Pulling $branch from $remote complete."
1164 rescan
[list
set ui_status_value \
1165 "Conflicts detected while pulling $branch from $remote."]
1169 proc push_to
{remote
} {
1170 set w
[new_console
"push $remote" \
1171 "Pushing changes to $remote"]
1172 set cmd
[list git push
]
1174 console_exec
$w $cmd
1177 ######################################################################
1181 proc mapicon
{w state path
} {
1184 if {[catch
{set r
$all_icons($state$w)}]} {
1185 puts
"error: no icon for $w state={$state} $path"
1191 proc mapdesc
{state path
} {
1194 if {[catch
{set r
$all_descs($state)}]} {
1195 puts
"error: no desc for state={$state} $path"
1201 proc escape_path
{path
} {
1202 regsub
-all "\n" $path "\\n" path
1206 proc short_path
{path
} {
1207 return [escape_path
[lindex
[file split $path] end
]]
1211 set null_sha1
[string repeat
0 40]
1213 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1214 global file_states next_icon_id null_sha1
1216 set s0
[string index
$new_state 0]
1217 set s1
[string index
$new_state 1]
1219 if {[catch
{set info
$file_states($path)}]} {
1221 set icon n
[incr next_icon_id
]
1223 set state
[lindex
$info 0]
1224 set icon
[lindex
$info 1]
1225 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1226 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1229 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1230 elseif
{$s0 eq
{_
}} {set s0 _
}
1232 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1233 elseif
{$s1 eq
{_
}} {set s1 _
}
1235 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1236 set head_info
[list
0 $null_sha1]
1237 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1238 && $head_info eq
{}} {
1239 set head_info
$index_info
1242 set file_states
($path) [list
$s0$s1 $icon \
1243 $head_info $index_info \
1248 proc display_file_helper
{w path icon_name old_m new_m
} {
1251 if {$new_m eq
{_
}} {
1252 set lno
[lsearch
-sorted $file_lists($w) $path]
1254 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1256 $w conf
-state normal
1257 $w delete
$lno.0 [expr {$lno + 1}].0
1258 $w conf
-state disabled
1260 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1261 lappend file_lists
($w) $path
1262 set file_lists
($w) [lsort
-unique $file_lists($w)]
1263 set lno
[lsearch
-sorted $file_lists($w) $path]
1265 $w conf
-state normal
1266 $w image create
$lno.0 \
1267 -align center
-padx 5 -pady 1 \
1269 -image [mapicon
$w $new_m $path]
1270 $w insert
$lno.1 "[escape_path $path]\n"
1271 $w conf
-state disabled
1272 } elseif
{$old_m ne
$new_m} {
1273 $w conf
-state normal
1274 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1275 $w conf
-state disabled
1279 proc display_file
{path state
} {
1280 global file_states selected_paths
1281 global ui_index ui_workdir
1283 set old_m
[merge_state
$path $state]
1284 set s
$file_states($path)
1285 set new_m
[lindex
$s 0]
1286 set icon_name
[lindex
$s 1]
1288 display_file_helper
$ui_index $path $icon_name \
1289 [string index
$old_m 0] \
1290 [string index
$new_m 0]
1291 display_file_helper
$ui_workdir $path $icon_name \
1292 [string index
$old_m 1] \
1293 [string index
$new_m 1]
1295 if {$new_m eq
{__
}} {
1296 unset file_states
($path)
1297 catch
{unset selected_paths
($path)}
1301 proc display_all_files_helper
{w path icon_name m
} {
1304 lappend file_lists
($w) $path
1305 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1306 $w image create end \
1307 -align center
-padx 5 -pady 1 \
1309 -image [mapicon
$w $m $path]
1310 $w insert end
"[escape_path $path]\n"
1313 proc display_all_files
{} {
1314 global ui_index ui_workdir
1315 global file_states file_lists
1318 $ui_index conf
-state normal
1319 $ui_workdir conf
-state normal
1321 $ui_index delete
0.0 end
1322 $ui_workdir delete
0.0 end
1325 set file_lists
($ui_index) [list
]
1326 set file_lists
($ui_workdir) [list
]
1328 foreach path
[lsort
[array names file_states
]] {
1329 set s
$file_states($path)
1331 set icon_name
[lindex
$s 1]
1333 if {[string index
$m 0] ne
{_
}} {
1334 display_all_files_helper
$ui_index $path \
1335 $icon_name [string index
$m 0]
1337 if {[string index
$m 1] ne
{_
}} {
1338 display_all_files_helper
$ui_workdir $path \
1339 $icon_name [string index
$m 1]
1343 $ui_index conf
-state disabled
1344 $ui_workdir conf
-state disabled
1347 proc update_indexinfo
{msg pathList after
} {
1348 global update_index_cp ui_status_value
1350 if {![lock_index update
]} return
1352 set update_index_cp
0
1353 set pathList
[lsort
$pathList]
1354 set totalCnt
[llength
$pathList]
1355 set batch [expr {int
($totalCnt * .01) + 1}]
1356 if {$batch > 25} {set batch 25}
1358 set ui_status_value
[format \
1359 "$msg... %i/%i files (%.2f%%)" \
1363 set fd
[open
"| git update-index -z --index-info" w
]
1369 fileevent
$fd writable
[list \
1370 write_update_indexinfo \
1380 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1381 global update_index_cp ui_status_value
1382 global file_states current_diff
1384 if {$update_index_cp >= $totalCnt} {
1391 for {set i
$batch} \
1392 {$update_index_cp < $totalCnt && $i > 0} \
1394 set path
[lindex
$pathList $update_index_cp]
1395 incr update_index_cp
1397 set s
$file_states($path)
1398 switch
-glob -- [lindex
$s 0] {
1405 set info
[lindex
$s 2]
1406 if {$info eq
{}} continue
1408 puts
-nonewline $fd "$info\t$path\0"
1409 display_file
$path $new
1412 set ui_status_value
[format \
1413 "$msg... %i/%i files (%.2f%%)" \
1416 [expr {100.0 * $update_index_cp / $totalCnt}]]
1419 proc update_index
{msg pathList after
} {
1420 global update_index_cp ui_status_value
1422 if {![lock_index update
]} return
1424 set update_index_cp
0
1425 set pathList
[lsort
$pathList]
1426 set totalCnt
[llength
$pathList]
1427 set batch [expr {int
($totalCnt * .01) + 1}]
1428 if {$batch > 25} {set batch 25}
1430 set ui_status_value
[format \
1431 "$msg... %i/%i files (%.2f%%)" \
1435 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1441 fileevent
$fd writable
[list \
1442 write_update_index \
1452 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1453 global update_index_cp ui_status_value
1454 global file_states current_diff
1456 if {$update_index_cp >= $totalCnt} {
1463 for {set i
$batch} \
1464 {$update_index_cp < $totalCnt && $i > 0} \
1466 set path
[lindex
$pathList $update_index_cp]
1467 incr update_index_cp
1469 switch
-glob -- [lindex
$file_states($path) 0] {
1478 puts
-nonewline $fd "$path\0"
1479 display_file
$path $new
1482 set ui_status_value
[format \
1483 "$msg... %i/%i files (%.2f%%)" \
1486 [expr {100.0 * $update_index_cp / $totalCnt}]]
1489 proc checkout_index
{msg pathList after
} {
1490 global update_index_cp ui_status_value
1492 if {![lock_index update
]} return
1494 set update_index_cp
0
1495 set pathList
[lsort
$pathList]
1496 set totalCnt
[llength
$pathList]
1497 set batch [expr {int
($totalCnt * .01) + 1}]
1498 if {$batch > 25} {set batch 25}
1500 set ui_status_value
[format \
1501 "$msg... %i/%i files (%.2f%%)" \
1505 set cmd
[list git checkout-index
]
1511 set fd
[open
"| $cmd " w
]
1517 fileevent
$fd writable
[list \
1518 write_checkout_index \
1528 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1529 global update_index_cp ui_status_value
1530 global file_states current_diff
1532 if {$update_index_cp >= $totalCnt} {
1539 for {set i
$batch} \
1540 {$update_index_cp < $totalCnt && $i > 0} \
1542 set path
[lindex
$pathList $update_index_cp]
1543 incr update_index_cp
1544 switch
-glob -- [lindex
$file_states($path) 0] {
1548 puts
-nonewline $fd "$path\0"
1549 display_file
$path ?_
1554 set ui_status_value
[format \
1555 "$msg... %i/%i files (%.2f%%)" \
1558 [expr {100.0 * $update_index_cp / $totalCnt}]]
1561 ######################################################################
1563 ## branch management
1565 proc load_all_heads
{} {
1566 global all_heads tracking_branches
1568 set all_heads
[list
]
1569 set cmd
[list git for-each-ref
]
1570 lappend cmd
--format=%(refname
)
1571 lappend cmd refs
/heads
1572 set fd
[open
"| $cmd" r
]
1573 while {[gets
$fd line
] > 0} {
1574 if {![catch
{set info
$tracking_branches($line)}]} continue
1575 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1576 lappend all_heads
$name
1580 set all_heads
[lsort
$all_heads]
1583 proc populate_branch_menu
{} {
1584 global all_heads disable_on_lock
1587 set last
[$m index last
]
1588 for {set i
0} {$i <= $last} {incr i
} {
1589 if {[$m type $i] eq
{separator
}} {
1592 foreach a
$disable_on_lock {
1593 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1597 set disable_on_lock
$new_dol
1603 foreach b
$all_heads {
1604 $m add radiobutton \
1606 -command [list switch_branch
$b] \
1607 -variable current_branch \
1610 lappend disable_on_lock \
1611 [list
$m entryconf
[$m index last
] -state]
1615 proc do_create_branch_action
{w
} {
1616 global all_heads null_sha1
1617 global create_branch_checkout create_branch_revtype
1618 global create_branch_head create_branch_trackinghead
1620 set newbranch
[string trim
[$w.name.t get
0.0 end
]]
1621 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1625 -title [wm title
$w] \
1627 -message "Branch '$newbranch' already exists."
1631 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1635 -title [wm title
$w] \
1637 -message "We do not like '$newbranch' as a branch name."
1643 switch
-- $create_branch_revtype {
1644 head {set rev $create_branch_head}
1645 tracking
{set rev $create_branch_trackinghead}
1646 expression
{set rev [string trim
[$w.from.exp.t get
0.0 end
]]}
1648 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1652 -title [wm title
$w] \
1654 -message "Invalid starting revision: $rev"
1657 set cmd
[list git update-ref
]
1659 lappend cmd
"branch: Created from $rev"
1660 lappend cmd
"refs/heads/$newbranch"
1662 lappend cmd
$null_sha1
1663 if {[catch
{eval exec $cmd} err
]} {
1667 -title [wm title
$w] \
1669 -message "Failed to create '$newbranch'.\n\n$err"
1673 lappend all_heads
$newbranch
1674 set all_heads
[lsort
$all_heads]
1675 populate_branch_menu
1679 proc do_create_branch
{} {
1680 global all_heads current_branch tracking_branches
1681 global create_branch_checkout create_branch_revtype
1682 global create_branch_head create_branch_trackinghead
1684 set create_branch_checkout true
1685 set create_branch_revtype
head
1686 set create_branch_head
$current_branch
1687 set create_branch_trackinghead
{}
1689 set w .branch_editor
1691 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1693 label
$w.header
-text {Create New Branch
} \
1695 pack
$w.header
-side top
-fill x
1698 button
$w.buttons.create
-text Create \
1701 -command [list do_create_branch_action
$w]
1702 pack
$w.buttons.create
-side right
1703 button
$w.buttons.cancel
-text {Cancel
} \
1705 -command [list destroy
$w]
1706 pack
$w.buttons.cancel
-side right
-padx 5
1707 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1709 labelframe
$w.name \
1710 -text {Branch Description
} \
1712 label
$w.name.l
-text {Name
:} -font font_ui
1719 bind $w.name.t
<Shift-Key-Tab
> "focus $w.postActions.checkout;break"
1720 bind $w.name.t
<Key-Tab
> "focus $w.from.exp.t;break"
1721 bind $w.name.t
<Key-Return
> "do_create_branch_action $w;break"
1722 bind $w.name.t
<Key
> {
1723 if {{%K
} ne
{BackSpace
}
1726 && {%K
} ne
{Return
}} {
1728 if {[string first
%A
{~^
:?
*[}] >= 0} break
1731 pack
$w.name.l
-side left
-padx 5
1732 pack
$w.name.t
-side left
-fill x
-expand 1
1733 pack
$w.name
-anchor nw
-fill x
-pady 5 -padx 5
1735 set all_trackings
[list
]
1736 foreach b
[array names tracking_branches
] {
1737 regsub ^refs
/(heads|remotes
)/ $b {} b
1738 lappend all_trackings
$b
1740 set all_trackings
[lsort
-unique $all_trackings]
1741 if {$all_trackings ne
{}} {
1742 set create_branch_trackinghead
[lindex
$all_trackings 0]
1745 labelframe
$w.from \
1746 -text {Starting Revision
} \
1749 radiobutton
$w.from.
head.r \
1750 -text {Local Branch
:} \
1752 -variable create_branch_revtype \
1754 eval tk_optionMenu
$w.from.
head.m create_branch_head
$all_heads
1755 pack
$w.from.
head.r
-side left
1756 pack
$w.from.
head.m
-side left
1757 frame
$w.from.tracking
1758 radiobutton
$w.from.tracking.r \
1759 -text {Tracking Branch
:} \
1761 -variable create_branch_revtype \
1763 eval tk_optionMenu
$w.from.tracking.m \
1764 create_branch_trackinghead \
1766 pack
$w.from.tracking.r
-side left
1767 pack
$w.from.tracking.m
-side left
1769 radiobutton
$w.from.exp.r \
1770 -text {Revision Expression
:} \
1772 -variable create_branch_revtype \
1774 text
$w.from.exp.t \
1780 bind $w.from.exp.t
<Shift-Key-Tab
> "focus $w.name.t;break"
1781 bind $w.from.exp.t
<Key-Tab
> "focus $w.postActions.checkout;break"
1782 bind $w.from.exp.t
<Key-Return
> "do_create_branch_action $w;break"
1783 pack
$w.from.exp.r
-side left
1784 pack
$w.from.exp.t
-side left
-fill x
-expand 1
1785 pack
$w.from.
head -padx 5 -fill x
-expand 1
1786 pack
$w.from.tracking
-padx 5 -fill x
-expand 1
1787 pack
$w.from.exp
-padx 5 -fill x
-expand 1
1788 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1790 labelframe
$w.postActions \
1791 -text {Post Creation Actions
} \
1793 checkbutton
$w.postActions.checkout \
1794 -text {Checkout after creation
} \
1797 -variable create_branch_checkout \
1799 pack
$w.postActions.checkout
-anchor nw
1800 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1802 bind $w <Visibility
> "grab $w; focus $w.name.t"
1803 bind $w <Key-Escape
> "destroy $w"
1804 bind $w <Key-Return
> "do_create_branch_action $w;break"
1805 wm title
$w "[appname] ([reponame]): Create Branch"
1809 proc do_delete_branch_action
{w
} {
1811 global delete_branch_checkhead delete_branch_head
1813 set to_delete
[list
]
1814 set not_merged
[list
]
1815 foreach i
[$w.list.l curselection
] {
1816 set b
[$w.list.l get
$i]
1817 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
1818 if {$delete_branch_checkhead} {
1819 if {$b eq
$delete_branch_head} continue
1820 if {[catch
{set m
[exec git merge-base
$o $delete_branch_head]}]} continue
1822 lappend not_merged
$b
1826 lappend to_delete
[list
$b $o]
1828 if {$not_merged ne
{}} {
1829 set msg
"The following branches are not completely merged into $delete_branch_head:
1831 - [join $not_merged "\n - "]"
1835 -title [wm title
$w] \
1839 if {$to_delete eq
{}} return
1840 if {!$delete_branch_checkhead} {
1841 set msg
{Recovering deleted branches is difficult.
1843 Delete the selected branches?
}
1844 if {[tk_messageBox \
1847 -title [wm title
$w] \
1849 -message $msg] ne
yes} {
1855 foreach i
$to_delete {
1858 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
1859 append failed
" - $b: $err\n"
1861 set x
[lsearch
-sorted $all_heads $b]
1863 set all_heads
[lreplace
$all_heads $x $x]
1868 if {$failed ne
{}} {
1872 -title [wm title
$w] \
1874 -message "Failed to delete branches:\n$failed"
1877 set all_heads
[lsort
$all_heads]
1878 populate_branch_menu
1882 proc do_delete_branch
{} {
1883 global all_heads tracking_branches current_branch
1884 global delete_branch_checkhead delete_branch_head
1886 set delete_branch_checkhead
1
1887 set delete_branch_head
$current_branch
1889 set w .branch_editor
1891 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1893 label
$w.header
-text {Delete Local Branch
} \
1895 pack
$w.header
-side top
-fill x
1898 button
$w.buttons.create
-text Delete \
1900 -command [list do_delete_branch_action
$w]
1901 pack
$w.buttons.create
-side right
1902 button
$w.buttons.cancel
-text {Cancel
} \
1904 -command [list destroy
$w]
1905 pack
$w.buttons.cancel
-side right
-padx 5
1906 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1908 labelframe
$w.list \
1909 -text {Local Branches
} \
1914 -selectmode extended \
1916 foreach h
$all_heads {
1917 if {$h ne
$current_branch} {
1918 $w.list.l insert end
$h
1921 pack
$w.list.l
-fill both
-pady 5 -padx 5
1922 pack
$w.list
-fill both
-pady 5 -padx 5
1924 set all_trackings
[list
]
1925 foreach b
[array names tracking_branches
] {
1926 regsub ^refs
/(heads|remotes
)/ $b {} b
1927 lappend all_trackings
$b
1930 labelframe
$w.validate \
1931 -text {Only Delete If
} \
1933 frame
$w.validate.
head
1934 checkbutton
$w.validate.
head.r \
1935 -text {Already Merged Into
:} \
1936 -variable delete_branch_checkhead \
1938 eval tk_optionMenu
$w.validate.
head.m delete_branch_head \
1940 [lsort
-unique $all_trackings]
1941 pack
$w.validate.
head.r
-side left
1942 pack
$w.validate.
head.m
-side left
1943 pack
$w.validate.
head -padx 5 -fill x
-expand 1
1944 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
1946 bind $w <Visibility
> "grab $w; focus $w"
1947 bind $w <Key-Escape
> "destroy $w"
1948 wm title
$w "[appname] ([reponame]): Delete Branch"
1952 proc switch_branch
{b
} {
1953 global HEAD commit_type file_states current_branch
1954 global selected_commit_type ui_comm
1956 if {![lock_index switch
]} return
1958 # -- Backup the selected branch (repository_state resets it)
1960 set new_branch
$current_branch
1962 # -- Our in memory state should match the repository.
1964 repository_state curType curHEAD curMERGE_HEAD
1965 if {[string match amend
* $commit_type]
1966 && $curType eq
{normal
}
1967 && $curHEAD eq
$HEAD} {
1968 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1969 info_popup
{Last scanned state does not match repository state.
1971 Another Git program has modified this repository
1972 since the last scan. A rescan must be performed
1973 before the current branch can be changed.
1975 The rescan will be automatically started now.
1978 rescan
{set ui_status_value
{Ready.
}}
1982 # -- Toss the message buffer if we are in amend mode.
1984 if {[string match amend
* $curType]} {
1985 $ui_comm delete
0.0 end
1987 $ui_comm edit modified false
1990 set selected_commit_type new
1991 set current_branch
$new_branch
1994 error
"NOT FINISHED"
1997 ######################################################################
1999 ## remote management
2001 proc load_all_remotes
{} {
2003 global all_remotes tracking_branches
2005 set all_remotes
[list
]
2006 array
unset tracking_branches
2008 set rm_dir
[gitdir remotes
]
2009 if {[file isdirectory
$rm_dir]} {
2010 set all_remotes
[glob \
2014 -directory $rm_dir *]
2016 foreach name
$all_remotes {
2018 set fd
[open
[file join $rm_dir $name] r
]
2019 while {[gets
$fd line
] >= 0} {
2020 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2021 $line line src dst
]} continue
2022 if {![regexp ^refs
/ $dst]} {
2023 set dst
"refs/heads/$dst"
2025 set tracking_branches
($dst) [list
$name $src]
2032 foreach line
[array names repo_config remote.
*.url
] {
2033 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2034 lappend all_remotes
$name
2036 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2040 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2041 if {![regexp ^refs
/ $dst]} {
2042 set dst
"refs/heads/$dst"
2044 set tracking_branches
($dst) [list
$name $src]
2048 set all_remotes
[lsort
-unique $all_remotes]
2051 proc populate_fetch_menu
{m
} {
2052 global all_remotes repo_config
2054 foreach r
$all_remotes {
2056 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2057 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2062 set fd
[open
[gitdir remotes
$r] r
]
2063 while {[gets
$fd n
] >= 0} {
2064 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2075 -label "Fetch from $r..." \
2076 -command [list fetch_from
$r] \
2082 proc populate_push_menu
{m
} {
2083 global all_remotes repo_config
2085 foreach r
$all_remotes {
2087 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2088 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2093 set fd
[open
[gitdir remotes
$r] r
]
2094 while {[gets
$fd n
] >= 0} {
2095 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2106 -label "Push to $r..." \
2107 -command [list push_to
$r] \
2113 proc populate_pull_menu
{m
} {
2114 global repo_config all_remotes disable_on_lock
2116 foreach remote
$all_remotes {
2118 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2119 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2120 foreach line
$repo_config(remote.
$remote.fetch
) {
2121 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2128 set fd
[open
[gitdir remotes
$remote] r
]
2129 while {[gets
$fd line
] >= 0} {
2130 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2138 foreach rb
$rb_list {
2139 regsub ^refs
/heads
/ $rb {} rb_short
2141 -label "Branch $rb_short from $remote..." \
2142 -command [list pull_remote
$remote $rb] \
2144 lappend disable_on_lock \
2145 [list
$m entryconf
[$m index last
] -state]
2150 ######################################################################
2155 #define mask_width 14
2156 #define mask_height 15
2157 static unsigned char mask_bits
[] = {
2158 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2159 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2160 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2163 image create bitmap file_plain
-background white
-foreground black
-data {
2164 #define plain_width 14
2165 #define plain_height 15
2166 static unsigned char plain_bits
[] = {
2167 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2168 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2169 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2170 } -maskdata $filemask
2172 image create bitmap file_mod
-background white
-foreground blue
-data {
2173 #define mod_width 14
2174 #define mod_height 15
2175 static unsigned char mod_bits
[] = {
2176 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2177 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2178 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2179 } -maskdata $filemask
2181 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2182 #define file_fulltick_width 14
2183 #define file_fulltick_height 15
2184 static unsigned char file_fulltick_bits
[] = {
2185 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2186 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2187 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2188 } -maskdata $filemask
2190 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2191 #define parttick_width 14
2192 #define parttick_height 15
2193 static unsigned char parttick_bits
[] = {
2194 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2195 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2196 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2197 } -maskdata $filemask
2199 image create bitmap file_question
-background white
-foreground black
-data {
2200 #define file_question_width 14
2201 #define file_question_height 15
2202 static unsigned char file_question_bits
[] = {
2203 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2204 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2205 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2206 } -maskdata $filemask
2208 image create bitmap file_removed
-background white
-foreground red
-data {
2209 #define file_removed_width 14
2210 #define file_removed_height 15
2211 static unsigned char file_removed_bits
[] = {
2212 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2213 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2214 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2215 } -maskdata $filemask
2217 image create bitmap file_merge
-background white
-foreground blue
-data {
2218 #define file_merge_width 14
2219 #define file_merge_height 15
2220 static unsigned char file_merge_bits
[] = {
2221 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2222 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2223 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2224 } -maskdata $filemask
2226 set ui_index .vpane.files.index.list
2227 set ui_workdir .vpane.files.workdir.list
2229 set all_icons
(_
$ui_index) file_plain
2230 set all_icons
(A
$ui_index) file_fulltick
2231 set all_icons
(M
$ui_index) file_fulltick
2232 set all_icons
(D
$ui_index) file_removed
2233 set all_icons
(U
$ui_index) file_merge
2235 set all_icons
(_
$ui_workdir) file_plain
2236 set all_icons
(M
$ui_workdir) file_mod
2237 set all_icons
(D
$ui_workdir) file_question
2238 set all_icons
(O
$ui_workdir) file_plain
2240 set max_status_desc
0
2244 {_M
"Modified, not staged"}
2245 {M_
"Staged for commit"}
2246 {MM
"Portions staged for commit"}
2247 {MD
"Staged for commit, missing"}
2249 {_O
"Untracked, not staged"}
2250 {A_
"Staged for commit"}
2251 {AM
"Portions staged for commit"}
2252 {AD
"Staged for commit, missing"}
2255 {D_
"Staged for removal"}
2256 {DO
"Staged for removal, still present"}
2258 {U_
"Requires merge resolution"}
2259 {UM
"Requires merge resolution"}
2260 {UD
"Requires merge resolution"}
2262 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2263 set max_status_desc
[string length
[lindex
$i 1]]
2265 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2269 ######################################################################
2274 global tcl_platform tk_library
2275 if {[tk windowingsystem
] eq
{aqua
}} {
2281 proc is_Windows
{} {
2283 if {$tcl_platform(platform
) eq
{windows
}} {
2289 proc bind_button3
{w cmd
} {
2290 bind $w <Any-Button-3
> $cmd
2292 bind $w <Control-Button-1
> $cmd
2296 proc incr_font_size
{font
{amt
1}} {
2297 set sz
[font configure
$font -size]
2299 font configure
$font -size $sz
2300 font configure
${font}bold
-size $sz
2303 proc hook_failed_popup
{hook msg
} {
2308 label
$w.m.l1
-text "$hook hook failed:" \
2313 -background white
-borderwidth 1 \
2315 -width 80 -height 10 \
2317 -yscrollcommand [list
$w.m.sby
set]
2319 -text {You must correct the above errors before committing.
} \
2323 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2324 pack
$w.m.l1
-side top
-fill x
2325 pack
$w.m.l2
-side bottom
-fill x
2326 pack
$w.m.sby
-side right
-fill y
2327 pack
$w.m.t
-side left
-fill both
-expand 1
2328 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2330 $w.m.t insert
1.0 $msg
2331 $w.m.t conf
-state disabled
2333 button
$w.ok
-text OK \
2336 -command "destroy $w"
2337 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2339 bind $w <Visibility
> "grab $w; focus $w"
2340 bind $w <Key-Return
> "destroy $w"
2341 wm title
$w "[appname] ([reponame]): error"
2345 set next_console_id
0
2347 proc new_console
{short_title long_title
} {
2348 global next_console_id console_data
2349 set w .console
[incr next_console_id
]
2350 set console_data
($w) [list
$short_title $long_title]
2351 return [console_init
$w]
2354 proc console_init
{w
} {
2355 global console_cr console_data M1B
2357 set console_cr
($w) 1.0
2360 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2365 -background white
-borderwidth 1 \
2367 -width 80 -height 10 \
2370 -yscrollcommand [list
$w.m.sby
set]
2371 label
$w.m.s
-text {Working... please
wait...
} \
2375 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2376 pack
$w.m.l1
-side top
-fill x
2377 pack
$w.m.s
-side bottom
-fill x
2378 pack
$w.m.sby
-side right
-fill y
2379 pack
$w.m.t
-side left
-fill both
-expand 1
2380 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2382 menu
$w.ctxm
-tearoff 0
2383 $w.ctxm add
command -label "Copy" \
2385 -command "tk_textCopy $w.m.t"
2386 $w.ctxm add
command -label "Select All" \
2388 -command "$w.m.t tag add sel 0.0 end"
2389 $w.ctxm add
command -label "Copy All" \
2392 $w.m.t tag add sel 0.0 end
2394 $w.m.t tag remove sel 0.0 end
2397 button
$w.ok
-text {Close
} \
2400 -command "destroy $w"
2401 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2403 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2404 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2405 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2406 bind $w <Visibility
> "focus $w"
2407 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2411 proc console_exec
{w cmd
{after
{}}} {
2412 # -- Windows tosses the enviroment when we exec our child.
2413 # But most users need that so we have to relogin. :-(
2416 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2419 # -- Tcl won't let us redirect both stdout and stderr to
2420 # the same pipe. So pass it through cat...
2422 set cmd
[concat |
$cmd |
& cat]
2424 set fd_f
[open
$cmd r
]
2425 fconfigure
$fd_f -blocking 0 -translation binary
2426 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2429 proc console_read
{w fd after
} {
2430 global console_cr console_data
2434 if {![winfo exists
$w]} {console_init
$w}
2435 $w.m.t conf
-state normal
2437 set n
[string length
$buf]
2439 set cr
[string first
"\r" $buf $c]
2440 set lf
[string first
"\n" $buf $c]
2441 if {$cr < 0} {set cr
[expr {$n + 1}]}
2442 if {$lf < 0} {set lf
[expr {$n + 1}]}
2445 $w.m.t insert end
[string range
$buf $c $lf]
2446 set console_cr
($w) [$w.m.t index
{end
-1c}]
2450 $w.m.t delete
$console_cr($w) end
2451 $w.m.t insert end
"\n"
2452 $w.m.t insert end
[string range
$buf $c $cr]
2457 $w.m.t conf
-state disabled
2461 fconfigure
$fd -blocking 1
2463 if {[catch
{close
$fd}]} {
2464 if {![winfo exists
$w]} {console_init
$w}
2465 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2466 $w.ok conf
-state normal
2468 } elseif
{[winfo exists
$w]} {
2469 $w.m.s conf
-background green
-text {Success
}
2470 $w.ok conf
-state normal
2473 array
unset console_cr
$w
2474 array
unset console_data
$w
2476 uplevel
#0 $after $ok
2480 fconfigure
$fd -blocking 0
2483 ######################################################################
2487 set starting_gitk_msg
{Starting gitk... please
wait...
}
2489 proc do_gitk
{revs
} {
2490 global ui_status_value starting_gitk_msg
2498 set cmd
"sh -c \"exec $cmd\""
2502 if {[catch
{eval exec $cmd} err
]} {
2503 error_popup
"Failed to start gitk:\n\n$err"
2505 set ui_status_value
$starting_gitk_msg
2507 if {$ui_status_value eq
$starting_gitk_msg} {
2508 set ui_status_value
{Ready.
}
2515 set w
[new_console
{gc
} {Compressing the object database
}]
2516 console_exec
$w {git gc
}
2519 proc do_fsck_objects
{} {
2520 set w
[new_console
{fsck-objects
} \
2521 {Verifying the object database with fsck-objects
}]
2522 set cmd
[list git fsck-objects
]
2525 lappend cmd
--strict
2526 console_exec
$w $cmd
2532 global ui_comm is_quitting repo_config commit_type
2534 if {$is_quitting} return
2537 # -- Stash our current commit buffer.
2539 set save
[gitdir GITGUI_MSG
]
2540 set msg
[string trim
[$ui_comm get
0.0 end
]]
2541 if {![string match amend
* $commit_type]
2542 && [$ui_comm edit modified
]
2545 set fd
[open
$save w
]
2546 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2550 catch
{file delete
$save}
2553 # -- Stash our current window geometry into this repository.
2555 set cfg_geometry
[list
]
2556 lappend cfg_geometry
[wm geometry .
]
2557 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2558 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2559 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2562 if {$cfg_geometry ne
$rc_geometry} {
2563 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2570 rescan
{set ui_status_value
{Ready.
}}
2573 proc unstage_helper
{txt paths
} {
2574 global file_states current_diff
2576 if {![lock_index begin-update
]} return
2580 foreach path
$paths {
2581 switch
-glob -- [lindex
$file_states($path) 0] {
2585 lappend pathList
$path
2586 if {$path eq
$current_diff} {
2587 set after
{reshow_diff
;}
2592 if {$pathList eq
{}} {
2598 [concat
$after {set ui_status_value
{Ready.
}}]
2602 proc do_unstage_selection
{} {
2603 global current_diff selected_paths
2605 if {[array size selected_paths
] > 0} {
2607 {Unstaging selected files from commit
} \
2608 [array names selected_paths
]
2609 } elseif
{$current_diff ne
{}} {
2611 "Unstaging [short_path $current_diff] from commit" \
2612 [list
$current_diff]
2616 proc add_helper
{txt paths
} {
2617 global file_states current_diff
2619 if {![lock_index begin-update
]} return
2623 foreach path
$paths {
2624 switch
-glob -- [lindex
$file_states($path) 0] {
2629 lappend pathList
$path
2630 if {$path eq
$current_diff} {
2631 set after
{reshow_diff
;}
2636 if {$pathList eq
{}} {
2642 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2646 proc do_add_selection
{} {
2647 global current_diff selected_paths
2649 if {[array size selected_paths
] > 0} {
2651 {Adding selected files
} \
2652 [array names selected_paths
]
2653 } elseif
{$current_diff ne
{}} {
2655 "Adding [short_path $current_diff]" \
2656 [list
$current_diff]
2660 proc do_add_all
{} {
2664 foreach path
[array names file_states
] {
2665 switch
-glob -- [lindex
$file_states($path) 0] {
2668 ?D
{lappend paths
$path}
2671 add_helper
{Adding all changed files
} $paths
2674 proc revert_helper
{txt paths
} {
2675 global file_states current_diff
2677 if {![lock_index begin-update
]} return
2681 foreach path
$paths {
2682 switch
-glob -- [lindex
$file_states($path) 0] {
2686 lappend pathList
$path
2687 if {$path eq
$current_diff} {
2688 set after
{reshow_diff
;}
2694 set n
[llength
$pathList]
2698 } elseif
{$n == 1} {
2699 set s
"[short_path [lindex $pathList]]"
2701 set s
"these $n files"
2704 set reply
[tk_dialog \
2706 "[appname] ([reponame])" \
2707 "Revert changes in $s?
2709 Any unadded changes will be permanently lost by the revert." \
2719 [concat
$after {set ui_status_value
{Ready.
}}]
2725 proc do_revert_selection
{} {
2726 global current_diff selected_paths
2728 if {[array size selected_paths
] > 0} {
2730 {Reverting selected files
} \
2731 [array names selected_paths
]
2732 } elseif
{$current_diff ne
{}} {
2734 "Reverting [short_path $current_diff]" \
2735 [list
$current_diff]
2739 proc do_signoff
{} {
2742 set me
[committer_ident
]
2743 if {$me eq
{}} return
2745 set sob
"Signed-off-by: $me"
2746 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
2747 if {$last ne
$sob} {
2748 $ui_comm edit separator
2750 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
2751 $ui_comm insert end
"\n"
2753 $ui_comm insert end
"\n$sob"
2754 $ui_comm edit separator
2759 proc do_select_commit_type
{} {
2760 global commit_type selected_commit_type
2762 if {$selected_commit_type eq
{new
}
2763 && [string match amend
* $commit_type]} {
2765 } elseif
{$selected_commit_type eq
{amend
}
2766 && ![string match amend
* $commit_type]} {
2769 # The amend request was rejected...
2771 if {![string match amend
* $commit_type]} {
2772 set selected_commit_type new
2782 global appvers copyright
2783 global tcl_patchLevel tk_patchLevel
2787 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2789 label
$w.header
-text "About [appname]" \
2791 pack
$w.header
-side top
-fill x
2794 button
$w.buttons.close
-text {Close
} \
2796 -command [list destroy
$w]
2797 pack
$w.buttons.close
-side right
2798 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2801 -text "[appname] - a commit creation tool for Git.
2809 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
2812 append v
"[appname] version $appvers\n"
2813 append v
"[exec git version]\n"
2815 if {$tcl_patchLevel eq
$tk_patchLevel} {
2816 append v
"Tcl/Tk version $tcl_patchLevel"
2818 append v
"Tcl version $tcl_patchLevel"
2819 append v
", Tk version $tk_patchLevel"
2830 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
2832 menu
$w.ctxm
-tearoff 0
2833 $w.ctxm add
command \
2838 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
2841 bind $w <Visibility
> "grab $w; focus $w"
2842 bind $w <Key-Escape
> "destroy $w"
2843 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
2844 wm title
$w "About [appname]"
2848 proc do_options
{} {
2849 global repo_config global_config font_descs
2850 global repo_config_new global_config_new
2852 array
unset repo_config_new
2853 array
unset global_config_new
2854 foreach name
[array names repo_config
] {
2855 set repo_config_new
($name) $repo_config($name)
2858 foreach name
[array names repo_config
] {
2860 gui.diffcontext
{continue}
2862 set repo_config_new
($name) $repo_config($name)
2864 foreach name
[array names global_config
] {
2865 set global_config_new
($name) $global_config($name)
2868 set w .options_editor
2870 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2872 label
$w.header
-text "[appname] Options" \
2874 pack
$w.header
-side top
-fill x
2877 button
$w.buttons.restore
-text {Restore Defaults
} \
2879 -command do_restore_defaults
2880 pack
$w.buttons.restore
-side left
2881 button
$w.buttons.save
-text Save \
2883 -command [list do_save_config
$w]
2884 pack
$w.buttons.save
-side right
2885 button
$w.buttons.cancel
-text {Cancel
} \
2887 -command [list destroy
$w]
2888 pack
$w.buttons.cancel
-side right
-padx 5
2889 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2891 labelframe
$w.repo
-text "[reponame] Repository" \
2893 -relief raised
-borderwidth 2
2894 labelframe
$w.global
-text {Global
(All Repositories
)} \
2896 -relief raised
-borderwidth 2
2897 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
2898 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
2901 {b pullsummary
{Show Pull Summary
}}
2902 {b trustmtime
{Trust File Modification Timestamps
}}
2903 {i diffcontext
{Number of Diff Context Lines
}}
2905 set type [lindex
$option 0]
2906 set name
[lindex
$option 1]
2907 set text
[lindex
$option 2]
2908 foreach f
{repo global
} {
2911 checkbutton
$w.
$f.
$name -text $text \
2912 -variable ${f}_config_new
(gui.
$name) \
2916 pack
$w.
$f.
$name -side top
-anchor w
2920 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
2921 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
2922 spinbox
$w.
$f.
$name.v \
2923 -textvariable ${f}_config_new
(gui.
$name) \
2924 -from 1 -to 99 -increment 1 \
2927 pack
$w.
$f.
$name.v
-side right
-anchor e
2928 pack
$w.
$f.
$name -side top
-anchor w
-fill x
2934 set all_fonts
[lsort
[font families
]]
2935 foreach option
$font_descs {
2936 set name
[lindex
$option 0]
2937 set font
[lindex
$option 1]
2938 set text
[lindex
$option 2]
2940 set global_config_new
(gui.
$font^^family
) \
2941 [font configure
$font -family]
2942 set global_config_new
(gui.
$font^^size
) \
2943 [font configure
$font -size]
2945 frame
$w.global.
$name
2946 label
$w.global.
$name.l
-text "$text:" -font font_ui
2947 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
2948 eval tk_optionMenu
$w.global.
$name.family \
2949 global_config_new
(gui.
$font^^family
) \
2951 spinbox
$w.global.
$name.size \
2952 -textvariable global_config_new
(gui.
$font^^size
) \
2953 -from 2 -to 80 -increment 1 \
2956 pack
$w.global.
$name.size
-side right
-anchor e
2957 pack
$w.global.
$name.family
-side right
-anchor e
2958 pack
$w.global.
$name -side top
-anchor w
-fill x
2961 bind $w <Visibility
> "grab $w; focus $w"
2962 bind $w <Key-Escape
> "destroy $w"
2963 wm title
$w "[appname] ([reponame]): Options"
2967 proc do_restore_defaults
{} {
2968 global font_descs default_config repo_config
2969 global repo_config_new global_config_new
2971 foreach name
[array names default_config
] {
2972 set repo_config_new
($name) $default_config($name)
2973 set global_config_new
($name) $default_config($name)
2976 foreach option
$font_descs {
2977 set name
[lindex
$option 0]
2978 set repo_config
(gui.
$name) $default_config(gui.
$name)
2982 foreach option
$font_descs {
2983 set name
[lindex
$option 0]
2984 set font
[lindex
$option 1]
2985 set global_config_new
(gui.
$font^^family
) \
2986 [font configure
$font -family]
2987 set global_config_new
(gui.
$font^^size
) \
2988 [font configure
$font -size]
2992 proc do_save_config
{w
} {
2993 if {[catch
{save_config
} err
]} {
2994 error_popup
"Failed to completely save options:\n\n$err"
3000 proc do_windows_shortcut
{} {
3004 set desktop
[exec cygpath \
3012 set fn
[tk_getSaveFile \
3014 -title "[appname] ([reponame]): Create Desktop Icon" \
3015 -initialdir $desktop \
3016 -initialfile "Git [reponame].bat"]
3020 set sh
[exec cygpath \
3024 set me
[exec cygpath \
3028 set gd
[exec cygpath \
3032 set gw
[exec cygpath \
3035 [file dirname [gitdir
]]]
3036 regsub
-all ' $me "'\\''" me
3037 regsub -all ' $gd "'\\''" gd
3038 puts $fd "@ECHO Entering $gw"
3039 puts $fd "@ECHO Starting git-gui... please wait..."
3040 puts -nonewline $fd "@\"$sh\" --login -c \""
3041 puts -nonewline $fd "GIT_DIR='$gd'"
3042 puts -nonewline $fd " '$me'"
3046 error_popup "Cannot write script:\n\n$err"
3051 proc do_macosx_app {} {
3054 set fn [tk_getSaveFile \
3056 -title "[appname] ([reponame]): Create Desktop Icon" \
3057 -initialdir [file join $env(HOME) Desktop] \
3058 -initialfile "Git [reponame].app"]
3061 set Contents [file join $fn Contents]
3062 set MacOS [file join $Contents MacOS]
3063 set exe [file join $MacOS git-gui]
3067 set fd [open [file join $Contents Info.plist] w]
3068 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3069 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3070 <plist version="1.0">
3072 <key>CFBundleDevelopmentRegion</key>
3073 <string>English</string>
3074 <key>CFBundleExecutable</key>
3075 <string>git-gui</string>
3076 <key>CFBundleIdentifier</key>
3077 <string>org.spearce.git-gui</string>
3078 <key>CFBundleInfoDictionaryVersion</key>
3079 <string>6.0</string>
3080 <key>CFBundlePackageType</key>
3081 <string>APPL</string>
3082 <key>CFBundleSignature</key>
3083 <string>????</string>
3084 <key>CFBundleVersion</key>
3085 <string>1.0</string>
3086 <key>NSPrincipalClass</key>
3087 <string>NSApplication</string>
3092 set fd [open $exe w]
3093 set gd [file normalize [gitdir]]
3094 set ep [file normalize [exec git --exec-path]]
3095 regsub -all ' $gd "'\\''" gd
3096 regsub
-all ' $ep "'\\''" ep
3097 puts $fd "#!/bin/sh"
3098 foreach name
[array names env
] {
3099 if {[string match GIT_
* $name]} {
3100 regsub
-all ' $env($name) "'\\''" v
3101 puts $fd "export $name='$v'"
3104 puts $fd "export PATH
='$ep':\
$PATH"
3105 puts $fd "export GIT_DIR
='$gd'"
3106 puts $fd "exec [file normalize
$argv0]"
3109 file attributes $exe -permissions u+x,g+x,o+x
3111 error_popup "Cannot
write icon
:\n\n$err"
3116 proc toggle_or_diff {w x y} {
3117 global file_states file_lists current_diff ui_index ui_workdir
3118 global last_clicked selected_paths
3120 set pos [split [$w index @$x,$y] .]
3121 set lno [lindex $pos 0]
3122 set col [lindex $pos 1]
3123 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3129 set last_clicked [list $w $lno]
3130 array unset selected_paths
3131 $ui_index tag remove in_sel 0.0 end
3132 $ui_workdir tag remove in_sel 0.0 end
3135 if {$current_diff eq $path} {
3136 set after {reshow_diff;}
3140 if {$w eq $ui_index} {
3142 "Unstaging
[short_path
$path] from commit
" \
3144 [concat $after {set ui_status_value {Ready.}}]
3145 } elseif {$w eq $ui_workdir} {
3147 "Adding
[short_path
$path]" \
3149 [concat $after {set ui_status_value {Ready.}}]
3152 show_diff $path $w $lno
3156 proc add_one_to_selection {w x y} {
3157 global file_lists last_clicked selected_paths
3159 set lno [lindex [split [$w index @$x,$y] .] 0]
3160 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3166 if {$last_clicked ne {}
3167 && [lindex $last_clicked 0] ne $w} {
3168 array unset selected_paths
3169 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3172 set last_clicked [list $w $lno]
3173 if {[catch {set in_sel $selected_paths($path)}]} {
3177 unset selected_paths($path)
3178 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3180 set selected_paths($path) 1
3181 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3185 proc add_range_to_selection {w x y} {
3186 global file_lists last_clicked selected_paths
3188 if {[lindex $last_clicked 0] ne $w} {
3189 toggle_or_diff $w $x $y
3193 set lno [lindex [split [$w index @$x,$y] .] 0]
3194 set lc [lindex $last_clicked 1]
3203 foreach path [lrange $file_lists($w) \
3204 [expr {$begin - 1}] \
3205 [expr {$end - 1}]] {
3206 set selected_paths($path) 1
3208 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3211 ######################################################################
3215 set cursor_ptr arrow
3216 font create font_diff -family Courier -size 10
3220 eval font configure font_ui [font actual [.dummy cget -font]]
3224 font create font_uibold
3225 font create font_diffbold
3230 } elseif {[is_MacOSX]} {
3238 proc apply_config {} {
3239 global repo_config font_descs
3241 foreach option $font_descs {
3242 set name [lindex $option 0]
3243 set font [lindex $option 1]
3245 foreach {cn cv} $repo_config(gui.$name) {
3246 font configure $font $cn $cv
3249 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3251 foreach {cn cv} [font configure $font] {
3252 font configure ${font}bold $cn $cv
3254 font configure ${font}bold -weight bold
3258 set default_config(gui.trustmtime) false
3259 set default_config(gui.pullsummary) true
3260 set default_config(gui.diffcontext) 5
3261 set default_config(gui.fontui) [font configure font_ui]
3262 set default_config(gui.fontdiff) [font configure font_diff]
3264 {fontui font_ui {Main Font}}
3265 {fontdiff font_diff {Diff/Console Font}}
3270 ######################################################################
3276 menu .mbar -tearoff 0
3277 .mbar add cascade -label Repository -menu .mbar.repository
3278 .mbar add cascade -label Edit -menu .mbar.edit
3279 if {!$single_commit} {
3280 .mbar add cascade -label Branch -menu .mbar.branch
3282 .mbar add cascade -label Commit -menu .mbar.commit
3283 if {!$single_commit} {
3284 .mbar add cascade -label Fetch -menu .mbar.fetch
3285 .mbar add cascade -label Pull -menu .mbar.pull
3286 .mbar add cascade -label Push -menu .mbar.push
3288 . configure -menu .mbar
3290 # -- Repository Menu
3292 menu .mbar.repository
3293 .mbar.repository add command \
3294 -label {Visualize Current Branch} \
3295 -command {do_gitk {}} \
3298 .mbar.repository add command \
3299 -label {Visualize All Branches} \
3300 -command {do_gitk {--all}} \
3303 .mbar.repository add separator
3305 if {!$single_commit} {
3306 .mbar.repository add command -label {Compress Database} \
3310 .mbar.repository add command -label {Verify Database} \
3311 -command do_fsck_objects \
3314 .mbar.repository add separator
3317 .mbar.repository add command \
3318 -label {Create Desktop Icon} \
3319 -command do_windows_shortcut \
3321 } elseif {[is_MacOSX]} {
3322 .mbar.repository add command \
3323 -label {Create Desktop Icon} \
3324 -command do_macosx_app \
3329 .mbar.repository add command -label Quit \
3331 -accelerator $M1T-Q \
3337 .mbar.edit add command -label Undo \
3338 -command {catch {[focus] edit undo}} \
3339 -accelerator $M1T-Z \
3341 .mbar.edit add command -label Redo \
3342 -command {catch {[focus] edit redo}} \
3343 -accelerator $M1T-Y \
3345 .mbar.edit add separator
3346 .mbar.edit add command -label Cut \
3347 -command {catch {tk_textCut [focus]}} \
3348 -accelerator $M1T-X \
3350 .mbar.edit add command -label Copy \
3351 -command {catch {tk_textCopy [focus]}} \
3352 -accelerator $M1T-C \
3354 .mbar.edit add command -label Paste \
3355 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3356 -accelerator $M1T-V \
3358 .mbar.edit add command -label Delete \
3359 -command {catch {[focus] delete sel.first sel.last}} \
3362 .mbar.edit add separator
3363 .mbar.edit add command -label {Select All} \
3364 -command {catch {[focus] tag add sel 0.0 end}} \
3365 -accelerator $M1T-A \
3370 if {!$single_commit} {
3373 .mbar.branch add command -label {Create...} \
3374 -command do_create_branch \
3375 -accelerator $M1T-N \
3377 lappend disable_on_lock [list .mbar.branch entryconf \
3378 [.mbar.branch index last] -state]
3380 .mbar.branch add command -label {Delete...} \
3381 -command do_delete_branch \
3383 lappend disable_on_lock [list .mbar.branch entryconf \
3384 [.mbar.branch index last] -state]
3391 .mbar.commit add radiobutton \
3392 -label {New Commit} \
3393 -command do_select_commit_type \
3394 -variable selected_commit_type \
3397 lappend disable_on_lock \
3398 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3400 .mbar.commit add radiobutton \
3401 -label {Amend Last Commit} \
3402 -command do_select_commit_type \
3403 -variable selected_commit_type \
3406 lappend disable_on_lock \
3407 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3409 .mbar.commit add separator
3411 .mbar.commit add command -label Rescan \
3412 -command do_rescan \
3415 lappend disable_on_lock \
3416 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3418 .mbar.commit add command -label {Add To Commit} \
3419 -command do_add_selection \
3421 lappend disable_on_lock \
3422 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3424 .mbar.commit add command -label {Add All To Commit} \
3425 -command do_add_all \
3426 -accelerator $M1T-I \
3428 lappend disable_on_lock \
3429 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3431 .mbar.commit add command -label {Unstage From Commit} \
3432 -command do_unstage_selection \
3434 lappend disable_on_lock \
3435 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3437 .mbar.commit add command -label {Revert Changes} \
3438 -command do_revert_selection \
3440 lappend disable_on_lock \
3441 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3443 .mbar.commit add separator
3445 .mbar.commit add command -label {Sign Off} \
3446 -command do_signoff \
3447 -accelerator $M1T-S \
3450 .mbar.commit add command -label Commit \
3451 -command do_commit \
3452 -accelerator $M1T-Return \
3454 lappend disable_on_lock \
3455 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3457 # -- Transport menus
3459 if {!$single_commit} {
3466 # -- Apple Menu (Mac OS X only)
3468 .mbar add cascade -label Apple -menu .mbar.apple
3471 .mbar.apple add command -label "About
[appname
]" \
3474 .mbar.apple add command -label "[appname
] Options...
" \
3475 -command do_options \
3480 .mbar.edit add separator
3481 .mbar.edit add command -label {Options...} \
3482 -command do_options \
3487 if {[file exists /usr/local/miga/lib/gui-miga]
3488 && [file exists .pvcsrc]} {
3490 global ui_status_value
3491 if {![lock_index update]} return
3492 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3493 set miga_fd [open "|
$cmd" r]
3494 fconfigure $miga_fd -blocking 0
3495 fileevent $miga_fd readable [list miga_done $miga_fd]
3496 set ui_status_value {Running miga...}
3498 proc miga_done {fd} {
3503 rescan [list set ui_status_value {Ready.}]
3506 .mbar add cascade -label Tools -menu .mbar.tools
3508 .mbar.tools add command -label "Migrate
" \
3511 lappend disable_on_lock \
3512 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3517 .mbar add cascade -label Help -menu .mbar.help
3520 .mbar.help add command -label "About
[appname
]" \
3532 -text {Current Branch:} \
3537 -textvariable current_branch \
3541 pack .branch.l1 -side left
3542 pack .branch.cb -side left -fill x
3543 pack .branch -side top -fill x
3545 # -- Main Window Layout
3547 panedwindow .vpane -orient vertical
3548 panedwindow .vpane.files -orient horizontal
3549 .vpane add .vpane.files -sticky nsew -height 100 -width 400
3550 pack .vpane -anchor n -side top -fill both -expand 1
3552 # -- Index File List
3554 frame .vpane.files.index -height 100 -width 400
3555 label .vpane.files.index.title -text {Changes To Be Committed} \
3558 text $ui_index -background white -borderwidth 0 \
3559 -width 40 -height 10 \
3561 -cursor $cursor_ptr \
3562 -yscrollcommand {.vpane.files.index.sb set} \
3564 scrollbar .vpane.files.index.sb -command [list $ui_index yview]
3565 pack .vpane.files.index.title -side top -fill x
3566 pack .vpane.files.index.sb -side right -fill y
3567 pack $ui_index -side left -fill both -expand 1
3568 .vpane.files add .vpane.files.index -sticky nsew
3570 # -- Working Directory File List
3572 frame .vpane.files.workdir -height 100 -width 100
3573 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3576 text $ui_workdir -background white -borderwidth 0 \
3577 -width 40 -height 10 \
3579 -cursor $cursor_ptr \
3580 -yscrollcommand {.vpane.files.workdir.sb set} \
3582 scrollbar .vpane.files.workdir.sb -command [list $ui_workdir yview]
3583 pack .vpane.files.workdir.title -side top -fill x
3584 pack .vpane.files.workdir.sb -side right -fill y
3585 pack $ui_workdir -side left -fill both -expand 1
3586 .vpane.files add .vpane.files.workdir -sticky nsew
3588 foreach i [list $ui_index $ui_workdir] {
3589 $i tag conf in_diff -font font_uibold
3590 $i tag conf in_sel \
3591 -background [$i cget -foreground] \
3592 -foreground [$i cget -background]
3596 # -- Diff and Commit Area
3598 frame .vpane.lower -height 300 -width 400
3599 frame .vpane.lower.commarea
3600 frame .vpane.lower.diff -relief sunken -borderwidth 1
3601 pack .vpane.lower.commarea -side top -fill x
3602 pack .vpane.lower.diff -side bottom -fill both -expand 1
3603 .vpane add .vpane.lower -stick nsew
3605 # -- Commit Area Buttons
3607 frame .vpane.lower.commarea.buttons
3608 label .vpane.lower.commarea.buttons.l -text {} \
3612 pack .vpane.lower.commarea.buttons.l -side top -fill x
3613 pack .vpane.lower.commarea.buttons -side left -fill y
3615 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3616 -command do_rescan \
3618 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3619 lappend disable_on_lock \
3620 {.vpane.lower.commarea.buttons.rescan conf -state}
3622 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3623 -command do_add_all \
3625 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3626 lappend disable_on_lock \
3627 {.vpane.lower.commarea.buttons.incall conf -state}
3629 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3630 -command do_signoff \
3632 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3634 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3635 -command do_commit \
3637 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3638 lappend disable_on_lock \
3639 {.vpane.lower.commarea.buttons.commit conf -state}
3641 # -- Commit Message Buffer
3643 frame .vpane.lower.commarea.buffer
3644 frame .vpane.lower.commarea.buffer.header
3645 set ui_comm .vpane.lower.commarea.buffer.t
3646 set ui_coml .vpane.lower.commarea.buffer.header.l
3647 radiobutton .vpane.lower.commarea.buffer.header.new \
3648 -text {New Commit} \
3649 -command do_select_commit_type \
3650 -variable selected_commit_type \
3653 lappend disable_on_lock \
3654 [list .vpane.lower.commarea.buffer.header.new conf -state]
3655 radiobutton .vpane.lower.commarea.buffer.header.amend \
3656 -text {Amend Last Commit} \
3657 -command do_select_commit_type \
3658 -variable selected_commit_type \
3661 lappend disable_on_lock \
3662 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3667 proc trace_commit_type {varname args} {
3668 global ui_coml commit_type
3669 switch -glob -- $commit_type {
3670 initial {set txt {Initial Commit Message:}}
3671 amend {set txt {Amended Commit Message:}}
3672 amend-initial {set txt {Amended Initial Commit Message:}}
3673 amend-merge {set txt {Amended Merge Commit Message:}}
3674 merge {set txt {Merge Commit Message:}}
3675 * {set txt {Commit Message:}}
3677 $ui_coml conf -text $txt
3679 trace add variable commit_type write trace_commit_type
3680 pack $ui_coml -side left -fill x
3681 pack .vpane.lower.commarea.buffer.header.amend -side right
3682 pack .vpane.lower.commarea.buffer.header.new -side right
3684 text $ui_comm -background white -borderwidth 1 \
3687 -autoseparators true \
3689 -width 75 -height 9 -wrap none \
3691 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3692 scrollbar .vpane.lower.commarea.buffer.sby \
3693 -command [list $ui_comm yview]
3694 pack .vpane.lower.commarea.buffer.header -side top -fill x
3695 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3696 pack $ui_comm -side left -fill y
3697 pack .vpane.lower.commarea.buffer -side left -fill y
3699 # -- Commit Message Buffer Context Menu
3701 set ctxm .vpane.lower.commarea.buffer.ctxm
3702 menu $ctxm -tearoff 0
3706 -command {tk_textCut $ui_comm}
3710 -command {tk_textCopy $ui_comm}
3714 -command {tk_textPaste $ui_comm}
3718 -command {$ui_comm delete sel.first sel.last}
3721 -label {Select All} \
3723 -command {$ui_comm tag add sel 0.0 end}
3728 $ui_comm tag add sel 0.0 end
3729 tk_textCopy $ui_comm
3730 $ui_comm tag remove sel 0.0 end
3737 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
3742 set diff_actions [list]
3743 proc trace_current_diff {varname args} {
3744 global current_diff diff_actions file_states
3745 if {$current_diff eq {}} {
3752 set s [mapdesc [lindex $file_states($p) 0] $p]
3754 set p [escape_path $p]
3758 .vpane.lower.diff.header.status configure -text $s
3759 .vpane.lower.diff.header.file configure -text $f
3760 .vpane.lower.diff.header.path configure -text $p
3761 foreach w $diff_actions {
3765 trace add variable current_diff write trace_current_diff
3767 frame .vpane.lower.diff.header -background orange
3768 label .vpane.lower.diff.header.status \
3769 -background orange \
3770 -width $max_status_desc \
3774 label .vpane.lower.diff.header.file \
3775 -background orange \
3779 label .vpane.lower.diff.header.path \
3780 -background orange \
3784 pack .vpane.lower.diff.header.status -side left
3785 pack .vpane.lower.diff.header.file -side left
3786 pack .vpane.lower.diff.header.path -fill x
3787 set ctxm .vpane.lower.diff.header.ctxm
3788 menu $ctxm -tearoff 0
3799 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3800 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
3804 frame .vpane.lower.diff.body
3805 set ui_diff .vpane.lower.diff.body.t
3806 text $ui_diff -background white -borderwidth 0 \
3807 -width 80 -height 15 -wrap none \
3809 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3810 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3812 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3813 -command [list $ui_diff xview]
3814 scrollbar .vpane.lower.diff.body.sby -orient vertical \
3815 -command [list $ui_diff yview]
3816 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3817 pack .vpane.lower.diff.body.sby -side right -fill y
3818 pack $ui_diff -side left -fill both -expand 1
3819 pack .vpane.lower.diff.header -side top -fill x
3820 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3822 $ui_diff tag conf d_@ -font font_diffbold
3823 $ui_diff tag conf d_+ -foreground blue
3824 $ui_diff tag conf d_- -foreground red
3825 $ui_diff tag conf d_++ -foreground {#00a000}
3826 $ui_diff tag conf d_-- -foreground {#a000a0}
3827 $ui_diff tag conf d_+- \
3829 -background {light goldenrod yellow}
3830 $ui_diff tag conf d_-+ \
3834 # -- Diff Body Context Menu
3836 set ctxm .vpane.lower.diff.body.ctxm
3837 menu $ctxm -tearoff 0
3841 -command {tk_textCopy $ui_diff}
3842 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3844 -label {Select All} \
3846 -command {$ui_diff tag add sel 0.0 end}
3847 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3852 $ui_diff tag add sel 0.0 end
3853 tk_textCopy $ui_diff
3854 $ui_diff tag remove sel 0.0 end
3856 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3859 -label {Decrease Font Size} \
3861 -command {incr_font_size font_diff -1}
3862 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3864 -label {Increase Font Size} \
3866 -command {incr_font_size font_diff 1}
3867 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3870 -label {Show Less Context} \
3872 -command {if {$repo_config(gui.diffcontext) >= 2} {
3873 incr repo_config(gui.diffcontext) -1
3876 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3878 -label {Show More Context} \
3881 incr repo_config(gui.diffcontext)
3884 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3886 $ctxm add command -label {Options...} \
3889 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
3893 set ui_status_value {Initializing...}
3894 label .status -textvariable ui_status_value \
3900 pack .status -anchor w -side bottom -fill x
3905 set gm $repo_config(gui.geometry)
3906 wm geometry . [lindex $gm 0]
3907 .vpane sash place 0 \
3908 [lindex [.vpane sash coord 0] 0] \
3910 .vpane.files sash place 0 \
3912 [lindex [.vpane.files sash coord 0] 1]
3918 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3919 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3920 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3921 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3922 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3923 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3924 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3925 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3926 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3927 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3928 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3930 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3931 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3932 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3933 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3934 bind $ui_diff <$M1B-Key-v> {break}
3935 bind $ui_diff <$M1B-Key-V> {break}
3936 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3937 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3938 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3939 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3940 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3941 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3943 if {!$single_commit} {
3944 bind . <$M1B-Key-n> do_create_branch
3945 bind . <$M1B-Key-N> do_create_branch
3948 bind . <Destroy> do_quit
3949 bind all <Key-F5> do_rescan
3950 bind all <$M1B-Key-r> do_rescan
3951 bind all <$M1B-Key-R> do_rescan
3952 bind . <$M1B-Key-s> do_signoff
3953 bind . <$M1B-Key-S> do_signoff
3954 bind . <$M1B-Key-i> do_add_all
3955 bind . <$M1B-Key-I> do_add_all
3956 bind . <$M1B-Key-Return> do_commit
3957 bind all <$M1B-Key-q> do_quit
3958 bind all <$M1B-Key-Q> do_quit
3959 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
3960 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
3961 foreach i [list $ui_index $ui_workdir] {
3962 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
3963 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
3964 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
3968 set file_lists($ui_index) [list]
3969 set file_lists($ui_workdir) [list]
3973 set MERGE_HEAD [list]
3976 set current_branch {}
3978 set selected_commit_type new
3980 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
3981 focus -force $ui_comm
3983 # -- Warn the user about environmental problems. Cygwin's Tcl
3984 # does *not* pass its env array onto any processes it spawns.
3985 # This means that git processes get none of our environment.
3990 set msg "Possible environment issues exist.
3992 The following environment variables are probably
3993 going to be ignored by any Git subprocess run
3997 foreach name [array names env] {
3998 switch -regexp -- $name {
3999 {^GIT_INDEX_FILE$} -
4000 {^GIT_OBJECT_DIRECTORY$} -
4001 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4003 {^GIT_EXTERNAL_DIFF$} -
4007 {^GIT_CONFIG_LOCAL$} -
4008 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4009 append msg " - $name\n"
4012 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4013 append msg " - $name\n"
4015 set suggest_user $name
4019 if {$ignored_env > 0} {
4021 This is due to a known issue with the
4022 Tcl binary distributed by Cygwin.
"
4024 if {$suggest_user ne {}} {
4027 A good replacement
for $suggest_user
4028 is placing values
for the user.name and
4029 user.email settings into your personal
4035 unset ignored_env msg suggest_user name
4038 # -- Only initialize complex UI if we are going to stay running.
4040 if {!$single_commit} {
4044 populate_branch_menu
4045 populate_fetch_menu .mbar.fetch
4046 populate_pull_menu .mbar.pull
4047 populate_push_menu .mbar.push
4050 # -- Only suggest a gc run if we are going to stay running.
4052 if {!$single_commit} {
4053 set object_limit 2000
4054 if {[is_Windows]} {set object_limit 200}
4055 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4056 if {$objects_current >= $object_limit} {
4058 "This repository currently has
$objects_current loose objects.
4060 To maintain optimal performance it is strongly
4061 recommended that you
compress the database
4062 when
more than
$object_limit loose objects exist.
4064 Compress the database now?
"] eq yes} {
4068 unset object_limit _junk objects_current
4071 lock_index begin-read