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 $ui_comm delete
0.0 end
432 $ui_comm insert end
$content
438 proc read_diff_index
{fd after
} {
441 append buf_rdi
[read $fd]
443 set n
[string length
$buf_rdi]
445 set z1
[string first
"\0" $buf_rdi $c]
448 set z2
[string first
"\0" $buf_rdi $z1]
452 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
453 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
455 [encoding convertfrom
$p] \
457 [list
[lindex
$i 0] [lindex
$i 2]] \
463 set buf_rdi
[string range
$buf_rdi $c end
]
468 rescan_done
$fd buf_rdi
$after
471 proc read_diff_files
{fd after
} {
474 append buf_rdf
[read $fd]
476 set n
[string length
$buf_rdf]
478 set z1
[string first
"\0" $buf_rdf $c]
481 set z2
[string first
"\0" $buf_rdf $z1]
485 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
486 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
488 [encoding convertfrom
$p] \
491 [list
[lindex
$i 0] [lindex
$i 2]]
496 set buf_rdf
[string range
$buf_rdf $c end
]
501 rescan_done
$fd buf_rdf
$after
504 proc read_ls_others
{fd after
} {
507 append buf_rlo
[read $fd]
508 set pck
[split $buf_rlo "\0"]
509 set buf_rlo
[lindex
$pck end
]
510 foreach p
[lrange
$pck 0 end-1
] {
511 merge_state
[encoding convertfrom
$p] ?O
513 rescan_done
$fd buf_rlo
$after
516 proc rescan_done
{fd buf after
} {
518 global file_states repo_config
521 if {![eof
$fd]} return
524 if {[incr rescan_active
-1] > 0} return
533 proc prune_selection
{} {
534 global file_states selected_paths
536 foreach path
[array names selected_paths
] {
537 if {[catch
{set still_here
$file_states($path)}]} {
538 unset selected_paths
($path)
543 ######################################################################
548 global ui_diff current_diff_path ui_index ui_workdir
550 $ui_diff conf
-state normal
551 $ui_diff delete
0.0 end
552 $ui_diff conf
-state disabled
554 set current_diff_path
{}
556 $ui_index tag remove in_diff
0.0 end
557 $ui_workdir tag remove in_diff
0.0 end
560 proc reshow_diff
{} {
561 global ui_status_value file_states file_lists
562 global current_diff_path current_diff_side
564 set p
$current_diff_path
566 ||
$current_diff_side eq
{}
567 ||
[catch
{set s
$file_states($p)}]
568 ||
[lsearch
-sorted $file_lists($current_diff_side) $p] == -1} {
571 show_diff
$p $current_diff_side
575 proc handle_empty_diff
{} {
576 global current_diff_path file_states file_lists
578 set path
$current_diff_path
579 set s
$file_states($path)
580 if {[lindex
$s 0] ne
{_M
}} return
582 info_popup
"No differences detected.
584 [short_path $path] has no changes.
586 The modification date of this file was updated
587 by another application, but the content within
588 the file was not changed.
590 A rescan will be automatically started to find
591 other files which may have the same state."
594 display_file
$path __
595 rescan
{set ui_status_value
{Ready.
}} 0
598 proc show_diff
{path w
{lno
{}}} {
599 global file_states file_lists
600 global is_3way_diff diff_active repo_config
601 global ui_diff ui_status_value ui_index ui_workdir
602 global current_diff_path current_diff_side
604 if {$diff_active ||
![lock_index
read]} return
607 if {$w eq
{} ||
$lno == {}} {
608 foreach w
[array names file_lists
] {
609 set lno
[lsearch
-sorted $file_lists($w) $path]
616 if {$w ne
{} && $lno >= 1} {
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 ui_status_value
"Loading diff of [escape_path $path]..."
628 # - Git won't give us the diff, there's nothing to compare to!
631 set max_sz
[expr {128 * 1024}]
633 set fd
[open
$path r
]
634 set content
[read $fd $max_sz]
636 set sz
[file size
$path]
640 set ui_status_value
"Unable to display [escape_path $path]"
641 error_popup
"Error loading file:\n\n$err"
644 $ui_diff conf
-state normal
645 if {![catch
{set type [exec file $path]}]} {
646 set n
[string length
$path]
647 if {[string equal
-length $n $path $type]} {
648 set type [string range
$type $n end
]
649 regsub
{^
:?\s
*} $type {} type
651 $ui_diff insert end
"* $type\n" d_@
653 if {[string first
"\0" $content] != -1} {
654 $ui_diff insert end \
655 "* Binary file (not showing content)." \
659 $ui_diff insert end \
660 "* Untracked file is $sz bytes.
661 * Showing only first $max_sz bytes.
664 $ui_diff insert end
$content
666 $ui_diff insert end
"
667 * Untracked file clipped here by [appname].
668 * To see the entire file, use an external editor.
672 $ui_diff conf
-state disabled
675 set ui_status_value
{Ready.
}
680 if {$w eq
$ui_index} {
681 lappend cmd diff-index
683 } elseif
{$w eq
$ui_workdir} {
684 if {[string index
$m 0] eq
{U
}} {
687 lappend cmd diff-files
692 lappend cmd
--no-color
693 if {$repo_config(gui.diffcontext
) > 0} {
694 lappend cmd
"-U$repo_config(gui.diffcontext)"
696 if {$w eq
$ui_index} {
702 if {[catch
{set fd
[open
$cmd r
]} err
]} {
705 set ui_status_value
"Unable to display [escape_path $path]"
706 error_popup
"Error loading diff:\n\n$err"
710 fconfigure
$fd -blocking 0 -translation auto
711 fileevent
$fd readable
[list read_diff
$fd]
714 proc read_diff
{fd
} {
715 global ui_diff ui_status_value is_3way_diff diff_active
717 $ui_diff conf
-state normal
718 while {[gets
$fd line
] >= 0} {
719 # -- Cleanup uninteresting diff header lines.
721 if {[string match
{diff --git *} $line]} continue
722 if {[string match
{diff --cc *} $line]} continue
723 if {[string match
{diff --combined *} $line]} continue
724 if {[string match
{--- *} $line]} continue
725 if {[string match
{+++ *} $line]} continue
726 if {$line eq
{deleted
file mode
120000}} {
727 set line
"deleted symlink"
730 # -- Automatically detect if this is a 3 way diff.
732 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
734 if {[string match
{index
*} $line]
735 ||
[string match
{mode
*} $line]
736 ||
[string match
{new
file *} $line]
737 ||
[string match
{deleted
file *} $line]
738 ||
[string match
{Binary files
* and
* differ
} $line]
739 ||
$line eq
{\ No newline
at end of
file}
740 ||
[regexp
{^\
* Unmerged path
} $line]} {
742 } elseif
{$is_3way_diff} {
743 set op
[string range
$line 0 1]
753 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
754 set line
[string replace
$line 0 1 { }]
761 puts
"error: Unhandled 3 way diff marker: {$op}"
766 set op
[string index
$line 0]
772 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
773 set line
[string replace
$line 0 0 { }]
780 puts
"error: Unhandled 2 way diff marker: {$op}"
785 $ui_diff insert end
$line $tags
786 $ui_diff insert end
"\n" $tags
788 $ui_diff conf
-state disabled
794 set ui_status_value
{Ready.
}
796 if {[$ui_diff index end
] eq
{2.0}} {
802 ######################################################################
806 proc load_last_commit
{} {
807 global HEAD PARENT MERGE_HEAD commit_type ui_comm
810 if {[llength
$PARENT] == 0} {
811 error_popup
{There is nothing to amend.
813 You are about to create the initial commit.
814 There is no commit before this to amend.
819 repository_state curType curHEAD curMERGE_HEAD
820 if {$curType eq
{merge
}} {
821 error_popup
{Cannot amend
while merging.
823 You are currently
in the middle of a merge that
824 has not been fully completed. You cannot amend
825 the prior commit unless you first abort the
826 current merge activity.
834 set fd
[open
"| git cat-file commit $curHEAD" r
]
835 fconfigure
$fd -encoding binary
-translation lf
836 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
839 while {[gets
$fd line
] > 0} {
840 if {[string match
{parent
*} $line]} {
841 lappend parents
[string range
$line 7 end
]
842 } elseif
{[string match
{encoding
*} $line]} {
843 set enc
[string tolower
[string range
$line 9 end
]]
846 fconfigure
$fd -encoding $enc
847 set msg
[string trim
[read $fd]]
850 error_popup
"Error loading commit data for amend:\n\n$err"
856 set MERGE_HEAD
[list
]
857 switch
-- [llength
$parents] {
858 0 {set commit_type amend-initial
}
859 1 {set commit_type amend
}
860 default
{set commit_type amend-merge
}
863 $ui_comm delete
0.0 end
864 $ui_comm insert end
$msg
866 $ui_comm edit modified false
867 rescan
{set ui_status_value
{Ready.
}}
870 proc create_new_commit
{} {
871 global commit_type ui_comm
873 set commit_type normal
874 $ui_comm delete
0.0 end
876 $ui_comm edit modified false
877 rescan
{set ui_status_value
{Ready.
}}
880 set GIT_COMMITTER_IDENT
{}
882 proc committer_ident
{} {
883 global GIT_COMMITTER_IDENT
885 if {$GIT_COMMITTER_IDENT eq
{}} {
886 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
887 error_popup
"Unable to obtain your identity:\n\n$err"
890 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
891 $me me GIT_COMMITTER_IDENT
]} {
892 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
897 return $GIT_COMMITTER_IDENT
900 proc commit_tree
{} {
901 global HEAD commit_type file_states ui_comm repo_config
902 global ui_status_value pch_error
904 if {![lock_index update
]} return
905 if {[committer_ident
] eq
{}} return
907 # -- Our in memory state should match the repository.
909 repository_state curType curHEAD curMERGE_HEAD
910 if {[string match amend
* $commit_type]
911 && $curType eq
{normal
}
912 && $curHEAD eq
$HEAD} {
913 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
914 info_popup
{Last scanned state does not match repository state.
916 Another Git program has modified this repository
917 since the last scan. A rescan must be performed
918 before another commit can be created.
920 The rescan will be automatically started now.
923 rescan
{set ui_status_value
{Ready.
}}
927 # -- At least one file should differ in the index.
930 foreach path
[array names file_states
] {
931 switch
-glob -- [lindex
$file_states($path) 0] {
935 M?
{set files_ready
1}
937 error_popup
"Unmerged files cannot be committed.
939 File [short_path $path] has merge conflicts.
940 You must resolve them and add the file before committing.
946 error_popup
"Unknown file state [lindex $s 0] detected.
948 File [short_path $path] cannot be committed by this program.
954 info_popup
{No changes to commit.
956 You must add
at least
1 file before you can commit.
962 # -- A message is required.
964 set msg
[string trim
[$ui_comm get
1.0 end
]]
966 error_popup
{Please supply a commit message.
968 A good commit message has the following format
:
970 - First line
: Describe
in one sentance what you did.
972 - Remaining lines
: Describe why this change is good.
978 # -- Run the pre-commit hook.
980 set pchook
[gitdir hooks pre-commit
]
982 # On Cygwin [file executable] might lie so we need to ask
983 # the shell if the hook is executable. Yes that's annoying.
985 if {[is_Windows
] && [file isfile
$pchook]} {
986 set pchook
[list sh
-c [concat \
987 "if test -x \"$pchook\";" \
988 "then exec \"$pchook\" 2>&1;" \
990 } elseif
{[file executable
$pchook]} {
991 set pchook
[list
$pchook |
& cat]
993 commit_writetree
$curHEAD $msg
997 set ui_status_value
{Calling pre-commit hook...
}
999 set fd_ph
[open
"| $pchook" r
]
1000 fconfigure
$fd_ph -blocking 0 -translation binary
1001 fileevent
$fd_ph readable \
1002 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1005 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1006 global pch_error ui_status_value
1008 append pch_error
[read $fd_ph]
1009 fconfigure
$fd_ph -blocking 1
1011 if {[catch
{close
$fd_ph}]} {
1012 set ui_status_value
{Commit declined by pre-commit hook.
}
1013 hook_failed_popup pre-commit
$pch_error
1016 commit_writetree
$curHEAD $msg
1021 fconfigure
$fd_ph -blocking 0
1024 proc commit_writetree
{curHEAD msg
} {
1025 global ui_status_value
1027 set ui_status_value
{Committing changes...
}
1028 set fd_wt
[open
"| git write-tree" r
]
1029 fileevent
$fd_wt readable \
1030 [list commit_committree
$fd_wt $curHEAD $msg]
1033 proc commit_committree
{fd_wt curHEAD msg
} {
1034 global HEAD PARENT MERGE_HEAD commit_type
1035 global single_commit all_heads current_branch
1036 global ui_status_value ui_comm selected_commit_type
1037 global file_states selected_paths rescan_active
1041 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1042 error_popup
"write-tree failed:\n\n$err"
1043 set ui_status_value
{Commit failed.
}
1048 # -- Build the message.
1050 set msg_p
[gitdir COMMIT_EDITMSG
]
1051 set msg_wt
[open
$msg_p w
]
1052 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1055 fconfigure
$msg_wt -encoding $enc -translation binary
1056 puts
-nonewline $msg_wt $msg
1059 # -- Create the commit.
1061 set cmd
[list git commit-tree
$tree_id]
1062 set parents
[concat
$PARENT $MERGE_HEAD]
1063 if {[llength
$parents] > 0} {
1064 foreach p
$parents {
1068 # git commit-tree writes to stderr during initial commit.
1069 lappend cmd
2>/dev
/null
1072 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1073 error_popup
"commit-tree failed:\n\n$err"
1074 set ui_status_value
{Commit failed.
}
1079 # -- Update the HEAD ref.
1082 if {$commit_type ne
{normal
}} {
1083 append reflogm
" ($commit_type)"
1085 set i
[string first
"\n" $msg]
1087 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1089 append reflogm
{: } $msg
1091 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1092 if {[catch
{eval exec $cmd} err
]} {
1093 error_popup
"update-ref failed:\n\n$err"
1094 set ui_status_value
{Commit failed.
}
1099 # -- Make sure our current branch exists.
1101 if {$commit_type eq
{initial
}} {
1102 lappend all_heads
$current_branch
1103 set all_heads
[lsort
-unique $all_heads]
1104 populate_branch_menu
1107 # -- Cleanup after ourselves.
1109 catch
{file delete
$msg_p}
1110 catch
{file delete
[gitdir MERGE_HEAD
]}
1111 catch
{file delete
[gitdir MERGE_MSG
]}
1112 catch
{file delete
[gitdir SQUASH_MSG
]}
1113 catch
{file delete
[gitdir GITGUI_MSG
]}
1115 # -- Let rerere do its thing.
1117 if {[file isdirectory
[gitdir rr-cache
]]} {
1118 catch
{exec git rerere
}
1121 # -- Run the post-commit hook.
1123 set pchook
[gitdir hooks post-commit
]
1124 if {[is_Windows
] && [file isfile
$pchook]} {
1125 set pchook
[list sh
-c [concat \
1126 "if test -x \"$pchook\";" \
1127 "then exec \"$pchook\";" \
1129 } elseif
{![file executable
$pchook]} {
1132 if {$pchook ne
{}} {
1133 catch
{exec $pchook &}
1136 $ui_comm delete
0.0 end
1138 $ui_comm edit modified false
1140 if {$single_commit} do_quit
1142 # -- Update in memory status
1144 set selected_commit_type new
1145 set commit_type normal
1148 set MERGE_HEAD
[list
]
1150 foreach path
[array names file_states
] {
1151 set s
$file_states($path)
1153 switch
-glob -- $m {
1161 unset file_states
($path)
1162 catch
{unset selected_paths
($path)}
1165 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1171 set file_states
($path) [list \
1172 _
[string index
$m 1] \
1183 set ui_status_value \
1184 "Changes committed as [string range $cmt_id 0 7]."
1187 ######################################################################
1191 proc fetch_from
{remote
} {
1192 set w
[new_console
"fetch $remote" \
1193 "Fetching new changes from $remote"]
1194 set cmd
[list git fetch
]
1196 console_exec
$w $cmd
1199 proc pull_remote
{remote branch
} {
1200 global HEAD commit_type file_states repo_config
1202 if {![lock_index update
]} return
1204 # -- Our in memory state should match the repository.
1206 repository_state curType curHEAD curMERGE_HEAD
1207 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1208 info_popup
{Last scanned state does not match repository state.
1210 Another Git program has modified this repository
1211 since the last scan. A rescan must be performed
1212 before a pull operation can be started.
1214 The rescan will be automatically started now.
1217 rescan
{set ui_status_value
{Ready.
}}
1221 # -- No differences should exist before a pull.
1223 if {[array size file_states
] != 0} {
1224 error_popup
{Uncommitted but modified files are present.
1226 You should not perform a pull with unmodified
1227 files
in your working directory as Git will be
1228 unable to recover from an incorrect merge.
1230 You should commit or revert all changes before
1231 starting a pull operation.
1237 set w
[new_console
"pull $remote $branch" \
1238 "Pulling new changes from branch $branch in $remote"]
1239 set cmd
[list git pull
]
1240 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1241 lappend cmd
--no-summary
1245 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1248 proc post_pull_remote
{remote branch success
} {
1249 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1250 global ui_status_value
1254 repository_state commit_type HEAD MERGE_HEAD
1256 set selected_commit_type new
1257 set ui_status_value
"Pulling $branch from $remote complete."
1259 rescan
[list
set ui_status_value \
1260 "Conflicts detected while pulling $branch from $remote."]
1264 proc push_to
{remote
} {
1265 set w
[new_console
"push $remote" \
1266 "Pushing changes to $remote"]
1267 set cmd
[list git push
]
1269 console_exec
$w $cmd
1272 ######################################################################
1276 proc mapicon
{w state path
} {
1279 if {[catch
{set r
$all_icons($state$w)}]} {
1280 puts
"error: no icon for $w state={$state} $path"
1286 proc mapdesc
{state path
} {
1289 if {[catch
{set r
$all_descs($state)}]} {
1290 puts
"error: no desc for state={$state} $path"
1296 proc escape_path
{path
} {
1297 regsub
-all "\n" $path "\\n" path
1301 proc short_path
{path
} {
1302 return [escape_path
[lindex
[file split $path] end
]]
1306 set null_sha1
[string repeat
0 40]
1308 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1309 global file_states next_icon_id null_sha1
1311 set s0
[string index
$new_state 0]
1312 set s1
[string index
$new_state 1]
1314 if {[catch
{set info
$file_states($path)}]} {
1316 set icon n
[incr next_icon_id
]
1318 set state
[lindex
$info 0]
1319 set icon
[lindex
$info 1]
1320 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1321 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1324 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1325 elseif
{$s0 eq
{_
}} {set s0 _
}
1327 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1328 elseif
{$s1 eq
{_
}} {set s1 _
}
1330 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1331 set head_info
[list
0 $null_sha1]
1332 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1333 && $head_info eq
{}} {
1334 set head_info
$index_info
1337 set file_states
($path) [list
$s0$s1 $icon \
1338 $head_info $index_info \
1343 proc display_file_helper
{w path icon_name old_m new_m
} {
1346 if {$new_m eq
{_
}} {
1347 set lno
[lsearch
-sorted $file_lists($w) $path]
1349 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1351 $w conf
-state normal
1352 $w delete
$lno.0 [expr {$lno + 1}].0
1353 $w conf
-state disabled
1355 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1356 lappend file_lists
($w) $path
1357 set file_lists
($w) [lsort
-unique $file_lists($w)]
1358 set lno
[lsearch
-sorted $file_lists($w) $path]
1360 $w conf
-state normal
1361 $w image create
$lno.0 \
1362 -align center
-padx 5 -pady 1 \
1364 -image [mapicon
$w $new_m $path]
1365 $w insert
$lno.1 "[escape_path $path]\n"
1366 $w conf
-state disabled
1367 } elseif
{$old_m ne
$new_m} {
1368 $w conf
-state normal
1369 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1370 $w conf
-state disabled
1374 proc display_file
{path state
} {
1375 global file_states selected_paths
1376 global ui_index ui_workdir
1378 set old_m
[merge_state
$path $state]
1379 set s
$file_states($path)
1380 set new_m
[lindex
$s 0]
1381 set icon_name
[lindex
$s 1]
1383 set o
[string index
$old_m 0]
1384 set n
[string index
$new_m 0]
1391 display_file_helper
$ui_index $path $icon_name $o $n
1393 if {[string index
$old_m 0] eq
{U
}} {
1396 set o
[string index
$old_m 1]
1398 if {[string index
$new_m 0] eq
{U
}} {
1401 set n
[string index
$new_m 1]
1403 display_file_helper
$ui_workdir $path $icon_name $o $n
1405 if {$new_m eq
{__
}} {
1406 unset file_states
($path)
1407 catch
{unset selected_paths
($path)}
1411 proc display_all_files_helper
{w path icon_name m
} {
1414 lappend file_lists
($w) $path
1415 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1416 $w image create end \
1417 -align center
-padx 5 -pady 1 \
1419 -image [mapicon
$w $m $path]
1420 $w insert end
"[escape_path $path]\n"
1423 proc display_all_files
{} {
1424 global ui_index ui_workdir
1425 global file_states file_lists
1428 $ui_index conf
-state normal
1429 $ui_workdir conf
-state normal
1431 $ui_index delete
0.0 end
1432 $ui_workdir delete
0.0 end
1435 set file_lists
($ui_index) [list
]
1436 set file_lists
($ui_workdir) [list
]
1438 foreach path
[lsort
[array names file_states
]] {
1439 set s
$file_states($path)
1441 set icon_name
[lindex
$s 1]
1443 set s
[string index
$m 0]
1444 if {$s ne
{U
} && $s ne
{_
}} {
1445 display_all_files_helper
$ui_index $path \
1449 if {[string index
$m 0] eq
{U
}} {
1452 set s
[string index
$m 1]
1455 display_all_files_helper
$ui_workdir $path \
1460 $ui_index conf
-state disabled
1461 $ui_workdir conf
-state disabled
1464 proc update_indexinfo
{msg pathList after
} {
1465 global update_index_cp ui_status_value
1467 if {![lock_index update
]} return
1469 set update_index_cp
0
1470 set pathList
[lsort
$pathList]
1471 set totalCnt
[llength
$pathList]
1472 set batch [expr {int
($totalCnt * .01) + 1}]
1473 if {$batch > 25} {set batch 25}
1475 set ui_status_value
[format \
1476 "$msg... %i/%i files (%.2f%%)" \
1480 set fd
[open
"| git update-index -z --index-info" w
]
1487 fileevent
$fd writable
[list \
1488 write_update_indexinfo \
1498 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1499 global update_index_cp ui_status_value
1500 global file_states current_diff_path
1502 if {$update_index_cp >= $totalCnt} {
1509 for {set i
$batch} \
1510 {$update_index_cp < $totalCnt && $i > 0} \
1512 set path
[lindex
$pathList $update_index_cp]
1513 incr update_index_cp
1515 set s
$file_states($path)
1516 switch
-glob -- [lindex
$s 0] {
1523 set info
[lindex
$s 2]
1524 if {$info eq
{}} continue
1526 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1527 display_file
$path $new
1530 set ui_status_value
[format \
1531 "$msg... %i/%i files (%.2f%%)" \
1534 [expr {100.0 * $update_index_cp / $totalCnt}]]
1537 proc update_index
{msg pathList after
} {
1538 global update_index_cp ui_status_value
1540 if {![lock_index update
]} return
1542 set update_index_cp
0
1543 set pathList
[lsort
$pathList]
1544 set totalCnt
[llength
$pathList]
1545 set batch [expr {int
($totalCnt * .01) + 1}]
1546 if {$batch > 25} {set batch 25}
1548 set ui_status_value
[format \
1549 "$msg... %i/%i files (%.2f%%)" \
1553 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1560 fileevent
$fd writable
[list \
1561 write_update_index \
1571 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1572 global update_index_cp ui_status_value
1573 global file_states current_diff_path
1575 if {$update_index_cp >= $totalCnt} {
1582 for {set i
$batch} \
1583 {$update_index_cp < $totalCnt && $i > 0} \
1585 set path
[lindex
$pathList $update_index_cp]
1586 incr update_index_cp
1588 switch
-glob -- [lindex
$file_states($path) 0] {
1594 if {[file exists
$path]} {
1603 puts
-nonewline $fd "[encoding convertto $path]\0"
1604 display_file
$path $new
1607 set ui_status_value
[format \
1608 "$msg... %i/%i files (%.2f%%)" \
1611 [expr {100.0 * $update_index_cp / $totalCnt}]]
1614 proc checkout_index
{msg pathList after
} {
1615 global update_index_cp ui_status_value
1617 if {![lock_index update
]} return
1619 set update_index_cp
0
1620 set pathList
[lsort
$pathList]
1621 set totalCnt
[llength
$pathList]
1622 set batch [expr {int
($totalCnt * .01) + 1}]
1623 if {$batch > 25} {set batch 25}
1625 set ui_status_value
[format \
1626 "$msg... %i/%i files (%.2f%%)" \
1630 set cmd
[list git checkout-index
]
1636 set fd
[open
"| $cmd " w
]
1643 fileevent
$fd writable
[list \
1644 write_checkout_index \
1654 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1655 global update_index_cp ui_status_value
1656 global file_states current_diff_path
1658 if {$update_index_cp >= $totalCnt} {
1665 for {set i
$batch} \
1666 {$update_index_cp < $totalCnt && $i > 0} \
1668 set path
[lindex
$pathList $update_index_cp]
1669 incr update_index_cp
1670 switch
-glob -- [lindex
$file_states($path) 0] {
1674 puts
-nonewline $fd "[encoding convertto $path]\0"
1675 display_file
$path ?_
1680 set ui_status_value
[format \
1681 "$msg... %i/%i files (%.2f%%)" \
1684 [expr {100.0 * $update_index_cp / $totalCnt}]]
1687 ######################################################################
1689 ## branch management
1691 proc is_tracking_branch
{name
} {
1692 global tracking_branches
1694 if {![catch
{set info
$tracking_branches($name)}]} {
1697 foreach t
[array names tracking_branches
] {
1698 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1705 proc load_all_heads
{} {
1708 set all_heads
[list
]
1709 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1710 while {[gets
$fd line
] > 0} {
1711 if {[is_tracking_branch
$line]} continue
1712 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1713 lappend all_heads
$name
1717 set all_heads
[lsort
$all_heads]
1720 proc populate_branch_menu
{} {
1721 global all_heads disable_on_lock
1724 set last
[$m index last
]
1725 for {set i
0} {$i <= $last} {incr i
} {
1726 if {[$m type $i] eq
{separator
}} {
1729 foreach a
$disable_on_lock {
1730 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1734 set disable_on_lock
$new_dol
1740 foreach b
$all_heads {
1741 $m add radiobutton \
1743 -command [list switch_branch
$b] \
1744 -variable current_branch \
1747 lappend disable_on_lock \
1748 [list
$m entryconf
[$m index last
] -state]
1752 proc all_tracking_branches
{} {
1753 global tracking_branches
1755 set all_trackings
{}
1757 foreach name
[array names tracking_branches
] {
1758 if {[regsub
{/\
*$
} $name {} name
]} {
1761 regsub ^refs
/(heads|remotes
)/ $name {} name
1762 lappend all_trackings
$name
1767 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1768 while {[gets
$fd name
] > 0} {
1769 regsub ^refs
/(heads|remotes
)/ $name {} name
1770 lappend all_trackings
$name
1775 return [lsort
-unique $all_trackings]
1778 proc do_create_branch_action
{w
} {
1779 global all_heads null_sha1 repo_config
1780 global create_branch_checkout create_branch_revtype
1781 global create_branch_head create_branch_trackinghead
1783 set newbranch
[string trim
[$w.desc.name_t get
0.0 end
]]
1784 if {$newbranch eq
{}
1785 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1789 -title [wm title
$w] \
1791 -message "Please supply a branch name."
1792 focus
$w.desc.name_t
1795 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1799 -title [wm title
$w] \
1801 -message "Branch '$newbranch' already exists."
1802 focus
$w.desc.name_t
1805 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1809 -title [wm title
$w] \
1811 -message "We do not like '$newbranch' as a branch name."
1812 focus
$w.desc.name_t
1817 switch
-- $create_branch_revtype {
1818 head {set rev $create_branch_head}
1819 tracking
{set rev $create_branch_trackinghead}
1820 expression
{set rev [string trim
[$w.from.exp_t get
0.0 end
]]}
1822 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1826 -title [wm title
$w] \
1828 -message "Invalid starting revision: $rev"
1831 set cmd
[list git update-ref
]
1833 lappend cmd
"branch: Created from $rev"
1834 lappend cmd
"refs/heads/$newbranch"
1836 lappend cmd
$null_sha1
1837 if {[catch
{eval exec $cmd} err
]} {
1841 -title [wm title
$w] \
1843 -message "Failed to create '$newbranch'.\n\n$err"
1847 lappend all_heads
$newbranch
1848 set all_heads
[lsort
$all_heads]
1849 populate_branch_menu
1851 if {$create_branch_checkout} {
1852 switch_branch
$newbranch
1856 proc radio_selector
{varname value args
} {
1857 upvar
#0 $varname var
1861 trace add variable create_branch_head
write \
1862 [list radio_selector create_branch_revtype
head]
1863 trace add variable create_branch_trackinghead
write \
1864 [list radio_selector create_branch_revtype tracking
]
1866 trace add variable delete_branch_head
write \
1867 [list radio_selector delete_branch_checktype
head]
1868 trace add variable delete_branch_trackinghead
write \
1869 [list radio_selector delete_branch_checktype tracking
]
1871 proc do_create_branch
{} {
1872 global all_heads current_branch repo_config
1873 global create_branch_checkout create_branch_revtype
1874 global create_branch_head create_branch_trackinghead
1876 set w .branch_editor
1878 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1880 label
$w.header
-text {Create New Branch
} \
1882 pack
$w.header
-side top
-fill x
1885 button
$w.buttons.create
-text Create \
1888 -command [list do_create_branch_action
$w]
1889 pack
$w.buttons.create
-side right
1890 button
$w.buttons.cancel
-text {Cancel
} \
1892 -command [list destroy
$w]
1893 pack
$w.buttons.cancel
-side right
-padx 5
1894 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1896 labelframe
$w.desc \
1897 -text {Branch Description
} \
1899 label
$w.desc.name_l
-text {Name
:} -font font_ui
1900 text
$w.desc.name_t \
1906 $w.desc.name_t insert
0.0 $repo_config(gui.newbranchtemplate
)
1907 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
1908 bind $w.desc.name_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1909 bind $w.desc.name_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1910 bind $w.desc.name_t
<Key-Return
> "do_create_branch_action $w;break"
1911 bind $w.desc.name_t
<Key
> {
1912 if {{%K
} ne
{BackSpace
}
1915 && {%K
} ne
{Return
}} {
1917 if {[string first
%A
{~^
:?
*[}] >= 0} break
1920 grid columnconfigure
$w.desc
1 -weight 1
1921 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
1923 labelframe
$w.from \
1924 -text {Starting Revision
} \
1926 radiobutton
$w.from.head_r \
1927 -text {Local Branch
:} \
1929 -variable create_branch_revtype \
1931 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
1932 grid
$w.from.head_r
$w.from.head_m
-sticky w
1933 set all_trackings
[all_tracking_branches
]
1934 if {$all_trackings ne
{}} {
1935 set create_branch_trackinghead
[lindex
$all_trackings 0]
1936 radiobutton
$w.from.tracking_r \
1937 -text {Tracking Branch
:} \
1939 -variable create_branch_revtype \
1941 eval tk_optionMenu
$w.from.tracking_m \
1942 create_branch_trackinghead \
1944 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
1946 radiobutton
$w.from.exp_r \
1947 -text {Revision Expression
:} \
1949 -variable create_branch_revtype \
1951 text
$w.from.exp_t \
1957 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
1958 bind $w.from.exp_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1959 bind $w.from.exp_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1960 bind $w.from.exp_t
<Key-Return
> "do_create_branch_action $w;break"
1961 bind $w.from.exp_t
<Key-space
> break
1962 bind $w.from.exp_t
<Key
> {set create_branch_revtype expression
}
1963 grid columnconfigure
$w.from
1 -weight 1
1964 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1966 labelframe
$w.postActions \
1967 -text {Post Creation Actions
} \
1969 checkbutton
$w.postActions.checkout \
1970 -text {Checkout after creation
} \
1971 -variable create_branch_checkout \
1973 pack
$w.postActions.checkout
-anchor nw
1974 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1976 set create_branch_checkout
1
1977 set create_branch_head
$current_branch
1978 set create_branch_revtype
head
1980 bind $w <Visibility
> "grab $w; focus $w.desc.name_t"
1981 bind $w <Key-Escape
> "destroy $w"
1982 bind $w <Key-Return
> "do_create_branch_action $w;break"
1983 wm title
$w "[appname] ([reponame]): Create Branch"
1987 proc do_delete_branch_action
{w
} {
1989 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
1992 switch
-- $delete_branch_checktype {
1993 head {set check_rev
$delete_branch_head}
1994 tracking
{set check_rev
$delete_branch_trackinghead}
1995 always
{set check_rev
{:none
}}
1997 if {$check_rev eq
{:none
}} {
1999 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
2003 -title [wm title
$w] \
2005 -message "Invalid check revision: $check_rev"
2009 set to_delete
[list
]
2010 set not_merged
[list
]
2011 foreach i
[$w.list.l curselection
] {
2012 set b
[$w.list.l get
$i]
2013 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
2014 if {$check_cmt ne
{}} {
2015 if {$b eq
$check_rev} continue
2016 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
2018 lappend not_merged
$b
2022 lappend to_delete
[list
$b $o]
2024 if {$not_merged ne
{}} {
2025 set msg
"The following branches are not completely merged into $check_rev:
2027 - [join $not_merged "\n - "]"
2031 -title [wm title
$w] \
2035 if {$to_delete eq
{}} return
2036 if {$delete_branch_checktype eq
{always
}} {
2037 set msg
{Recovering deleted branches is difficult.
2039 Delete the selected branches?
}
2040 if {[tk_messageBox \
2043 -title [wm title
$w] \
2045 -message $msg] ne
yes} {
2051 foreach i
$to_delete {
2054 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2055 append failed
" - $b: $err\n"
2057 set x
[lsearch
-sorted $all_heads $b]
2059 set all_heads
[lreplace
$all_heads $x $x]
2064 if {$failed ne
{}} {
2068 -title [wm title
$w] \
2070 -message "Failed to delete branches:\n$failed"
2073 set all_heads
[lsort
$all_heads]
2074 populate_branch_menu
2078 proc do_delete_branch
{} {
2079 global all_heads tracking_branches current_branch
2080 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2082 set w .branch_editor
2084 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2086 label
$w.header
-text {Delete Local Branch
} \
2088 pack
$w.header
-side top
-fill x
2091 button
$w.buttons.create
-text Delete \
2093 -command [list do_delete_branch_action
$w]
2094 pack
$w.buttons.create
-side right
2095 button
$w.buttons.cancel
-text {Cancel
} \
2097 -command [list destroy
$w]
2098 pack
$w.buttons.cancel
-side right
-padx 5
2099 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2101 labelframe
$w.list \
2102 -text {Local Branches
} \
2107 -selectmode extended \
2109 foreach h
$all_heads {
2110 if {$h ne
$current_branch} {
2111 $w.list.l insert end
$h
2114 pack
$w.list.l
-fill both
-pady 5 -padx 5
2115 pack
$w.list
-fill both
-pady 5 -padx 5
2117 labelframe
$w.validate \
2118 -text {Delete Only If
} \
2120 radiobutton
$w.validate.head_r \
2121 -text {Merged Into Local Branch
:} \
2123 -variable delete_branch_checktype \
2125 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2126 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2127 set all_trackings
[all_tracking_branches
]
2128 if {$all_trackings ne
{}} {
2129 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2130 radiobutton
$w.validate.tracking_r \
2131 -text {Merged Into Tracking Branch
:} \
2133 -variable delete_branch_checktype \
2135 eval tk_optionMenu
$w.validate.tracking_m \
2136 delete_branch_trackinghead \
2138 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2140 radiobutton
$w.validate.always_r \
2141 -text {Always
(Do not perform merge checks
)} \
2143 -variable delete_branch_checktype \
2145 grid
$w.validate.always_r
-columnspan 2 -sticky w
2146 grid columnconfigure
$w.validate
1 -weight 1
2147 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2149 set delete_branch_head
$current_branch
2150 set delete_branch_checktype
head
2152 bind $w <Visibility
> "grab $w; focus $w"
2153 bind $w <Key-Escape
> "destroy $w"
2154 wm title
$w "[appname] ([reponame]): Delete Branch"
2158 proc switch_branch
{b
} {
2159 global HEAD commit_type file_states current_branch
2160 global selected_commit_type ui_comm
2162 if {![lock_index switch
]} return
2164 # -- Backup the selected branch (repository_state resets it)
2166 set new_branch
$current_branch
2168 # -- Our in memory state should match the repository.
2170 repository_state curType curHEAD curMERGE_HEAD
2171 if {[string match amend
* $commit_type]
2172 && $curType eq
{normal
}
2173 && $curHEAD eq
$HEAD} {
2174 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2175 info_popup
{Last scanned state does not match repository state.
2177 Another Git program has modified this repository
2178 since the last scan. A rescan must be performed
2179 before the current branch can be changed.
2181 The rescan will be automatically started now.
2184 rescan
{set ui_status_value
{Ready.
}}
2188 # -- Toss the message buffer if we are in amend mode.
2190 if {[string match amend
* $curType]} {
2191 $ui_comm delete
0.0 end
2193 $ui_comm edit modified false
2196 set selected_commit_type new
2197 set current_branch
$new_branch
2200 error
"NOT FINISHED"
2203 ######################################################################
2205 ## remote management
2207 proc load_all_remotes
{} {
2209 global all_remotes tracking_branches
2211 set all_remotes
[list
]
2212 array
unset tracking_branches
2214 set rm_dir
[gitdir remotes
]
2215 if {[file isdirectory
$rm_dir]} {
2216 set all_remotes
[glob \
2220 -directory $rm_dir *]
2222 foreach name
$all_remotes {
2224 set fd
[open
[file join $rm_dir $name] r
]
2225 while {[gets
$fd line
] >= 0} {
2226 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2227 $line line src dst
]} continue
2228 if {![regexp ^refs
/ $dst]} {
2229 set dst
"refs/heads/$dst"
2231 set tracking_branches
($dst) [list
$name $src]
2238 foreach line
[array names repo_config remote.
*.url
] {
2239 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2240 lappend all_remotes
$name
2242 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2246 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2247 if {![regexp ^refs
/ $dst]} {
2248 set dst
"refs/heads/$dst"
2250 set tracking_branches
($dst) [list
$name $src]
2254 set all_remotes
[lsort
-unique $all_remotes]
2257 proc populate_fetch_menu
{m
} {
2258 global all_remotes repo_config
2260 foreach r
$all_remotes {
2262 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2263 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2268 set fd
[open
[gitdir remotes
$r] r
]
2269 while {[gets
$fd n
] >= 0} {
2270 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2281 -label "Fetch from $r..." \
2282 -command [list fetch_from
$r] \
2288 proc populate_push_menu
{m
} {
2289 global all_remotes repo_config
2291 foreach r
$all_remotes {
2293 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2294 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2299 set fd
[open
[gitdir remotes
$r] r
]
2300 while {[gets
$fd n
] >= 0} {
2301 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2312 -label "Push to $r..." \
2313 -command [list push_to
$r] \
2319 proc populate_pull_menu
{m
} {
2320 global repo_config all_remotes disable_on_lock
2322 foreach remote
$all_remotes {
2324 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2325 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2326 foreach line
$repo_config(remote.
$remote.fetch
) {
2327 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2334 set fd
[open
[gitdir remotes
$remote] r
]
2335 while {[gets
$fd line
] >= 0} {
2336 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2344 foreach rb
$rb_list {
2345 regsub ^refs
/heads
/ $rb {} rb_short
2347 -label "Branch $rb_short from $remote..." \
2348 -command [list pull_remote
$remote $rb] \
2350 lappend disable_on_lock \
2351 [list
$m entryconf
[$m index last
] -state]
2356 ######################################################################
2361 #define mask_width 14
2362 #define mask_height 15
2363 static unsigned char mask_bits
[] = {
2364 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2365 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2366 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2369 image create bitmap file_plain
-background white
-foreground black
-data {
2370 #define plain_width 14
2371 #define plain_height 15
2372 static unsigned char plain_bits
[] = {
2373 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2374 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2375 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2376 } -maskdata $filemask
2378 image create bitmap file_mod
-background white
-foreground blue
-data {
2379 #define mod_width 14
2380 #define mod_height 15
2381 static unsigned char mod_bits
[] = {
2382 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2383 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2384 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2385 } -maskdata $filemask
2387 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2388 #define file_fulltick_width 14
2389 #define file_fulltick_height 15
2390 static unsigned char file_fulltick_bits
[] = {
2391 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2392 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2393 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2394 } -maskdata $filemask
2396 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2397 #define parttick_width 14
2398 #define parttick_height 15
2399 static unsigned char parttick_bits
[] = {
2400 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2401 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2402 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2403 } -maskdata $filemask
2405 image create bitmap file_question
-background white
-foreground black
-data {
2406 #define file_question_width 14
2407 #define file_question_height 15
2408 static unsigned char file_question_bits
[] = {
2409 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2410 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2411 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2412 } -maskdata $filemask
2414 image create bitmap file_removed
-background white
-foreground red
-data {
2415 #define file_removed_width 14
2416 #define file_removed_height 15
2417 static unsigned char file_removed_bits
[] = {
2418 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2419 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2420 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2421 } -maskdata $filemask
2423 image create bitmap file_merge
-background white
-foreground blue
-data {
2424 #define file_merge_width 14
2425 #define file_merge_height 15
2426 static unsigned char file_merge_bits
[] = {
2427 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2428 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2429 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2430 } -maskdata $filemask
2432 set ui_index .vpane.files.index.list
2433 set ui_workdir .vpane.files.workdir.list
2435 set all_icons
(_
$ui_index) file_plain
2436 set all_icons
(A
$ui_index) file_fulltick
2437 set all_icons
(M
$ui_index) file_fulltick
2438 set all_icons
(D
$ui_index) file_removed
2439 set all_icons
(U
$ui_index) file_merge
2441 set all_icons
(_
$ui_workdir) file_plain
2442 set all_icons
(M
$ui_workdir) file_mod
2443 set all_icons
(D
$ui_workdir) file_question
2444 set all_icons
(U
$ui_workdir) file_merge
2445 set all_icons
(O
$ui_workdir) file_plain
2447 set max_status_desc
0
2451 {_M
"Modified, not staged"}
2452 {M_
"Staged for commit"}
2453 {MM
"Portions staged for commit"}
2454 {MD
"Staged for commit, missing"}
2456 {_O
"Untracked, not staged"}
2457 {A_
"Staged for commit"}
2458 {AM
"Portions staged for commit"}
2459 {AD
"Staged for commit, missing"}
2462 {D_
"Staged for removal"}
2463 {DO
"Staged for removal, still present"}
2465 {U_
"Requires merge resolution"}
2466 {UU
"Requires merge resolution"}
2467 {UM
"Requires merge resolution"}
2468 {UD
"Requires merge resolution"}
2470 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2471 set max_status_desc
[string length
[lindex
$i 1]]
2473 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2477 ######################################################################
2482 global tcl_platform tk_library
2483 if {[tk windowingsystem
] eq
{aqua
}} {
2489 proc is_Windows
{} {
2491 if {$tcl_platform(platform
) eq
{windows
}} {
2497 proc bind_button3
{w cmd
} {
2498 bind $w <Any-Button-3
> $cmd
2500 bind $w <Control-Button-1
> $cmd
2504 proc incr_font_size
{font
{amt
1}} {
2505 set sz
[font configure
$font -size]
2507 font configure
$font -size $sz
2508 font configure
${font}bold
-size $sz
2511 proc hook_failed_popup
{hook msg
} {
2516 label
$w.m.l1
-text "$hook hook failed:" \
2521 -background white
-borderwidth 1 \
2523 -width 80 -height 10 \
2525 -yscrollcommand [list
$w.m.sby
set]
2527 -text {You must correct the above errors before committing.
} \
2531 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2532 pack
$w.m.l1
-side top
-fill x
2533 pack
$w.m.l2
-side bottom
-fill x
2534 pack
$w.m.sby
-side right
-fill y
2535 pack
$w.m.t
-side left
-fill both
-expand 1
2536 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2538 $w.m.t insert
1.0 $msg
2539 $w.m.t conf
-state disabled
2541 button
$w.ok
-text OK \
2544 -command "destroy $w"
2545 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2547 bind $w <Visibility
> "grab $w; focus $w"
2548 bind $w <Key-Return
> "destroy $w"
2549 wm title
$w "[appname] ([reponame]): error"
2553 set next_console_id
0
2555 proc new_console
{short_title long_title
} {
2556 global next_console_id console_data
2557 set w .console
[incr next_console_id
]
2558 set console_data
($w) [list
$short_title $long_title]
2559 return [console_init
$w]
2562 proc console_init
{w
} {
2563 global console_cr console_data M1B
2565 set console_cr
($w) 1.0
2568 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2573 -background white
-borderwidth 1 \
2575 -width 80 -height 10 \
2578 -yscrollcommand [list
$w.m.sby
set]
2579 label
$w.m.s
-text {Working... please
wait...
} \
2583 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2584 pack
$w.m.l1
-side top
-fill x
2585 pack
$w.m.s
-side bottom
-fill x
2586 pack
$w.m.sby
-side right
-fill y
2587 pack
$w.m.t
-side left
-fill both
-expand 1
2588 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2590 menu
$w.ctxm
-tearoff 0
2591 $w.ctxm add
command -label "Copy" \
2593 -command "tk_textCopy $w.m.t"
2594 $w.ctxm add
command -label "Select All" \
2596 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
2597 $w.ctxm add
command -label "Copy All" \
2600 $w.m.t tag add sel 0.0 end
2602 $w.m.t tag remove sel 0.0 end
2605 button
$w.ok
-text {Close
} \
2608 -command "destroy $w"
2609 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2611 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2612 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2613 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2614 bind $w <Visibility
> "focus $w"
2615 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2619 proc console_exec
{w cmd
{after
{}}} {
2620 # -- Windows tosses the enviroment when we exec our child.
2621 # But most users need that so we have to relogin. :-(
2624 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2627 # -- Tcl won't let us redirect both stdout and stderr to
2628 # the same pipe. So pass it through cat...
2630 set cmd
[concat |
$cmd |
& cat]
2632 set fd_f
[open
$cmd r
]
2633 fconfigure
$fd_f -blocking 0 -translation binary
2634 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2637 proc console_read
{w fd after
} {
2638 global console_cr console_data
2642 if {![winfo exists
$w]} {console_init
$w}
2643 $w.m.t conf
-state normal
2645 set n
[string length
$buf]
2647 set cr
[string first
"\r" $buf $c]
2648 set lf
[string first
"\n" $buf $c]
2649 if {$cr < 0} {set cr
[expr {$n + 1}]}
2650 if {$lf < 0} {set lf
[expr {$n + 1}]}
2653 $w.m.t insert end
[string range
$buf $c $lf]
2654 set console_cr
($w) [$w.m.t index
{end
-1c}]
2658 $w.m.t delete
$console_cr($w) end
2659 $w.m.t insert end
"\n"
2660 $w.m.t insert end
[string range
$buf $c $cr]
2665 $w.m.t conf
-state disabled
2669 fconfigure
$fd -blocking 1
2671 if {[catch
{close
$fd}]} {
2672 if {![winfo exists
$w]} {console_init
$w}
2673 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2674 $w.ok conf
-state normal
2676 } elseif
{[winfo exists
$w]} {
2677 $w.m.s conf
-background green
-text {Success
}
2678 $w.ok conf
-state normal
2681 array
unset console_cr
$w
2682 array
unset console_data
$w
2684 uplevel
#0 $after $ok
2688 fconfigure
$fd -blocking 0
2691 ######################################################################
2695 set starting_gitk_msg
{Starting gitk... please
wait...
}
2697 proc do_gitk
{revs
} {
2698 global ui_status_value starting_gitk_msg
2706 set cmd
"sh -c \"exec $cmd\""
2710 if {[catch
{eval exec $cmd} err
]} {
2711 error_popup
"Failed to start gitk:\n\n$err"
2713 set ui_status_value
$starting_gitk_msg
2715 if {$ui_status_value eq
$starting_gitk_msg} {
2716 set ui_status_value
{Ready.
}
2723 set fd
[open
"| git count-objects -v" r
]
2724 while {[gets
$fd line
] > 0} {
2725 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
2726 set stats
($name) $value
2733 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2735 label
$w.header
-text {Database Statistics
} \
2737 pack
$w.header
-side top
-fill x
2739 frame
$w.buttons
-border 1
2740 button
$w.buttons.close
-text Close \
2742 -command [list destroy
$w]
2743 button
$w.buttons.gc
-text {Compress Database
} \
2745 -command "destroy $w;do_gc"
2746 pack
$w.buttons.close
-side right
2747 pack
$w.buttons.gc
-side left
2748 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2750 frame
$w.stat
-borderwidth 1 -relief solid
2752 {count
{Number of loose objects
}}
2753 {size
{Disk space used by loose objects
} { KiB
}}
2754 {in-pack
{Number of packed objects
}}
2755 {packs
{Number of packs
}}
2756 {prune-packable
{Packed objects waiting
for pruning
}}
2757 {garbage
{Garbage files
}}
2759 set name
[lindex
$s 0]
2760 set label
[lindex
$s 1]
2761 if {[catch
{set value
$stats($name)}]} continue
2762 if {[llength
$s] > 2} {
2763 set value
"$value[lindex $s 2]"
2766 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
2767 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
2768 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
2772 bind $w <Visibility
> "grab $w; focus $w"
2773 bind $w <Key-Escape
> [list destroy
$w]
2774 bind $w <Key-Return
> [list destroy
$w]
2775 wm title
$w "[appname] ([reponame]): Database Statistics"
2780 set w
[new_console
{gc
} {Compressing the object database
}]
2781 console_exec
$w {git gc
}
2784 proc do_fsck_objects
{} {
2785 set w
[new_console
{fsck-objects
} \
2786 {Verifying the object database with fsck-objects
}]
2787 set cmd
[list git fsck-objects
]
2790 lappend cmd
--strict
2791 console_exec
$w $cmd
2797 global ui_comm is_quitting repo_config commit_type
2799 if {$is_quitting} return
2802 # -- Stash our current commit buffer.
2804 set save
[gitdir GITGUI_MSG
]
2805 set msg
[string trim
[$ui_comm get
0.0 end
]]
2806 if {![string match amend
* $commit_type]
2807 && [$ui_comm edit modified
]
2810 set fd
[open
$save w
]
2811 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2815 catch
{file delete
$save}
2818 # -- Stash our current window geometry into this repository.
2820 set cfg_geometry
[list
]
2821 lappend cfg_geometry
[wm geometry .
]
2822 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2823 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2824 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2827 if {$cfg_geometry ne
$rc_geometry} {
2828 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2835 rescan
{set ui_status_value
{Ready.
}}
2838 proc unstage_helper
{txt paths
} {
2839 global file_states current_diff_path
2841 if {![lock_index begin-update
]} return
2845 foreach path
$paths {
2846 switch
-glob -- [lindex
$file_states($path) 0] {
2850 lappend pathList
$path
2851 if {$path eq
$current_diff_path} {
2852 set after
{reshow_diff
;}
2857 if {$pathList eq
{}} {
2863 [concat
$after {set ui_status_value
{Ready.
}}]
2867 proc do_unstage_selection
{} {
2868 global current_diff_path selected_paths
2870 if {[array size selected_paths
] > 0} {
2872 {Unstaging selected files from commit
} \
2873 [array names selected_paths
]
2874 } elseif
{$current_diff_path ne
{}} {
2876 "Unstaging [short_path $current_diff_path] from commit" \
2877 [list
$current_diff_path]
2881 proc add_helper
{txt paths
} {
2882 global file_states current_diff_path
2884 if {![lock_index begin-update
]} return
2888 foreach path
$paths {
2889 switch
-glob -- [lindex
$file_states($path) 0] {
2894 lappend pathList
$path
2895 if {$path eq
$current_diff_path} {
2896 set after
{reshow_diff
;}
2901 if {$pathList eq
{}} {
2907 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2911 proc do_add_selection
{} {
2912 global current_diff_path selected_paths
2914 if {[array size selected_paths
] > 0} {
2916 {Adding selected files
} \
2917 [array names selected_paths
]
2918 } elseif
{$current_diff_path ne
{}} {
2920 "Adding [short_path $current_diff_path]" \
2921 [list
$current_diff_path]
2925 proc do_add_all
{} {
2929 foreach path
[array names file_states
] {
2930 switch
-glob -- [lindex
$file_states($path) 0] {
2933 ?D
{lappend paths
$path}
2936 add_helper
{Adding all changed files
} $paths
2939 proc revert_helper
{txt paths
} {
2940 global file_states current_diff_path
2942 if {![lock_index begin-update
]} return
2946 foreach path
$paths {
2947 switch
-glob -- [lindex
$file_states($path) 0] {
2951 lappend pathList
$path
2952 if {$path eq
$current_diff_path} {
2953 set after
{reshow_diff
;}
2959 set n
[llength
$pathList]
2963 } elseif
{$n == 1} {
2964 set s
"[short_path [lindex $pathList]]"
2966 set s
"these $n files"
2969 set reply
[tk_dialog \
2971 "[appname] ([reponame])" \
2972 "Revert changes in $s?
2974 Any unadded changes will be permanently lost by the revert." \
2984 [concat
$after {set ui_status_value
{Ready.
}}]
2990 proc do_revert_selection
{} {
2991 global current_diff_path selected_paths
2993 if {[array size selected_paths
] > 0} {
2995 {Reverting selected files
} \
2996 [array names selected_paths
]
2997 } elseif
{$current_diff_path ne
{}} {
2999 "Reverting [short_path $current_diff_path]" \
3000 [list
$current_diff_path]
3004 proc do_signoff
{} {
3007 set me
[committer_ident
]
3008 if {$me eq
{}} return
3010 set sob
"Signed-off-by: $me"
3011 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
3012 if {$last ne
$sob} {
3013 $ui_comm edit separator
3015 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
3016 $ui_comm insert end
"\n"
3018 $ui_comm insert end
"\n$sob"
3019 $ui_comm edit separator
3024 proc do_select_commit_type
{} {
3025 global commit_type selected_commit_type
3027 if {$selected_commit_type eq
{new
}
3028 && [string match amend
* $commit_type]} {
3030 } elseif
{$selected_commit_type eq
{amend
}
3031 && ![string match amend
* $commit_type]} {
3034 # The amend request was rejected...
3036 if {![string match amend
* $commit_type]} {
3037 set selected_commit_type new
3047 global appvers copyright
3048 global tcl_patchLevel tk_patchLevel
3052 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3054 label
$w.header
-text "About [appname]" \
3056 pack
$w.header
-side top
-fill x
3059 button
$w.buttons.close
-text {Close
} \
3061 -command [list destroy
$w]
3062 pack
$w.buttons.close
-side right
3063 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3066 -text "[appname] - a commit creation tool for Git.
3074 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
3077 append v
"[appname] version $appvers\n"
3078 append v
"[exec git version]\n"
3080 if {$tcl_patchLevel eq
$tk_patchLevel} {
3081 append v
"Tcl/Tk version $tcl_patchLevel"
3083 append v
"Tcl version $tcl_patchLevel"
3084 append v
", Tk version $tk_patchLevel"
3095 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
3097 menu
$w.ctxm
-tearoff 0
3098 $w.ctxm add
command \
3103 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
3106 bind $w <Visibility
> "grab $w; focus $w"
3107 bind $w <Key-Escape
> "destroy $w"
3108 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3109 wm title
$w "About [appname]"
3113 proc do_options
{} {
3114 global repo_config global_config font_descs
3115 global repo_config_new global_config_new
3117 array
unset repo_config_new
3118 array
unset global_config_new
3119 foreach name
[array names repo_config
] {
3120 set repo_config_new
($name) $repo_config($name)
3123 foreach name
[array names repo_config
] {
3125 gui.diffcontext
{continue}
3127 set repo_config_new
($name) $repo_config($name)
3129 foreach name
[array names global_config
] {
3130 set global_config_new
($name) $global_config($name)
3133 set w .options_editor
3135 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3137 label
$w.header
-text "[appname] Options" \
3139 pack
$w.header
-side top
-fill x
3142 button
$w.buttons.restore
-text {Restore Defaults
} \
3144 -command do_restore_defaults
3145 pack
$w.buttons.restore
-side left
3146 button
$w.buttons.save
-text Save \
3149 catch {eval \[bind \[focus -displayof $w\] <FocusOut>\]}
3152 pack
$w.buttons.save
-side right
3153 button
$w.buttons.cancel
-text {Cancel
} \
3155 -command [list destroy
$w]
3156 pack
$w.buttons.cancel
-side right
-padx 5
3157 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3159 labelframe
$w.repo
-text "[reponame] Repository" \
3161 -relief raised
-borderwidth 2
3162 labelframe
$w.global
-text {Global
(All Repositories
)} \
3164 -relief raised
-borderwidth 2
3165 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3166 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3169 {b pullsummary
{Show Pull Summary
}}
3170 {b trustmtime
{Trust File Modification Timestamps
}}
3171 {i diffcontext
{Number of Diff Context Lines
}}
3172 {t newbranchtemplate
{New Branch Name Template
}}
3174 set type [lindex
$option 0]
3175 set name
[lindex
$option 1]
3176 set text
[lindex
$option 2]
3177 foreach f
{repo global
} {
3180 checkbutton
$w.
$f.
$name -text $text \
3181 -variable ${f}_config_new
(gui.
$name) \
3185 pack
$w.
$f.
$name -side top
-anchor w
3189 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3190 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
3191 spinbox
$w.
$f.
$name.v \
3192 -textvariable ${f}_config_new
(gui.
$name) \
3193 -from 1 -to 99 -increment 1 \
3196 bind $w.
$f.
$name.v
<FocusIn
> {%W selection range
0 end
}
3197 pack
$w.
$f.
$name.v
-side right
-anchor e
-padx 5
3198 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3202 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3203 text
$w.
$f.
$name.v \
3209 $w.
$f.
$name.v insert
0.0 [set ${f}_config_new
(gui.
$name)]
3210 bind $w.
$f.
$name.v
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
3211 bind $w.
$f.
$name.v
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
3212 bind $w.
$f.
$name.v
<Key-Return
> break
3213 bind $w.
$f.
$name.v
<FocusIn
> "$w.$f.$name.v tag add sel 0.0 end"
3214 bind $w.
$f.
$name.v
<FocusOut
> "
3215 set ${f}_config_new(gui.$name) \
3216 \[string trim \[$w.$f.$name.v get 0.0 end\]\]
3218 pack
$w.
$f.
$name.l
-side left
-anchor w
3219 pack
$w.
$f.
$name.v
-side left
-anchor w \
3222 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3228 set all_fonts
[lsort
[font families
]]
3229 foreach option
$font_descs {
3230 set name
[lindex
$option 0]
3231 set font
[lindex
$option 1]
3232 set text
[lindex
$option 2]
3234 set global_config_new
(gui.
$font^^family
) \
3235 [font configure
$font -family]
3236 set global_config_new
(gui.
$font^^size
) \
3237 [font configure
$font -size]
3239 frame
$w.global.
$name
3240 label
$w.global.
$name.l
-text "$text:" -font font_ui
3241 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3242 eval tk_optionMenu
$w.global.
$name.family \
3243 global_config_new
(gui.
$font^^family
) \
3245 spinbox
$w.global.
$name.size \
3246 -textvariable global_config_new
(gui.
$font^^size
) \
3247 -from 2 -to 80 -increment 1 \
3250 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3251 pack
$w.global.
$name.size
-side right
-anchor e
3252 pack
$w.global.
$name.family
-side right
-anchor e
3253 pack
$w.global.
$name -side top
-anchor w
-fill x
3256 bind $w <Visibility
> "grab $w; focus $w"
3257 bind $w <Key-Escape
> "destroy $w"
3258 wm title
$w "[appname] ([reponame]): Options"
3262 proc do_restore_defaults
{} {
3263 global font_descs default_config repo_config
3264 global repo_config_new global_config_new
3266 foreach name
[array names default_config
] {
3267 set repo_config_new
($name) $default_config($name)
3268 set global_config_new
($name) $default_config($name)
3271 foreach option
$font_descs {
3272 set name
[lindex
$option 0]
3273 set repo_config
(gui.
$name) $default_config(gui.
$name)
3277 foreach option
$font_descs {
3278 set name
[lindex
$option 0]
3279 set font
[lindex
$option 1]
3280 set global_config_new
(gui.
$font^^family
) \
3281 [font configure
$font -family]
3282 set global_config_new
(gui.
$font^^size
) \
3283 [font configure
$font -size]
3287 proc do_save_config
{w
} {
3288 if {[catch
{save_config
} err
]} {
3289 error_popup
"Failed to completely save options:\n\n$err"
3295 proc do_windows_shortcut
{} {
3299 set desktop
[exec cygpath \
3307 set fn
[tk_getSaveFile \
3309 -title "[appname] ([reponame]): Create Desktop Icon" \
3310 -initialdir $desktop \
3311 -initialfile "Git [reponame].bat"]
3315 set sh
[exec cygpath \
3319 set me
[exec cygpath \
3323 set gd
[exec cygpath \
3327 set gw
[exec cygpath \
3330 [file dirname [gitdir
]]]
3331 regsub
-all ' $me "'\\''" me
3332 regsub -all ' $gd "'\\''" gd
3333 puts $fd "@ECHO Entering $gw"
3334 puts $fd "@ECHO Starting git-gui... please wait..."
3335 puts -nonewline $fd "@\"$sh\" --login -c \""
3336 puts -nonewline $fd "GIT_DIR='$gd'"
3337 puts -nonewline $fd " '$me'"
3341 error_popup "Cannot write script:\n\n$err"
3346 proc do_macosx_app {} {
3349 set fn [tk_getSaveFile \
3351 -title "[appname] ([reponame]): Create Desktop Icon" \
3352 -initialdir [file join $env(HOME) Desktop] \
3353 -initialfile "Git [reponame].app"]
3356 set Contents [file join $fn Contents]
3357 set MacOS [file join $Contents MacOS]
3358 set exe [file join $MacOS git-gui]
3362 set fd [open [file join $Contents Info.plist] w]
3363 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3364 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3365 <plist version="1.0">
3367 <key>CFBundleDevelopmentRegion</key>
3368 <string>English</string>
3369 <key>CFBundleExecutable</key>
3370 <string>git-gui</string>
3371 <key>CFBundleIdentifier</key>
3372 <string>org.spearce.git-gui</string>
3373 <key>CFBundleInfoDictionaryVersion</key>
3374 <string>6.0</string>
3375 <key>CFBundlePackageType</key>
3376 <string>APPL</string>
3377 <key>CFBundleSignature</key>
3378 <string>????</string>
3379 <key>CFBundleVersion</key>
3380 <string>1.0</string>
3381 <key>NSPrincipalClass</key>
3382 <string>NSApplication</string>
3387 set fd [open $exe w]
3388 set gd [file normalize [gitdir]]
3389 set ep [file normalize [exec git --exec-path]]
3390 regsub -all ' $gd "'\\''" gd
3391 regsub
-all ' $ep "'\\''" ep
3392 puts $fd "#!/bin/sh"
3393 foreach name
[array names env
] {
3394 if {[string match GIT_
* $name]} {
3395 regsub
-all ' $env($name) "'\\''" v
3396 puts $fd "export $name='$v'"
3399 puts $fd "export PATH
='$ep':\
$PATH"
3400 puts $fd "export GIT_DIR
='$gd'"
3401 puts $fd "exec [file normalize
$argv0]"
3404 file attributes $exe -permissions u+x,g+x,o+x
3406 error_popup "Cannot
write icon
:\n\n$err"
3411 proc toggle_or_diff {w x y} {
3412 global file_states file_lists current_diff_path ui_index ui_workdir
3413 global last_clicked selected_paths
3415 set pos [split [$w index @$x,$y] .]
3416 set lno [lindex $pos 0]
3417 set col [lindex $pos 1]
3418 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3424 set last_clicked [list $w $lno]
3425 array unset selected_paths
3426 $ui_index tag remove in_sel 0.0 end
3427 $ui_workdir tag remove in_sel 0.0 end
3430 if {$current_diff_path eq $path} {
3431 set after {reshow_diff;}
3435 if {$w eq $ui_index} {
3437 "Unstaging
[short_path
$path] from commit
" \
3439 [concat $after {set ui_status_value {Ready.}}]
3440 } elseif {$w eq $ui_workdir} {
3442 "Adding
[short_path
$path]" \
3444 [concat $after {set ui_status_value {Ready.}}]
3447 show_diff $path $w $lno
3451 proc add_one_to_selection {w x y} {
3452 global file_lists last_clicked selected_paths
3454 set lno [lindex [split [$w index @$x,$y] .] 0]
3455 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3461 if {$last_clicked ne {}
3462 && [lindex $last_clicked 0] ne $w} {
3463 array unset selected_paths
3464 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3467 set last_clicked [list $w $lno]
3468 if {[catch {set in_sel $selected_paths($path)}]} {
3472 unset selected_paths($path)
3473 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3475 set selected_paths($path) 1
3476 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3480 proc add_range_to_selection {w x y} {
3481 global file_lists last_clicked selected_paths
3483 if {[lindex $last_clicked 0] ne $w} {
3484 toggle_or_diff $w $x $y
3488 set lno [lindex [split [$w index @$x,$y] .] 0]
3489 set lc [lindex $last_clicked 1]
3498 foreach path [lrange $file_lists($w) \
3499 [expr {$begin - 1}] \
3500 [expr {$end - 1}]] {
3501 set selected_paths($path) 1
3503 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3506 ######################################################################
3510 set cursor_ptr arrow
3511 font create font_diff -family Courier -size 10
3515 eval font configure font_ui [font actual [.dummy cget -font]]
3519 font create font_uibold
3520 font create font_diffbold
3525 } elseif {[is_MacOSX]} {
3533 proc apply_config {} {
3534 global repo_config font_descs
3536 foreach option $font_descs {
3537 set name [lindex $option 0]
3538 set font [lindex $option 1]
3540 foreach {cn cv} $repo_config(gui.$name) {
3541 font configure $font $cn $cv
3544 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3546 foreach {cn cv} [font configure $font] {
3547 font configure ${font}bold $cn $cv
3549 font configure ${font}bold -weight bold
3553 set default_config(gui.trustmtime) false
3554 set default_config(gui.pullsummary) true
3555 set default_config(gui.diffcontext) 5
3556 set default_config(gui.newbranchtemplate) {}
3557 set default_config(gui.fontui) [font configure font_ui]
3558 set default_config(gui.fontdiff) [font configure font_diff]
3560 {fontui font_ui {Main Font}}
3561 {fontdiff font_diff {Diff/Console Font}}
3566 ######################################################################
3572 menu .mbar -tearoff 0
3573 .mbar add cascade -label Repository -menu .mbar.repository
3574 .mbar add cascade -label Edit -menu .mbar.edit
3575 if {!$single_commit} {
3576 .mbar add cascade -label Branch -menu .mbar.branch
3578 .mbar add cascade -label Commit -menu .mbar.commit
3579 if {!$single_commit} {
3580 .mbar add cascade -label Fetch -menu .mbar.fetch
3581 .mbar add cascade -label Pull -menu .mbar.pull
3582 .mbar add cascade -label Push -menu .mbar.push
3584 . configure -menu .mbar
3586 # -- Repository Menu
3588 menu .mbar.repository
3589 .mbar.repository add command \
3590 -label {Visualize Current Branch} \
3591 -command {do_gitk {}} \
3594 .mbar.repository add command \
3595 -label {Visualize All Branches} \
3596 -command {do_gitk {--all}} \
3599 .mbar.repository add separator
3601 if {!$single_commit} {
3602 .mbar.repository add command -label {Database Statistics} \
3606 .mbar.repository add command -label {Compress Database} \
3610 .mbar.repository add command -label {Verify Database} \
3611 -command do_fsck_objects \
3614 .mbar.repository add separator
3617 .mbar.repository add command \
3618 -label {Create Desktop Icon} \
3619 -command do_windows_shortcut \
3621 } elseif {[is_MacOSX]} {
3622 .mbar.repository add command \
3623 -label {Create Desktop Icon} \
3624 -command do_macosx_app \
3629 .mbar.repository add command -label Quit \
3631 -accelerator $M1T-Q \
3637 .mbar.edit add command -label Undo \
3638 -command {catch {[focus] edit undo}} \
3639 -accelerator $M1T-Z \
3641 .mbar.edit add command -label Redo \
3642 -command {catch {[focus] edit redo}} \
3643 -accelerator $M1T-Y \
3645 .mbar.edit add separator
3646 .mbar.edit add command -label Cut \
3647 -command {catch {tk_textCut [focus]}} \
3648 -accelerator $M1T-X \
3650 .mbar.edit add command -label Copy \
3651 -command {catch {tk_textCopy [focus]}} \
3652 -accelerator $M1T-C \
3654 .mbar.edit add command -label Paste \
3655 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3656 -accelerator $M1T-V \
3658 .mbar.edit add command -label Delete \
3659 -command {catch {[focus] delete sel.first sel.last}} \
3662 .mbar.edit add separator
3663 .mbar.edit add command -label {Select All} \
3664 -command {catch {[focus] tag add sel 0.0 end}} \
3665 -accelerator $M1T-A \
3670 if {!$single_commit} {
3673 .mbar.branch add command -label {Create...} \
3674 -command do_create_branch \
3675 -accelerator $M1T-N \
3677 lappend disable_on_lock [list .mbar.branch entryconf \
3678 [.mbar.branch index last] -state]
3680 .mbar.branch add command -label {Delete...} \
3681 -command do_delete_branch \
3683 lappend disable_on_lock [list .mbar.branch entryconf \
3684 [.mbar.branch index last] -state]
3691 .mbar.commit add radiobutton \
3692 -label {New Commit} \
3693 -command do_select_commit_type \
3694 -variable selected_commit_type \
3697 lappend disable_on_lock \
3698 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3700 .mbar.commit add radiobutton \
3701 -label {Amend Last Commit} \
3702 -command do_select_commit_type \
3703 -variable selected_commit_type \
3706 lappend disable_on_lock \
3707 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3709 .mbar.commit add separator
3711 .mbar.commit add command -label Rescan \
3712 -command do_rescan \
3715 lappend disable_on_lock \
3716 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3718 .mbar.commit add command -label {Add To Commit} \
3719 -command do_add_selection \
3721 lappend disable_on_lock \
3722 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3724 .mbar.commit add command -label {Add All To Commit} \
3725 -command do_add_all \
3726 -accelerator $M1T-I \
3728 lappend disable_on_lock \
3729 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3731 .mbar.commit add command -label {Unstage From Commit} \
3732 -command do_unstage_selection \
3734 lappend disable_on_lock \
3735 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3737 .mbar.commit add command -label {Revert Changes} \
3738 -command do_revert_selection \
3740 lappend disable_on_lock \
3741 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3743 .mbar.commit add separator
3745 .mbar.commit add command -label {Sign Off} \
3746 -command do_signoff \
3747 -accelerator $M1T-S \
3750 .mbar.commit add command -label Commit \
3751 -command do_commit \
3752 -accelerator $M1T-Return \
3754 lappend disable_on_lock \
3755 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3757 # -- Transport menus
3759 if {!$single_commit} {
3766 # -- Apple Menu (Mac OS X only)
3768 .mbar add cascade -label Apple -menu .mbar.apple
3771 .mbar.apple add command -label "About
[appname
]" \
3774 .mbar.apple add command -label "[appname
] Options...
" \
3775 -command do_options \
3780 .mbar.edit add separator
3781 .mbar.edit add command -label {Options...} \
3782 -command do_options \
3787 if {[file exists /usr/local/miga/lib/gui-miga]
3788 && [file exists .pvcsrc]} {
3790 global ui_status_value
3791 if {![lock_index update]} return
3792 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3793 set miga_fd [open "|
$cmd" r]
3794 fconfigure $miga_fd -blocking 0
3795 fileevent $miga_fd readable [list miga_done $miga_fd]
3796 set ui_status_value {Running miga...}
3798 proc miga_done {fd} {
3803 rescan [list set ui_status_value {Ready.}]
3806 .mbar add cascade -label Tools -menu .mbar.tools
3808 .mbar.tools add command -label "Migrate
" \
3811 lappend disable_on_lock \
3812 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3817 .mbar add cascade -label Help -menu .mbar.help
3820 .mbar.help add command -label "About
[appname
]" \
3832 -text {Current Branch:} \
3837 -textvariable current_branch \
3841 pack .branch.l1 -side left
3842 pack .branch.cb -side left -fill x
3843 pack .branch -side top -fill x
3845 # -- Main Window Layout
3847 panedwindow .vpane -orient vertical
3848 panedwindow .vpane.files -orient horizontal
3849 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3850 pack .vpane -anchor n -side top -fill both -expand 1
3852 # -- Index File List
3854 frame .vpane.files.index -height 100 -width 200
3855 label .vpane.files.index.title -text {Changes To Be Committed} \
3858 text $ui_index -background white -borderwidth 0 \
3859 -width 20 -height 10 \
3862 -cursor $cursor_ptr \
3863 -xscrollcommand {.vpane.files.index.sx set} \
3864 -yscrollcommand {.vpane.files.index.sy set} \
3866 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3867 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3868 pack .vpane.files.index.title -side top -fill x
3869 pack .vpane.files.index.sx -side bottom -fill x
3870 pack .vpane.files.index.sy -side right -fill y
3871 pack $ui_index -side left -fill both -expand 1
3872 .vpane.files add .vpane.files.index -sticky nsew
3874 # -- Working Directory File List
3876 frame .vpane.files.workdir -height 100 -width 200
3877 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3880 text $ui_workdir -background white -borderwidth 0 \
3881 -width 20 -height 10 \
3884 -cursor $cursor_ptr \
3885 -xscrollcommand {.vpane.files.workdir.sx set} \
3886 -yscrollcommand {.vpane.files.workdir.sy set} \
3888 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3889 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3890 pack .vpane.files.workdir.title -side top -fill x
3891 pack .vpane.files.workdir.sx -side bottom -fill x
3892 pack .vpane.files.workdir.sy -side right -fill y
3893 pack $ui_workdir -side left -fill both -expand 1
3894 .vpane.files add .vpane.files.workdir -sticky nsew
3896 foreach i [list $ui_index $ui_workdir] {
3897 $i tag conf in_diff -font font_uibold
3898 $i tag conf in_sel \
3899 -background [$i cget -foreground] \
3900 -foreground [$i cget -background]
3904 # -- Diff and Commit Area
3906 frame .vpane.lower -height 300 -width 400
3907 frame .vpane.lower.commarea
3908 frame .vpane.lower.diff -relief sunken -borderwidth 1
3909 pack .vpane.lower.commarea -side top -fill x
3910 pack .vpane.lower.diff -side bottom -fill both -expand 1
3911 .vpane add .vpane.lower -sticky nsew
3913 # -- Commit Area Buttons
3915 frame .vpane.lower.commarea.buttons
3916 label .vpane.lower.commarea.buttons.l -text {} \
3920 pack .vpane.lower.commarea.buttons.l -side top -fill x
3921 pack .vpane.lower.commarea.buttons -side left -fill y
3923 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3924 -command do_rescan \
3926 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3927 lappend disable_on_lock \
3928 {.vpane.lower.commarea.buttons.rescan conf -state}
3930 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3931 -command do_add_all \
3933 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3934 lappend disable_on_lock \
3935 {.vpane.lower.commarea.buttons.incall conf -state}
3937 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3938 -command do_signoff \
3940 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3942 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3943 -command do_commit \
3945 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3946 lappend disable_on_lock \
3947 {.vpane.lower.commarea.buttons.commit conf -state}
3949 # -- Commit Message Buffer
3951 frame .vpane.lower.commarea.buffer
3952 frame .vpane.lower.commarea.buffer.header
3953 set ui_comm .vpane.lower.commarea.buffer.t
3954 set ui_coml .vpane.lower.commarea.buffer.header.l
3955 radiobutton .vpane.lower.commarea.buffer.header.new \
3956 -text {New Commit} \
3957 -command do_select_commit_type \
3958 -variable selected_commit_type \
3961 lappend disable_on_lock \
3962 [list .vpane.lower.commarea.buffer.header.new conf -state]
3963 radiobutton .vpane.lower.commarea.buffer.header.amend \
3964 -text {Amend Last Commit} \
3965 -command do_select_commit_type \
3966 -variable selected_commit_type \
3969 lappend disable_on_lock \
3970 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3975 proc trace_commit_type {varname args} {
3976 global ui_coml commit_type
3977 switch -glob -- $commit_type {
3978 initial {set txt {Initial Commit Message:}}
3979 amend {set txt {Amended Commit Message:}}
3980 amend-initial {set txt {Amended Initial Commit Message:}}
3981 amend-merge {set txt {Amended Merge Commit Message:}}
3982 merge {set txt {Merge Commit Message:}}
3983 * {set txt {Commit Message:}}
3985 $ui_coml conf -text $txt
3987 trace add variable commit_type write trace_commit_type
3988 pack $ui_coml -side left -fill x
3989 pack .vpane.lower.commarea.buffer.header.amend -side right
3990 pack .vpane.lower.commarea.buffer.header.new -side right
3992 text $ui_comm -background white -borderwidth 1 \
3995 -autoseparators true \
3997 -width 75 -height 9 -wrap none \
3999 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
4000 scrollbar .vpane.lower.commarea.buffer.sby \
4001 -command [list $ui_comm yview]
4002 pack .vpane.lower.commarea.buffer.header -side top -fill x
4003 pack .vpane.lower.commarea.buffer.sby -side right -fill y
4004 pack $ui_comm -side left -fill y
4005 pack .vpane.lower.commarea.buffer -side left -fill y
4007 # -- Commit Message Buffer Context Menu
4009 set ctxm .vpane.lower.commarea.buffer.ctxm
4010 menu $ctxm -tearoff 0
4014 -command {tk_textCut $ui_comm}
4018 -command {tk_textCopy $ui_comm}
4022 -command {tk_textPaste $ui_comm}
4026 -command {$ui_comm delete sel.first sel.last}
4029 -label {Select All} \
4031 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
4036 $ui_comm tag add sel 0.0 end
4037 tk_textCopy $ui_comm
4038 $ui_comm tag remove sel 0.0 end
4045 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
4049 set current_diff_path {}
4050 set diff_actions [list]
4051 proc trace_current_diff_path {varname args} {
4052 global current_diff_path diff_actions file_states
4053 if {$current_diff_path eq {}} {
4059 set p $current_diff_path
4060 set s [mapdesc [lindex $file_states($p) 0] $p]
4062 set p [escape_path $p]
4066 .vpane.lower.diff.header.status configure -text $s
4067 .vpane.lower.diff.header.file configure -text $f
4068 .vpane.lower.diff.header.path configure -text $p
4069 foreach w $diff_actions {
4073 trace add variable current_diff_path write trace_current_diff_path
4075 frame .vpane.lower.diff.header -background orange
4076 label .vpane.lower.diff.header.status \
4077 -background orange \
4078 -width $max_status_desc \
4082 label .vpane.lower.diff.header.file \
4083 -background orange \
4087 label .vpane.lower.diff.header.path \
4088 -background orange \
4092 pack .vpane.lower.diff.header.status -side left
4093 pack .vpane.lower.diff.header.file -side left
4094 pack .vpane.lower.diff.header.path -fill x
4095 set ctxm .vpane.lower.diff.header.ctxm
4096 menu $ctxm -tearoff 0
4105 -- $current_diff_path
4107 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4108 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
4112 frame .vpane.lower.diff.body
4113 set ui_diff .vpane.lower.diff.body.t
4114 text $ui_diff -background white -borderwidth 0 \
4115 -width 80 -height 15 -wrap none \
4117 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4118 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4120 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4121 -command [list $ui_diff xview]
4122 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4123 -command [list $ui_diff yview]
4124 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4125 pack .vpane.lower.diff.body.sby -side right -fill y
4126 pack $ui_diff -side left -fill both -expand 1
4127 pack .vpane.lower.diff.header -side top -fill x
4128 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4130 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4131 $ui_diff tag conf d_+ -foreground {#00a000}
4132 $ui_diff tag conf d_- -foreground red
4134 $ui_diff tag conf d_++ -foreground {#00a000}
4135 $ui_diff tag conf d_-- -foreground red
4136 $ui_diff tag conf d_+s \
4137 -foreground {#00a000} \
4138 -background {#e2effa}
4139 $ui_diff tag conf d_-s \
4141 -background {#e2effa}
4142 $ui_diff tag conf d_s+ \
4143 -foreground {#00a000} \
4145 $ui_diff tag conf d_s- \
4149 $ui_diff tag conf d<<<<<<< \
4150 -foreground orange \
4152 $ui_diff tag conf d======= \
4153 -foreground orange \
4155 $ui_diff tag conf d>>>>>>> \
4156 -foreground orange \
4159 $ui_diff tag raise sel
4161 # -- Diff Body Context Menu
4163 set ctxm .vpane.lower.diff.body.ctxm
4164 menu $ctxm -tearoff 0
4168 -command reshow_diff
4172 -command {tk_textCopy $ui_diff}
4173 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4175 -label {Select All} \
4177 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4178 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4183 $ui_diff tag add sel 0.0 end
4184 tk_textCopy $ui_diff
4185 $ui_diff tag remove sel 0.0 end
4187 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4190 -label {Decrease Font Size} \
4192 -command {incr_font_size font_diff -1}
4193 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4195 -label {Increase Font Size} \
4197 -command {incr_font_size font_diff 1}
4198 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4201 -label {Show Less Context} \
4203 -command {if {$repo_config(gui.diffcontext) >= 2} {
4204 incr repo_config(gui.diffcontext) -1
4207 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4209 -label {Show More Context} \
4212 incr repo_config(gui.diffcontext)
4215 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4217 $ctxm add command -label {Options...} \
4220 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
4224 set ui_status_value {Initializing...}
4225 label .status -textvariable ui_status_value \
4231 pack .status -anchor w -side bottom -fill x
4236 set gm $repo_config(gui.geometry)
4237 wm geometry . [lindex $gm 0]
4238 .vpane sash place 0 \
4239 [lindex [.vpane sash coord 0] 0] \
4241 .vpane.files sash place 0 \
4243 [lindex [.vpane.files sash coord 0] 1]
4249 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4250 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4251 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4252 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4253 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4254 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4255 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4256 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4257 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4258 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4259 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4261 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4262 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4263 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4264 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4265 bind $ui_diff <$M1B-Key-v> {break}
4266 bind $ui_diff <$M1B-Key-V> {break}
4267 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4268 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4269 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4270 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4271 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4272 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4274 if {!$single_commit} {
4275 bind . <$M1B-Key-n> do_create_branch
4276 bind . <$M1B-Key-N> do_create_branch
4279 bind . <Destroy> do_quit
4280 bind all <Key-F5> do_rescan
4281 bind all <$M1B-Key-r> do_rescan
4282 bind all <$M1B-Key-R> do_rescan
4283 bind . <$M1B-Key-s> do_signoff
4284 bind . <$M1B-Key-S> do_signoff
4285 bind . <$M1B-Key-i> do_add_all
4286 bind . <$M1B-Key-I> do_add_all
4287 bind . <$M1B-Key-Return> do_commit
4288 bind all <$M1B-Key-q> do_quit
4289 bind all <$M1B-Key-Q> do_quit
4290 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4291 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4292 foreach i [list $ui_index $ui_workdir] {
4293 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4294 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4295 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4299 set file_lists($ui_index) [list]
4300 set file_lists($ui_workdir) [list]
4304 set MERGE_HEAD [list]
4307 set current_branch {}
4308 set current_diff_path {}
4309 set selected_commit_type new
4311 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4312 focus -force $ui_comm
4314 # -- Warn the user about environmental problems. Cygwin's Tcl
4315 # does *not* pass its env array onto any processes it spawns.
4316 # This means that git processes get none of our environment.
4321 set msg "Possible environment issues exist.
4323 The following environment variables are probably
4324 going to be ignored by any Git subprocess run
4328 foreach name [array names env] {
4329 switch -regexp -- $name {
4330 {^GIT_INDEX_FILE$} -
4331 {^GIT_OBJECT_DIRECTORY$} -
4332 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4334 {^GIT_EXTERNAL_DIFF$} -
4338 {^GIT_CONFIG_LOCAL$} -
4339 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4340 append msg " - $name\n"
4343 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4344 append msg " - $name\n"
4346 set suggest_user $name
4350 if {$ignored_env > 0} {
4352 This is due to a known issue with the
4353 Tcl binary distributed by Cygwin.
"
4355 if {$suggest_user ne {}} {
4358 A good replacement
for $suggest_user
4359 is placing values
for the user.name and
4360 user.email settings into your personal
4366 unset ignored_env msg suggest_user name
4369 # -- Only initialize complex UI if we are going to stay running.
4371 if {!$single_commit} {
4375 populate_branch_menu
4376 populate_fetch_menu .mbar.fetch
4377 populate_pull_menu .mbar.pull
4378 populate_push_menu .mbar.push
4381 # -- Only suggest a gc run if we are going to stay running.
4383 if {!$single_commit} {
4384 set object_limit 2000
4385 if {[is_Windows]} {set object_limit 200}
4386 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4387 if {$objects_current >= $object_limit} {
4389 "This repository currently has
$objects_current loose objects.
4391 To maintain optimal performance it is strongly
4392 recommended that you
compress the database
4393 when
more than
$object_limit loose objects exist.
4395 Compress the database now?
"] eq yes} {
4399 unset object_limit _junk objects_current
4402 lock_index begin-read