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 --combined *} $line]} continue
697 if {[string match
{--- *} $line]} continue
698 if {[string match
{+++ *} $line]} continue
699 if {$line eq
{deleted
file mode
120000}} {
700 set line
"deleted symlink"
703 # -- Automatically detect if this is a 3 way diff.
705 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
707 # -- Reformat a 3 way diff, 'cause its too weird.
710 set op
[string range
$line 0 1]
713 {++} {set tags d_
+ ; set op
{ +}}
714 {--} {set tags d_-
; set op
{ -}}
715 { +} {set tags d_
++; set op
{++}}
716 { -} {set tags d_--
; set op
{--}}
717 {+ } {set tags d_-
+; set op
{-+}}
718 {- } {set tags d_
+-; set op
{+-}}
719 default
{set tags
{}}
721 set line
[string replace
$line 0 1 $op]
723 switch
-- [string index
$line 0] {
727 default
{set tags
{}}
730 $ui_diff insert end
$line $tags
731 $ui_diff insert end
"\n" $tags
733 $ui_diff conf
-state disabled
739 set ui_status_value
{Ready.
}
741 if {$repo_config(gui.trustmtime
) eq
{true
}
742 && [$ui_diff index end
] eq
{2.0}} {
748 ######################################################################
752 proc load_last_commit
{} {
753 global HEAD PARENT MERGE_HEAD commit_type ui_comm
755 if {[llength
$PARENT] == 0} {
756 error_popup
{There is nothing to amend.
758 You are about to create the initial commit.
759 There is no commit before this to amend.
764 repository_state curType curHEAD curMERGE_HEAD
765 if {$curType eq
{merge
}} {
766 error_popup
{Cannot amend
while merging.
768 You are currently
in the middle of a merge that
769 has not been fully completed. You cannot amend
770 the prior commit unless you first abort the
771 current merge activity.
779 set fd
[open
"| git cat-file commit $curHEAD" r
]
780 while {[gets
$fd line
] > 0} {
781 if {[string match
{parent
*} $line]} {
782 lappend parents
[string range
$line 7 end
]
785 set msg
[string trim
[read $fd]]
788 error_popup
"Error loading commit data for amend:\n\n$err"
794 set MERGE_HEAD
[list
]
795 switch
-- [llength
$parents] {
796 0 {set commit_type amend-initial
}
797 1 {set commit_type amend
}
798 default
{set commit_type amend-merge
}
801 $ui_comm delete
0.0 end
802 $ui_comm insert end
$msg
804 $ui_comm edit modified false
805 rescan
{set ui_status_value
{Ready.
}}
808 proc create_new_commit
{} {
809 global commit_type ui_comm
811 set commit_type normal
812 $ui_comm delete
0.0 end
814 $ui_comm edit modified false
815 rescan
{set ui_status_value
{Ready.
}}
818 set GIT_COMMITTER_IDENT
{}
820 proc committer_ident
{} {
821 global GIT_COMMITTER_IDENT
823 if {$GIT_COMMITTER_IDENT eq
{}} {
824 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
825 error_popup
"Unable to obtain your identity:\n\n$err"
828 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
829 $me me GIT_COMMITTER_IDENT
]} {
830 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
835 return $GIT_COMMITTER_IDENT
838 proc commit_tree
{} {
839 global HEAD commit_type file_states ui_comm repo_config
840 global ui_status_value pch_error
842 if {![lock_index update
]} return
843 if {[committer_ident
] eq
{}} return
845 # -- Our in memory state should match the repository.
847 repository_state curType curHEAD curMERGE_HEAD
848 if {[string match amend
* $commit_type]
849 && $curType eq
{normal
}
850 && $curHEAD eq
$HEAD} {
851 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
852 info_popup
{Last scanned state does not match repository state.
854 Another Git program has modified this repository
855 since the last scan. A rescan must be performed
856 before another commit can be created.
858 The rescan will be automatically started now.
861 rescan
{set ui_status_value
{Ready.
}}
865 # -- At least one file should differ in the index.
868 foreach path
[array names file_states
] {
869 switch
-glob -- [lindex
$file_states($path) 0] {
873 M?
{set files_ready
1; break}
875 error_popup
"Unmerged files cannot be committed.
877 File [short_path $path] has merge conflicts.
878 You must resolve them and include the file before committing.
884 error_popup
"Unknown file state [lindex $s 0] detected.
886 File [short_path $path] cannot be committed by this program.
892 error_popup
{No included files to commit.
894 You must include
at least
1 file before you can commit.
900 # -- A message is required.
902 set msg
[string trim
[$ui_comm get
1.0 end
]]
904 error_popup
{Please supply a commit message.
906 A good commit message has the following format
:
908 - First line
: Describe
in one sentance what you did.
910 - Remaining lines
: Describe why this change is good.
916 # -- Run the pre-commit hook.
918 set pchook
[gitdir hooks pre-commit
]
920 # On Cygwin [file executable] might lie so we need to ask
921 # the shell if the hook is executable. Yes that's annoying.
923 if {[is_Windows
] && [file isfile
$pchook]} {
924 set pchook
[list sh
-c [concat \
925 "if test -x \"$pchook\";" \
926 "then exec \"$pchook\" 2>&1;" \
928 } elseif
{[file executable
$pchook]} {
929 set pchook
[list
$pchook |
& cat]
931 commit_writetree
$curHEAD $msg
935 set ui_status_value
{Calling pre-commit hook...
}
937 set fd_ph
[open
"| $pchook" r
]
938 fconfigure
$fd_ph -blocking 0 -translation binary
939 fileevent
$fd_ph readable \
940 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
943 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
944 global pch_error ui_status_value
946 append pch_error
[read $fd_ph]
947 fconfigure
$fd_ph -blocking 1
949 if {[catch
{close
$fd_ph}]} {
950 set ui_status_value
{Commit declined by pre-commit hook.
}
951 hook_failed_popup pre-commit
$pch_error
954 commit_writetree
$curHEAD $msg
959 fconfigure
$fd_ph -blocking 0
962 proc commit_writetree
{curHEAD msg
} {
963 global ui_status_value
965 set ui_status_value
{Committing changes...
}
966 set fd_wt
[open
"| git write-tree" r
]
967 fileevent
$fd_wt readable \
968 [list commit_committree
$fd_wt $curHEAD $msg]
971 proc commit_committree
{fd_wt curHEAD msg
} {
972 global HEAD PARENT MERGE_HEAD commit_type
974 global ui_status_value ui_comm selected_commit_type
975 global file_states selected_paths rescan_active
978 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
979 error_popup
"write-tree failed:\n\n$err"
980 set ui_status_value
{Commit failed.
}
985 # -- Create the commit.
987 set cmd
[list git commit-tree
$tree_id]
988 set parents
[concat
$PARENT $MERGE_HEAD]
989 if {[llength
$parents] > 0} {
994 # git commit-tree writes to stderr during initial commit.
995 lappend cmd
2>/dev
/null
998 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
999 error_popup
"commit-tree failed:\n\n$err"
1000 set ui_status_value
{Commit failed.
}
1005 # -- Update the HEAD ref.
1008 if {$commit_type ne
{normal
}} {
1009 append reflogm
" ($commit_type)"
1011 set i
[string first
"\n" $msg]
1013 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1015 append reflogm
{: } $msg
1017 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1018 if {[catch
{eval exec $cmd} err
]} {
1019 error_popup
"update-ref failed:\n\n$err"
1020 set ui_status_value
{Commit failed.
}
1025 # -- Cleanup after ourselves.
1027 catch
{file delete
[gitdir MERGE_HEAD
]}
1028 catch
{file delete
[gitdir MERGE_MSG
]}
1029 catch
{file delete
[gitdir SQUASH_MSG
]}
1030 catch
{file delete
[gitdir GITGUI_MSG
]}
1032 # -- Let rerere do its thing.
1034 if {[file isdirectory
[gitdir rr-cache
]]} {
1035 catch
{exec git rerere
}
1038 # -- Run the post-commit hook.
1040 set pchook
[gitdir hooks post-commit
]
1041 if {[is_Windows
] && [file isfile
$pchook]} {
1042 set pchook
[list sh
-c [concat \
1043 "if test -x \"$pchook\";" \
1044 "then exec \"$pchook\";" \
1046 } elseif
{![file executable
$pchook]} {
1049 if {$pchook ne
{}} {
1050 catch
{exec $pchook &}
1053 $ui_comm delete
0.0 end
1055 $ui_comm edit modified false
1057 if {$single_commit} do_quit
1059 # -- Update in memory status
1061 set selected_commit_type new
1062 set commit_type normal
1065 set MERGE_HEAD
[list
]
1067 foreach path
[array names file_states
] {
1068 set s
$file_states($path)
1070 switch
-glob -- $m {
1078 unset file_states
($path)
1079 catch
{unset selected_paths
($path)}
1082 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1088 set file_states
($path) [list \
1089 _
[string index
$m 1] \
1100 set ui_status_value \
1101 "Changes committed as [string range $cmt_id 0 7]."
1104 ######################################################################
1108 proc fetch_from
{remote
} {
1109 set w
[new_console
"fetch $remote" \
1110 "Fetching new changes from $remote"]
1111 set cmd
[list git fetch
]
1113 console_exec
$w $cmd
1116 proc pull_remote
{remote branch
} {
1117 global HEAD commit_type file_states repo_config
1119 if {![lock_index update
]} return
1121 # -- Our in memory state should match the repository.
1123 repository_state curType curHEAD curMERGE_HEAD
1124 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1125 info_popup
{Last scanned state does not match repository state.
1127 Another Git program has modified this repository
1128 since the last scan. A rescan must be performed
1129 before a pull operation can be started.
1131 The rescan will be automatically started now.
1134 rescan
{set ui_status_value
{Ready.
}}
1138 # -- No differences should exist before a pull.
1140 if {[array size file_states
] != 0} {
1141 error_popup
{Uncommitted but modified files are present.
1143 You should not perform a pull with unmodified
1144 files
in your working directory as Git will be
1145 unable to recover from an incorrect merge.
1147 You should commit or revert all changes before
1148 starting a pull operation.
1154 set w
[new_console
"pull $remote $branch" \
1155 "Pulling new changes from branch $branch in $remote"]
1156 set cmd
[list git pull
]
1157 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1158 lappend cmd
--no-summary
1162 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1165 proc post_pull_remote
{remote branch success
} {
1166 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1167 global ui_status_value
1171 repository_state commit_type HEAD MERGE_HEAD
1173 set selected_commit_type new
1174 set ui_status_value
"Pulling $branch from $remote complete."
1176 rescan
[list
set ui_status_value \
1177 "Conflicts detected while pulling $branch from $remote."]
1181 proc push_to
{remote
} {
1182 set w
[new_console
"push $remote" \
1183 "Pushing changes to $remote"]
1184 set cmd
[list git push
]
1186 console_exec
$w $cmd
1189 ######################################################################
1193 proc mapicon
{w state path
} {
1196 if {[catch
{set r
$all_icons($state$w)}]} {
1197 puts
"error: no icon for $w state={$state} $path"
1203 proc mapdesc
{state path
} {
1206 if {[catch
{set r
$all_descs($state)}]} {
1207 puts
"error: no desc for state={$state} $path"
1213 proc escape_path
{path
} {
1214 regsub
-all "\n" $path "\\n" path
1218 proc short_path
{path
} {
1219 return [escape_path
[lindex
[file split $path] end
]]
1223 set null_sha1
[string repeat
0 40]
1225 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1226 global file_states next_icon_id null_sha1
1228 set s0
[string index
$new_state 0]
1229 set s1
[string index
$new_state 1]
1231 if {[catch
{set info
$file_states($path)}]} {
1233 set icon n
[incr next_icon_id
]
1235 set state
[lindex
$info 0]
1236 set icon
[lindex
$info 1]
1237 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1238 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1241 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1242 elseif
{$s0 eq
{_
}} {set s0 _
}
1244 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1245 elseif
{$s1 eq
{_
}} {set s1 _
}
1247 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1248 set head_info
[list
0 $null_sha1]
1249 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1250 && $head_info eq
{}} {
1251 set head_info
$index_info
1254 set file_states
($path) [list
$s0$s1 $icon \
1255 $head_info $index_info \
1260 proc display_file_helper
{w path icon_name old_m new_m
} {
1263 if {$new_m eq
{_
}} {
1264 set lno
[lsearch
-sorted $file_lists($w) $path]
1266 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1268 $w conf
-state normal
1269 $w delete
$lno.0 [expr {$lno + 1}].0
1270 $w conf
-state disabled
1272 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1273 lappend file_lists
($w) $path
1274 set file_lists
($w) [lsort
-unique $file_lists($w)]
1275 set lno
[lsearch
-sorted $file_lists($w) $path]
1277 $w conf
-state normal
1278 $w image create
$lno.0 \
1279 -align center
-padx 5 -pady 1 \
1281 -image [mapicon
$w $new_m $path]
1282 $w insert
$lno.1 "[escape_path $path]\n"
1283 $w conf
-state disabled
1284 } elseif
{$old_m ne
$new_m} {
1285 $w conf
-state normal
1286 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1287 $w conf
-state disabled
1291 proc display_file
{path state
} {
1292 global file_states selected_paths
1293 global ui_index ui_workdir
1295 set old_m
[merge_state
$path $state]
1296 set s
$file_states($path)
1297 set new_m
[lindex
$s 0]
1298 set icon_name
[lindex
$s 1]
1300 set s
[string index
$new_m 0]
1304 display_file_helper
$ui_index $path $icon_name \
1305 [string index
$old_m 0] $s
1307 if {[string index
$new_m 0] eq
{U
}} {
1310 set s
[string index
$new_m 1]
1312 display_file_helper
$ui_workdir $path $icon_name \
1313 [string index
$old_m 1] $s
1315 if {$new_m eq
{__
}} {
1316 unset file_states
($path)
1317 catch
{unset selected_paths
($path)}
1321 proc display_all_files_helper
{w path icon_name m
} {
1324 lappend file_lists
($w) $path
1325 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1326 $w image create end \
1327 -align center
-padx 5 -pady 1 \
1329 -image [mapicon
$w $m $path]
1330 $w insert end
"[escape_path $path]\n"
1333 proc display_all_files
{} {
1334 global ui_index ui_workdir
1335 global file_states file_lists
1338 $ui_index conf
-state normal
1339 $ui_workdir conf
-state normal
1341 $ui_index delete
0.0 end
1342 $ui_workdir delete
0.0 end
1345 set file_lists
($ui_index) [list
]
1346 set file_lists
($ui_workdir) [list
]
1348 foreach path
[lsort
[array names file_states
]] {
1349 set s
$file_states($path)
1351 set icon_name
[lindex
$s 1]
1353 set s
[string index
$m 0]
1354 if {$s ne
{U
} && $s ne
{_
}} {
1355 display_all_files_helper
$ui_index $path \
1359 if {[string index
$m 0] eq
{U
}} {
1362 set s
[string index
$m 1]
1365 display_all_files_helper
$ui_workdir $path \
1370 $ui_index conf
-state disabled
1371 $ui_workdir conf
-state disabled
1374 proc update_indexinfo
{msg pathList after
} {
1375 global update_index_cp ui_status_value
1377 if {![lock_index update
]} return
1379 set update_index_cp
0
1380 set pathList
[lsort
$pathList]
1381 set totalCnt
[llength
$pathList]
1382 set batch [expr {int
($totalCnt * .01) + 1}]
1383 if {$batch > 25} {set batch 25}
1385 set ui_status_value
[format \
1386 "$msg... %i/%i files (%.2f%%)" \
1390 set fd
[open
"| git update-index -z --index-info" w
]
1396 fileevent
$fd writable
[list \
1397 write_update_indexinfo \
1407 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1408 global update_index_cp ui_status_value
1409 global file_states current_diff_path
1411 if {$update_index_cp >= $totalCnt} {
1418 for {set i
$batch} \
1419 {$update_index_cp < $totalCnt && $i > 0} \
1421 set path
[lindex
$pathList $update_index_cp]
1422 incr update_index_cp
1424 set s
$file_states($path)
1425 switch
-glob -- [lindex
$s 0] {
1432 set info
[lindex
$s 2]
1433 if {$info eq
{}} continue
1435 puts
-nonewline $fd "$info\t$path\0"
1436 display_file
$path $new
1439 set ui_status_value
[format \
1440 "$msg... %i/%i files (%.2f%%)" \
1443 [expr {100.0 * $update_index_cp / $totalCnt}]]
1446 proc update_index
{msg pathList after
} {
1447 global update_index_cp ui_status_value
1449 if {![lock_index update
]} return
1451 set update_index_cp
0
1452 set pathList
[lsort
$pathList]
1453 set totalCnt
[llength
$pathList]
1454 set batch [expr {int
($totalCnt * .01) + 1}]
1455 if {$batch > 25} {set batch 25}
1457 set ui_status_value
[format \
1458 "$msg... %i/%i files (%.2f%%)" \
1462 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1468 fileevent
$fd writable
[list \
1469 write_update_index \
1479 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1480 global update_index_cp ui_status_value
1481 global file_states current_diff_path
1483 if {$update_index_cp >= $totalCnt} {
1490 for {set i
$batch} \
1491 {$update_index_cp < $totalCnt && $i > 0} \
1493 set path
[lindex
$pathList $update_index_cp]
1494 incr update_index_cp
1496 switch
-glob -- [lindex
$file_states($path) 0] {
1502 if {[file exists
$path]} {
1511 puts
-nonewline $fd "$path\0"
1512 display_file
$path $new
1515 set ui_status_value
[format \
1516 "$msg... %i/%i files (%.2f%%)" \
1519 [expr {100.0 * $update_index_cp / $totalCnt}]]
1522 proc checkout_index
{msg pathList after
} {
1523 global update_index_cp ui_status_value
1525 if {![lock_index update
]} return
1527 set update_index_cp
0
1528 set pathList
[lsort
$pathList]
1529 set totalCnt
[llength
$pathList]
1530 set batch [expr {int
($totalCnt * .01) + 1}]
1531 if {$batch > 25} {set batch 25}
1533 set ui_status_value
[format \
1534 "$msg... %i/%i files (%.2f%%)" \
1538 set cmd
[list git checkout-index
]
1544 set fd
[open
"| $cmd " w
]
1550 fileevent
$fd writable
[list \
1551 write_checkout_index \
1561 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1562 global update_index_cp ui_status_value
1563 global file_states current_diff_path
1565 if {$update_index_cp >= $totalCnt} {
1572 for {set i
$batch} \
1573 {$update_index_cp < $totalCnt && $i > 0} \
1575 set path
[lindex
$pathList $update_index_cp]
1576 incr update_index_cp
1577 switch
-glob -- [lindex
$file_states($path) 0] {
1581 puts
-nonewline $fd "$path\0"
1582 display_file
$path ?_
1587 set ui_status_value
[format \
1588 "$msg... %i/%i files (%.2f%%)" \
1591 [expr {100.0 * $update_index_cp / $totalCnt}]]
1594 ######################################################################
1596 ## branch management
1598 proc load_all_heads
{} {
1599 global all_heads tracking_branches
1601 set all_heads
[list
]
1602 set cmd
[list git for-each-ref
]
1603 lappend cmd
--format=%(refname
)
1604 lappend cmd refs
/heads
1605 set fd
[open
"| $cmd" r
]
1606 while {[gets
$fd line
] > 0} {
1607 if {![catch
{set info
$tracking_branches($line)}]} continue
1608 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1609 lappend all_heads
$name
1613 set all_heads
[lsort
$all_heads]
1616 proc populate_branch_menu
{} {
1617 global all_heads disable_on_lock
1620 set last
[$m index last
]
1621 for {set i
0} {$i <= $last} {incr i
} {
1622 if {[$m type $i] eq
{separator
}} {
1625 foreach a
$disable_on_lock {
1626 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1630 set disable_on_lock
$new_dol
1636 foreach b
$all_heads {
1637 $m add radiobutton \
1639 -command [list switch_branch
$b] \
1640 -variable current_branch \
1643 lappend disable_on_lock \
1644 [list
$m entryconf
[$m index last
] -state]
1648 proc do_create_branch_action
{w
} {
1649 global all_heads null_sha1
1650 global create_branch_checkout create_branch_revtype
1651 global create_branch_head create_branch_trackinghead
1653 set newbranch
[string trim
[$w.name.t get
0.0 end
]]
1654 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1658 -title [wm title
$w] \
1660 -message "Branch '$newbranch' already exists."
1664 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1668 -title [wm title
$w] \
1670 -message "We do not like '$newbranch' as a branch name."
1676 switch
-- $create_branch_revtype {
1677 head {set rev $create_branch_head}
1678 tracking
{set rev $create_branch_trackinghead}
1679 expression
{set rev [string trim
[$w.from.exp.t get
0.0 end
]]}
1681 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1685 -title [wm title
$w] \
1687 -message "Invalid starting revision: $rev"
1690 set cmd
[list git update-ref
]
1692 lappend cmd
"branch: Created from $rev"
1693 lappend cmd
"refs/heads/$newbranch"
1695 lappend cmd
$null_sha1
1696 if {[catch
{eval exec $cmd} err
]} {
1700 -title [wm title
$w] \
1702 -message "Failed to create '$newbranch'.\n\n$err"
1706 lappend all_heads
$newbranch
1707 set all_heads
[lsort
$all_heads]
1708 populate_branch_menu
1710 if {$create_branch_checkout} {
1711 switch_branch
$newbranch
1715 proc do_create_branch
{} {
1716 global all_heads current_branch tracking_branches
1717 global create_branch_checkout create_branch_revtype
1718 global create_branch_head create_branch_trackinghead
1720 set create_branch_checkout
1
1721 set create_branch_revtype
head
1722 set create_branch_head
$current_branch
1723 set create_branch_trackinghead
{}
1725 set w .branch_editor
1727 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1729 label
$w.header
-text {Create New Branch
} \
1731 pack
$w.header
-side top
-fill x
1734 button
$w.buttons.create
-text Create \
1737 -command [list do_create_branch_action
$w]
1738 pack
$w.buttons.create
-side right
1739 button
$w.buttons.cancel
-text {Cancel
} \
1741 -command [list destroy
$w]
1742 pack
$w.buttons.cancel
-side right
-padx 5
1743 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1745 labelframe
$w.name \
1746 -text {Branch Description
} \
1748 label
$w.name.l
-text {Name
:} -font font_ui
1755 bind $w.name.t
<Shift-Key-Tab
> "focus $w.postActions.checkout;break"
1756 bind $w.name.t
<Key-Tab
> "focus $w.from.exp.t;break"
1757 bind $w.name.t
<Key-Return
> "do_create_branch_action $w;break"
1758 bind $w.name.t
<Key
> {
1759 if {{%K
} ne
{BackSpace
}
1762 && {%K
} ne
{Return
}} {
1764 if {[string first
%A
{~^
:?
*[}] >= 0} break
1767 pack
$w.name.l
-side left
-padx 5
1768 pack
$w.name.t
-side left
-fill x
-expand 1
1769 pack
$w.name
-anchor nw
-fill x
-pady 5 -padx 5
1771 set all_trackings
[list
]
1772 foreach b
[array names tracking_branches
] {
1773 regsub ^refs
/(heads|remotes
)/ $b {} b
1774 lappend all_trackings
$b
1776 set all_trackings
[lsort
-unique $all_trackings]
1777 if {$all_trackings ne
{}} {
1778 set create_branch_trackinghead
[lindex
$all_trackings 0]
1781 labelframe
$w.from \
1782 -text {Starting Revision
} \
1785 radiobutton
$w.from.
head.r \
1786 -text {Local Branch
:} \
1788 -variable create_branch_revtype \
1790 eval tk_optionMenu
$w.from.
head.m create_branch_head
$all_heads
1791 pack
$w.from.
head.r
-side left
1792 pack
$w.from.
head.m
-side left
1793 frame
$w.from.tracking
1794 radiobutton
$w.from.tracking.r \
1795 -text {Tracking Branch
:} \
1797 -variable create_branch_revtype \
1799 eval tk_optionMenu
$w.from.tracking.m \
1800 create_branch_trackinghead \
1802 pack
$w.from.tracking.r
-side left
1803 pack
$w.from.tracking.m
-side left
1805 radiobutton
$w.from.exp.r \
1806 -text {Revision Expression
:} \
1808 -variable create_branch_revtype \
1810 text
$w.from.exp.t \
1816 bind $w.from.exp.t
<Shift-Key-Tab
> "focus $w.name.t;break"
1817 bind $w.from.exp.t
<Key-Tab
> "focus $w.postActions.checkout;break"
1818 bind $w.from.exp.t
<Key-Return
> "do_create_branch_action $w;break"
1819 pack
$w.from.exp.r
-side left
1820 pack
$w.from.exp.t
-side left
-fill x
-expand 1
1821 pack
$w.from.
head -padx 5 -fill x
-expand 1
1822 pack
$w.from.tracking
-padx 5 -fill x
-expand 1
1823 pack
$w.from.exp
-padx 5 -fill x
-expand 1
1824 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1826 labelframe
$w.postActions \
1827 -text {Post Creation Actions
} \
1829 checkbutton
$w.postActions.checkout \
1830 -text {Checkout after creation
} \
1831 -variable create_branch_checkout \
1833 pack
$w.postActions.checkout
-anchor nw
1834 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1836 bind $w <Visibility
> "grab $w; focus $w.name.t"
1837 bind $w <Key-Escape
> "destroy $w"
1838 bind $w <Key-Return
> "do_create_branch_action $w;break"
1839 wm title
$w "[appname] ([reponame]): Create Branch"
1843 proc do_delete_branch_action
{w
} {
1845 global delete_branch_checkhead delete_branch_head
1847 set to_delete
[list
]
1848 set not_merged
[list
]
1849 foreach i
[$w.list.l curselection
] {
1850 set b
[$w.list.l get
$i]
1851 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
1852 if {$delete_branch_checkhead} {
1853 if {$b eq
$delete_branch_head} continue
1854 if {[catch
{set m
[exec git merge-base
$o $delete_branch_head]}]} continue
1856 lappend not_merged
$b
1860 lappend to_delete
[list
$b $o]
1862 if {$not_merged ne
{}} {
1863 set msg
"The following branches are not completely merged into $delete_branch_head:
1865 - [join $not_merged "\n - "]"
1869 -title [wm title
$w] \
1873 if {$to_delete eq
{}} return
1874 if {!$delete_branch_checkhead} {
1875 set msg
{Recovering deleted branches is difficult.
1877 Delete the selected branches?
}
1878 if {[tk_messageBox \
1881 -title [wm title
$w] \
1883 -message $msg] ne
yes} {
1889 foreach i
$to_delete {
1892 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
1893 append failed
" - $b: $err\n"
1895 set x
[lsearch
-sorted $all_heads $b]
1897 set all_heads
[lreplace
$all_heads $x $x]
1902 if {$failed ne
{}} {
1906 -title [wm title
$w] \
1908 -message "Failed to delete branches:\n$failed"
1911 set all_heads
[lsort
$all_heads]
1912 populate_branch_menu
1916 proc do_delete_branch
{} {
1917 global all_heads tracking_branches current_branch
1918 global delete_branch_checkhead delete_branch_head
1920 set delete_branch_checkhead
1
1921 set delete_branch_head
$current_branch
1923 set w .branch_editor
1925 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1927 label
$w.header
-text {Delete Local Branch
} \
1929 pack
$w.header
-side top
-fill x
1932 button
$w.buttons.create
-text Delete \
1934 -command [list do_delete_branch_action
$w]
1935 pack
$w.buttons.create
-side right
1936 button
$w.buttons.cancel
-text {Cancel
} \
1938 -command [list destroy
$w]
1939 pack
$w.buttons.cancel
-side right
-padx 5
1940 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1942 labelframe
$w.list \
1943 -text {Local Branches
} \
1948 -selectmode extended \
1950 foreach h
$all_heads {
1951 if {$h ne
$current_branch} {
1952 $w.list.l insert end
$h
1955 pack
$w.list.l
-fill both
-pady 5 -padx 5
1956 pack
$w.list
-fill both
-pady 5 -padx 5
1958 set all_trackings
[list
]
1959 foreach b
[array names tracking_branches
] {
1960 regsub ^refs
/(heads|remotes
)/ $b {} b
1961 lappend all_trackings
$b
1964 labelframe
$w.validate \
1965 -text {Only Delete If
} \
1967 frame
$w.validate.
head
1968 checkbutton
$w.validate.
head.r \
1969 -text {Already Merged Into
:} \
1970 -variable delete_branch_checkhead \
1972 eval tk_optionMenu
$w.validate.
head.m delete_branch_head \
1974 [lsort
-unique $all_trackings]
1975 pack
$w.validate.
head.r
-side left
1976 pack
$w.validate.
head.m
-side left
1977 pack
$w.validate.
head -padx 5 -fill x
-expand 1
1978 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
1980 bind $w <Visibility
> "grab $w; focus $w"
1981 bind $w <Key-Escape
> "destroy $w"
1982 wm title
$w "[appname] ([reponame]): Delete Branch"
1986 proc switch_branch
{b
} {
1987 global HEAD commit_type file_states current_branch
1988 global selected_commit_type ui_comm
1990 if {![lock_index switch
]} return
1992 # -- Backup the selected branch (repository_state resets it)
1994 set new_branch
$current_branch
1996 # -- Our in memory state should match the repository.
1998 repository_state curType curHEAD curMERGE_HEAD
1999 if {[string match amend
* $commit_type]
2000 && $curType eq
{normal
}
2001 && $curHEAD eq
$HEAD} {
2002 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2003 info_popup
{Last scanned state does not match repository state.
2005 Another Git program has modified this repository
2006 since the last scan. A rescan must be performed
2007 before the current branch can be changed.
2009 The rescan will be automatically started now.
2012 rescan
{set ui_status_value
{Ready.
}}
2016 # -- Toss the message buffer if we are in amend mode.
2018 if {[string match amend
* $curType]} {
2019 $ui_comm delete
0.0 end
2021 $ui_comm edit modified false
2024 set selected_commit_type new
2025 set current_branch
$new_branch
2028 error
"NOT FINISHED"
2031 ######################################################################
2033 ## remote management
2035 proc load_all_remotes
{} {
2037 global all_remotes tracking_branches
2039 set all_remotes
[list
]
2040 array
unset tracking_branches
2042 set rm_dir
[gitdir remotes
]
2043 if {[file isdirectory
$rm_dir]} {
2044 set all_remotes
[glob \
2048 -directory $rm_dir *]
2050 foreach name
$all_remotes {
2052 set fd
[open
[file join $rm_dir $name] r
]
2053 while {[gets
$fd line
] >= 0} {
2054 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2055 $line line src dst
]} continue
2056 if {![regexp ^refs
/ $dst]} {
2057 set dst
"refs/heads/$dst"
2059 set tracking_branches
($dst) [list
$name $src]
2066 foreach line
[array names repo_config remote.
*.url
] {
2067 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2068 lappend all_remotes
$name
2070 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2074 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2075 if {![regexp ^refs
/ $dst]} {
2076 set dst
"refs/heads/$dst"
2078 set tracking_branches
($dst) [list
$name $src]
2082 set all_remotes
[lsort
-unique $all_remotes]
2085 proc populate_fetch_menu
{m
} {
2086 global all_remotes repo_config
2088 foreach r
$all_remotes {
2090 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2091 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2096 set fd
[open
[gitdir remotes
$r] r
]
2097 while {[gets
$fd n
] >= 0} {
2098 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2109 -label "Fetch from $r..." \
2110 -command [list fetch_from
$r] \
2116 proc populate_push_menu
{m
} {
2117 global all_remotes repo_config
2119 foreach r
$all_remotes {
2121 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2122 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2127 set fd
[open
[gitdir remotes
$r] r
]
2128 while {[gets
$fd n
] >= 0} {
2129 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2140 -label "Push to $r..." \
2141 -command [list push_to
$r] \
2147 proc populate_pull_menu
{m
} {
2148 global repo_config all_remotes disable_on_lock
2150 foreach remote
$all_remotes {
2152 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2153 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2154 foreach line
$repo_config(remote.
$remote.fetch
) {
2155 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2162 set fd
[open
[gitdir remotes
$remote] r
]
2163 while {[gets
$fd line
] >= 0} {
2164 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2172 foreach rb
$rb_list {
2173 regsub ^refs
/heads
/ $rb {} rb_short
2175 -label "Branch $rb_short from $remote..." \
2176 -command [list pull_remote
$remote $rb] \
2178 lappend disable_on_lock \
2179 [list
$m entryconf
[$m index last
] -state]
2184 ######################################################################
2189 #define mask_width 14
2190 #define mask_height 15
2191 static unsigned char mask_bits
[] = {
2192 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2193 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2194 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2197 image create bitmap file_plain
-background white
-foreground black
-data {
2198 #define plain_width 14
2199 #define plain_height 15
2200 static unsigned char plain_bits
[] = {
2201 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2202 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2203 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2204 } -maskdata $filemask
2206 image create bitmap file_mod
-background white
-foreground blue
-data {
2207 #define mod_width 14
2208 #define mod_height 15
2209 static unsigned char mod_bits
[] = {
2210 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2211 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2212 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2213 } -maskdata $filemask
2215 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2216 #define file_fulltick_width 14
2217 #define file_fulltick_height 15
2218 static unsigned char file_fulltick_bits
[] = {
2219 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2220 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2221 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2222 } -maskdata $filemask
2224 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2225 #define parttick_width 14
2226 #define parttick_height 15
2227 static unsigned char parttick_bits
[] = {
2228 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2229 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2230 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2231 } -maskdata $filemask
2233 image create bitmap file_question
-background white
-foreground black
-data {
2234 #define file_question_width 14
2235 #define file_question_height 15
2236 static unsigned char file_question_bits
[] = {
2237 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2238 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2239 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2240 } -maskdata $filemask
2242 image create bitmap file_removed
-background white
-foreground red
-data {
2243 #define file_removed_width 14
2244 #define file_removed_height 15
2245 static unsigned char file_removed_bits
[] = {
2246 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2247 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2248 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2249 } -maskdata $filemask
2251 image create bitmap file_merge
-background white
-foreground blue
-data {
2252 #define file_merge_width 14
2253 #define file_merge_height 15
2254 static unsigned char file_merge_bits
[] = {
2255 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2256 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2257 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2258 } -maskdata $filemask
2260 set ui_index .vpane.files.index.list
2261 set ui_workdir .vpane.files.workdir.list
2263 set all_icons
(_
$ui_index) file_plain
2264 set all_icons
(A
$ui_index) file_fulltick
2265 set all_icons
(M
$ui_index) file_fulltick
2266 set all_icons
(D
$ui_index) file_removed
2267 set all_icons
(U
$ui_index) file_merge
2269 set all_icons
(_
$ui_workdir) file_plain
2270 set all_icons
(M
$ui_workdir) file_mod
2271 set all_icons
(D
$ui_workdir) file_question
2272 set all_icons
(U
$ui_workdir) file_merge
2273 set all_icons
(O
$ui_workdir) file_plain
2275 set max_status_desc
0
2279 {_M
"Modified, not staged"}
2280 {M_
"Staged for commit"}
2281 {MM
"Portions staged for commit"}
2282 {MD
"Staged for commit, missing"}
2284 {_O
"Untracked, not staged"}
2285 {A_
"Staged for commit"}
2286 {AM
"Portions staged for commit"}
2287 {AD
"Staged for commit, missing"}
2290 {D_
"Staged for removal"}
2291 {DO
"Staged for removal, still present"}
2293 {U_
"Requires merge resolution"}
2294 {UU
"Requires merge resolution"}
2295 {UM
"Requires merge resolution"}
2296 {UD
"Requires merge resolution"}
2298 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2299 set max_status_desc
[string length
[lindex
$i 1]]
2301 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2305 ######################################################################
2310 global tcl_platform tk_library
2311 if {[tk windowingsystem
] eq
{aqua
}} {
2317 proc is_Windows
{} {
2319 if {$tcl_platform(platform
) eq
{windows
}} {
2325 proc bind_button3
{w cmd
} {
2326 bind $w <Any-Button-3
> $cmd
2328 bind $w <Control-Button-1
> $cmd
2332 proc incr_font_size
{font
{amt
1}} {
2333 set sz
[font configure
$font -size]
2335 font configure
$font -size $sz
2336 font configure
${font}bold
-size $sz
2339 proc hook_failed_popup
{hook msg
} {
2344 label
$w.m.l1
-text "$hook hook failed:" \
2349 -background white
-borderwidth 1 \
2351 -width 80 -height 10 \
2353 -yscrollcommand [list
$w.m.sby
set]
2355 -text {You must correct the above errors before committing.
} \
2359 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2360 pack
$w.m.l1
-side top
-fill x
2361 pack
$w.m.l2
-side bottom
-fill x
2362 pack
$w.m.sby
-side right
-fill y
2363 pack
$w.m.t
-side left
-fill both
-expand 1
2364 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2366 $w.m.t insert
1.0 $msg
2367 $w.m.t conf
-state disabled
2369 button
$w.ok
-text OK \
2372 -command "destroy $w"
2373 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2375 bind $w <Visibility
> "grab $w; focus $w"
2376 bind $w <Key-Return
> "destroy $w"
2377 wm title
$w "[appname] ([reponame]): error"
2381 set next_console_id
0
2383 proc new_console
{short_title long_title
} {
2384 global next_console_id console_data
2385 set w .console
[incr next_console_id
]
2386 set console_data
($w) [list
$short_title $long_title]
2387 return [console_init
$w]
2390 proc console_init
{w
} {
2391 global console_cr console_data M1B
2393 set console_cr
($w) 1.0
2396 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2401 -background white
-borderwidth 1 \
2403 -width 80 -height 10 \
2406 -yscrollcommand [list
$w.m.sby
set]
2407 label
$w.m.s
-text {Working... please
wait...
} \
2411 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2412 pack
$w.m.l1
-side top
-fill x
2413 pack
$w.m.s
-side bottom
-fill x
2414 pack
$w.m.sby
-side right
-fill y
2415 pack
$w.m.t
-side left
-fill both
-expand 1
2416 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2418 menu
$w.ctxm
-tearoff 0
2419 $w.ctxm add
command -label "Copy" \
2421 -command "tk_textCopy $w.m.t"
2422 $w.ctxm add
command -label "Select All" \
2424 -command "$w.m.t tag add sel 0.0 end"
2425 $w.ctxm add
command -label "Copy All" \
2428 $w.m.t tag add sel 0.0 end
2430 $w.m.t tag remove sel 0.0 end
2433 button
$w.ok
-text {Close
} \
2436 -command "destroy $w"
2437 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2439 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2440 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2441 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2442 bind $w <Visibility
> "focus $w"
2443 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2447 proc console_exec
{w cmd
{after
{}}} {
2448 # -- Windows tosses the enviroment when we exec our child.
2449 # But most users need that so we have to relogin. :-(
2452 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2455 # -- Tcl won't let us redirect both stdout and stderr to
2456 # the same pipe. So pass it through cat...
2458 set cmd
[concat |
$cmd |
& cat]
2460 set fd_f
[open
$cmd r
]
2461 fconfigure
$fd_f -blocking 0 -translation binary
2462 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2465 proc console_read
{w fd after
} {
2466 global console_cr console_data
2470 if {![winfo exists
$w]} {console_init
$w}
2471 $w.m.t conf
-state normal
2473 set n
[string length
$buf]
2475 set cr
[string first
"\r" $buf $c]
2476 set lf
[string first
"\n" $buf $c]
2477 if {$cr < 0} {set cr
[expr {$n + 1}]}
2478 if {$lf < 0} {set lf
[expr {$n + 1}]}
2481 $w.m.t insert end
[string range
$buf $c $lf]
2482 set console_cr
($w) [$w.m.t index
{end
-1c}]
2486 $w.m.t delete
$console_cr($w) end
2487 $w.m.t insert end
"\n"
2488 $w.m.t insert end
[string range
$buf $c $cr]
2493 $w.m.t conf
-state disabled
2497 fconfigure
$fd -blocking 1
2499 if {[catch
{close
$fd}]} {
2500 if {![winfo exists
$w]} {console_init
$w}
2501 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2502 $w.ok conf
-state normal
2504 } elseif
{[winfo exists
$w]} {
2505 $w.m.s conf
-background green
-text {Success
}
2506 $w.ok conf
-state normal
2509 array
unset console_cr
$w
2510 array
unset console_data
$w
2512 uplevel
#0 $after $ok
2516 fconfigure
$fd -blocking 0
2519 ######################################################################
2523 set starting_gitk_msg
{Starting gitk... please
wait...
}
2525 proc do_gitk
{revs
} {
2526 global ui_status_value starting_gitk_msg
2534 set cmd
"sh -c \"exec $cmd\""
2538 if {[catch
{eval exec $cmd} err
]} {
2539 error_popup
"Failed to start gitk:\n\n$err"
2541 set ui_status_value
$starting_gitk_msg
2543 if {$ui_status_value eq
$starting_gitk_msg} {
2544 set ui_status_value
{Ready.
}
2551 set w
[new_console
{gc
} {Compressing the object database
}]
2552 console_exec
$w {git gc
}
2555 proc do_fsck_objects
{} {
2556 set w
[new_console
{fsck-objects
} \
2557 {Verifying the object database with fsck-objects
}]
2558 set cmd
[list git fsck-objects
]
2561 lappend cmd
--strict
2562 console_exec
$w $cmd
2568 global ui_comm is_quitting repo_config commit_type
2570 if {$is_quitting} return
2573 # -- Stash our current commit buffer.
2575 set save
[gitdir GITGUI_MSG
]
2576 set msg
[string trim
[$ui_comm get
0.0 end
]]
2577 if {![string match amend
* $commit_type]
2578 && [$ui_comm edit modified
]
2581 set fd
[open
$save w
]
2582 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2586 catch
{file delete
$save}
2589 # -- Stash our current window geometry into this repository.
2591 set cfg_geometry
[list
]
2592 lappend cfg_geometry
[wm geometry .
]
2593 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2594 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2595 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2598 if {$cfg_geometry ne
$rc_geometry} {
2599 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2606 rescan
{set ui_status_value
{Ready.
}}
2609 proc unstage_helper
{txt paths
} {
2610 global file_states current_diff_path
2612 if {![lock_index begin-update
]} return
2616 foreach path
$paths {
2617 switch
-glob -- [lindex
$file_states($path) 0] {
2621 lappend pathList
$path
2622 if {$path eq
$current_diff_path} {
2623 set after
{reshow_diff
;}
2628 if {$pathList eq
{}} {
2634 [concat
$after {set ui_status_value
{Ready.
}}]
2638 proc do_unstage_selection
{} {
2639 global current_diff_path selected_paths
2641 if {[array size selected_paths
] > 0} {
2643 {Unstaging selected files from commit
} \
2644 [array names selected_paths
]
2645 } elseif
{$current_diff_path ne
{}} {
2647 "Unstaging [short_path $current_diff_path] from commit" \
2648 [list
$current_diff_path]
2652 proc add_helper
{txt paths
} {
2653 global file_states current_diff_path
2655 if {![lock_index begin-update
]} return
2659 foreach path
$paths {
2660 switch
-glob -- [lindex
$file_states($path) 0] {
2665 lappend pathList
$path
2666 if {$path eq
$current_diff_path} {
2667 set after
{reshow_diff
;}
2672 if {$pathList eq
{}} {
2678 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2682 proc do_add_selection
{} {
2683 global current_diff_path selected_paths
2685 if {[array size selected_paths
] > 0} {
2687 {Adding selected files
} \
2688 [array names selected_paths
]
2689 } elseif
{$current_diff_path ne
{}} {
2691 "Adding [short_path $current_diff_path]" \
2692 [list
$current_diff_path]
2696 proc do_add_all
{} {
2700 foreach path
[array names file_states
] {
2701 switch
-glob -- [lindex
$file_states($path) 0] {
2704 ?D
{lappend paths
$path}
2707 add_helper
{Adding all changed files
} $paths
2710 proc revert_helper
{txt paths
} {
2711 global file_states current_diff_path
2713 if {![lock_index begin-update
]} return
2717 foreach path
$paths {
2718 switch
-glob -- [lindex
$file_states($path) 0] {
2722 lappend pathList
$path
2723 if {$path eq
$current_diff_path} {
2724 set after
{reshow_diff
;}
2730 set n
[llength
$pathList]
2734 } elseif
{$n == 1} {
2735 set s
"[short_path [lindex $pathList]]"
2737 set s
"these $n files"
2740 set reply
[tk_dialog \
2742 "[appname] ([reponame])" \
2743 "Revert changes in $s?
2745 Any unadded changes will be permanently lost by the revert." \
2755 [concat
$after {set ui_status_value
{Ready.
}}]
2761 proc do_revert_selection
{} {
2762 global current_diff_path selected_paths
2764 if {[array size selected_paths
] > 0} {
2766 {Reverting selected files
} \
2767 [array names selected_paths
]
2768 } elseif
{$current_diff_path ne
{}} {
2770 "Reverting [short_path $current_diff_path]" \
2771 [list
$current_diff_path]
2775 proc do_signoff
{} {
2778 set me
[committer_ident
]
2779 if {$me eq
{}} return
2781 set sob
"Signed-off-by: $me"
2782 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
2783 if {$last ne
$sob} {
2784 $ui_comm edit separator
2786 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
2787 $ui_comm insert end
"\n"
2789 $ui_comm insert end
"\n$sob"
2790 $ui_comm edit separator
2795 proc do_select_commit_type
{} {
2796 global commit_type selected_commit_type
2798 if {$selected_commit_type eq
{new
}
2799 && [string match amend
* $commit_type]} {
2801 } elseif
{$selected_commit_type eq
{amend
}
2802 && ![string match amend
* $commit_type]} {
2805 # The amend request was rejected...
2807 if {![string match amend
* $commit_type]} {
2808 set selected_commit_type new
2818 global appvers copyright
2819 global tcl_patchLevel tk_patchLevel
2823 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2825 label
$w.header
-text "About [appname]" \
2827 pack
$w.header
-side top
-fill x
2830 button
$w.buttons.close
-text {Close
} \
2832 -command [list destroy
$w]
2833 pack
$w.buttons.close
-side right
2834 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2837 -text "[appname] - a commit creation tool for Git.
2845 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
2848 append v
"[appname] version $appvers\n"
2849 append v
"[exec git version]\n"
2851 if {$tcl_patchLevel eq
$tk_patchLevel} {
2852 append v
"Tcl/Tk version $tcl_patchLevel"
2854 append v
"Tcl version $tcl_patchLevel"
2855 append v
", Tk version $tk_patchLevel"
2866 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
2868 menu
$w.ctxm
-tearoff 0
2869 $w.ctxm add
command \
2874 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
2877 bind $w <Visibility
> "grab $w; focus $w"
2878 bind $w <Key-Escape
> "destroy $w"
2879 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
2880 wm title
$w "About [appname]"
2884 proc do_options
{} {
2885 global repo_config global_config font_descs
2886 global repo_config_new global_config_new
2888 array
unset repo_config_new
2889 array
unset global_config_new
2890 foreach name
[array names repo_config
] {
2891 set repo_config_new
($name) $repo_config($name)
2894 foreach name
[array names repo_config
] {
2896 gui.diffcontext
{continue}
2898 set repo_config_new
($name) $repo_config($name)
2900 foreach name
[array names global_config
] {
2901 set global_config_new
($name) $global_config($name)
2904 set w .options_editor
2906 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2908 label
$w.header
-text "[appname] Options" \
2910 pack
$w.header
-side top
-fill x
2913 button
$w.buttons.restore
-text {Restore Defaults
} \
2915 -command do_restore_defaults
2916 pack
$w.buttons.restore
-side left
2917 button
$w.buttons.save
-text Save \
2919 -command [list do_save_config
$w]
2920 pack
$w.buttons.save
-side right
2921 button
$w.buttons.cancel
-text {Cancel
} \
2923 -command [list destroy
$w]
2924 pack
$w.buttons.cancel
-side right
-padx 5
2925 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2927 labelframe
$w.repo
-text "[reponame] Repository" \
2929 -relief raised
-borderwidth 2
2930 labelframe
$w.global
-text {Global
(All Repositories
)} \
2932 -relief raised
-borderwidth 2
2933 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
2934 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
2937 {b pullsummary
{Show Pull Summary
}}
2938 {b trustmtime
{Trust File Modification Timestamps
}}
2939 {i diffcontext
{Number of Diff Context Lines
}}
2941 set type [lindex
$option 0]
2942 set name
[lindex
$option 1]
2943 set text
[lindex
$option 2]
2944 foreach f
{repo global
} {
2947 checkbutton
$w.
$f.
$name -text $text \
2948 -variable ${f}_config_new
(gui.
$name) \
2952 pack
$w.
$f.
$name -side top
-anchor w
2956 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
2957 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
2958 spinbox
$w.
$f.
$name.v \
2959 -textvariable ${f}_config_new
(gui.
$name) \
2960 -from 1 -to 99 -increment 1 \
2963 pack
$w.
$f.
$name.v
-side right
-anchor e
2964 pack
$w.
$f.
$name -side top
-anchor w
-fill x
2970 set all_fonts
[lsort
[font families
]]
2971 foreach option
$font_descs {
2972 set name
[lindex
$option 0]
2973 set font
[lindex
$option 1]
2974 set text
[lindex
$option 2]
2976 set global_config_new
(gui.
$font^^family
) \
2977 [font configure
$font -family]
2978 set global_config_new
(gui.
$font^^size
) \
2979 [font configure
$font -size]
2981 frame
$w.global.
$name
2982 label
$w.global.
$name.l
-text "$text:" -font font_ui
2983 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
2984 eval tk_optionMenu
$w.global.
$name.family \
2985 global_config_new
(gui.
$font^^family
) \
2987 spinbox
$w.global.
$name.size \
2988 -textvariable global_config_new
(gui.
$font^^size
) \
2989 -from 2 -to 80 -increment 1 \
2992 pack
$w.global.
$name.size
-side right
-anchor e
2993 pack
$w.global.
$name.family
-side right
-anchor e
2994 pack
$w.global.
$name -side top
-anchor w
-fill x
2997 bind $w <Visibility
> "grab $w; focus $w"
2998 bind $w <Key-Escape
> "destroy $w"
2999 wm title
$w "[appname] ([reponame]): Options"
3003 proc do_restore_defaults
{} {
3004 global font_descs default_config repo_config
3005 global repo_config_new global_config_new
3007 foreach name
[array names default_config
] {
3008 set repo_config_new
($name) $default_config($name)
3009 set global_config_new
($name) $default_config($name)
3012 foreach option
$font_descs {
3013 set name
[lindex
$option 0]
3014 set repo_config
(gui.
$name) $default_config(gui.
$name)
3018 foreach option
$font_descs {
3019 set name
[lindex
$option 0]
3020 set font
[lindex
$option 1]
3021 set global_config_new
(gui.
$font^^family
) \
3022 [font configure
$font -family]
3023 set global_config_new
(gui.
$font^^size
) \
3024 [font configure
$font -size]
3028 proc do_save_config
{w
} {
3029 if {[catch
{save_config
} err
]} {
3030 error_popup
"Failed to completely save options:\n\n$err"
3036 proc do_windows_shortcut
{} {
3040 set desktop
[exec cygpath \
3048 set fn
[tk_getSaveFile \
3050 -title "[appname] ([reponame]): Create Desktop Icon" \
3051 -initialdir $desktop \
3052 -initialfile "Git [reponame].bat"]
3056 set sh
[exec cygpath \
3060 set me
[exec cygpath \
3064 set gd
[exec cygpath \
3068 set gw
[exec cygpath \
3071 [file dirname [gitdir
]]]
3072 regsub
-all ' $me "'\\''" me
3073 regsub -all ' $gd "'\\''" gd
3074 puts $fd "@ECHO Entering $gw"
3075 puts $fd "@ECHO Starting git-gui... please wait..."
3076 puts -nonewline $fd "@\"$sh\" --login -c \""
3077 puts -nonewline $fd "GIT_DIR='$gd'"
3078 puts -nonewline $fd " '$me'"
3082 error_popup "Cannot write script:\n\n$err"
3087 proc do_macosx_app {} {
3090 set fn [tk_getSaveFile \
3092 -title "[appname] ([reponame]): Create Desktop Icon" \
3093 -initialdir [file join $env(HOME) Desktop] \
3094 -initialfile "Git [reponame].app"]
3097 set Contents [file join $fn Contents]
3098 set MacOS [file join $Contents MacOS]
3099 set exe [file join $MacOS git-gui]
3103 set fd [open [file join $Contents Info.plist] w]
3104 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3105 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3106 <plist version="1.0">
3108 <key>CFBundleDevelopmentRegion</key>
3109 <string>English</string>
3110 <key>CFBundleExecutable</key>
3111 <string>git-gui</string>
3112 <key>CFBundleIdentifier</key>
3113 <string>org.spearce.git-gui</string>
3114 <key>CFBundleInfoDictionaryVersion</key>
3115 <string>6.0</string>
3116 <key>CFBundlePackageType</key>
3117 <string>APPL</string>
3118 <key>CFBundleSignature</key>
3119 <string>????</string>
3120 <key>CFBundleVersion</key>
3121 <string>1.0</string>
3122 <key>NSPrincipalClass</key>
3123 <string>NSApplication</string>
3128 set fd [open $exe w]
3129 set gd [file normalize [gitdir]]
3130 set ep [file normalize [exec git --exec-path]]
3131 regsub -all ' $gd "'\\''" gd
3132 regsub
-all ' $ep "'\\''" ep
3133 puts $fd "#!/bin/sh"
3134 foreach name
[array names env
] {
3135 if {[string match GIT_
* $name]} {
3136 regsub
-all ' $env($name) "'\\''" v
3137 puts $fd "export $name='$v'"
3140 puts $fd "export PATH
='$ep':\
$PATH"
3141 puts $fd "export GIT_DIR
='$gd'"
3142 puts $fd "exec [file normalize
$argv0]"
3145 file attributes $exe -permissions u+x,g+x,o+x
3147 error_popup "Cannot
write icon
:\n\n$err"
3152 proc toggle_or_diff {w x y} {
3153 global file_states file_lists current_diff_path ui_index ui_workdir
3154 global last_clicked selected_paths
3156 set pos [split [$w index @$x,$y] .]
3157 set lno [lindex $pos 0]
3158 set col [lindex $pos 1]
3159 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3165 set last_clicked [list $w $lno]
3166 array unset selected_paths
3167 $ui_index tag remove in_sel 0.0 end
3168 $ui_workdir tag remove in_sel 0.0 end
3171 if {$current_diff_path eq $path} {
3172 set after {reshow_diff;}
3176 if {$w eq $ui_index} {
3178 "Unstaging
[short_path
$path] from commit
" \
3180 [concat $after {set ui_status_value {Ready.}}]
3181 } elseif {$w eq $ui_workdir} {
3183 "Adding
[short_path
$path]" \
3185 [concat $after {set ui_status_value {Ready.}}]
3188 show_diff $path $w $lno
3192 proc add_one_to_selection {w x y} {
3193 global file_lists last_clicked selected_paths
3195 set lno [lindex [split [$w index @$x,$y] .] 0]
3196 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3202 if {$last_clicked ne {}
3203 && [lindex $last_clicked 0] ne $w} {
3204 array unset selected_paths
3205 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3208 set last_clicked [list $w $lno]
3209 if {[catch {set in_sel $selected_paths($path)}]} {
3213 unset selected_paths($path)
3214 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3216 set selected_paths($path) 1
3217 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3221 proc add_range_to_selection {w x y} {
3222 global file_lists last_clicked selected_paths
3224 if {[lindex $last_clicked 0] ne $w} {
3225 toggle_or_diff $w $x $y
3229 set lno [lindex [split [$w index @$x,$y] .] 0]
3230 set lc [lindex $last_clicked 1]
3239 foreach path [lrange $file_lists($w) \
3240 [expr {$begin - 1}] \
3241 [expr {$end - 1}]] {
3242 set selected_paths($path) 1
3244 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3247 ######################################################################
3251 set cursor_ptr arrow
3252 font create font_diff -family Courier -size 10
3256 eval font configure font_ui [font actual [.dummy cget -font]]
3260 font create font_uibold
3261 font create font_diffbold
3266 } elseif {[is_MacOSX]} {
3274 proc apply_config {} {
3275 global repo_config font_descs
3277 foreach option $font_descs {
3278 set name [lindex $option 0]
3279 set font [lindex $option 1]
3281 foreach {cn cv} $repo_config(gui.$name) {
3282 font configure $font $cn $cv
3285 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3287 foreach {cn cv} [font configure $font] {
3288 font configure ${font}bold $cn $cv
3290 font configure ${font}bold -weight bold
3294 set default_config(gui.trustmtime) false
3295 set default_config(gui.pullsummary) true
3296 set default_config(gui.diffcontext) 5
3297 set default_config(gui.fontui) [font configure font_ui]
3298 set default_config(gui.fontdiff) [font configure font_diff]
3300 {fontui font_ui {Main Font}}
3301 {fontdiff font_diff {Diff/Console Font}}
3306 ######################################################################
3312 menu .mbar -tearoff 0
3313 .mbar add cascade -label Repository -menu .mbar.repository
3314 .mbar add cascade -label Edit -menu .mbar.edit
3315 if {!$single_commit} {
3316 .mbar add cascade -label Branch -menu .mbar.branch
3318 .mbar add cascade -label Commit -menu .mbar.commit
3319 if {!$single_commit} {
3320 .mbar add cascade -label Fetch -menu .mbar.fetch
3321 .mbar add cascade -label Pull -menu .mbar.pull
3322 .mbar add cascade -label Push -menu .mbar.push
3324 . configure -menu .mbar
3326 # -- Repository Menu
3328 menu .mbar.repository
3329 .mbar.repository add command \
3330 -label {Visualize Current Branch} \
3331 -command {do_gitk {}} \
3334 .mbar.repository add command \
3335 -label {Visualize All Branches} \
3336 -command {do_gitk {--all}} \
3339 .mbar.repository add separator
3341 if {!$single_commit} {
3342 .mbar.repository add command -label {Compress Database} \
3346 .mbar.repository add command -label {Verify Database} \
3347 -command do_fsck_objects \
3350 .mbar.repository add separator
3353 .mbar.repository add command \
3354 -label {Create Desktop Icon} \
3355 -command do_windows_shortcut \
3357 } elseif {[is_MacOSX]} {
3358 .mbar.repository add command \
3359 -label {Create Desktop Icon} \
3360 -command do_macosx_app \
3365 .mbar.repository add command -label Quit \
3367 -accelerator $M1T-Q \
3373 .mbar.edit add command -label Undo \
3374 -command {catch {[focus] edit undo}} \
3375 -accelerator $M1T-Z \
3377 .mbar.edit add command -label Redo \
3378 -command {catch {[focus] edit redo}} \
3379 -accelerator $M1T-Y \
3381 .mbar.edit add separator
3382 .mbar.edit add command -label Cut \
3383 -command {catch {tk_textCut [focus]}} \
3384 -accelerator $M1T-X \
3386 .mbar.edit add command -label Copy \
3387 -command {catch {tk_textCopy [focus]}} \
3388 -accelerator $M1T-C \
3390 .mbar.edit add command -label Paste \
3391 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3392 -accelerator $M1T-V \
3394 .mbar.edit add command -label Delete \
3395 -command {catch {[focus] delete sel.first sel.last}} \
3398 .mbar.edit add separator
3399 .mbar.edit add command -label {Select All} \
3400 -command {catch {[focus] tag add sel 0.0 end}} \
3401 -accelerator $M1T-A \
3406 if {!$single_commit} {
3409 .mbar.branch add command -label {Create...} \
3410 -command do_create_branch \
3411 -accelerator $M1T-N \
3413 lappend disable_on_lock [list .mbar.branch entryconf \
3414 [.mbar.branch index last] -state]
3416 .mbar.branch add command -label {Delete...} \
3417 -command do_delete_branch \
3419 lappend disable_on_lock [list .mbar.branch entryconf \
3420 [.mbar.branch index last] -state]
3427 .mbar.commit add radiobutton \
3428 -label {New Commit} \
3429 -command do_select_commit_type \
3430 -variable selected_commit_type \
3433 lappend disable_on_lock \
3434 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3436 .mbar.commit add radiobutton \
3437 -label {Amend Last Commit} \
3438 -command do_select_commit_type \
3439 -variable selected_commit_type \
3442 lappend disable_on_lock \
3443 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3445 .mbar.commit add separator
3447 .mbar.commit add command -label Rescan \
3448 -command do_rescan \
3451 lappend disable_on_lock \
3452 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3454 .mbar.commit add command -label {Add To Commit} \
3455 -command do_add_selection \
3457 lappend disable_on_lock \
3458 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3460 .mbar.commit add command -label {Add All To Commit} \
3461 -command do_add_all \
3462 -accelerator $M1T-I \
3464 lappend disable_on_lock \
3465 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3467 .mbar.commit add command -label {Unstage From Commit} \
3468 -command do_unstage_selection \
3470 lappend disable_on_lock \
3471 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3473 .mbar.commit add command -label {Revert Changes} \
3474 -command do_revert_selection \
3476 lappend disable_on_lock \
3477 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3479 .mbar.commit add separator
3481 .mbar.commit add command -label {Sign Off} \
3482 -command do_signoff \
3483 -accelerator $M1T-S \
3486 .mbar.commit add command -label Commit \
3487 -command do_commit \
3488 -accelerator $M1T-Return \
3490 lappend disable_on_lock \
3491 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3493 # -- Transport menus
3495 if {!$single_commit} {
3502 # -- Apple Menu (Mac OS X only)
3504 .mbar add cascade -label Apple -menu .mbar.apple
3507 .mbar.apple add command -label "About
[appname
]" \
3510 .mbar.apple add command -label "[appname
] Options...
" \
3511 -command do_options \
3516 .mbar.edit add separator
3517 .mbar.edit add command -label {Options...} \
3518 -command do_options \
3523 if {[file exists /usr/local/miga/lib/gui-miga]
3524 && [file exists .pvcsrc]} {
3526 global ui_status_value
3527 if {![lock_index update]} return
3528 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3529 set miga_fd [open "|
$cmd" r]
3530 fconfigure $miga_fd -blocking 0
3531 fileevent $miga_fd readable [list miga_done $miga_fd]
3532 set ui_status_value {Running miga...}
3534 proc miga_done {fd} {
3539 rescan [list set ui_status_value {Ready.}]
3542 .mbar add cascade -label Tools -menu .mbar.tools
3544 .mbar.tools add command -label "Migrate
" \
3547 lappend disable_on_lock \
3548 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3553 .mbar add cascade -label Help -menu .mbar.help
3556 .mbar.help add command -label "About
[appname
]" \
3568 -text {Current Branch:} \
3573 -textvariable current_branch \
3577 pack .branch.l1 -side left
3578 pack .branch.cb -side left -fill x
3579 pack .branch -side top -fill x
3581 # -- Main Window Layout
3583 panedwindow .vpane -orient vertical
3584 panedwindow .vpane.files -orient horizontal
3585 .vpane add .vpane.files -sticky nsew -height 100 -width 400
3586 pack .vpane -anchor n -side top -fill both -expand 1
3588 # -- Index File List
3590 frame .vpane.files.index -height 100 -width 400
3591 label .vpane.files.index.title -text {Changes To Be Committed} \
3594 text $ui_index -background white -borderwidth 0 \
3595 -width 40 -height 10 \
3597 -cursor $cursor_ptr \
3598 -yscrollcommand {.vpane.files.index.sb set} \
3600 scrollbar .vpane.files.index.sb -command [list $ui_index yview]
3601 pack .vpane.files.index.title -side top -fill x
3602 pack .vpane.files.index.sb -side right -fill y
3603 pack $ui_index -side left -fill both -expand 1
3604 .vpane.files add .vpane.files.index -sticky nsew
3606 # -- Working Directory File List
3608 frame .vpane.files.workdir -height 100 -width 100
3609 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3612 text $ui_workdir -background white -borderwidth 0 \
3613 -width 40 -height 10 \
3615 -cursor $cursor_ptr \
3616 -yscrollcommand {.vpane.files.workdir.sb set} \
3618 scrollbar .vpane.files.workdir.sb -command [list $ui_workdir yview]
3619 pack .vpane.files.workdir.title -side top -fill x
3620 pack .vpane.files.workdir.sb -side right -fill y
3621 pack $ui_workdir -side left -fill both -expand 1
3622 .vpane.files add .vpane.files.workdir -sticky nsew
3624 foreach i [list $ui_index $ui_workdir] {
3625 $i tag conf in_diff -font font_uibold
3626 $i tag conf in_sel \
3627 -background [$i cget -foreground] \
3628 -foreground [$i cget -background]
3632 # -- Diff and Commit Area
3634 frame .vpane.lower -height 300 -width 400
3635 frame .vpane.lower.commarea
3636 frame .vpane.lower.diff -relief sunken -borderwidth 1
3637 pack .vpane.lower.commarea -side top -fill x
3638 pack .vpane.lower.diff -side bottom -fill both -expand 1
3639 .vpane add .vpane.lower -stick nsew
3641 # -- Commit Area Buttons
3643 frame .vpane.lower.commarea.buttons
3644 label .vpane.lower.commarea.buttons.l -text {} \
3648 pack .vpane.lower.commarea.buttons.l -side top -fill x
3649 pack .vpane.lower.commarea.buttons -side left -fill y
3651 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3652 -command do_rescan \
3654 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3655 lappend disable_on_lock \
3656 {.vpane.lower.commarea.buttons.rescan conf -state}
3658 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3659 -command do_add_all \
3661 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3662 lappend disable_on_lock \
3663 {.vpane.lower.commarea.buttons.incall conf -state}
3665 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3666 -command do_signoff \
3668 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3670 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3671 -command do_commit \
3673 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3674 lappend disable_on_lock \
3675 {.vpane.lower.commarea.buttons.commit conf -state}
3677 # -- Commit Message Buffer
3679 frame .vpane.lower.commarea.buffer
3680 frame .vpane.lower.commarea.buffer.header
3681 set ui_comm .vpane.lower.commarea.buffer.t
3682 set ui_coml .vpane.lower.commarea.buffer.header.l
3683 radiobutton .vpane.lower.commarea.buffer.header.new \
3684 -text {New Commit} \
3685 -command do_select_commit_type \
3686 -variable selected_commit_type \
3689 lappend disable_on_lock \
3690 [list .vpane.lower.commarea.buffer.header.new conf -state]
3691 radiobutton .vpane.lower.commarea.buffer.header.amend \
3692 -text {Amend Last Commit} \
3693 -command do_select_commit_type \
3694 -variable selected_commit_type \
3697 lappend disable_on_lock \
3698 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3703 proc trace_commit_type {varname args} {
3704 global ui_coml commit_type
3705 switch -glob -- $commit_type {
3706 initial {set txt {Initial Commit Message:}}
3707 amend {set txt {Amended Commit Message:}}
3708 amend-initial {set txt {Amended Initial Commit Message:}}
3709 amend-merge {set txt {Amended Merge Commit Message:}}
3710 merge {set txt {Merge Commit Message:}}
3711 * {set txt {Commit Message:}}
3713 $ui_coml conf -text $txt
3715 trace add variable commit_type write trace_commit_type
3716 pack $ui_coml -side left -fill x
3717 pack .vpane.lower.commarea.buffer.header.amend -side right
3718 pack .vpane.lower.commarea.buffer.header.new -side right
3720 text $ui_comm -background white -borderwidth 1 \
3723 -autoseparators true \
3725 -width 75 -height 9 -wrap none \
3727 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3728 scrollbar .vpane.lower.commarea.buffer.sby \
3729 -command [list $ui_comm yview]
3730 pack .vpane.lower.commarea.buffer.header -side top -fill x
3731 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3732 pack $ui_comm -side left -fill y
3733 pack .vpane.lower.commarea.buffer -side left -fill y
3735 # -- Commit Message Buffer Context Menu
3737 set ctxm .vpane.lower.commarea.buffer.ctxm
3738 menu $ctxm -tearoff 0
3742 -command {tk_textCut $ui_comm}
3746 -command {tk_textCopy $ui_comm}
3750 -command {tk_textPaste $ui_comm}
3754 -command {$ui_comm delete sel.first sel.last}
3757 -label {Select All} \
3759 -command {$ui_comm tag add sel 0.0 end}
3764 $ui_comm tag add sel 0.0 end
3765 tk_textCopy $ui_comm
3766 $ui_comm tag remove sel 0.0 end
3773 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
3777 set current_diff_path {}
3778 set diff_actions [list]
3779 proc trace_current_diff_path {varname args} {
3780 global current_diff_path diff_actions file_states
3781 if {$current_diff_path eq {}} {
3787 set p $current_diff_path
3788 set s [mapdesc [lindex $file_states($p) 0] $p]
3790 set p [escape_path $p]
3794 .vpane.lower.diff.header.status configure -text $s
3795 .vpane.lower.diff.header.file configure -text $f
3796 .vpane.lower.diff.header.path configure -text $p
3797 foreach w $diff_actions {
3801 trace add variable current_diff_path write trace_current_diff_path
3803 frame .vpane.lower.diff.header -background orange
3804 label .vpane.lower.diff.header.status \
3805 -background orange \
3806 -width $max_status_desc \
3810 label .vpane.lower.diff.header.file \
3811 -background orange \
3815 label .vpane.lower.diff.header.path \
3816 -background orange \
3820 pack .vpane.lower.diff.header.status -side left
3821 pack .vpane.lower.diff.header.file -side left
3822 pack .vpane.lower.diff.header.path -fill x
3823 set ctxm .vpane.lower.diff.header.ctxm
3824 menu $ctxm -tearoff 0
3833 -- $current_diff_path
3835 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3836 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
3840 frame .vpane.lower.diff.body
3841 set ui_diff .vpane.lower.diff.body.t
3842 text $ui_diff -background white -borderwidth 0 \
3843 -width 80 -height 15 -wrap none \
3845 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3846 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3848 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3849 -command [list $ui_diff xview]
3850 scrollbar .vpane.lower.diff.body.sby -orient vertical \
3851 -command [list $ui_diff yview]
3852 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3853 pack .vpane.lower.diff.body.sby -side right -fill y
3854 pack $ui_diff -side left -fill both -expand 1
3855 pack .vpane.lower.diff.header -side top -fill x
3856 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3858 $ui_diff tag conf d_@ -font font_diffbold
3859 $ui_diff tag conf d_+ -foreground blue
3860 $ui_diff tag conf d_- -foreground red
3861 $ui_diff tag conf d_++ -foreground {#00a000}
3862 $ui_diff tag conf d_-- -foreground {#a000a0}
3863 $ui_diff tag conf d_+- \
3865 -background {light goldenrod yellow}
3866 $ui_diff tag conf d_-+ \
3870 # -- Diff Body Context Menu
3872 set ctxm .vpane.lower.diff.body.ctxm
3873 menu $ctxm -tearoff 0
3877 -command {tk_textCopy $ui_diff}
3878 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3880 -label {Select All} \
3882 -command {$ui_diff tag add sel 0.0 end}
3883 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3888 $ui_diff tag add sel 0.0 end
3889 tk_textCopy $ui_diff
3890 $ui_diff tag remove sel 0.0 end
3892 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3895 -label {Decrease Font Size} \
3897 -command {incr_font_size font_diff -1}
3898 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3900 -label {Increase Font Size} \
3902 -command {incr_font_size font_diff 1}
3903 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3906 -label {Show Less Context} \
3908 -command {if {$repo_config(gui.diffcontext) >= 2} {
3909 incr repo_config(gui.diffcontext) -1
3912 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3914 -label {Show More Context} \
3917 incr repo_config(gui.diffcontext)
3920 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3922 $ctxm add command -label {Options...} \
3925 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
3929 set ui_status_value {Initializing...}
3930 label .status -textvariable ui_status_value \
3936 pack .status -anchor w -side bottom -fill x
3941 set gm $repo_config(gui.geometry)
3942 wm geometry . [lindex $gm 0]
3943 .vpane sash place 0 \
3944 [lindex [.vpane sash coord 0] 0] \
3946 .vpane.files sash place 0 \
3948 [lindex [.vpane.files sash coord 0] 1]
3954 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3955 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3956 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3957 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3958 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3959 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3960 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3961 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3962 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3963 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3964 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3966 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3967 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3968 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3969 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3970 bind $ui_diff <$M1B-Key-v> {break}
3971 bind $ui_diff <$M1B-Key-V> {break}
3972 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3973 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3974 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3975 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3976 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3977 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3979 if {!$single_commit} {
3980 bind . <$M1B-Key-n> do_create_branch
3981 bind . <$M1B-Key-N> do_create_branch
3984 bind . <Destroy> do_quit
3985 bind all <Key-F5> do_rescan
3986 bind all <$M1B-Key-r> do_rescan
3987 bind all <$M1B-Key-R> do_rescan
3988 bind . <$M1B-Key-s> do_signoff
3989 bind . <$M1B-Key-S> do_signoff
3990 bind . <$M1B-Key-i> do_add_all
3991 bind . <$M1B-Key-I> do_add_all
3992 bind . <$M1B-Key-Return> do_commit
3993 bind all <$M1B-Key-q> do_quit
3994 bind all <$M1B-Key-Q> do_quit
3995 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
3996 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
3997 foreach i [list $ui_index $ui_workdir] {
3998 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
3999 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4000 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4004 set file_lists($ui_index) [list]
4005 set file_lists($ui_workdir) [list]
4009 set MERGE_HEAD [list]
4012 set current_branch {}
4013 set current_diff_path {}
4014 set selected_commit_type new
4016 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4017 focus -force $ui_comm
4019 # -- Warn the user about environmental problems. Cygwin's Tcl
4020 # does *not* pass its env array onto any processes it spawns.
4021 # This means that git processes get none of our environment.
4026 set msg "Possible environment issues exist.
4028 The following environment variables are probably
4029 going to be ignored by any Git subprocess run
4033 foreach name [array names env] {
4034 switch -regexp -- $name {
4035 {^GIT_INDEX_FILE$} -
4036 {^GIT_OBJECT_DIRECTORY$} -
4037 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4039 {^GIT_EXTERNAL_DIFF$} -
4043 {^GIT_CONFIG_LOCAL$} -
4044 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4045 append msg " - $name\n"
4048 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4049 append msg " - $name\n"
4051 set suggest_user $name
4055 if {$ignored_env > 0} {
4057 This is due to a known issue with the
4058 Tcl binary distributed by Cygwin.
"
4060 if {$suggest_user ne {}} {
4063 A good replacement
for $suggest_user
4064 is placing values
for the user.name and
4065 user.email settings into your personal
4071 unset ignored_env msg suggest_user name
4074 # -- Only initialize complex UI if we are going to stay running.
4076 if {!$single_commit} {
4080 populate_branch_menu
4081 populate_fetch_menu .mbar.fetch
4082 populate_pull_menu .mbar.pull
4083 populate_push_menu .mbar.push
4086 # -- Only suggest a gc run if we are going to stay running.
4088 if {!$single_commit} {
4089 set object_limit 2000
4090 if {[is_Windows]} {set object_limit 200}
4091 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4092 if {$objects_current >= $object_limit} {
4094 "This repository currently has
$objects_current loose objects.
4096 To maintain optimal performance it is strongly
4097 recommended that you
compress the database
4098 when
more than
$object_limit loose objects exist.
4100 Compress the database now?
"] eq yes} {
4104 unset object_limit _junk objects_current
4107 lock_index begin-read