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
{honor_trustmtime
1}} {
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 {$honor_trustmtime && $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
-encoding binary
414 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
415 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding 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 regsub
-all -line {[ \r\t]+$
} $content {} content
432 $ui_comm delete
0.0 end
433 $ui_comm insert end
$content
439 proc read_diff_index
{fd after
} {
442 append buf_rdi
[read $fd]
444 set n
[string length
$buf_rdi]
446 set z1
[string first
"\0" $buf_rdi $c]
449 set z2
[string first
"\0" $buf_rdi $z1]
453 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
454 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
456 [encoding convertfrom
$p] \
458 [list
[lindex
$i 0] [lindex
$i 2]] \
464 set buf_rdi
[string range
$buf_rdi $c end
]
469 rescan_done
$fd buf_rdi
$after
472 proc read_diff_files
{fd after
} {
475 append buf_rdf
[read $fd]
477 set n
[string length
$buf_rdf]
479 set z1
[string first
"\0" $buf_rdf $c]
482 set z2
[string first
"\0" $buf_rdf $z1]
486 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
487 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
489 [encoding convertfrom
$p] \
492 [list
[lindex
$i 0] [lindex
$i 2]]
497 set buf_rdf
[string range
$buf_rdf $c end
]
502 rescan_done
$fd buf_rdf
$after
505 proc read_ls_others
{fd after
} {
508 append buf_rlo
[read $fd]
509 set pck
[split $buf_rlo "\0"]
510 set buf_rlo
[lindex
$pck end
]
511 foreach p
[lrange
$pck 0 end-1
] {
512 merge_state
[encoding convertfrom
$p] ?O
514 rescan_done
$fd buf_rlo
$after
517 proc rescan_done
{fd buf after
} {
519 global file_states repo_config
522 if {![eof
$fd]} return
525 if {[incr rescan_active
-1] > 0} return
534 proc prune_selection
{} {
535 global file_states selected_paths
537 foreach path
[array names selected_paths
] {
538 if {[catch
{set still_here
$file_states($path)}]} {
539 unset selected_paths
($path)
544 ######################################################################
549 global ui_diff current_diff_path current_diff_header
550 global ui_index ui_workdir
552 $ui_diff conf
-state normal
553 $ui_diff delete
0.0 end
554 $ui_diff conf
-state disabled
556 set current_diff_path
{}
557 set current_diff_header
{}
559 $ui_index tag remove in_diff
0.0 end
560 $ui_workdir tag remove in_diff
0.0 end
563 proc reshow_diff
{} {
564 global ui_status_value file_states file_lists
565 global current_diff_path current_diff_side
567 set p
$current_diff_path
569 ||
$current_diff_side eq
{}
570 ||
[catch
{set s
$file_states($p)}]
571 ||
[lsearch
-sorted -exact $file_lists($current_diff_side) $p] == -1} {
574 show_diff
$p $current_diff_side
578 proc handle_empty_diff
{} {
579 global current_diff_path file_states file_lists
581 set path
$current_diff_path
582 set s
$file_states($path)
583 if {[lindex
$s 0] ne
{_M
}} return
585 info_popup
"No differences detected.
587 [short_path $path] has no changes.
589 The modification date of this file was updated
590 by another application, but the content within
591 the file was not changed.
593 A rescan will be automatically started to find
594 other files which may have the same state."
597 display_file
$path __
598 rescan
{set ui_status_value
{Ready.
}} 0
601 proc show_diff
{path w
{lno
{}}} {
602 global file_states file_lists
603 global is_3way_diff diff_active repo_config
604 global ui_diff ui_status_value ui_index ui_workdir
605 global current_diff_path current_diff_side current_diff_header
607 if {$diff_active ||
![lock_index
read]} return
611 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
617 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
620 set s
$file_states($path)
624 set current_diff_path
$path
625 set current_diff_side
$w
626 set current_diff_header
{}
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!
632 set max_sz
[expr {128 * 1024}]
634 set fd
[open
$path r
]
635 set content
[read $fd $max_sz]
637 set sz
[file size
$path]
641 set ui_status_value
"Unable to display [escape_path $path]"
642 error_popup
"Error loading file:\n\n$err"
645 $ui_diff conf
-state normal
646 if {![catch
{set type [exec file $path]}]} {
647 set n
[string length
$path]
648 if {[string equal
-length $n $path $type]} {
649 set type [string range
$type $n end
]
650 regsub
{^
:?\s
*} $type {} type
652 $ui_diff insert end
"* $type\n" d_@
654 if {[string first
"\0" $content] != -1} {
655 $ui_diff insert end \
656 "* Binary file (not showing content)." \
660 $ui_diff insert end \
661 "* Untracked file is $sz bytes.
662 * Showing only first $max_sz bytes.
665 $ui_diff insert end
$content
667 $ui_diff insert end
"
668 * Untracked file clipped here by [appname].
669 * To see the entire file, use an external editor.
673 $ui_diff conf
-state disabled
676 set ui_status_value
{Ready.
}
681 if {$w eq
$ui_index} {
682 lappend cmd diff-index
684 } elseif
{$w eq
$ui_workdir} {
685 if {[string index
$m 0] eq
{U
}} {
688 lappend cmd diff-files
693 lappend cmd
--no-color
694 if {$repo_config(gui.diffcontext
) > 0} {
695 lappend cmd
"-U$repo_config(gui.diffcontext)"
697 if {$w eq
$ui_index} {
703 if {[catch
{set fd
[open
$cmd r
]} err
]} {
706 set ui_status_value
"Unable to display [escape_path $path]"
707 error_popup
"Error loading diff:\n\n$err"
715 fileevent
$fd readable
[list read_diff
$fd]
718 proc read_diff
{fd
} {
719 global ui_diff ui_status_value diff_active
720 global is_3way_diff current_diff_header
722 $ui_diff conf
-state normal
723 while {[gets
$fd line
] >= 0} {
724 # -- Cleanup uninteresting diff header lines.
726 if { [string match
{diff --git *} $line]
727 ||
[string match
{diff --cc *} $line]
728 ||
[string match
{diff --combined *} $line]
729 ||
[string match
{--- *} $line]
730 ||
[string match
{+++ *} $line]} {
731 append current_diff_header
$line "\n"
734 if {[string match
{index
*} $line]} continue
735 if {$line eq
{deleted
file mode
120000}} {
736 set line
"deleted symlink"
739 # -- Automatically detect if this is a 3 way diff.
741 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
743 if {[string match
{mode
*} $line]
744 ||
[string match
{new
file *} $line]
745 ||
[string match
{deleted
file *} $line]
746 ||
[string match
{Binary files
* and
* differ
} $line]
747 ||
$line eq
{\ No newline
at end of
file}
748 ||
[regexp
{^\
* Unmerged path
} $line]} {
750 } elseif
{$is_3way_diff} {
751 set op
[string range
$line 0 1]
761 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
762 set line
[string replace
$line 0 1 { }]
769 puts
"error: Unhandled 3 way diff marker: {$op}"
774 set op
[string index
$line 0]
780 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
781 set line
[string replace
$line 0 0 { }]
788 puts
"error: Unhandled 2 way diff marker: {$op}"
793 $ui_diff insert end
$line $tags
794 if {[string index
$line end
] eq
"\r"} {
795 $ui_diff tag add d_cr
{end
- 2c
}
797 $ui_diff insert end
"\n" $tags
799 $ui_diff conf
-state disabled
805 set ui_status_value
{Ready.
}
807 if {[$ui_diff index end
] eq
{2.0}} {
813 proc apply_hunk
{x y
} {
814 global current_diff_path current_diff_header current_diff_side
815 global ui_diff ui_index file_states
817 if {$current_diff_path eq
{} ||
$current_diff_header eq
{}} return
818 if {![lock_index apply_hunk
]} return
820 set apply_cmd
{git apply
--cached --whitespace=nowarn
}
821 set mi
[lindex
$file_states($current_diff_path) 0]
822 if {$current_diff_side eq
$ui_index} {
824 lappend apply_cmd
--reverse
825 if {[string index
$mi 0] ne
{M
}} {
831 if {[string index
$mi 1] ne
{M
}} {
837 set s_lno
[lindex
[split [$ui_diff index @
$x,$y] .
] 0]
838 set s_lno
[$ui_diff search
-backwards -regexp ^@@
$s_lno.0 0.0]
844 set e_lno
[$ui_diff search
-forwards -regexp ^@@
"$s_lno + 1 lines" end
]
850 set p
[open
"| $apply_cmd" w
]
851 fconfigure
$p -translation binary
-encoding binary
852 puts
-nonewline $p $current_diff_header
853 puts
-nonewline $p [$ui_diff get
$s_lno $e_lno]
855 error_popup
"Failed to $mode selected hunk.\n\n$err"
860 $ui_diff conf
-state normal
861 $ui_diff delete
$s_lno $e_lno
862 $ui_diff conf
-state disabled
864 if {[$ui_diff get
1.0 end
] eq
"\n"} {
870 if {$current_diff_side eq
$ui_index} {
872 } elseif
{[string index
$mi 0] eq
{_
}} {
878 display_file
$current_diff_path $mi
884 ######################################################################
888 proc load_last_commit
{} {
889 global HEAD PARENT MERGE_HEAD commit_type ui_comm
892 if {[llength
$PARENT] == 0} {
893 error_popup
{There is nothing to amend.
895 You are about to create the initial commit.
896 There is no commit before this to amend.
901 repository_state curType curHEAD curMERGE_HEAD
902 if {$curType eq
{merge
}} {
903 error_popup
{Cannot amend
while merging.
905 You are currently
in the middle of a merge that
906 has not been fully completed. You cannot amend
907 the prior commit unless you first abort the
908 current merge activity.
916 set fd
[open
"| git cat-file commit $curHEAD" r
]
917 fconfigure
$fd -encoding binary
-translation lf
918 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
921 while {[gets
$fd line
] > 0} {
922 if {[string match
{parent
*} $line]} {
923 lappend parents
[string range
$line 7 end
]
924 } elseif
{[string match
{encoding
*} $line]} {
925 set enc
[string tolower
[string range
$line 9 end
]]
928 fconfigure
$fd -encoding $enc
929 set msg
[string trim
[read $fd]]
932 error_popup
"Error loading commit data for amend:\n\n$err"
938 set MERGE_HEAD
[list
]
939 switch
-- [llength
$parents] {
940 0 {set commit_type amend-initial
}
941 1 {set commit_type amend
}
942 default
{set commit_type amend-merge
}
945 $ui_comm delete
0.0 end
946 $ui_comm insert end
$msg
948 $ui_comm edit modified false
949 rescan
{set ui_status_value
{Ready.
}}
952 proc create_new_commit
{} {
953 global commit_type ui_comm
955 set commit_type normal
956 $ui_comm delete
0.0 end
958 $ui_comm edit modified false
959 rescan
{set ui_status_value
{Ready.
}}
962 set GIT_COMMITTER_IDENT
{}
964 proc committer_ident
{} {
965 global GIT_COMMITTER_IDENT
967 if {$GIT_COMMITTER_IDENT eq
{}} {
968 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
969 error_popup
"Unable to obtain your identity:\n\n$err"
972 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
973 $me me GIT_COMMITTER_IDENT
]} {
974 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
979 return $GIT_COMMITTER_IDENT
982 proc commit_tree
{} {
983 global HEAD commit_type file_states ui_comm repo_config
984 global ui_status_value pch_error
986 if {[committer_ident
] eq
{}} return
987 if {![lock_index update
]} return
989 # -- Our in memory state should match the repository.
991 repository_state curType curHEAD curMERGE_HEAD
992 if {[string match amend
* $commit_type]
993 && $curType eq
{normal
}
994 && $curHEAD eq
$HEAD} {
995 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
996 info_popup
{Last scanned state does not match repository state.
998 Another Git program has modified this repository
999 since the last scan. A rescan must be performed
1000 before another commit can be created.
1002 The rescan will be automatically started now.
1005 rescan
{set ui_status_value
{Ready.
}}
1009 # -- At least one file should differ in the index.
1012 foreach path
[array names file_states
] {
1013 switch
-glob -- [lindex
$file_states($path) 0] {
1017 M?
{set files_ready
1}
1019 error_popup
"Unmerged files cannot be committed.
1021 File [short_path $path] has merge conflicts.
1022 You must resolve them and add the file before committing.
1028 error_popup
"Unknown file state [lindex $s 0] detected.
1030 File [short_path $path] cannot be committed by this program.
1035 if {!$files_ready} {
1036 info_popup
{No changes to commit.
1038 You must add
at least
1 file before you can commit.
1044 # -- A message is required.
1046 set msg
[string trim
[$ui_comm get
1.0 end
]]
1047 regsub
-all -line {[ \t\r]+$
} $msg {} msg
1049 error_popup
{Please supply a commit message.
1051 A good commit message has the following format
:
1053 - First line
: Describe
in one sentance what you did.
1054 - Second line
: Blank
1055 - Remaining lines
: Describe why this change is good.
1061 # -- Run the pre-commit hook.
1063 set pchook
[gitdir hooks pre-commit
]
1065 # On Cygwin [file executable] might lie so we need to ask
1066 # the shell if the hook is executable. Yes that's annoying.
1068 if {[is_Windows
] && [file isfile
$pchook]} {
1069 set pchook
[list sh
-c [concat \
1070 "if test -x \"$pchook\";" \
1071 "then exec \"$pchook\" 2>&1;" \
1073 } elseif
{[file executable
$pchook]} {
1074 set pchook
[list
$pchook |
& cat]
1076 commit_writetree
$curHEAD $msg
1080 set ui_status_value
{Calling pre-commit hook...
}
1082 set fd_ph
[open
"| $pchook" r
]
1083 fconfigure
$fd_ph -blocking 0 -translation binary
1084 fileevent
$fd_ph readable \
1085 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1088 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1089 global pch_error ui_status_value
1091 append pch_error
[read $fd_ph]
1092 fconfigure
$fd_ph -blocking 1
1094 if {[catch
{close
$fd_ph}]} {
1095 set ui_status_value
{Commit declined by pre-commit hook.
}
1096 hook_failed_popup pre-commit
$pch_error
1099 commit_writetree
$curHEAD $msg
1104 fconfigure
$fd_ph -blocking 0
1107 proc commit_writetree
{curHEAD msg
} {
1108 global ui_status_value
1110 set ui_status_value
{Committing changes...
}
1111 set fd_wt
[open
"| git write-tree" r
]
1112 fileevent
$fd_wt readable \
1113 [list commit_committree
$fd_wt $curHEAD $msg]
1116 proc commit_committree
{fd_wt curHEAD msg
} {
1117 global HEAD PARENT MERGE_HEAD commit_type
1118 global single_commit all_heads current_branch
1119 global ui_status_value ui_comm selected_commit_type
1120 global file_states selected_paths rescan_active
1124 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1125 error_popup
"write-tree failed:\n\n$err"
1126 set ui_status_value
{Commit failed.
}
1131 # -- Build the message.
1133 set msg_p
[gitdir COMMIT_EDITMSG
]
1134 set msg_wt
[open
$msg_p w
]
1135 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1138 fconfigure
$msg_wt -encoding $enc -translation binary
1139 puts
-nonewline $msg_wt $msg
1142 # -- Create the commit.
1144 set cmd
[list git commit-tree
$tree_id]
1145 set parents
[concat
$PARENT $MERGE_HEAD]
1146 if {[llength
$parents] > 0} {
1147 foreach p
$parents {
1151 # git commit-tree writes to stderr during initial commit.
1152 lappend cmd
2>/dev
/null
1155 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1156 error_popup
"commit-tree failed:\n\n$err"
1157 set ui_status_value
{Commit failed.
}
1162 # -- Update the HEAD ref.
1165 if {$commit_type ne
{normal
}} {
1166 append reflogm
" ($commit_type)"
1168 set i
[string first
"\n" $msg]
1170 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1172 append reflogm
{: } $msg
1174 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1175 if {[catch
{eval exec $cmd} err
]} {
1176 error_popup
"update-ref failed:\n\n$err"
1177 set ui_status_value
{Commit failed.
}
1182 # -- Make sure our current branch exists.
1184 if {$commit_type eq
{initial
}} {
1185 lappend all_heads
$current_branch
1186 set all_heads
[lsort
-unique $all_heads]
1187 populate_branch_menu
1190 # -- Cleanup after ourselves.
1192 catch
{file delete
$msg_p}
1193 catch
{file delete
[gitdir MERGE_HEAD
]}
1194 catch
{file delete
[gitdir MERGE_MSG
]}
1195 catch
{file delete
[gitdir SQUASH_MSG
]}
1196 catch
{file delete
[gitdir GITGUI_MSG
]}
1198 # -- Let rerere do its thing.
1200 if {[file isdirectory
[gitdir rr-cache
]]} {
1201 catch
{exec git rerere
}
1204 # -- Run the post-commit hook.
1206 set pchook
[gitdir hooks post-commit
]
1207 if {[is_Windows
] && [file isfile
$pchook]} {
1208 set pchook
[list sh
-c [concat \
1209 "if test -x \"$pchook\";" \
1210 "then exec \"$pchook\";" \
1212 } elseif
{![file executable
$pchook]} {
1215 if {$pchook ne
{}} {
1216 catch
{exec $pchook &}
1219 $ui_comm delete
0.0 end
1221 $ui_comm edit modified false
1223 if {$single_commit} do_quit
1225 # -- Update in memory status
1227 set selected_commit_type new
1228 set commit_type normal
1231 set MERGE_HEAD
[list
]
1233 foreach path
[array names file_states
] {
1234 set s
$file_states($path)
1236 switch
-glob -- $m {
1244 unset file_states
($path)
1245 catch
{unset selected_paths
($path)}
1248 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1254 set file_states
($path) [list \
1255 _
[string index
$m 1] \
1266 set ui_status_value \
1267 "Changes committed as [string range $cmt_id 0 7]."
1270 ######################################################################
1274 proc fetch_from
{remote
} {
1275 set w
[new_console \
1277 "Fetching new changes from $remote"]
1278 set cmd
[list git fetch
]
1280 console_exec
$w $cmd console_done
1283 proc push_to
{remote
} {
1284 set w
[new_console \
1286 "Pushing changes to $remote"]
1287 set cmd
[list git push
]
1290 console_exec
$w $cmd console_done
1293 ######################################################################
1297 proc mapicon
{w state path
} {
1300 if {[catch
{set r
$all_icons($state$w)}]} {
1301 puts
"error: no icon for $w state={$state} $path"
1307 proc mapdesc
{state path
} {
1310 if {[catch
{set r
$all_descs($state)}]} {
1311 puts
"error: no desc for state={$state} $path"
1317 proc escape_path
{path
} {
1318 regsub
-all "\n" $path "\\n" path
1322 proc short_path
{path
} {
1323 return [escape_path
[lindex
[file split $path] end
]]
1327 set null_sha1
[string repeat
0 40]
1329 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1330 global file_states next_icon_id null_sha1
1332 set s0
[string index
$new_state 0]
1333 set s1
[string index
$new_state 1]
1335 if {[catch
{set info
$file_states($path)}]} {
1337 set icon n
[incr next_icon_id
]
1339 set state
[lindex
$info 0]
1340 set icon
[lindex
$info 1]
1341 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1342 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1345 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1346 elseif
{$s0 eq
{_
}} {set s0 _
}
1348 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1349 elseif
{$s1 eq
{_
}} {set s1 _
}
1351 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1352 set head_info
[list
0 $null_sha1]
1353 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1354 && $head_info eq
{}} {
1355 set head_info
$index_info
1358 set file_states
($path) [list
$s0$s1 $icon \
1359 $head_info $index_info \
1364 proc display_file_helper
{w path icon_name old_m new_m
} {
1367 if {$new_m eq
{_
}} {
1368 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1370 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1372 $w conf
-state normal
1373 $w delete
$lno.0 [expr {$lno + 1}].0
1374 $w conf
-state disabled
1376 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1377 lappend file_lists
($w) $path
1378 set file_lists
($w) [lsort
-unique $file_lists($w)]
1379 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1381 $w conf
-state normal
1382 $w image create
$lno.0 \
1383 -align center
-padx 5 -pady 1 \
1385 -image [mapicon
$w $new_m $path]
1386 $w insert
$lno.1 "[escape_path $path]\n"
1387 $w conf
-state disabled
1388 } elseif
{$old_m ne
$new_m} {
1389 $w conf
-state normal
1390 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1391 $w conf
-state disabled
1395 proc display_file
{path state
} {
1396 global file_states selected_paths
1397 global ui_index ui_workdir
1399 set old_m
[merge_state
$path $state]
1400 set s
$file_states($path)
1401 set new_m
[lindex
$s 0]
1402 set icon_name
[lindex
$s 1]
1404 set o
[string index
$old_m 0]
1405 set n
[string index
$new_m 0]
1412 display_file_helper
$ui_index $path $icon_name $o $n
1414 if {[string index
$old_m 0] eq
{U
}} {
1417 set o
[string index
$old_m 1]
1419 if {[string index
$new_m 0] eq
{U
}} {
1422 set n
[string index
$new_m 1]
1424 display_file_helper
$ui_workdir $path $icon_name $o $n
1426 if {$new_m eq
{__
}} {
1427 unset file_states
($path)
1428 catch
{unset selected_paths
($path)}
1432 proc display_all_files_helper
{w path icon_name m
} {
1435 lappend file_lists
($w) $path
1436 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1437 $w image create end \
1438 -align center
-padx 5 -pady 1 \
1440 -image [mapicon
$w $m $path]
1441 $w insert end
"[escape_path $path]\n"
1444 proc display_all_files
{} {
1445 global ui_index ui_workdir
1446 global file_states file_lists
1449 $ui_index conf
-state normal
1450 $ui_workdir conf
-state normal
1452 $ui_index delete
0.0 end
1453 $ui_workdir delete
0.0 end
1456 set file_lists
($ui_index) [list
]
1457 set file_lists
($ui_workdir) [list
]
1459 foreach path
[lsort
[array names file_states
]] {
1460 set s
$file_states($path)
1462 set icon_name
[lindex
$s 1]
1464 set s
[string index
$m 0]
1465 if {$s ne
{U
} && $s ne
{_
}} {
1466 display_all_files_helper
$ui_index $path \
1470 if {[string index
$m 0] eq
{U
}} {
1473 set s
[string index
$m 1]
1476 display_all_files_helper
$ui_workdir $path \
1481 $ui_index conf
-state disabled
1482 $ui_workdir conf
-state disabled
1485 proc update_indexinfo
{msg pathList after
} {
1486 global update_index_cp ui_status_value
1488 if {![lock_index update
]} return
1490 set update_index_cp
0
1491 set pathList
[lsort
$pathList]
1492 set totalCnt
[llength
$pathList]
1493 set batch [expr {int
($totalCnt * .01) + 1}]
1494 if {$batch > 25} {set batch 25}
1496 set ui_status_value
[format \
1497 "$msg... %i/%i files (%.2f%%)" \
1501 set fd
[open
"| git update-index -z --index-info" w
]
1508 fileevent
$fd writable
[list \
1509 write_update_indexinfo \
1519 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1520 global update_index_cp ui_status_value
1521 global file_states current_diff_path
1523 if {$update_index_cp >= $totalCnt} {
1530 for {set i
$batch} \
1531 {$update_index_cp < $totalCnt && $i > 0} \
1533 set path
[lindex
$pathList $update_index_cp]
1534 incr update_index_cp
1536 set s
$file_states($path)
1537 switch
-glob -- [lindex
$s 0] {
1544 set info
[lindex
$s 2]
1545 if {$info eq
{}} continue
1547 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1548 display_file
$path $new
1551 set ui_status_value
[format \
1552 "$msg... %i/%i files (%.2f%%)" \
1555 [expr {100.0 * $update_index_cp / $totalCnt}]]
1558 proc update_index
{msg pathList after
} {
1559 global update_index_cp ui_status_value
1561 if {![lock_index update
]} return
1563 set update_index_cp
0
1564 set pathList
[lsort
$pathList]
1565 set totalCnt
[llength
$pathList]
1566 set batch [expr {int
($totalCnt * .01) + 1}]
1567 if {$batch > 25} {set batch 25}
1569 set ui_status_value
[format \
1570 "$msg... %i/%i files (%.2f%%)" \
1574 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1581 fileevent
$fd writable
[list \
1582 write_update_index \
1592 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1593 global update_index_cp ui_status_value
1594 global file_states current_diff_path
1596 if {$update_index_cp >= $totalCnt} {
1603 for {set i
$batch} \
1604 {$update_index_cp < $totalCnt && $i > 0} \
1606 set path
[lindex
$pathList $update_index_cp]
1607 incr update_index_cp
1609 switch
-glob -- [lindex
$file_states($path) 0] {
1615 if {[file exists
$path]} {
1624 puts
-nonewline $fd "[encoding convertto $path]\0"
1625 display_file
$path $new
1628 set ui_status_value
[format \
1629 "$msg... %i/%i files (%.2f%%)" \
1632 [expr {100.0 * $update_index_cp / $totalCnt}]]
1635 proc checkout_index
{msg pathList after
} {
1636 global update_index_cp ui_status_value
1638 if {![lock_index update
]} return
1640 set update_index_cp
0
1641 set pathList
[lsort
$pathList]
1642 set totalCnt
[llength
$pathList]
1643 set batch [expr {int
($totalCnt * .01) + 1}]
1644 if {$batch > 25} {set batch 25}
1646 set ui_status_value
[format \
1647 "$msg... %i/%i files (%.2f%%)" \
1651 set cmd
[list git checkout-index
]
1657 set fd
[open
"| $cmd " w
]
1664 fileevent
$fd writable
[list \
1665 write_checkout_index \
1675 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1676 global update_index_cp ui_status_value
1677 global file_states current_diff_path
1679 if {$update_index_cp >= $totalCnt} {
1686 for {set i
$batch} \
1687 {$update_index_cp < $totalCnt && $i > 0} \
1689 set path
[lindex
$pathList $update_index_cp]
1690 incr update_index_cp
1691 switch
-glob -- [lindex
$file_states($path) 0] {
1695 puts
-nonewline $fd "[encoding convertto $path]\0"
1696 display_file
$path ?_
1701 set ui_status_value
[format \
1702 "$msg... %i/%i files (%.2f%%)" \
1705 [expr {100.0 * $update_index_cp / $totalCnt}]]
1708 ######################################################################
1710 ## branch management
1712 proc is_tracking_branch
{name
} {
1713 global tracking_branches
1715 if {![catch
{set info
$tracking_branches($name)}]} {
1718 foreach t
[array names tracking_branches
] {
1719 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1726 proc load_all_heads
{} {
1729 set all_heads
[list
]
1730 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1731 while {[gets
$fd line
] > 0} {
1732 if {[is_tracking_branch
$line]} continue
1733 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1734 lappend all_heads
$name
1738 set all_heads
[lsort
$all_heads]
1741 proc populate_branch_menu
{} {
1742 global all_heads disable_on_lock
1745 set last
[$m index last
]
1746 for {set i
0} {$i <= $last} {incr i
} {
1747 if {[$m type $i] eq
{separator
}} {
1750 foreach a
$disable_on_lock {
1751 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1755 set disable_on_lock
$new_dol
1760 if {$all_heads ne
{}} {
1763 foreach b
$all_heads {
1764 $m add radiobutton \
1766 -command [list switch_branch
$b] \
1767 -variable current_branch \
1770 lappend disable_on_lock \
1771 [list
$m entryconf
[$m index last
] -state]
1775 proc all_tracking_branches
{} {
1776 global tracking_branches
1778 set all_trackings
{}
1780 foreach name
[array names tracking_branches
] {
1781 if {[regsub
{/\
*$
} $name {} name
]} {
1784 regsub ^refs
/(heads|remotes
)/ $name {} name
1785 lappend all_trackings
$name
1790 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1791 while {[gets
$fd name
] > 0} {
1792 regsub ^refs
/(heads|remotes
)/ $name {} name
1793 lappend all_trackings
$name
1798 return [lsort
-unique $all_trackings]
1801 proc do_create_branch_action
{w
} {
1802 global all_heads null_sha1 repo_config
1803 global create_branch_checkout create_branch_revtype
1804 global create_branch_head create_branch_trackinghead
1805 global create_branch_name create_branch_revexp
1807 set newbranch
$create_branch_name
1808 if {$newbranch eq
{}
1809 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1813 -title [wm title
$w] \
1815 -message "Please supply a branch name."
1816 focus
$w.desc.name_t
1819 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1823 -title [wm title
$w] \
1825 -message "Branch '$newbranch' already exists."
1826 focus
$w.desc.name_t
1829 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1833 -title [wm title
$w] \
1835 -message "We do not like '$newbranch' as a branch name."
1836 focus
$w.desc.name_t
1841 switch
-- $create_branch_revtype {
1842 head {set rev $create_branch_head}
1843 tracking
{set rev $create_branch_trackinghead}
1844 expression
{set rev $create_branch_revexp}
1846 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1850 -title [wm title
$w] \
1852 -message "Invalid starting revision: $rev"
1855 set cmd
[list git update-ref
]
1857 lappend cmd
"branch: Created from $rev"
1858 lappend cmd
"refs/heads/$newbranch"
1860 lappend cmd
$null_sha1
1861 if {[catch
{eval exec $cmd} err
]} {
1865 -title [wm title
$w] \
1867 -message "Failed to create '$newbranch'.\n\n$err"
1871 lappend all_heads
$newbranch
1872 set all_heads
[lsort
$all_heads]
1873 populate_branch_menu
1875 if {$create_branch_checkout} {
1876 switch_branch
$newbranch
1880 proc radio_selector
{varname value args
} {
1881 upvar
#0 $varname var
1885 trace add variable create_branch_head
write \
1886 [list radio_selector create_branch_revtype
head]
1887 trace add variable create_branch_trackinghead
write \
1888 [list radio_selector create_branch_revtype tracking
]
1890 trace add variable delete_branch_head
write \
1891 [list radio_selector delete_branch_checktype
head]
1892 trace add variable delete_branch_trackinghead
write \
1893 [list radio_selector delete_branch_checktype tracking
]
1895 proc do_create_branch
{} {
1896 global all_heads current_branch repo_config
1897 global create_branch_checkout create_branch_revtype
1898 global create_branch_head create_branch_trackinghead
1899 global create_branch_name create_branch_revexp
1901 set w .branch_editor
1903 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1905 label
$w.header
-text {Create New Branch
} \
1907 pack
$w.header
-side top
-fill x
1910 button
$w.buttons.create
-text Create \
1913 -command [list do_create_branch_action
$w]
1914 pack
$w.buttons.create
-side right
1915 button
$w.buttons.cancel
-text {Cancel
} \
1917 -command [list destroy
$w]
1918 pack
$w.buttons.cancel
-side right
-padx 5
1919 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1921 labelframe
$w.desc \
1922 -text {Branch Description
} \
1924 label
$w.desc.name_l
-text {Name
:} -font font_ui
1925 entry
$w.desc.name_t \
1929 -textvariable create_branch_name \
1933 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
1936 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
1937 grid columnconfigure
$w.desc
1 -weight 1
1938 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
1940 labelframe
$w.from \
1941 -text {Starting Revision
} \
1943 radiobutton
$w.from.head_r \
1944 -text {Local Branch
:} \
1946 -variable create_branch_revtype \
1948 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
1949 grid
$w.from.head_r
$w.from.head_m
-sticky w
1950 set all_trackings
[all_tracking_branches
]
1951 if {$all_trackings ne
{}} {
1952 set create_branch_trackinghead
[lindex
$all_trackings 0]
1953 radiobutton
$w.from.tracking_r \
1954 -text {Tracking Branch
:} \
1956 -variable create_branch_revtype \
1958 eval tk_optionMenu
$w.from.tracking_m \
1959 create_branch_trackinghead \
1961 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
1963 radiobutton
$w.from.exp_r \
1964 -text {Revision Expression
:} \
1966 -variable create_branch_revtype \
1968 entry
$w.from.exp_t \
1972 -textvariable create_branch_revexp \
1976 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
1977 if {%d
== 1 && [string length
%S
] > 0} {
1978 set create_branch_revtype expression
1982 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
1983 grid columnconfigure
$w.from
1 -weight 1
1984 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1986 labelframe
$w.postActions \
1987 -text {Post Creation Actions
} \
1989 checkbutton
$w.postActions.checkout \
1990 -text {Checkout after creation
} \
1991 -variable create_branch_checkout \
1993 pack
$w.postActions.checkout
-anchor nw
1994 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1996 set create_branch_checkout
1
1997 set create_branch_head
$current_branch
1998 set create_branch_revtype
head
1999 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2000 set create_branch_revexp
{}
2002 bind $w <Visibility
> "
2004 $w.desc.name_t icursor end
2005 focus $w.desc.name_t
2007 bind $w <Key-Escape
> "destroy $w"
2008 bind $w <Key-Return
> "do_create_branch_action $w;break"
2009 wm title
$w "[appname] ([reponame]): Create Branch"
2013 proc do_delete_branch_action
{w
} {
2015 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2018 switch
-- $delete_branch_checktype {
2019 head {set check_rev
$delete_branch_head}
2020 tracking
{set check_rev
$delete_branch_trackinghead}
2021 always
{set check_rev
{:none
}}
2023 if {$check_rev eq
{:none
}} {
2025 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
2029 -title [wm title
$w] \
2031 -message "Invalid check revision: $check_rev"
2035 set to_delete
[list
]
2036 set not_merged
[list
]
2037 foreach i
[$w.list.l curselection
] {
2038 set b
[$w.list.l get
$i]
2039 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
2040 if {$check_cmt ne
{}} {
2041 if {$b eq
$check_rev} continue
2042 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
2044 lappend not_merged
$b
2048 lappend to_delete
[list
$b $o]
2050 if {$not_merged ne
{}} {
2051 set msg
"The following branches are not completely merged into $check_rev:
2053 - [join $not_merged "\n - "]"
2057 -title [wm title
$w] \
2061 if {$to_delete eq
{}} return
2062 if {$delete_branch_checktype eq
{always
}} {
2063 set msg
{Recovering deleted branches is difficult.
2065 Delete the selected branches?
}
2066 if {[tk_messageBox \
2069 -title [wm title
$w] \
2071 -message $msg] ne
yes} {
2077 foreach i
$to_delete {
2080 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2081 append failed
" - $b: $err\n"
2083 set x
[lsearch
-sorted -exact $all_heads $b]
2085 set all_heads
[lreplace
$all_heads $x $x]
2090 if {$failed ne
{}} {
2094 -title [wm title
$w] \
2096 -message "Failed to delete branches:\n$failed"
2099 set all_heads
[lsort
$all_heads]
2100 populate_branch_menu
2104 proc do_delete_branch
{} {
2105 global all_heads tracking_branches current_branch
2106 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2108 set w .branch_editor
2110 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2112 label
$w.header
-text {Delete Local Branch
} \
2114 pack
$w.header
-side top
-fill x
2117 button
$w.buttons.create
-text Delete \
2119 -command [list do_delete_branch_action
$w]
2120 pack
$w.buttons.create
-side right
2121 button
$w.buttons.cancel
-text {Cancel
} \
2123 -command [list destroy
$w]
2124 pack
$w.buttons.cancel
-side right
-padx 5
2125 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2127 labelframe
$w.list \
2128 -text {Local Branches
} \
2133 -selectmode extended \
2135 foreach h
$all_heads {
2136 if {$h ne
$current_branch} {
2137 $w.list.l insert end
$h
2140 pack
$w.list.l
-fill both
-pady 5 -padx 5
2141 pack
$w.list
-fill both
-pady 5 -padx 5
2143 labelframe
$w.validate \
2144 -text {Delete Only If
} \
2146 radiobutton
$w.validate.head_r \
2147 -text {Merged Into Local Branch
:} \
2149 -variable delete_branch_checktype \
2151 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2152 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2153 set all_trackings
[all_tracking_branches
]
2154 if {$all_trackings ne
{}} {
2155 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2156 radiobutton
$w.validate.tracking_r \
2157 -text {Merged Into Tracking Branch
:} \
2159 -variable delete_branch_checktype \
2161 eval tk_optionMenu
$w.validate.tracking_m \
2162 delete_branch_trackinghead \
2164 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2166 radiobutton
$w.validate.always_r \
2167 -text {Always
(Do not perform merge checks
)} \
2169 -variable delete_branch_checktype \
2171 grid
$w.validate.always_r
-columnspan 2 -sticky w
2172 grid columnconfigure
$w.validate
1 -weight 1
2173 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2175 set delete_branch_head
$current_branch
2176 set delete_branch_checktype
head
2178 bind $w <Visibility
> "grab $w; focus $w"
2179 bind $w <Key-Escape
> "destroy $w"
2180 wm title
$w "[appname] ([reponame]): Delete Branch"
2184 proc switch_branch
{new_branch
} {
2185 global HEAD commit_type current_branch repo_config
2187 if {![lock_index switch
]} return
2189 # -- Our in memory state should match the repository.
2191 repository_state curType curHEAD curMERGE_HEAD
2192 if {[string match amend
* $commit_type]
2193 && $curType eq
{normal
}
2194 && $curHEAD eq
$HEAD} {
2195 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2196 info_popup
{Last scanned state does not match repository state.
2198 Another Git program has modified this repository
2199 since the last scan. A rescan must be performed
2200 before the current branch can be changed.
2202 The rescan will be automatically started now.
2205 rescan
{set ui_status_value
{Ready.
}}
2209 # -- Don't do a pointless switch.
2211 if {$current_branch eq
$new_branch} {
2216 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2217 switch_branch_stage2
{} $new_branch
2219 set ui_status_value
{Refreshing
file status...
}
2220 set cmd
[list git update-index
]
2222 lappend cmd
--unmerged
2223 lappend cmd
--ignore-missing
2224 lappend cmd
--refresh
2225 set fd_rf
[open
"| $cmd" r
]
2226 fconfigure
$fd_rf -blocking 0 -translation binary
2227 fileevent
$fd_rf readable \
2228 [list switch_branch_stage2
$fd_rf $new_branch]
2232 proc switch_branch_stage2
{fd_rf new_branch
} {
2233 global ui_status_value HEAD
2237 if {![eof
$fd_rf]} return
2241 set ui_status_value
"Updating working directory to '$new_branch'..."
2242 set cmd
[list git read-tree
]
2245 lappend cmd
--exclude-per-directory=.gitignore
2247 lappend cmd
$new_branch
2248 set fd_rt
[open
"| $cmd" r
]
2249 fconfigure
$fd_rt -blocking 0 -translation binary
2250 fileevent
$fd_rt readable \
2251 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2254 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2255 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2256 global current_branch
2257 global ui_comm ui_status_value
2259 # -- We never get interesting output on stdout; only stderr.
2262 fconfigure
$fd_rt -blocking 1
2263 if {![eof
$fd_rt]} {
2264 fconfigure
$fd_rt -blocking 0
2268 # -- The working directory wasn't in sync with the index and
2269 # we'd have to overwrite something to make the switch. A
2270 # merge is required.
2272 if {[catch
{close
$fd_rt} err
]} {
2273 regsub
{^fatal
: } $err {} err
2274 warn_popup
"File level merge required.
2278 Staying on branch '$current_branch'."
2279 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2284 # -- Update the symbolic ref. Core git doesn't even check for failure
2285 # here, it Just Works(tm). If it doesn't we are in some really ugly
2286 # state that is difficult to recover from within git-gui.
2288 if {[catch
{exec git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2289 error_popup
"Failed to set current branch.
2291 This working directory is only partially switched.
2292 We successfully updated your files, but failed to
2293 update an internal Git file.
2295 This should not have occurred. [appname] will now
2303 # -- Update our repository state. If we were previously in amend mode
2304 # we need to toss the current buffer and do a full rescan to update
2305 # our file lists. If we weren't in amend mode our file lists are
2306 # accurate and we can avoid the rescan.
2309 set selected_commit_type new
2310 if {[string match amend
* $commit_type]} {
2311 $ui_comm delete
0.0 end
2313 $ui_comm edit modified false
2314 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2316 repository_state commit_type HEAD MERGE_HEAD
2318 set ui_status_value
"Checked out branch '$current_branch'."
2322 ######################################################################
2324 ## remote management
2326 proc load_all_remotes
{} {
2328 global all_remotes tracking_branches
2330 set all_remotes
[list
]
2331 array
unset tracking_branches
2333 set rm_dir
[gitdir remotes
]
2334 if {[file isdirectory
$rm_dir]} {
2335 set all_remotes
[glob \
2339 -directory $rm_dir *]
2341 foreach name
$all_remotes {
2343 set fd
[open
[file join $rm_dir $name] r
]
2344 while {[gets
$fd line
] >= 0} {
2345 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2346 $line line src dst
]} continue
2347 if {![regexp ^refs
/ $dst]} {
2348 set dst
"refs/heads/$dst"
2350 set tracking_branches
($dst) [list
$name $src]
2357 foreach line
[array names repo_config remote.
*.url
] {
2358 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2359 lappend all_remotes
$name
2361 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2365 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2366 if {![regexp ^refs
/ $dst]} {
2367 set dst
"refs/heads/$dst"
2369 set tracking_branches
($dst) [list
$name $src]
2373 set all_remotes
[lsort
-unique $all_remotes]
2376 proc populate_fetch_menu
{} {
2377 global all_remotes repo_config
2380 foreach r
$all_remotes {
2382 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2383 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2388 set fd
[open
[gitdir remotes
$r] r
]
2389 while {[gets
$fd n
] >= 0} {
2390 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2401 -label "Fetch from $r..." \
2402 -command [list fetch_from
$r] \
2408 proc populate_push_menu
{} {
2409 global all_remotes repo_config
2413 foreach r
$all_remotes {
2415 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2416 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2421 set fd
[open
[gitdir remotes
$r] r
]
2422 while {[gets
$fd n
] >= 0} {
2423 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2437 -label "Push to $r..." \
2438 -command [list push_to
$r] \
2445 proc start_push_anywhere_action
{w
} {
2446 global push_urltype push_remote push_url push_thin push_tags
2449 switch
-- $push_urltype {
2450 remote
{set r_url
$push_remote}
2451 url
{set r_url
$push_url}
2453 if {$r_url eq
{}} return
2455 set cmd
[list git push
]
2465 foreach i
[$w.
source.l curselection
] {
2466 set b
[$w.
source.l get
$i]
2467 lappend cmd
"refs/heads/$b:refs/heads/$b"
2472 } elseif
{$cnt == 1} {
2478 set cons
[new_console
"push $r_url" "Pushing $cnt $unit to $r_url"]
2479 console_exec
$cons $cmd console_done
2483 trace add variable push_remote
write \
2484 [list radio_selector push_urltype remote
]
2486 proc do_push_anywhere
{} {
2487 global all_heads all_remotes current_branch
2488 global push_urltype push_remote push_url push_thin push_tags
2492 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2494 label
$w.header
-text {Push Branches
} -font font_uibold
2495 pack
$w.header
-side top
-fill x
2498 button
$w.buttons.create
-text Push \
2500 -command [list start_push_anywhere_action
$w]
2501 pack
$w.buttons.create
-side right
2502 button
$w.buttons.cancel
-text {Cancel
} \
2504 -command [list destroy
$w]
2505 pack
$w.buttons.cancel
-side right
-padx 5
2506 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2508 labelframe
$w.
source \
2509 -text {Source Branches
} \
2511 listbox
$w.
source.l \
2514 -selectmode extended \
2516 foreach h
$all_heads {
2517 $w.
source.l insert end
$h
2518 if {$h eq
$current_branch} {
2519 $w.
source.l
select set end
2522 pack
$w.
source.l
-fill both
-pady 5 -padx 5
2523 pack
$w.
source -fill both
-pady 5 -padx 5
2525 labelframe
$w.dest \
2526 -text {Destination Repository
} \
2528 if {$all_remotes ne
{}} {
2529 radiobutton
$w.dest.remote_r \
2532 -variable push_urltype \
2534 eval tk_optionMenu
$w.dest.remote_m push_remote
$all_remotes
2535 grid
$w.dest.remote_r
$w.dest.remote_m
-sticky w
2536 if {[lsearch
-sorted -exact $all_remotes origin
] != -1} {
2537 set push_remote origin
2539 set push_remote
[lindex
$all_remotes 0]
2541 set push_urltype remote
2543 set push_urltype url
2545 radiobutton
$w.dest.url_r \
2546 -text {Arbitrary URL
:} \
2548 -variable push_urltype \
2550 entry
$w.dest.url_t \
2554 -textvariable push_url \
2558 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2559 if {%d
== 1 && [string length
%S
] > 0} {
2560 set push_urltype url
2564 grid
$w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
2565 grid columnconfigure
$w.dest
1 -weight 1
2566 pack
$w.dest
-anchor nw
-fill x
-pady 5 -padx 5
2568 labelframe
$w.options \
2569 -text {Transfer Options
} \
2571 checkbutton
$w.options.thin \
2572 -text {Use thin pack
(for slow network connections
)} \
2573 -variable push_thin \
2575 grid
$w.options.thin
-columnspan 2 -sticky w
2576 checkbutton
$w.options.tags \
2577 -text {Include tags
} \
2578 -variable push_tags \
2580 grid
$w.options.tags
-columnspan 2 -sticky w
2581 grid columnconfigure
$w.options
1 -weight 1
2582 pack
$w.options
-anchor nw
-fill x
-pady 5 -padx 5
2588 bind $w <Visibility
> "grab $w"
2589 bind $w <Key-Escape
> "destroy $w"
2590 wm title
$w "[appname] ([reponame]): Push"
2594 ######################################################################
2599 global HEAD commit_type file_states
2601 if {[string match amend
* $commit_type]} {
2602 info_popup
{Cannot merge
while amending.
2604 You must finish amending this commit before
2605 starting any
type of merge.
2610 if {[committer_ident
] eq
{}} {return 0}
2611 if {![lock_index merge
]} {return 0}
2613 # -- Our in memory state should match the repository.
2615 repository_state curType curHEAD curMERGE_HEAD
2616 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2617 info_popup
{Last scanned state does not match repository state.
2619 Another Git program has modified this repository
2620 since the last scan. A rescan must be performed
2621 before a merge can be performed.
2623 The rescan will be automatically started now.
2626 rescan
{set ui_status_value
{Ready.
}}
2630 foreach path
[array names file_states
] {
2631 switch
-glob -- [lindex
$file_states($path) 0] {
2633 error_popup
"You are in the middle of a conflicted merge.
2635 File [short_path $path] has merge conflicts.
2637 You must resolve them, add the file, and commit to
2638 complete the current merge. Only then can you
2639 begin another merge.
2650 proc visualize_local_merge
{w
} {
2652 foreach i
[$w.
source.l curselection
] {
2653 lappend revs
[$w.
source.l get
$i]
2655 if {$revs eq
{}} return
2656 lappend revs
--not HEAD
2660 proc start_local_merge_action
{w
} {
2661 global HEAD ui_status_value current_branch
2663 set cmd
[list git merge
]
2666 foreach i
[$w.
source.l curselection
] {
2667 set b
[$w.
source.l get
$i]
2675 } elseif
{$revcnt == 1} {
2677 } elseif
{$revcnt <= 15} {
2683 -title [wm title
$w] \
2685 -message "Too many branches selected.
2687 You have requested to merge $revcnt branches
2688 in an octopus merge. This exceeds Git's
2689 internal limit of 15 branches per merge.
2691 Please select fewer branches. To merge more
2692 than 15 branches, merge the branches in batches.
2697 set msg
"Merging $current_branch, [join $names {, }]"
2698 set ui_status_value
"$msg..."
2699 set cons
[new_console
"Merge" $msg]
2700 console_exec
$cons $cmd finish_merge
2701 bind $w <Destroy
> {}
2705 proc finish_merge
{w ok
} {
2708 set msg
{Merge completed successfully.
}
2710 set msg
{Merge failed. Conflict resolution is required.
}
2713 rescan
[list
set ui_status_value
$msg]
2716 proc do_local_merge
{} {
2717 global current_branch
2719 if {![can_merge
]} return
2723 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2726 -text "Merge Into $current_branch" \
2728 pack
$w.header
-side top
-fill x
2731 button
$w.buttons.visualize
-text Visualize \
2733 -command [list visualize_local_merge
$w]
2734 pack
$w.buttons.visualize
-side left
2735 button
$w.buttons.create
-text Merge \
2737 -command [list start_local_merge_action
$w]
2738 pack
$w.buttons.create
-side right
2739 button
$w.buttons.cancel
-text {Cancel
} \
2741 -command [list destroy
$w]
2742 pack
$w.buttons.cancel
-side right
-padx 5
2743 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2745 labelframe
$w.
source \
2746 -text {Source Branches
} \
2748 listbox
$w.
source.l \
2751 -selectmode extended \
2752 -yscrollcommand [list
$w.
source.sby
set] \
2754 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2755 pack
$w.
source.sby
-side right
-fill y
2756 pack
$w.
source.l
-side left
-fill both
-expand 1
2757 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2759 set cmd
[list git for-each-ref
]
2760 lappend cmd
{--format=%(objectname
) %(refname
)}
2761 lappend cmd refs
/heads
2762 lappend cmd refs
/remotes
2763 set fr_fd
[open
"| $cmd" r
]
2764 fconfigure
$fr_fd -translation binary
2765 while {[gets
$fr_fd line
] > 0} {
2766 set line
[split $line { }]
2767 set sha1
([lindex
$line 0]) [lindex
$line 1]
2772 set fr_fd
[open
"| git rev-list --all --not HEAD"]
2773 while {[gets
$fr_fd line
] > 0} {
2774 if {[catch
{set ref
$sha1($line)}]} continue
2775 regsub ^refs
/(heads|remotes
)/ $ref {} ref
2776 lappend to_show
$ref
2780 foreach ref
[lsort
-unique $to_show] {
2781 $w.
source.l insert end
$ref
2784 bind $w <Visibility
> "grab $w"
2785 bind $w <Key-Escape
> "unlock_index;destroy $w"
2786 bind $w <Destroy
> unlock_index
2787 wm title
$w "[appname] ([reponame]): Merge"
2791 proc do_reset_hard
{} {
2792 global HEAD commit_type file_states
2794 if {[string match amend
* $commit_type]} {
2795 info_popup
{Cannot abort
while amending.
2797 You must finish amending this commit.
2802 if {![lock_index abort
]} return
2804 if {[string match
*merge
* $commit_type]} {
2810 if {[ask_popup
"Abort $op?
2812 Aborting the current $op will cause
2813 *ALL* uncommitted changes to be lost.
2815 Continue with aborting the current $op?"] eq
{yes}} {
2816 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2817 fconfigure
$fd -blocking 0 -translation binary
2818 fileevent
$fd readable
[list reset_hard_wait
$fd]
2819 set ui_status_value
{Aborting... please
wait...
}
2825 proc reset_hard_wait
{fd
} {
2833 $ui_comm delete
0.0 end
2834 $ui_comm edit modified false
2836 catch
{file delete
[gitdir MERGE_HEAD
]}
2837 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
2838 catch
{file delete
[gitdir SQUASH_MSG
]}
2839 catch
{file delete
[gitdir MERGE_MSG
]}
2840 catch
{file delete
[gitdir GITGUI_MSG
]}
2842 rescan
{set ui_status_value
{Abort completed. Ready.
}}
2846 ######################################################################
2851 #define mask_width 14
2852 #define mask_height 15
2853 static unsigned char mask_bits
[] = {
2854 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2855 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2856 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2859 image create bitmap file_plain
-background white
-foreground black
-data {
2860 #define plain_width 14
2861 #define plain_height 15
2862 static unsigned char plain_bits
[] = {
2863 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2864 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2865 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2866 } -maskdata $filemask
2868 image create bitmap file_mod
-background white
-foreground blue
-data {
2869 #define mod_width 14
2870 #define mod_height 15
2871 static unsigned char mod_bits
[] = {
2872 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2873 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2874 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2875 } -maskdata $filemask
2877 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2878 #define file_fulltick_width 14
2879 #define file_fulltick_height 15
2880 static unsigned char file_fulltick_bits
[] = {
2881 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2882 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2883 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2884 } -maskdata $filemask
2886 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2887 #define parttick_width 14
2888 #define parttick_height 15
2889 static unsigned char parttick_bits
[] = {
2890 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2891 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2892 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2893 } -maskdata $filemask
2895 image create bitmap file_question
-background white
-foreground black
-data {
2896 #define file_question_width 14
2897 #define file_question_height 15
2898 static unsigned char file_question_bits
[] = {
2899 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2900 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2901 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2902 } -maskdata $filemask
2904 image create bitmap file_removed
-background white
-foreground red
-data {
2905 #define file_removed_width 14
2906 #define file_removed_height 15
2907 static unsigned char file_removed_bits
[] = {
2908 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2909 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2910 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2911 } -maskdata $filemask
2913 image create bitmap file_merge
-background white
-foreground blue
-data {
2914 #define file_merge_width 14
2915 #define file_merge_height 15
2916 static unsigned char file_merge_bits
[] = {
2917 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2918 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2919 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2920 } -maskdata $filemask
2922 set ui_index .vpane.files.index.list
2923 set ui_workdir .vpane.files.workdir.list
2925 set all_icons
(_
$ui_index) file_plain
2926 set all_icons
(A
$ui_index) file_fulltick
2927 set all_icons
(M
$ui_index) file_fulltick
2928 set all_icons
(D
$ui_index) file_removed
2929 set all_icons
(U
$ui_index) file_merge
2931 set all_icons
(_
$ui_workdir) file_plain
2932 set all_icons
(M
$ui_workdir) file_mod
2933 set all_icons
(D
$ui_workdir) file_question
2934 set all_icons
(U
$ui_workdir) file_merge
2935 set all_icons
(O
$ui_workdir) file_plain
2937 set max_status_desc
0
2941 {_M
"Modified, not staged"}
2942 {M_
"Staged for commit"}
2943 {MM
"Portions staged for commit"}
2944 {MD
"Staged for commit, missing"}
2946 {_O
"Untracked, not staged"}
2947 {A_
"Staged for commit"}
2948 {AM
"Portions staged for commit"}
2949 {AD
"Staged for commit, missing"}
2952 {D_
"Staged for removal"}
2953 {DO
"Staged for removal, still present"}
2955 {U_
"Requires merge resolution"}
2956 {UU
"Requires merge resolution"}
2957 {UM
"Requires merge resolution"}
2958 {UD
"Requires merge resolution"}
2960 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2961 set max_status_desc
[string length
[lindex
$i 1]]
2963 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2967 ######################################################################
2972 global tcl_platform tk_library
2973 if {[tk windowingsystem
] eq
{aqua
}} {
2979 proc is_Windows
{} {
2981 if {$tcl_platform(platform
) eq
{windows
}} {
2987 proc bind_button3
{w cmd
} {
2988 bind $w <Any-Button-3
> $cmd
2990 bind $w <Control-Button-1
> $cmd
2994 proc incr_font_size
{font
{amt
1}} {
2995 set sz
[font configure
$font -size]
2997 font configure
$font -size $sz
2998 font configure
${font}bold
-size $sz
3001 proc hook_failed_popup
{hook msg
} {
3006 label
$w.m.l1
-text "$hook hook failed:" \
3011 -background white
-borderwidth 1 \
3013 -width 80 -height 10 \
3015 -yscrollcommand [list
$w.m.sby
set]
3017 -text {You must correct the above errors before committing.
} \
3021 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3022 pack
$w.m.l1
-side top
-fill x
3023 pack
$w.m.l2
-side bottom
-fill x
3024 pack
$w.m.sby
-side right
-fill y
3025 pack
$w.m.t
-side left
-fill both
-expand 1
3026 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3028 $w.m.t insert
1.0 $msg
3029 $w.m.t conf
-state disabled
3031 button
$w.ok
-text OK \
3034 -command "destroy $w"
3035 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3037 bind $w <Visibility
> "grab $w; focus $w"
3038 bind $w <Key-Return
> "destroy $w"
3039 wm title
$w "[appname] ([reponame]): error"
3043 set next_console_id
0
3045 proc new_console
{short_title long_title
} {
3046 global next_console_id console_data
3047 set w .console
[incr next_console_id
]
3048 set console_data
($w) [list
$short_title $long_title]
3049 return [console_init
$w]
3052 proc console_init
{w
} {
3053 global console_cr console_data M1B
3055 set console_cr
($w) 1.0
3058 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3063 -background white
-borderwidth 1 \
3065 -width 80 -height 10 \
3068 -yscrollcommand [list
$w.m.sby
set]
3069 label
$w.m.s
-text {Working... please
wait...
} \
3073 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3074 pack
$w.m.l1
-side top
-fill x
3075 pack
$w.m.s
-side bottom
-fill x
3076 pack
$w.m.sby
-side right
-fill y
3077 pack
$w.m.t
-side left
-fill both
-expand 1
3078 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3080 menu
$w.ctxm
-tearoff 0
3081 $w.ctxm add
command -label "Copy" \
3083 -command "tk_textCopy $w.m.t"
3084 $w.ctxm add
command -label "Select All" \
3086 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3087 $w.ctxm add
command -label "Copy All" \
3090 $w.m.t tag add sel 0.0 end
3092 $w.m.t tag remove sel 0.0 end
3095 button
$w.ok
-text {Close
} \
3098 -command "destroy $w"
3099 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3101 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
3102 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3103 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3104 bind $w <Visibility
> "focus $w"
3105 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3109 proc console_exec
{w cmd after
} {
3110 # -- Windows tosses the enviroment when we exec our child.
3111 # But most users need that so we have to relogin. :-(
3114 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
3117 # -- Tcl won't let us redirect both stdout and stderr to
3118 # the same pipe. So pass it through cat...
3120 set cmd
[concat |
$cmd |
& cat]
3122 set fd_f
[open
$cmd r
]
3123 fconfigure
$fd_f -blocking 0 -translation binary
3124 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
3127 proc console_read
{w fd after
} {
3132 if {![winfo exists
$w]} {console_init
$w}
3133 $w.m.t conf
-state normal
3135 set n
[string length
$buf]
3137 set cr
[string first
"\r" $buf $c]
3138 set lf
[string first
"\n" $buf $c]
3139 if {$cr < 0} {set cr
[expr {$n + 1}]}
3140 if {$lf < 0} {set lf
[expr {$n + 1}]}
3143 $w.m.t insert end
[string range
$buf $c $lf]
3144 set console_cr
($w) [$w.m.t index
{end
-1c}]
3148 $w.m.t delete
$console_cr($w) end
3149 $w.m.t insert end
"\n"
3150 $w.m.t insert end
[string range
$buf $c $cr]
3155 $w.m.t conf
-state disabled
3159 fconfigure
$fd -blocking 1
3161 if {[catch
{close
$fd}]} {
3166 uplevel
#0 $after $w $ok
3169 fconfigure
$fd -blocking 0
3172 proc console_chain
{cmdlist w
{ok
1}} {
3174 if {[llength
$cmdlist] == 0} {
3179 set cmd
[lindex
$cmdlist 0]
3180 set cmdlist
[lrange
$cmdlist 1 end
]
3182 if {[lindex
$cmd 0] eq
{console_exec
}} {
3185 [list console_chain
$cmdlist]
3187 uplevel
#0 $cmd $cmdlist $w $ok
3194 proc console_done
{args
} {
3195 global console_cr console_data
3197 switch
-- [llength
$args] {
3199 set w
[lindex
$args 0]
3200 set ok
[lindex
$args 1]
3203 set w
[lindex
$args 1]
3204 set ok
[lindex
$args 2]
3207 error
"wrong number of args: console_done ?ignored? w ok"
3212 if {[winfo exists
$w]} {
3213 $w.m.s conf
-background green
-text {Success
}
3214 $w.ok conf
-state normal
3217 if {![winfo exists
$w]} {
3220 $w.m.s conf
-background red
-text {Error
: Command Failed
}
3221 $w.ok conf
-state normal
3224 array
unset console_cr
$w
3225 array
unset console_data
$w
3228 ######################################################################
3232 set starting_gitk_msg
{Starting gitk... please
wait...
}
3234 proc do_gitk
{revs
} {
3235 global ui_status_value starting_gitk_msg
3243 set cmd
"sh -c \"exec $cmd\""
3247 if {[catch
{eval exec $cmd} err
]} {
3248 error_popup
"Failed to start gitk:\n\n$err"
3250 set ui_status_value
$starting_gitk_msg
3252 if {$ui_status_value eq
$starting_gitk_msg} {
3253 set ui_status_value
{Ready.
}
3260 set fd
[open
"| git count-objects -v" r
]
3261 while {[gets
$fd line
] > 0} {
3262 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
3263 set stats
($name) $value
3269 foreach p
[glob
-directory [gitdir objects pack
] \
3272 incr packed_sz
[file size
$p]
3274 if {$packed_sz > 0} {
3275 set stats
(size-pack
) [expr {$packed_sz / 1024}]
3280 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3282 label
$w.header
-text {Database Statistics
} \
3284 pack
$w.header
-side top
-fill x
3286 frame
$w.buttons
-border 1
3287 button
$w.buttons.close
-text Close \
3289 -command [list destroy
$w]
3290 button
$w.buttons.gc
-text {Compress Database
} \
3292 -command "destroy $w;do_gc"
3293 pack
$w.buttons.close
-side right
3294 pack
$w.buttons.gc
-side left
3295 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3297 frame
$w.stat
-borderwidth 1 -relief solid
3299 {count
{Number of loose objects
}}
3300 {size
{Disk space used by loose objects
} { KiB
}}
3301 {in-pack
{Number of packed objects
}}
3302 {packs
{Number of packs
}}
3303 {size-pack
{Disk space used by packed objects
} { KiB
}}
3304 {prune-packable
{Packed objects waiting
for pruning
}}
3305 {garbage
{Garbage files
}}
3307 set name
[lindex
$s 0]
3308 set label
[lindex
$s 1]
3309 if {[catch
{set value
$stats($name)}]} continue
3310 if {[llength
$s] > 2} {
3311 set value
"$value[lindex $s 2]"
3314 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
3315 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
3316 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
3318 pack
$w.stat
-pady 10 -padx 10
3320 bind $w <Visibility
> "grab $w; focus $w"
3321 bind $w <Key-Escape
> [list destroy
$w]
3322 bind $w <Key-Return
> [list destroy
$w]
3323 wm title
$w "[appname] ([reponame]): Database Statistics"
3328 set w
[new_console
{gc
} {Compressing the object database
}]
3330 {console_exec
{git pack-refs
--prune}}
3331 {console_exec
{git reflog expire
--all}}
3332 {console_exec
{git repack
-a -d -l}}
3333 {console_exec
{git rerere gc
}}
3337 proc do_fsck_objects
{} {
3338 set w
[new_console
{fsck-objects
} \
3339 {Verifying the object database with fsck-objects
}]
3340 set cmd
[list git fsck-objects
]
3343 lappend cmd
--strict
3344 console_exec
$w $cmd console_done
3350 global ui_comm is_quitting repo_config commit_type
3352 if {$is_quitting} return
3355 # -- Stash our current commit buffer.
3357 set save
[gitdir GITGUI_MSG
]
3358 set msg
[string trim
[$ui_comm get
0.0 end
]]
3359 regsub
-all -line {[ \r\t]+$
} $msg {} msg
3360 if {(![string match amend
* $commit_type]
3361 ||
[$ui_comm edit modified
])
3364 set fd
[open
$save w
]
3365 puts
-nonewline $fd $msg
3369 catch
{file delete
$save}
3372 # -- Stash our current window geometry into this repository.
3374 set cfg_geometry
[list
]
3375 lappend cfg_geometry
[wm geometry .
]
3376 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
3377 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
3378 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
3381 if {$cfg_geometry ne
$rc_geometry} {
3382 catch
{exec git repo-config gui.geometry
$cfg_geometry}
3389 rescan
{set ui_status_value
{Ready.
}}
3392 proc unstage_helper
{txt paths
} {
3393 global file_states current_diff_path
3395 if {![lock_index begin-update
]} return
3399 foreach path
$paths {
3400 switch
-glob -- [lindex
$file_states($path) 0] {
3404 lappend pathList
$path
3405 if {$path eq
$current_diff_path} {
3406 set after
{reshow_diff
;}
3411 if {$pathList eq
{}} {
3417 [concat
$after {set ui_status_value
{Ready.
}}]
3421 proc do_unstage_selection
{} {
3422 global current_diff_path selected_paths
3424 if {[array size selected_paths
] > 0} {
3426 {Unstaging selected files from commit
} \
3427 [array names selected_paths
]
3428 } elseif
{$current_diff_path ne
{}} {
3430 "Unstaging [short_path $current_diff_path] from commit" \
3431 [list
$current_diff_path]
3435 proc add_helper
{txt paths
} {
3436 global file_states current_diff_path
3438 if {![lock_index begin-update
]} return
3442 foreach path
$paths {
3443 switch
-glob -- [lindex
$file_states($path) 0] {
3448 lappend pathList
$path
3449 if {$path eq
$current_diff_path} {
3450 set after
{reshow_diff
;}
3455 if {$pathList eq
{}} {
3461 [concat
$after {set ui_status_value
{Ready to commit.
}}]
3465 proc do_add_selection
{} {
3466 global current_diff_path selected_paths
3468 if {[array size selected_paths
] > 0} {
3470 {Adding selected files
} \
3471 [array names selected_paths
]
3472 } elseif
{$current_diff_path ne
{}} {
3474 "Adding [short_path $current_diff_path]" \
3475 [list
$current_diff_path]
3479 proc do_add_all
{} {
3483 foreach path
[array names file_states
] {
3484 switch
-glob -- [lindex
$file_states($path) 0] {
3487 ?D
{lappend paths
$path}
3490 add_helper
{Adding all changed files
} $paths
3493 proc revert_helper
{txt paths
} {
3494 global file_states current_diff_path
3496 if {![lock_index begin-update
]} return
3500 foreach path
$paths {
3501 switch
-glob -- [lindex
$file_states($path) 0] {
3505 lappend pathList
$path
3506 if {$path eq
$current_diff_path} {
3507 set after
{reshow_diff
;}
3513 set n
[llength
$pathList]
3517 } elseif
{$n == 1} {
3518 set s
"[short_path [lindex $pathList]]"
3520 set s
"these $n files"
3523 set reply
[tk_dialog \
3525 "[appname] ([reponame])" \
3526 "Revert changes in $s?
3528 Any unadded changes will be permanently lost by the revert." \
3538 [concat
$after {set ui_status_value
{Ready.
}}]
3544 proc do_revert_selection
{} {
3545 global current_diff_path selected_paths
3547 if {[array size selected_paths
] > 0} {
3549 {Reverting selected files
} \
3550 [array names selected_paths
]
3551 } elseif
{$current_diff_path ne
{}} {
3553 "Reverting [short_path $current_diff_path]" \
3554 [list
$current_diff_path]
3558 proc do_signoff
{} {
3561 set me
[committer_ident
]
3562 if {$me eq
{}} return
3564 set sob
"Signed-off-by: $me"
3565 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
3566 if {$last ne
$sob} {
3567 $ui_comm edit separator
3569 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
3570 $ui_comm insert end
"\n"
3572 $ui_comm insert end
"\n$sob"
3573 $ui_comm edit separator
3578 proc do_select_commit_type
{} {
3579 global commit_type selected_commit_type
3581 if {$selected_commit_type eq
{new
}
3582 && [string match amend
* $commit_type]} {
3584 } elseif
{$selected_commit_type eq
{amend
}
3585 && ![string match amend
* $commit_type]} {
3588 # The amend request was rejected...
3590 if {![string match amend
* $commit_type]} {
3591 set selected_commit_type new
3601 global appvers copyright
3602 global tcl_patchLevel tk_patchLevel
3606 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3608 label
$w.header
-text "About [appname]" \
3610 pack
$w.header
-side top
-fill x
3613 button
$w.buttons.close
-text {Close
} \
3615 -command [list destroy
$w]
3616 pack
$w.buttons.close
-side right
3617 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3620 -text "[appname] - a commit creation tool for Git.
3628 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
3631 append v
"[appname] version $appvers\n"
3632 append v
"[exec git version]\n"
3634 if {$tcl_patchLevel eq
$tk_patchLevel} {
3635 append v
"Tcl/Tk version $tcl_patchLevel"
3637 append v
"Tcl version $tcl_patchLevel"
3638 append v
", Tk version $tk_patchLevel"
3649 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
3651 menu
$w.ctxm
-tearoff 0
3652 $w.ctxm add
command \
3657 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
3660 bind $w <Visibility
> "grab $w; focus $w"
3661 bind $w <Key-Escape
> "destroy $w"
3662 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3663 wm title
$w "About [appname]"
3667 proc do_options
{} {
3668 global repo_config global_config font_descs
3669 global repo_config_new global_config_new
3671 array
unset repo_config_new
3672 array
unset global_config_new
3673 foreach name
[array names repo_config
] {
3674 set repo_config_new
($name) $repo_config($name)
3677 foreach name
[array names repo_config
] {
3679 gui.diffcontext
{continue}
3681 set repo_config_new
($name) $repo_config($name)
3683 foreach name
[array names global_config
] {
3684 set global_config_new
($name) $global_config($name)
3687 set w .options_editor
3689 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3691 label
$w.header
-text "[appname] Options" \
3693 pack
$w.header
-side top
-fill x
3696 button
$w.buttons.restore
-text {Restore Defaults
} \
3698 -command do_restore_defaults
3699 pack
$w.buttons.restore
-side left
3700 button
$w.buttons.save
-text Save \
3702 -command [list do_save_config
$w]
3703 pack
$w.buttons.save
-side right
3704 button
$w.buttons.cancel
-text {Cancel
} \
3706 -command [list destroy
$w]
3707 pack
$w.buttons.cancel
-side right
-padx 5
3708 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3710 labelframe
$w.repo
-text "[reponame] Repository" \
3712 labelframe
$w.global
-text {Global
(All Repositories
)} \
3714 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3715 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3718 {b pullsummary
{Show Pull Summary
}}
3719 {b trustmtime
{Trust File Modification Timestamps
}}
3720 {i diffcontext
{Number of Diff Context Lines
}}
3721 {t newbranchtemplate
{New Branch Name Template
}}
3723 set type [lindex
$option 0]
3724 set name
[lindex
$option 1]
3725 set text
[lindex
$option 2]
3726 foreach f
{repo global
} {
3729 checkbutton
$w.
$f.
$name -text $text \
3730 -variable ${f}_config_new
(gui.
$name) \
3734 pack
$w.
$f.
$name -side top
-anchor w
3738 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3739 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
3740 spinbox
$w.
$f.
$name.v \
3741 -textvariable ${f}_config_new
(gui.
$name) \
3742 -from 1 -to 99 -increment 1 \
3745 bind $w.
$f.
$name.v
<FocusIn
> {%W selection range
0 end
}
3746 pack
$w.
$f.
$name.v
-side right
-anchor e
-padx 5
3747 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3751 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3752 entry
$w.
$f.
$name.v \
3756 -textvariable ${f}_config_new
(gui.
$name) \
3758 pack
$w.
$f.
$name.l
-side left
-anchor w
3759 pack
$w.
$f.
$name.v
-side left
-anchor w \
3762 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3768 set all_fonts
[lsort
[font families
]]
3769 foreach option
$font_descs {
3770 set name
[lindex
$option 0]
3771 set font
[lindex
$option 1]
3772 set text
[lindex
$option 2]
3774 set global_config_new
(gui.
$font^^family
) \
3775 [font configure
$font -family]
3776 set global_config_new
(gui.
$font^^size
) \
3777 [font configure
$font -size]
3779 frame
$w.global.
$name
3780 label
$w.global.
$name.l
-text "$text:" -font font_ui
3781 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3782 eval tk_optionMenu
$w.global.
$name.family \
3783 global_config_new
(gui.
$font^^family
) \
3785 spinbox
$w.global.
$name.size \
3786 -textvariable global_config_new
(gui.
$font^^size
) \
3787 -from 2 -to 80 -increment 1 \
3790 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3791 pack
$w.global.
$name.size
-side right
-anchor e
3792 pack
$w.global.
$name.family
-side right
-anchor e
3793 pack
$w.global.
$name -side top
-anchor w
-fill x
3796 bind $w <Visibility
> "grab $w; focus $w"
3797 bind $w <Key-Escape
> "destroy $w"
3798 wm title
$w "[appname] ([reponame]): Options"
3802 proc do_restore_defaults
{} {
3803 global font_descs default_config repo_config
3804 global repo_config_new global_config_new
3806 foreach name
[array names default_config
] {
3807 set repo_config_new
($name) $default_config($name)
3808 set global_config_new
($name) $default_config($name)
3811 foreach option
$font_descs {
3812 set name
[lindex
$option 0]
3813 set repo_config
(gui.
$name) $default_config(gui.
$name)
3817 foreach option
$font_descs {
3818 set name
[lindex
$option 0]
3819 set font
[lindex
$option 1]
3820 set global_config_new
(gui.
$font^^family
) \
3821 [font configure
$font -family]
3822 set global_config_new
(gui.
$font^^size
) \
3823 [font configure
$font -size]
3827 proc do_save_config
{w
} {
3828 if {[catch
{save_config
} err
]} {
3829 error_popup
"Failed to completely save options:\n\n$err"
3835 proc do_windows_shortcut
{} {
3839 set desktop
[exec cygpath \
3847 set fn
[tk_getSaveFile \
3849 -title "[appname] ([reponame]): Create Desktop Icon" \
3850 -initialdir $desktop \
3851 -initialfile "Git [reponame].bat"]
3855 set sh
[exec cygpath \
3859 set me
[exec cygpath \
3863 set gd
[exec cygpath \
3867 set gw
[exec cygpath \
3870 [file dirname [gitdir
]]]
3871 regsub
-all ' $me "'\\''" me
3872 regsub -all ' $gd "'\\''" gd
3873 puts $fd "@ECHO Entering $gw"
3874 puts $fd "@ECHO Starting git-gui... please wait..."
3875 puts -nonewline $fd "@\"$sh\" --login -c \""
3876 puts -nonewline $fd "GIT_DIR='$gd'"
3877 puts -nonewline $fd " '$me'"
3881 error_popup "Cannot write script:\n\n$err"
3886 proc do_macosx_app {} {
3889 set fn [tk_getSaveFile \
3891 -title "[appname] ([reponame]): Create Desktop Icon" \
3892 -initialdir [file join $env(HOME) Desktop] \
3893 -initialfile "Git [reponame].app"]
3896 set Contents [file join $fn Contents]
3897 set MacOS [file join $Contents MacOS]
3898 set exe [file join $MacOS git-gui]
3902 set fd [open [file join $Contents Info.plist] w]
3903 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3904 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3905 <plist version="1.0">
3907 <key>CFBundleDevelopmentRegion</key>
3908 <string>English</string>
3909 <key>CFBundleExecutable</key>
3910 <string>git-gui</string>
3911 <key>CFBundleIdentifier</key>
3912 <string>org.spearce.git-gui</string>
3913 <key>CFBundleInfoDictionaryVersion</key>
3914 <string>6.0</string>
3915 <key>CFBundlePackageType</key>
3916 <string>APPL</string>
3917 <key>CFBundleSignature</key>
3918 <string>????</string>
3919 <key>CFBundleVersion</key>
3920 <string>1.0</string>
3921 <key>NSPrincipalClass</key>
3922 <string>NSApplication</string>
3927 set fd [open $exe w]
3928 set gd [file normalize [gitdir]]
3929 set ep [file normalize [exec git --exec-path]]
3930 regsub -all ' $gd "'\\''" gd
3931 regsub
-all ' $ep "'\\''" ep
3932 puts $fd "#!/bin/sh"
3933 foreach name
[array names env
] {
3934 if {[string match GIT_
* $name]} {
3935 regsub
-all ' $env($name) "'\\''" v
3936 puts $fd "export $name='$v'"
3939 puts $fd "export PATH
='$ep':\
$PATH"
3940 puts $fd "export GIT_DIR
='$gd'"
3941 puts $fd "exec [file normalize
$argv0]"
3944 file attributes $exe -permissions u+x,g+x,o+x
3946 error_popup "Cannot
write icon
:\n\n$err"
3951 proc toggle_or_diff {w x y} {
3952 global file_states file_lists current_diff_path ui_index ui_workdir
3953 global last_clicked selected_paths
3955 set pos [split [$w index @$x,$y] .]
3956 set lno [lindex $pos 0]
3957 set col [lindex $pos 1]
3958 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3964 set last_clicked [list $w $lno]
3965 array unset selected_paths
3966 $ui_index tag remove in_sel 0.0 end
3967 $ui_workdir tag remove in_sel 0.0 end
3970 if {$current_diff_path eq $path} {
3971 set after {reshow_diff;}
3975 if {$w eq $ui_index} {
3977 "Unstaging
[short_path
$path] from commit
" \
3979 [concat $after {set ui_status_value {Ready.}}]
3980 } elseif {$w eq $ui_workdir} {
3982 "Adding
[short_path
$path]" \
3984 [concat $after {set ui_status_value {Ready.}}]
3987 show_diff $path $w $lno
3991 proc add_one_to_selection {w x y} {
3992 global file_lists last_clicked selected_paths
3994 set lno [lindex [split [$w index @$x,$y] .] 0]
3995 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4001 if {$last_clicked ne {}
4002 && [lindex $last_clicked 0] ne $w} {
4003 array unset selected_paths
4004 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4007 set last_clicked [list $w $lno]
4008 if {[catch {set in_sel $selected_paths($path)}]} {
4012 unset selected_paths($path)
4013 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4015 set selected_paths($path) 1
4016 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4020 proc add_range_to_selection {w x y} {
4021 global file_lists last_clicked selected_paths
4023 if {[lindex $last_clicked 0] ne $w} {
4024 toggle_or_diff $w $x $y
4028 set lno [lindex [split [$w index @$x,$y] .] 0]
4029 set lc [lindex $last_clicked 1]
4038 foreach path [lrange $file_lists($w) \
4039 [expr {$begin - 1}] \
4040 [expr {$end - 1}]] {
4041 set selected_paths($path) 1
4043 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4046 ######################################################################
4050 set cursor_ptr arrow
4051 font create font_diff -family Courier -size 10
4055 eval font configure font_ui [font actual [.dummy cget -font]]
4059 font create font_uibold
4060 font create font_diffbold
4065 } elseif {[is_MacOSX]} {
4073 proc apply_config {} {
4074 global repo_config font_descs
4076 foreach option $font_descs {
4077 set name [lindex $option 0]
4078 set font [lindex $option 1]
4080 foreach {cn cv} $repo_config(gui.$name) {
4081 font configure $font $cn $cv
4084 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
4086 foreach {cn cv} [font configure $font] {
4087 font configure ${font}bold $cn $cv
4089 font configure ${font}bold -weight bold
4093 set default_config(gui.trustmtime) false
4094 set default_config(gui.pullsummary) true
4095 set default_config(gui.diffcontext) 5
4096 set default_config(gui.newbranchtemplate) {}
4097 set default_config(gui.fontui) [font configure font_ui]
4098 set default_config(gui.fontdiff) [font configure font_diff]
4100 {fontui font_ui {Main Font}}
4101 {fontdiff font_diff {Diff/Console Font}}
4106 ######################################################################
4112 menu .mbar -tearoff 0
4113 .mbar add cascade -label Repository -menu .mbar.repository
4114 .mbar add cascade -label Edit -menu .mbar.edit
4115 if {!$single_commit} {
4116 .mbar add cascade -label Branch -menu .mbar.branch
4118 .mbar add cascade -label Commit -menu .mbar.commit
4119 if {!$single_commit} {
4120 .mbar add cascade -label Merge -menu .mbar.merge
4121 .mbar add cascade -label Fetch -menu .mbar.fetch
4122 .mbar add cascade -label Push -menu .mbar.push
4124 . configure -menu .mbar
4126 # -- Repository Menu
4128 menu .mbar.repository
4129 .mbar.repository add command \
4130 -label {Visualize Current Branch} \
4131 -command {do_gitk {}} \
4133 .mbar.repository add command \
4134 -label {Visualize All Branches} \
4135 -command {do_gitk {--all}} \
4137 .mbar.repository add separator
4139 if {!$single_commit} {
4140 .mbar.repository add command -label {Database Statistics} \
4144 .mbar.repository add command -label {Compress Database} \
4148 .mbar.repository add command -label {Verify Database} \
4149 -command do_fsck_objects \
4152 .mbar.repository add separator
4155 .mbar.repository add command \
4156 -label {Create Desktop Icon} \
4157 -command do_windows_shortcut \
4159 } elseif {[is_MacOSX]} {
4160 .mbar.repository add command \
4161 -label {Create Desktop Icon} \
4162 -command do_macosx_app \
4167 .mbar.repository add command -label Quit \
4169 -accelerator $M1T-Q \
4175 .mbar.edit add command -label Undo \
4176 -command {catch {[focus] edit undo}} \
4177 -accelerator $M1T-Z \
4179 .mbar.edit add command -label Redo \
4180 -command {catch {[focus] edit redo}} \
4181 -accelerator $M1T-Y \
4183 .mbar.edit add separator
4184 .mbar.edit add command -label Cut \
4185 -command {catch {tk_textCut [focus]}} \
4186 -accelerator $M1T-X \
4188 .mbar.edit add command -label Copy \
4189 -command {catch {tk_textCopy [focus]}} \
4190 -accelerator $M1T-C \
4192 .mbar.edit add command -label Paste \
4193 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
4194 -accelerator $M1T-V \
4196 .mbar.edit add command -label Delete \
4197 -command {catch {[focus] delete sel.first sel.last}} \
4200 .mbar.edit add separator
4201 .mbar.edit add command -label {Select All} \
4202 -command {catch {[focus] tag add sel 0.0 end}} \
4203 -accelerator $M1T-A \
4208 if {!$single_commit} {
4211 .mbar.branch add command -label {Create...} \
4212 -command do_create_branch \
4213 -accelerator $M1T-N \
4215 lappend disable_on_lock [list .mbar.branch entryconf \
4216 [.mbar.branch index last] -state]
4218 .mbar.branch add command -label {Delete...} \
4219 -command do_delete_branch \
4221 lappend disable_on_lock [list .mbar.branch entryconf \
4222 [.mbar.branch index last] -state]
4229 .mbar.commit add radiobutton \
4230 -label {New Commit} \
4231 -command do_select_commit_type \
4232 -variable selected_commit_type \
4235 lappend disable_on_lock \
4236 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4238 .mbar.commit add radiobutton \
4239 -label {Amend Last Commit} \
4240 -command do_select_commit_type \
4241 -variable selected_commit_type \
4244 lappend disable_on_lock \
4245 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4247 .mbar.commit add separator
4249 .mbar.commit add command -label Rescan \
4250 -command do_rescan \
4253 lappend disable_on_lock \
4254 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4256 .mbar.commit add command -label {Add To Commit} \
4257 -command do_add_selection \
4259 lappend disable_on_lock \
4260 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4262 .mbar.commit add command -label {Add All To Commit} \
4263 -command do_add_all \
4264 -accelerator $M1T-I \
4266 lappend disable_on_lock \
4267 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4269 .mbar.commit add command -label {Unstage From Commit} \
4270 -command do_unstage_selection \
4272 lappend disable_on_lock \
4273 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4275 .mbar.commit add command -label {Revert Changes} \
4276 -command do_revert_selection \
4278 lappend disable_on_lock \
4279 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4281 .mbar.commit add separator
4283 .mbar.commit add command -label {Sign Off} \
4284 -command do_signoff \
4285 -accelerator $M1T-S \
4288 .mbar.commit add command -label Commit \
4289 -command do_commit \
4290 -accelerator $M1T-Return \
4292 lappend disable_on_lock \
4293 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4296 # -- Apple Menu (Mac OS X only)
4298 .mbar add cascade -label Apple -menu .mbar.apple
4301 .mbar.apple add command -label "About
[appname
]" \
4304 .mbar.apple add command -label "[appname
] Options...
" \
4305 -command do_options \
4310 .mbar.edit add separator
4311 .mbar.edit add command -label {Options...} \
4312 -command do_options \
4317 if {[file exists /usr/local/miga/lib/gui-miga]
4318 && [file exists .pvcsrc]} {
4320 global ui_status_value
4321 if {![lock_index update]} return
4322 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
4323 set miga_fd [open "|
$cmd" r]
4324 fconfigure $miga_fd -blocking 0
4325 fileevent $miga_fd readable [list miga_done $miga_fd]
4326 set ui_status_value {Running miga...}
4328 proc miga_done {fd} {
4333 rescan [list set ui_status_value {Ready.}]
4336 .mbar add cascade -label Tools -menu .mbar.tools
4338 .mbar.tools add command -label "Migrate
" \
4341 lappend disable_on_lock \
4342 [list .mbar.tools entryconf [.mbar.tools index last] -state]
4347 .mbar add cascade -label Help -menu .mbar.help
4350 .mbar.help add command -label "About
[appname
]" \
4362 -text {Current Branch:} \
4367 -textvariable current_branch \
4371 pack .branch.l1 -side left
4372 pack .branch.cb -side left -fill x
4373 pack .branch -side top -fill x
4375 if {!$single_commit} {
4377 .mbar.merge add command -label {Local Merge...} \
4378 -command do_local_merge \
4380 lappend disable_on_lock \
4381 [list .mbar.merge entryconf [.mbar.merge index last] -state]
4382 .mbar.merge add command -label {Abort Merge...} \
4383 -command do_reset_hard \
4385 lappend disable_on_lock \
4386 [list .mbar.merge entryconf [.mbar.merge index last] -state]
4392 .mbar.push add command -label {Push...} \
4393 -command do_push_anywhere \
4397 # -- Main Window Layout
4399 panedwindow .vpane -orient vertical
4400 panedwindow .vpane.files -orient horizontal
4401 .vpane add .vpane.files -sticky nsew -height 100 -width 200
4402 pack .vpane -anchor n -side top -fill both -expand 1
4404 # -- Index File List
4406 frame .vpane.files.index -height 100 -width 200
4407 label .vpane.files.index.title -text {Changes To Be Committed} \
4410 text $ui_index -background white -borderwidth 0 \
4411 -width 20 -height 10 \
4414 -cursor $cursor_ptr \
4415 -xscrollcommand {.vpane.files.index.sx set} \
4416 -yscrollcommand {.vpane.files.index.sy set} \
4418 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
4419 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
4420 pack .vpane.files.index.title -side top -fill x
4421 pack .vpane.files.index.sx -side bottom -fill x
4422 pack .vpane.files.index.sy -side right -fill y
4423 pack $ui_index -side left -fill both -expand 1
4424 .vpane.files add .vpane.files.index -sticky nsew
4426 # -- Working Directory File List
4428 frame .vpane.files.workdir -height 100 -width 200
4429 label .vpane.files.workdir.title -text {Changed But Not Updated} \
4432 text $ui_workdir -background white -borderwidth 0 \
4433 -width 20 -height 10 \
4436 -cursor $cursor_ptr \
4437 -xscrollcommand {.vpane.files.workdir.sx set} \
4438 -yscrollcommand {.vpane.files.workdir.sy set} \
4440 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
4441 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
4442 pack .vpane.files.workdir.title -side top -fill x
4443 pack .vpane.files.workdir.sx -side bottom -fill x
4444 pack .vpane.files.workdir.sy -side right -fill y
4445 pack $ui_workdir -side left -fill both -expand 1
4446 .vpane.files add .vpane.files.workdir -sticky nsew
4448 foreach i [list $ui_index $ui_workdir] {
4449 $i tag conf in_diff -font font_uibold
4450 $i tag conf in_sel \
4451 -background [$i cget -foreground] \
4452 -foreground [$i cget -background]
4456 # -- Diff and Commit Area
4458 frame .vpane.lower -height 300 -width 400
4459 frame .vpane.lower.commarea
4460 frame .vpane.lower.diff -relief sunken -borderwidth 1
4461 pack .vpane.lower.commarea -side top -fill x
4462 pack .vpane.lower.diff -side bottom -fill both -expand 1
4463 .vpane add .vpane.lower -sticky nsew
4465 # -- Commit Area Buttons
4467 frame .vpane.lower.commarea.buttons
4468 label .vpane.lower.commarea.buttons.l -text {} \
4472 pack .vpane.lower.commarea.buttons.l -side top -fill x
4473 pack .vpane.lower.commarea.buttons -side left -fill y
4475 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
4476 -command do_rescan \
4478 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
4479 lappend disable_on_lock \
4480 {.vpane.lower.commarea.buttons.rescan conf -state}
4482 button .vpane.lower.commarea.buttons.incall -text {Add All} \
4483 -command do_add_all \
4485 pack .vpane.lower.commarea.buttons.incall -side top -fill x
4486 lappend disable_on_lock \
4487 {.vpane.lower.commarea.buttons.incall conf -state}
4489 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
4490 -command do_signoff \
4492 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
4494 button .vpane.lower.commarea.buttons.commit -text {Commit} \
4495 -command do_commit \
4497 pack .vpane.lower.commarea.buttons.commit -side top -fill x
4498 lappend disable_on_lock \
4499 {.vpane.lower.commarea.buttons.commit conf -state}
4501 # -- Commit Message Buffer
4503 frame .vpane.lower.commarea.buffer
4504 frame .vpane.lower.commarea.buffer.header
4505 set ui_comm .vpane.lower.commarea.buffer.t
4506 set ui_coml .vpane.lower.commarea.buffer.header.l
4507 radiobutton .vpane.lower.commarea.buffer.header.new \
4508 -text {New Commit} \
4509 -command do_select_commit_type \
4510 -variable selected_commit_type \
4513 lappend disable_on_lock \
4514 [list .vpane.lower.commarea.buffer.header.new conf -state]
4515 radiobutton .vpane.lower.commarea.buffer.header.amend \
4516 -text {Amend Last Commit} \
4517 -command do_select_commit_type \
4518 -variable selected_commit_type \
4521 lappend disable_on_lock \
4522 [list .vpane.lower.commarea.buffer.header.amend conf -state]
4527 proc trace_commit_type {varname args} {
4528 global ui_coml commit_type
4529 switch -glob -- $commit_type {
4530 initial {set txt {Initial Commit Message:}}
4531 amend {set txt {Amended Commit Message:}}
4532 amend-initial {set txt {Amended Initial Commit Message:}}
4533 amend-merge {set txt {Amended Merge Commit Message:}}
4534 merge {set txt {Merge Commit Message:}}
4535 * {set txt {Commit Message:}}
4537 $ui_coml conf -text $txt
4539 trace add variable commit_type write trace_commit_type
4540 pack $ui_coml -side left -fill x
4541 pack .vpane.lower.commarea.buffer.header.amend -side right
4542 pack .vpane.lower.commarea.buffer.header.new -side right
4544 text $ui_comm -background white -borderwidth 1 \
4547 -autoseparators true \
4549 -width 75 -height 9 -wrap none \
4551 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
4552 scrollbar .vpane.lower.commarea.buffer.sby \
4553 -command [list $ui_comm yview]
4554 pack .vpane.lower.commarea.buffer.header -side top -fill x
4555 pack .vpane.lower.commarea.buffer.sby -side right -fill y
4556 pack $ui_comm -side left -fill y
4557 pack .vpane.lower.commarea.buffer -side left -fill y
4559 # -- Commit Message Buffer Context Menu
4561 set ctxm .vpane.lower.commarea.buffer.ctxm
4562 menu $ctxm -tearoff 0
4566 -command {tk_textCut $ui_comm}
4570 -command {tk_textCopy $ui_comm}
4574 -command {tk_textPaste $ui_comm}
4578 -command {$ui_comm delete sel.first sel.last}
4581 -label {Select All} \
4583 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
4588 $ui_comm tag add sel 0.0 end
4589 tk_textCopy $ui_comm
4590 $ui_comm tag remove sel 0.0 end
4597 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
4601 set current_diff_path {}
4602 set current_diff_side {}
4603 set diff_actions [list]
4604 proc trace_current_diff_path {varname args} {
4605 global current_diff_path diff_actions file_states
4606 if {$current_diff_path eq {}} {
4612 set p $current_diff_path
4613 set s [mapdesc [lindex $file_states($p) 0] $p]
4615 set p [escape_path $p]
4619 .vpane.lower.diff.header.status configure -text $s
4620 .vpane.lower.diff.header.file configure -text $f
4621 .vpane.lower.diff.header.path configure -text $p
4622 foreach w $diff_actions {
4626 trace add variable current_diff_path write trace_current_diff_path
4628 frame .vpane.lower.diff.header -background orange
4629 label .vpane.lower.diff.header.status \
4630 -background orange \
4631 -width $max_status_desc \
4635 label .vpane.lower.diff.header.file \
4636 -background orange \
4640 label .vpane.lower.diff.header.path \
4641 -background orange \
4645 pack .vpane.lower.diff.header.status -side left
4646 pack .vpane.lower.diff.header.file -side left
4647 pack .vpane.lower.diff.header.path -fill x
4648 set ctxm .vpane.lower.diff.header.ctxm
4649 menu $ctxm -tearoff 0
4658 -- $current_diff_path
4660 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4661 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
4665 frame .vpane.lower.diff.body
4666 set ui_diff .vpane.lower.diff.body.t
4667 text $ui_diff -background white -borderwidth 0 \
4668 -width 80 -height 15 -wrap none \
4670 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4671 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4673 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4674 -command [list $ui_diff xview]
4675 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4676 -command [list $ui_diff yview]
4677 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4678 pack .vpane.lower.diff.body.sby -side right -fill y
4679 pack $ui_diff -side left -fill both -expand 1
4680 pack .vpane.lower.diff.header -side top -fill x
4681 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4683 $ui_diff tag conf d_cr -elide true
4684 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4685 $ui_diff tag conf d_+ -foreground {#00a000}
4686 $ui_diff tag conf d_- -foreground red
4688 $ui_diff tag conf d_++ -foreground {#00a000}
4689 $ui_diff tag conf d_-- -foreground red
4690 $ui_diff tag conf d_+s \
4691 -foreground {#00a000} \
4692 -background {#e2effa}
4693 $ui_diff tag conf d_-s \
4695 -background {#e2effa}
4696 $ui_diff tag conf d_s+ \
4697 -foreground {#00a000} \
4699 $ui_diff tag conf d_s- \
4703 $ui_diff tag conf d<<<<<<< \
4704 -foreground orange \
4706 $ui_diff tag conf d======= \
4707 -foreground orange \
4709 $ui_diff tag conf d>>>>>>> \
4710 -foreground orange \
4713 $ui_diff tag raise sel
4715 # -- Diff Body Context Menu
4717 set ctxm .vpane.lower.diff.body.ctxm
4718 menu $ctxm -tearoff 0
4722 -command reshow_diff
4723 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4727 -command {tk_textCopy $ui_diff}
4728 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4730 -label {Select All} \
4732 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4733 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4738 $ui_diff tag add sel 0.0 end
4739 tk_textCopy $ui_diff
4740 $ui_diff tag remove sel 0.0 end
4742 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4745 -label {Apply/Reverse Hunk} \
4747 -command {apply_hunk $cursorX $cursorY}
4748 set ui_diff_applyhunk [$ctxm index last]
4749 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
4752 -label {Decrease Font Size} \
4754 -command {incr_font_size font_diff -1}
4755 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4757 -label {Increase Font Size} \
4759 -command {incr_font_size font_diff 1}
4760 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4763 -label {Show Less Context} \
4765 -command {if {$repo_config(gui.diffcontext) >= 2} {
4766 incr repo_config(gui.diffcontext) -1
4769 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4771 -label {Show More Context} \
4774 incr repo_config(gui.diffcontext)
4777 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4779 $ctxm add command -label {Options...} \
4782 bind_button3 $ui_diff "
4785 if {\
$ui_index eq \
$current_diff_side} {
4786 $ctxm entryconf
$ui_diff_applyhunk -label {Unstage Hunk From Commit
}
4788 $ctxm entryconf
$ui_diff_applyhunk -label {Stage Hunk For Commit
}
4790 tk_popup
$ctxm %X
%Y
4792 unset ui_diff_applyhunk
4796 set ui_status_value {Initializing...}
4797 label .status -textvariable ui_status_value \
4803 pack .status -anchor w -side bottom -fill x
4808 set gm $repo_config(gui.geometry)
4809 wm geometry . [lindex $gm 0]
4810 .vpane sash place 0 \
4811 [lindex [.vpane sash coord 0] 0] \
4813 .vpane.files sash place 0 \
4815 [lindex [.vpane.files sash coord 0] 1]
4821 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4822 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4823 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4824 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4825 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4826 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4827 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4828 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4829 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4830 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4831 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4833 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4834 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4835 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4836 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4837 bind $ui_diff <$M1B-Key-v> {break}
4838 bind $ui_diff <$M1B-Key-V> {break}
4839 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4840 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4841 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4842 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4843 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4844 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4845 bind $ui_diff <Button-1> {focus %W}
4847 if {!$single_commit} {
4848 bind . <$M1B-Key-n> do_create_branch
4849 bind . <$M1B-Key-N> do_create_branch
4852 bind . <Destroy> do_quit
4853 bind all <Key-F5> do_rescan
4854 bind all <$M1B-Key-r> do_rescan
4855 bind all <$M1B-Key-R> do_rescan
4856 bind . <$M1B-Key-s> do_signoff
4857 bind . <$M1B-Key-S> do_signoff
4858 bind . <$M1B-Key-i> do_add_all
4859 bind . <$M1B-Key-I> do_add_all
4860 bind . <$M1B-Key-Return> do_commit
4861 bind all <$M1B-Key-q> do_quit
4862 bind all <$M1B-Key-Q> do_quit
4863 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4864 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4865 foreach i [list $ui_index $ui_workdir] {
4866 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4867 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4868 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4872 set file_lists($ui_index) [list]
4873 set file_lists($ui_workdir) [list]
4877 set MERGE_HEAD [list]
4880 set current_branch {}
4881 set current_diff_path {}
4882 set selected_commit_type new
4884 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4885 focus -force $ui_comm
4887 # -- Warn the user about environmental problems. Cygwin's Tcl
4888 # does *not* pass its env array onto any processes it spawns.
4889 # This means that git processes get none of our environment.
4894 set msg "Possible environment issues exist.
4896 The following environment variables are probably
4897 going to be ignored by any Git subprocess run
4901 foreach name [array names env] {
4902 switch -regexp -- $name {
4903 {^GIT_INDEX_FILE$} -
4904 {^GIT_OBJECT_DIRECTORY$} -
4905 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4907 {^GIT_EXTERNAL_DIFF$} -
4911 {^GIT_CONFIG_LOCAL$} -
4912 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4913 append msg " - $name\n"
4916 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4917 append msg " - $name\n"
4919 set suggest_user $name
4923 if {$ignored_env > 0} {
4925 This is due to a known issue with the
4926 Tcl binary distributed by Cygwin.
"
4928 if {$suggest_user ne {}} {
4931 A good replacement
for $suggest_user
4932 is placing values
for the user.name and
4933 user.email settings into your personal
4939 unset ignored_env msg suggest_user name
4942 # -- Only initialize complex UI if we are going to stay running.
4944 if {!$single_commit} {
4948 populate_branch_menu
4953 # -- Only suggest a gc run if we are going to stay running.
4955 if {!$single_commit} {
4956 set object_limit 2000
4957 if {[is_Windows]} {set object_limit 200}
4958 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4959 if {$objects_current >= $object_limit} {
4961 "This repository currently has
$objects_current loose objects.
4963 To maintain optimal performance it is strongly
4964 recommended that you
compress the database
4965 when
more than
$object_limit loose objects exist.
4967 Compress the database now?
"] eq yes} {
4971 unset object_limit _junk objects_current
4974 lock_index begin-read