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
809 if {[llength
$PARENT] == 0} {
810 error_popup
{There is nothing to amend.
812 You are about to create the initial commit.
813 There is no commit before this to amend.
818 repository_state curType curHEAD curMERGE_HEAD
819 if {$curType eq
{merge
}} {
820 error_popup
{Cannot amend
while merging.
822 You are currently
in the middle of a merge that
823 has not been fully completed. You cannot amend
824 the prior commit unless you first abort the
825 current merge activity.
833 set fd
[open
"| git cat-file commit $curHEAD" r
]
834 while {[gets
$fd line
] > 0} {
835 if {[string match
{parent
*} $line]} {
836 lappend parents
[string range
$line 7 end
]
839 set msg
[string trim
[read $fd]]
842 error_popup
"Error loading commit data for amend:\n\n$err"
848 set MERGE_HEAD
[list
]
849 switch
-- [llength
$parents] {
850 0 {set commit_type amend-initial
}
851 1 {set commit_type amend
}
852 default
{set commit_type amend-merge
}
855 $ui_comm delete
0.0 end
856 $ui_comm insert end
$msg
858 $ui_comm edit modified false
859 rescan
{set ui_status_value
{Ready.
}}
862 proc create_new_commit
{} {
863 global commit_type ui_comm
865 set commit_type normal
866 $ui_comm delete
0.0 end
868 $ui_comm edit modified false
869 rescan
{set ui_status_value
{Ready.
}}
872 set GIT_COMMITTER_IDENT
{}
874 proc committer_ident
{} {
875 global GIT_COMMITTER_IDENT
877 if {$GIT_COMMITTER_IDENT eq
{}} {
878 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
879 error_popup
"Unable to obtain your identity:\n\n$err"
882 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
883 $me me GIT_COMMITTER_IDENT
]} {
884 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
889 return $GIT_COMMITTER_IDENT
892 proc commit_tree
{} {
893 global HEAD commit_type file_states ui_comm repo_config
894 global ui_status_value pch_error
896 if {![lock_index update
]} return
897 if {[committer_ident
] eq
{}} return
899 # -- Our in memory state should match the repository.
901 repository_state curType curHEAD curMERGE_HEAD
902 if {[string match amend
* $commit_type]
903 && $curType eq
{normal
}
904 && $curHEAD eq
$HEAD} {
905 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
906 info_popup
{Last scanned state does not match repository state.
908 Another Git program has modified this repository
909 since the last scan. A rescan must be performed
910 before another commit can be created.
912 The rescan will be automatically started now.
915 rescan
{set ui_status_value
{Ready.
}}
919 # -- At least one file should differ in the index.
922 foreach path
[array names file_states
] {
923 switch
-glob -- [lindex
$file_states($path) 0] {
927 M?
{set files_ready
1}
929 error_popup
"Unmerged files cannot be committed.
931 File [short_path $path] has merge conflicts.
932 You must resolve them and add the file before committing.
938 error_popup
"Unknown file state [lindex $s 0] detected.
940 File [short_path $path] cannot be committed by this program.
946 info_popup
{No changes to commit.
948 You must add
at least
1 file before you can commit.
954 # -- A message is required.
956 set msg
[string trim
[$ui_comm get
1.0 end
]]
958 error_popup
{Please supply a commit message.
960 A good commit message has the following format
:
962 - First line
: Describe
in one sentance what you did.
964 - Remaining lines
: Describe why this change is good.
970 # -- Run the pre-commit hook.
972 set pchook
[gitdir hooks pre-commit
]
974 # On Cygwin [file executable] might lie so we need to ask
975 # the shell if the hook is executable. Yes that's annoying.
977 if {[is_Windows
] && [file isfile
$pchook]} {
978 set pchook
[list sh
-c [concat \
979 "if test -x \"$pchook\";" \
980 "then exec \"$pchook\" 2>&1;" \
982 } elseif
{[file executable
$pchook]} {
983 set pchook
[list
$pchook |
& cat]
985 commit_writetree
$curHEAD $msg
989 set ui_status_value
{Calling pre-commit hook...
}
991 set fd_ph
[open
"| $pchook" r
]
992 fconfigure
$fd_ph -blocking 0 -translation binary
993 fileevent
$fd_ph readable \
994 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
997 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
998 global pch_error ui_status_value
1000 append pch_error
[read $fd_ph]
1001 fconfigure
$fd_ph -blocking 1
1003 if {[catch
{close
$fd_ph}]} {
1004 set ui_status_value
{Commit declined by pre-commit hook.
}
1005 hook_failed_popup pre-commit
$pch_error
1008 commit_writetree
$curHEAD $msg
1013 fconfigure
$fd_ph -blocking 0
1016 proc commit_writetree
{curHEAD msg
} {
1017 global ui_status_value
1019 set ui_status_value
{Committing changes...
}
1020 set fd_wt
[open
"| git write-tree" r
]
1021 fileevent
$fd_wt readable \
1022 [list commit_committree
$fd_wt $curHEAD $msg]
1025 proc commit_committree
{fd_wt curHEAD msg
} {
1026 global HEAD PARENT MERGE_HEAD commit_type
1027 global single_commit all_heads current_branch
1028 global ui_status_value ui_comm selected_commit_type
1029 global file_states selected_paths rescan_active
1032 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1033 error_popup
"write-tree failed:\n\n$err"
1034 set ui_status_value
{Commit failed.
}
1039 # -- Create the commit.
1041 set cmd
[list git commit-tree
$tree_id]
1042 set parents
[concat
$PARENT $MERGE_HEAD]
1043 if {[llength
$parents] > 0} {
1044 foreach p
$parents {
1048 # git commit-tree writes to stderr during initial commit.
1049 lappend cmd
2>/dev
/null
1052 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1053 error_popup
"commit-tree failed:\n\n$err"
1054 set ui_status_value
{Commit failed.
}
1059 # -- Update the HEAD ref.
1062 if {$commit_type ne
{normal
}} {
1063 append reflogm
" ($commit_type)"
1065 set i
[string first
"\n" $msg]
1067 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1069 append reflogm
{: } $msg
1071 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1072 if {[catch
{eval exec $cmd} err
]} {
1073 error_popup
"update-ref failed:\n\n$err"
1074 set ui_status_value
{Commit failed.
}
1079 # -- Make sure our current branch exists.
1081 if {$commit_type eq
{initial
}} {
1082 lappend all_heads
$current_branch
1083 set all_heads
[lsort
-unique $all_heads]
1084 populate_branch_menu
1087 # -- Cleanup after ourselves.
1089 catch
{file delete
[gitdir MERGE_HEAD
]}
1090 catch
{file delete
[gitdir MERGE_MSG
]}
1091 catch
{file delete
[gitdir SQUASH_MSG
]}
1092 catch
{file delete
[gitdir GITGUI_MSG
]}
1094 # -- Let rerere do its thing.
1096 if {[file isdirectory
[gitdir rr-cache
]]} {
1097 catch
{exec git rerere
}
1100 # -- Run the post-commit hook.
1102 set pchook
[gitdir hooks post-commit
]
1103 if {[is_Windows
] && [file isfile
$pchook]} {
1104 set pchook
[list sh
-c [concat \
1105 "if test -x \"$pchook\";" \
1106 "then exec \"$pchook\";" \
1108 } elseif
{![file executable
$pchook]} {
1111 if {$pchook ne
{}} {
1112 catch
{exec $pchook &}
1115 $ui_comm delete
0.0 end
1117 $ui_comm edit modified false
1119 if {$single_commit} do_quit
1121 # -- Update in memory status
1123 set selected_commit_type new
1124 set commit_type normal
1127 set MERGE_HEAD
[list
]
1129 foreach path
[array names file_states
] {
1130 set s
$file_states($path)
1132 switch
-glob -- $m {
1140 unset file_states
($path)
1141 catch
{unset selected_paths
($path)}
1144 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1150 set file_states
($path) [list \
1151 _
[string index
$m 1] \
1162 set ui_status_value \
1163 "Changes committed as [string range $cmt_id 0 7]."
1166 ######################################################################
1170 proc fetch_from
{remote
} {
1171 set w
[new_console
"fetch $remote" \
1172 "Fetching new changes from $remote"]
1173 set cmd
[list git fetch
]
1175 console_exec
$w $cmd
1178 proc pull_remote
{remote branch
} {
1179 global HEAD commit_type file_states repo_config
1181 if {![lock_index update
]} return
1183 # -- Our in memory state should match the repository.
1185 repository_state curType curHEAD curMERGE_HEAD
1186 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1187 info_popup
{Last scanned state does not match repository state.
1189 Another Git program has modified this repository
1190 since the last scan. A rescan must be performed
1191 before a pull operation can be started.
1193 The rescan will be automatically started now.
1196 rescan
{set ui_status_value
{Ready.
}}
1200 # -- No differences should exist before a pull.
1202 if {[array size file_states
] != 0} {
1203 error_popup
{Uncommitted but modified files are present.
1205 You should not perform a pull with unmodified
1206 files
in your working directory as Git will be
1207 unable to recover from an incorrect merge.
1209 You should commit or revert all changes before
1210 starting a pull operation.
1216 set w
[new_console
"pull $remote $branch" \
1217 "Pulling new changes from branch $branch in $remote"]
1218 set cmd
[list git pull
]
1219 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1220 lappend cmd
--no-summary
1224 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1227 proc post_pull_remote
{remote branch success
} {
1228 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1229 global ui_status_value
1233 repository_state commit_type HEAD MERGE_HEAD
1235 set selected_commit_type new
1236 set ui_status_value
"Pulling $branch from $remote complete."
1238 rescan
[list
set ui_status_value \
1239 "Conflicts detected while pulling $branch from $remote."]
1243 proc push_to
{remote
} {
1244 set w
[new_console
"push $remote" \
1245 "Pushing changes to $remote"]
1246 set cmd
[list git push
]
1248 console_exec
$w $cmd
1251 ######################################################################
1255 proc mapicon
{w state path
} {
1258 if {[catch
{set r
$all_icons($state$w)}]} {
1259 puts
"error: no icon for $w state={$state} $path"
1265 proc mapdesc
{state path
} {
1268 if {[catch
{set r
$all_descs($state)}]} {
1269 puts
"error: no desc for state={$state} $path"
1275 proc escape_path
{path
} {
1276 regsub
-all "\n" $path "\\n" path
1280 proc short_path
{path
} {
1281 return [escape_path
[lindex
[file split $path] end
]]
1285 set null_sha1
[string repeat
0 40]
1287 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1288 global file_states next_icon_id null_sha1
1290 set s0
[string index
$new_state 0]
1291 set s1
[string index
$new_state 1]
1293 if {[catch
{set info
$file_states($path)}]} {
1295 set icon n
[incr next_icon_id
]
1297 set state
[lindex
$info 0]
1298 set icon
[lindex
$info 1]
1299 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1300 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1303 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1304 elseif
{$s0 eq
{_
}} {set s0 _
}
1306 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1307 elseif
{$s1 eq
{_
}} {set s1 _
}
1309 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1310 set head_info
[list
0 $null_sha1]
1311 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1312 && $head_info eq
{}} {
1313 set head_info
$index_info
1316 set file_states
($path) [list
$s0$s1 $icon \
1317 $head_info $index_info \
1322 proc display_file_helper
{w path icon_name old_m new_m
} {
1325 if {$new_m eq
{_
}} {
1326 set lno
[lsearch
-sorted $file_lists($w) $path]
1328 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1330 $w conf
-state normal
1331 $w delete
$lno.0 [expr {$lno + 1}].0
1332 $w conf
-state disabled
1334 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1335 lappend file_lists
($w) $path
1336 set file_lists
($w) [lsort
-unique $file_lists($w)]
1337 set lno
[lsearch
-sorted $file_lists($w) $path]
1339 $w conf
-state normal
1340 $w image create
$lno.0 \
1341 -align center
-padx 5 -pady 1 \
1343 -image [mapicon
$w $new_m $path]
1344 $w insert
$lno.1 "[escape_path $path]\n"
1345 $w conf
-state disabled
1346 } elseif
{$old_m ne
$new_m} {
1347 $w conf
-state normal
1348 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1349 $w conf
-state disabled
1353 proc display_file
{path state
} {
1354 global file_states selected_paths
1355 global ui_index ui_workdir
1357 set old_m
[merge_state
$path $state]
1358 set s
$file_states($path)
1359 set new_m
[lindex
$s 0]
1360 set icon_name
[lindex
$s 1]
1362 set o
[string index
$old_m 0]
1363 set n
[string index
$new_m 0]
1370 display_file_helper
$ui_index $path $icon_name $o $n
1372 if {[string index
$old_m 0] eq
{U
}} {
1375 set o
[string index
$old_m 1]
1377 if {[string index
$new_m 0] eq
{U
}} {
1380 set n
[string index
$new_m 1]
1382 display_file_helper
$ui_workdir $path $icon_name $o $n
1384 if {$new_m eq
{__
}} {
1385 unset file_states
($path)
1386 catch
{unset selected_paths
($path)}
1390 proc display_all_files_helper
{w path icon_name m
} {
1393 lappend file_lists
($w) $path
1394 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1395 $w image create end \
1396 -align center
-padx 5 -pady 1 \
1398 -image [mapicon
$w $m $path]
1399 $w insert end
"[escape_path $path]\n"
1402 proc display_all_files
{} {
1403 global ui_index ui_workdir
1404 global file_states file_lists
1407 $ui_index conf
-state normal
1408 $ui_workdir conf
-state normal
1410 $ui_index delete
0.0 end
1411 $ui_workdir delete
0.0 end
1414 set file_lists
($ui_index) [list
]
1415 set file_lists
($ui_workdir) [list
]
1417 foreach path
[lsort
[array names file_states
]] {
1418 set s
$file_states($path)
1420 set icon_name
[lindex
$s 1]
1422 set s
[string index
$m 0]
1423 if {$s ne
{U
} && $s ne
{_
}} {
1424 display_all_files_helper
$ui_index $path \
1428 if {[string index
$m 0] eq
{U
}} {
1431 set s
[string index
$m 1]
1434 display_all_files_helper
$ui_workdir $path \
1439 $ui_index conf
-state disabled
1440 $ui_workdir conf
-state disabled
1443 proc update_indexinfo
{msg pathList after
} {
1444 global update_index_cp ui_status_value
1446 if {![lock_index update
]} return
1448 set update_index_cp
0
1449 set pathList
[lsort
$pathList]
1450 set totalCnt
[llength
$pathList]
1451 set batch [expr {int
($totalCnt * .01) + 1}]
1452 if {$batch > 25} {set batch 25}
1454 set ui_status_value
[format \
1455 "$msg... %i/%i files (%.2f%%)" \
1459 set fd
[open
"| git update-index -z --index-info" w
]
1466 fileevent
$fd writable
[list \
1467 write_update_indexinfo \
1477 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1478 global update_index_cp ui_status_value
1479 global file_states current_diff_path
1481 if {$update_index_cp >= $totalCnt} {
1488 for {set i
$batch} \
1489 {$update_index_cp < $totalCnt && $i > 0} \
1491 set path
[lindex
$pathList $update_index_cp]
1492 incr update_index_cp
1494 set s
$file_states($path)
1495 switch
-glob -- [lindex
$s 0] {
1502 set info
[lindex
$s 2]
1503 if {$info eq
{}} continue
1505 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1506 display_file
$path $new
1509 set ui_status_value
[format \
1510 "$msg... %i/%i files (%.2f%%)" \
1513 [expr {100.0 * $update_index_cp / $totalCnt}]]
1516 proc update_index
{msg pathList after
} {
1517 global update_index_cp ui_status_value
1519 if {![lock_index update
]} return
1521 set update_index_cp
0
1522 set pathList
[lsort
$pathList]
1523 set totalCnt
[llength
$pathList]
1524 set batch [expr {int
($totalCnt * .01) + 1}]
1525 if {$batch > 25} {set batch 25}
1527 set ui_status_value
[format \
1528 "$msg... %i/%i files (%.2f%%)" \
1532 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1539 fileevent
$fd writable
[list \
1540 write_update_index \
1550 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1551 global update_index_cp ui_status_value
1552 global file_states current_diff_path
1554 if {$update_index_cp >= $totalCnt} {
1561 for {set i
$batch} \
1562 {$update_index_cp < $totalCnt && $i > 0} \
1564 set path
[lindex
$pathList $update_index_cp]
1565 incr update_index_cp
1567 switch
-glob -- [lindex
$file_states($path) 0] {
1573 if {[file exists
$path]} {
1582 puts
-nonewline $fd "[encoding convertto $path]\0"
1583 display_file
$path $new
1586 set ui_status_value
[format \
1587 "$msg... %i/%i files (%.2f%%)" \
1590 [expr {100.0 * $update_index_cp / $totalCnt}]]
1593 proc checkout_index
{msg pathList after
} {
1594 global update_index_cp ui_status_value
1596 if {![lock_index update
]} return
1598 set update_index_cp
0
1599 set pathList
[lsort
$pathList]
1600 set totalCnt
[llength
$pathList]
1601 set batch [expr {int
($totalCnt * .01) + 1}]
1602 if {$batch > 25} {set batch 25}
1604 set ui_status_value
[format \
1605 "$msg... %i/%i files (%.2f%%)" \
1609 set cmd
[list git checkout-index
]
1615 set fd
[open
"| $cmd " w
]
1622 fileevent
$fd writable
[list \
1623 write_checkout_index \
1633 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1634 global update_index_cp ui_status_value
1635 global file_states current_diff_path
1637 if {$update_index_cp >= $totalCnt} {
1644 for {set i
$batch} \
1645 {$update_index_cp < $totalCnt && $i > 0} \
1647 set path
[lindex
$pathList $update_index_cp]
1648 incr update_index_cp
1649 switch
-glob -- [lindex
$file_states($path) 0] {
1653 puts
-nonewline $fd "[encoding convertto $path]\0"
1654 display_file
$path ?_
1659 set ui_status_value
[format \
1660 "$msg... %i/%i files (%.2f%%)" \
1663 [expr {100.0 * $update_index_cp / $totalCnt}]]
1666 ######################################################################
1668 ## branch management
1670 proc is_tracking_branch
{name
} {
1671 global tracking_branches
1673 if {![catch
{set info
$tracking_branches($name)}]} {
1676 foreach t
[array names tracking_branches
] {
1677 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1684 proc load_all_heads
{} {
1687 set all_heads
[list
]
1688 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1689 while {[gets
$fd line
] > 0} {
1690 if {[is_tracking_branch
$line]} continue
1691 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1692 lappend all_heads
$name
1696 set all_heads
[lsort
$all_heads]
1699 proc populate_branch_menu
{} {
1700 global all_heads disable_on_lock
1703 set last
[$m index last
]
1704 for {set i
0} {$i <= $last} {incr i
} {
1705 if {[$m type $i] eq
{separator
}} {
1708 foreach a
$disable_on_lock {
1709 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1713 set disable_on_lock
$new_dol
1719 foreach b
$all_heads {
1720 $m add radiobutton \
1722 -command [list switch_branch
$b] \
1723 -variable current_branch \
1726 lappend disable_on_lock \
1727 [list
$m entryconf
[$m index last
] -state]
1731 proc all_tracking_branches
{} {
1732 global tracking_branches
1734 set all_trackings
{}
1736 foreach name
[array names tracking_branches
] {
1737 if {[regsub
{/\
*$
} $name {} name
]} {
1740 regsub ^refs
/(heads|remotes
)/ $name {} name
1741 lappend all_trackings
$name
1746 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1747 while {[gets
$fd name
] > 0} {
1748 regsub ^refs
/(heads|remotes
)/ $name {} name
1749 lappend all_trackings
$name
1754 return [lsort
-unique $all_trackings]
1757 proc do_create_branch_action
{w
} {
1758 global all_heads null_sha1 repo_config
1759 global create_branch_checkout create_branch_revtype
1760 global create_branch_head create_branch_trackinghead
1762 set newbranch
[string trim
[$w.desc.name_t get
0.0 end
]]
1763 if {$newbranch eq
{}
1764 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1768 -title [wm title
$w] \
1770 -message "Please supply a branch name."
1771 focus
$w.desc.name_t
1774 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1778 -title [wm title
$w] \
1780 -message "Branch '$newbranch' already exists."
1781 focus
$w.desc.name_t
1784 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1788 -title [wm title
$w] \
1790 -message "We do not like '$newbranch' as a branch name."
1791 focus
$w.desc.name_t
1796 switch
-- $create_branch_revtype {
1797 head {set rev $create_branch_head}
1798 tracking
{set rev $create_branch_trackinghead}
1799 expression
{set rev [string trim
[$w.from.exp_t get
0.0 end
]]}
1801 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1805 -title [wm title
$w] \
1807 -message "Invalid starting revision: $rev"
1810 set cmd
[list git update-ref
]
1812 lappend cmd
"branch: Created from $rev"
1813 lappend cmd
"refs/heads/$newbranch"
1815 lappend cmd
$null_sha1
1816 if {[catch
{eval exec $cmd} err
]} {
1820 -title [wm title
$w] \
1822 -message "Failed to create '$newbranch'.\n\n$err"
1826 lappend all_heads
$newbranch
1827 set all_heads
[lsort
$all_heads]
1828 populate_branch_menu
1830 if {$create_branch_checkout} {
1831 switch_branch
$newbranch
1835 proc radio_selector
{varname value args
} {
1836 upvar
#0 $varname var
1840 trace add variable create_branch_head
write \
1841 [list radio_selector create_branch_revtype
head]
1842 trace add variable create_branch_trackinghead
write \
1843 [list radio_selector create_branch_revtype tracking
]
1845 trace add variable delete_branch_head
write \
1846 [list radio_selector delete_branch_checktype
head]
1847 trace add variable delete_branch_trackinghead
write \
1848 [list radio_selector delete_branch_checktype tracking
]
1850 proc do_create_branch
{} {
1851 global all_heads current_branch repo_config
1852 global create_branch_checkout create_branch_revtype
1853 global create_branch_head create_branch_trackinghead
1855 set w .branch_editor
1857 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1859 label
$w.header
-text {Create New Branch
} \
1861 pack
$w.header
-side top
-fill x
1864 button
$w.buttons.create
-text Create \
1867 -command [list do_create_branch_action
$w]
1868 pack
$w.buttons.create
-side right
1869 button
$w.buttons.cancel
-text {Cancel
} \
1871 -command [list destroy
$w]
1872 pack
$w.buttons.cancel
-side right
-padx 5
1873 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1875 labelframe
$w.desc \
1876 -text {Branch Description
} \
1878 label
$w.desc.name_l
-text {Name
:} -font font_ui
1879 text
$w.desc.name_t \
1885 $w.desc.name_t insert
0.0 $repo_config(gui.newbranchtemplate
)
1886 grid
$w.desc.name_l
$w.desc.name_t
-stick we
-padx {0 5}
1887 bind $w.desc.name_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1888 bind $w.desc.name_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1889 bind $w.desc.name_t
<Key-Return
> "do_create_branch_action $w;break"
1890 bind $w.desc.name_t
<Key
> {
1891 if {{%K
} ne
{BackSpace
}
1894 && {%K
} ne
{Return
}} {
1896 if {[string first
%A
{~^
:?
*[}] >= 0} break
1899 grid columnconfigure
$w.desc
1 -weight 1
1900 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
1902 labelframe
$w.from \
1903 -text {Starting Revision
} \
1905 radiobutton
$w.from.head_r \
1906 -text {Local Branch
:} \
1908 -variable create_branch_revtype \
1910 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
1911 grid
$w.from.head_r
$w.from.head_m
-sticky w
1912 set all_trackings
[all_tracking_branches
]
1913 if {$all_trackings ne
{}} {
1914 set create_branch_trackinghead
[lindex
$all_trackings 0]
1915 radiobutton
$w.from.tracking_r \
1916 -text {Tracking Branch
:} \
1918 -variable create_branch_revtype \
1920 eval tk_optionMenu
$w.from.tracking_m \
1921 create_branch_trackinghead \
1923 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
1925 radiobutton
$w.from.exp_r \
1926 -text {Revision Expression
:} \
1928 -variable create_branch_revtype \
1930 text
$w.from.exp_t \
1936 grid
$w.from.exp_r
$w.from.exp_t
-stick we
-padx {0 5}
1937 bind $w.from.exp_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1938 bind $w.from.exp_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1939 bind $w.from.exp_t
<Key-Return
> "do_create_branch_action $w;break"
1940 bind $w.from.exp_t
<Key-space
> break
1941 bind $w.from.exp_t
<Key
> {set create_branch_revtype expression
}
1942 grid columnconfigure
$w.from
1 -weight 1
1943 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1945 labelframe
$w.postActions \
1946 -text {Post Creation Actions
} \
1948 checkbutton
$w.postActions.checkout \
1949 -text {Checkout after creation
} \
1950 -variable create_branch_checkout \
1952 pack
$w.postActions.checkout
-anchor nw
1953 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1955 set create_branch_checkout
1
1956 set create_branch_head
$current_branch
1957 set create_branch_revtype
head
1959 bind $w <Visibility
> "grab $w; focus $w.desc.name_t"
1960 bind $w <Key-Escape
> "destroy $w"
1961 bind $w <Key-Return
> "do_create_branch_action $w;break"
1962 wm title
$w "[appname] ([reponame]): Create Branch"
1966 proc do_delete_branch_action
{w
} {
1968 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
1971 switch
-- $delete_branch_checktype {
1972 head {set check_rev
$delete_branch_head}
1973 tracking
{set check_rev
$delete_branch_trackinghead}
1974 always
{set check_rev
{:none
}}
1976 if {$check_rev eq
{:none
}} {
1978 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
1982 -title [wm title
$w] \
1984 -message "Invalid check revision: $check_rev"
1988 set to_delete
[list
]
1989 set not_merged
[list
]
1990 foreach i
[$w.list.l curselection
] {
1991 set b
[$w.list.l get
$i]
1992 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
1993 if {$check_cmt ne
{}} {
1994 if {$b eq
$check_rev} continue
1995 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
1997 lappend not_merged
$b
2001 lappend to_delete
[list
$b $o]
2003 if {$not_merged ne
{}} {
2004 set msg
"The following branches are not completely merged into $check_rev:
2006 - [join $not_merged "\n - "]"
2010 -title [wm title
$w] \
2014 if {$to_delete eq
{}} return
2015 if {$delete_branch_checktype eq
{always
}} {
2016 set msg
{Recovering deleted branches is difficult.
2018 Delete the selected branches?
}
2019 if {[tk_messageBox \
2022 -title [wm title
$w] \
2024 -message $msg] ne
yes} {
2030 foreach i
$to_delete {
2033 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2034 append failed
" - $b: $err\n"
2036 set x
[lsearch
-sorted $all_heads $b]
2038 set all_heads
[lreplace
$all_heads $x $x]
2043 if {$failed ne
{}} {
2047 -title [wm title
$w] \
2049 -message "Failed to delete branches:\n$failed"
2052 set all_heads
[lsort
$all_heads]
2053 populate_branch_menu
2057 proc do_delete_branch
{} {
2058 global all_heads tracking_branches current_branch
2059 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2061 set w .branch_editor
2063 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2065 label
$w.header
-text {Delete Local Branch
} \
2067 pack
$w.header
-side top
-fill x
2070 button
$w.buttons.create
-text Delete \
2072 -command [list do_delete_branch_action
$w]
2073 pack
$w.buttons.create
-side right
2074 button
$w.buttons.cancel
-text {Cancel
} \
2076 -command [list destroy
$w]
2077 pack
$w.buttons.cancel
-side right
-padx 5
2078 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2080 labelframe
$w.list \
2081 -text {Local Branches
} \
2086 -selectmode extended \
2088 foreach h
$all_heads {
2089 if {$h ne
$current_branch} {
2090 $w.list.l insert end
$h
2093 pack
$w.list.l
-fill both
-pady 5 -padx 5
2094 pack
$w.list
-fill both
-pady 5 -padx 5
2096 labelframe
$w.validate \
2097 -text {Delete Only If
} \
2099 radiobutton
$w.validate.head_r \
2100 -text {Merged Into Local Branch
:} \
2102 -variable delete_branch_checktype \
2104 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2105 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2106 set all_trackings
[all_tracking_branches
]
2107 if {$all_trackings ne
{}} {
2108 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2109 radiobutton
$w.validate.tracking_r \
2110 -text {Merged Into Tracking Branch
:} \
2112 -variable delete_branch_checktype \
2114 eval tk_optionMenu
$w.validate.tracking_m \
2115 delete_branch_trackinghead \
2117 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2119 radiobutton
$w.validate.always_r \
2120 -text {Always
(Do not perform merge checks
)} \
2122 -variable delete_branch_checktype \
2124 grid
$w.validate.always_r
-columnspan 2 -sticky w
2125 grid columnconfigure
$w.validate
1 -weight 1
2126 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2128 set delete_branch_head
$current_branch
2129 set delete_branch_checktype
head
2131 bind $w <Visibility
> "grab $w; focus $w"
2132 bind $w <Key-Escape
> "destroy $w"
2133 wm title
$w "[appname] ([reponame]): Delete Branch"
2137 proc switch_branch
{b
} {
2138 global HEAD commit_type file_states current_branch
2139 global selected_commit_type ui_comm
2141 if {![lock_index switch
]} return
2143 # -- Backup the selected branch (repository_state resets it)
2145 set new_branch
$current_branch
2147 # -- Our in memory state should match the repository.
2149 repository_state curType curHEAD curMERGE_HEAD
2150 if {[string match amend
* $commit_type]
2151 && $curType eq
{normal
}
2152 && $curHEAD eq
$HEAD} {
2153 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2154 info_popup
{Last scanned state does not match repository state.
2156 Another Git program has modified this repository
2157 since the last scan. A rescan must be performed
2158 before the current branch can be changed.
2160 The rescan will be automatically started now.
2163 rescan
{set ui_status_value
{Ready.
}}
2167 # -- Toss the message buffer if we are in amend mode.
2169 if {[string match amend
* $curType]} {
2170 $ui_comm delete
0.0 end
2172 $ui_comm edit modified false
2175 set selected_commit_type new
2176 set current_branch
$new_branch
2179 error
"NOT FINISHED"
2182 ######################################################################
2184 ## remote management
2186 proc load_all_remotes
{} {
2188 global all_remotes tracking_branches
2190 set all_remotes
[list
]
2191 array
unset tracking_branches
2193 set rm_dir
[gitdir remotes
]
2194 if {[file isdirectory
$rm_dir]} {
2195 set all_remotes
[glob \
2199 -directory $rm_dir *]
2201 foreach name
$all_remotes {
2203 set fd
[open
[file join $rm_dir $name] r
]
2204 while {[gets
$fd line
] >= 0} {
2205 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2206 $line line src dst
]} continue
2207 if {![regexp ^refs
/ $dst]} {
2208 set dst
"refs/heads/$dst"
2210 set tracking_branches
($dst) [list
$name $src]
2217 foreach line
[array names repo_config remote.
*.url
] {
2218 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2219 lappend all_remotes
$name
2221 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2225 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2226 if {![regexp ^refs
/ $dst]} {
2227 set dst
"refs/heads/$dst"
2229 set tracking_branches
($dst) [list
$name $src]
2233 set all_remotes
[lsort
-unique $all_remotes]
2236 proc populate_fetch_menu
{m
} {
2237 global all_remotes repo_config
2239 foreach r
$all_remotes {
2241 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2242 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2247 set fd
[open
[gitdir remotes
$r] r
]
2248 while {[gets
$fd n
] >= 0} {
2249 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2260 -label "Fetch from $r..." \
2261 -command [list fetch_from
$r] \
2267 proc populate_push_menu
{m
} {
2268 global all_remotes repo_config
2270 foreach r
$all_remotes {
2272 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2273 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2278 set fd
[open
[gitdir remotes
$r] r
]
2279 while {[gets
$fd n
] >= 0} {
2280 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2291 -label "Push to $r..." \
2292 -command [list push_to
$r] \
2298 proc populate_pull_menu
{m
} {
2299 global repo_config all_remotes disable_on_lock
2301 foreach remote
$all_remotes {
2303 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2304 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2305 foreach line
$repo_config(remote.
$remote.fetch
) {
2306 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2313 set fd
[open
[gitdir remotes
$remote] r
]
2314 while {[gets
$fd line
] >= 0} {
2315 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2323 foreach rb
$rb_list {
2324 regsub ^refs
/heads
/ $rb {} rb_short
2326 -label "Branch $rb_short from $remote..." \
2327 -command [list pull_remote
$remote $rb] \
2329 lappend disable_on_lock \
2330 [list
$m entryconf
[$m index last
] -state]
2335 ######################################################################
2340 #define mask_width 14
2341 #define mask_height 15
2342 static unsigned char mask_bits
[] = {
2343 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2344 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2345 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2348 image create bitmap file_plain
-background white
-foreground black
-data {
2349 #define plain_width 14
2350 #define plain_height 15
2351 static unsigned char plain_bits
[] = {
2352 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2353 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2354 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2355 } -maskdata $filemask
2357 image create bitmap file_mod
-background white
-foreground blue
-data {
2358 #define mod_width 14
2359 #define mod_height 15
2360 static unsigned char mod_bits
[] = {
2361 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2362 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2363 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2364 } -maskdata $filemask
2366 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2367 #define file_fulltick_width 14
2368 #define file_fulltick_height 15
2369 static unsigned char file_fulltick_bits
[] = {
2370 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2371 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2372 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2373 } -maskdata $filemask
2375 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2376 #define parttick_width 14
2377 #define parttick_height 15
2378 static unsigned char parttick_bits
[] = {
2379 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2380 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2381 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2382 } -maskdata $filemask
2384 image create bitmap file_question
-background white
-foreground black
-data {
2385 #define file_question_width 14
2386 #define file_question_height 15
2387 static unsigned char file_question_bits
[] = {
2388 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2389 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2390 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2391 } -maskdata $filemask
2393 image create bitmap file_removed
-background white
-foreground red
-data {
2394 #define file_removed_width 14
2395 #define file_removed_height 15
2396 static unsigned char file_removed_bits
[] = {
2397 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2398 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2399 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2400 } -maskdata $filemask
2402 image create bitmap file_merge
-background white
-foreground blue
-data {
2403 #define file_merge_width 14
2404 #define file_merge_height 15
2405 static unsigned char file_merge_bits
[] = {
2406 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2407 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2408 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2409 } -maskdata $filemask
2411 set ui_index .vpane.files.index.list
2412 set ui_workdir .vpane.files.workdir.list
2414 set all_icons
(_
$ui_index) file_plain
2415 set all_icons
(A
$ui_index) file_fulltick
2416 set all_icons
(M
$ui_index) file_fulltick
2417 set all_icons
(D
$ui_index) file_removed
2418 set all_icons
(U
$ui_index) file_merge
2420 set all_icons
(_
$ui_workdir) file_plain
2421 set all_icons
(M
$ui_workdir) file_mod
2422 set all_icons
(D
$ui_workdir) file_question
2423 set all_icons
(U
$ui_workdir) file_merge
2424 set all_icons
(O
$ui_workdir) file_plain
2426 set max_status_desc
0
2430 {_M
"Modified, not staged"}
2431 {M_
"Staged for commit"}
2432 {MM
"Portions staged for commit"}
2433 {MD
"Staged for commit, missing"}
2435 {_O
"Untracked, not staged"}
2436 {A_
"Staged for commit"}
2437 {AM
"Portions staged for commit"}
2438 {AD
"Staged for commit, missing"}
2441 {D_
"Staged for removal"}
2442 {DO
"Staged for removal, still present"}
2444 {U_
"Requires merge resolution"}
2445 {UU
"Requires merge resolution"}
2446 {UM
"Requires merge resolution"}
2447 {UD
"Requires merge resolution"}
2449 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2450 set max_status_desc
[string length
[lindex
$i 1]]
2452 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2456 ######################################################################
2461 global tcl_platform tk_library
2462 if {[tk windowingsystem
] eq
{aqua
}} {
2468 proc is_Windows
{} {
2470 if {$tcl_platform(platform
) eq
{windows
}} {
2476 proc bind_button3
{w cmd
} {
2477 bind $w <Any-Button-3
> $cmd
2479 bind $w <Control-Button-1
> $cmd
2483 proc incr_font_size
{font
{amt
1}} {
2484 set sz
[font configure
$font -size]
2486 font configure
$font -size $sz
2487 font configure
${font}bold
-size $sz
2490 proc hook_failed_popup
{hook msg
} {
2495 label
$w.m.l1
-text "$hook hook failed:" \
2500 -background white
-borderwidth 1 \
2502 -width 80 -height 10 \
2504 -yscrollcommand [list
$w.m.sby
set]
2506 -text {You must correct the above errors before committing.
} \
2510 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2511 pack
$w.m.l1
-side top
-fill x
2512 pack
$w.m.l2
-side bottom
-fill x
2513 pack
$w.m.sby
-side right
-fill y
2514 pack
$w.m.t
-side left
-fill both
-expand 1
2515 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2517 $w.m.t insert
1.0 $msg
2518 $w.m.t conf
-state disabled
2520 button
$w.ok
-text OK \
2523 -command "destroy $w"
2524 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2526 bind $w <Visibility
> "grab $w; focus $w"
2527 bind $w <Key-Return
> "destroy $w"
2528 wm title
$w "[appname] ([reponame]): error"
2532 set next_console_id
0
2534 proc new_console
{short_title long_title
} {
2535 global next_console_id console_data
2536 set w .console
[incr next_console_id
]
2537 set console_data
($w) [list
$short_title $long_title]
2538 return [console_init
$w]
2541 proc console_init
{w
} {
2542 global console_cr console_data M1B
2544 set console_cr
($w) 1.0
2547 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2552 -background white
-borderwidth 1 \
2554 -width 80 -height 10 \
2557 -yscrollcommand [list
$w.m.sby
set]
2558 label
$w.m.s
-text {Working... please
wait...
} \
2562 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2563 pack
$w.m.l1
-side top
-fill x
2564 pack
$w.m.s
-side bottom
-fill x
2565 pack
$w.m.sby
-side right
-fill y
2566 pack
$w.m.t
-side left
-fill both
-expand 1
2567 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2569 menu
$w.ctxm
-tearoff 0
2570 $w.ctxm add
command -label "Copy" \
2572 -command "tk_textCopy $w.m.t"
2573 $w.ctxm add
command -label "Select All" \
2575 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
2576 $w.ctxm add
command -label "Copy All" \
2579 $w.m.t tag add sel 0.0 end
2581 $w.m.t tag remove sel 0.0 end
2584 button
$w.ok
-text {Close
} \
2587 -command "destroy $w"
2588 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2590 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2591 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2592 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2593 bind $w <Visibility
> "focus $w"
2594 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2598 proc console_exec
{w cmd
{after
{}}} {
2599 # -- Windows tosses the enviroment when we exec our child.
2600 # But most users need that so we have to relogin. :-(
2603 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2606 # -- Tcl won't let us redirect both stdout and stderr to
2607 # the same pipe. So pass it through cat...
2609 set cmd
[concat |
$cmd |
& cat]
2611 set fd_f
[open
$cmd r
]
2612 fconfigure
$fd_f -blocking 0 -translation binary
2613 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2616 proc console_read
{w fd after
} {
2617 global console_cr console_data
2621 if {![winfo exists
$w]} {console_init
$w}
2622 $w.m.t conf
-state normal
2624 set n
[string length
$buf]
2626 set cr
[string first
"\r" $buf $c]
2627 set lf
[string first
"\n" $buf $c]
2628 if {$cr < 0} {set cr
[expr {$n + 1}]}
2629 if {$lf < 0} {set lf
[expr {$n + 1}]}
2632 $w.m.t insert end
[string range
$buf $c $lf]
2633 set console_cr
($w) [$w.m.t index
{end
-1c}]
2637 $w.m.t delete
$console_cr($w) end
2638 $w.m.t insert end
"\n"
2639 $w.m.t insert end
[string range
$buf $c $cr]
2644 $w.m.t conf
-state disabled
2648 fconfigure
$fd -blocking 1
2650 if {[catch
{close
$fd}]} {
2651 if {![winfo exists
$w]} {console_init
$w}
2652 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2653 $w.ok conf
-state normal
2655 } elseif
{[winfo exists
$w]} {
2656 $w.m.s conf
-background green
-text {Success
}
2657 $w.ok conf
-state normal
2660 array
unset console_cr
$w
2661 array
unset console_data
$w
2663 uplevel
#0 $after $ok
2667 fconfigure
$fd -blocking 0
2670 ######################################################################
2674 set starting_gitk_msg
{Starting gitk... please
wait...
}
2676 proc do_gitk
{revs
} {
2677 global ui_status_value starting_gitk_msg
2685 set cmd
"sh -c \"exec $cmd\""
2689 if {[catch
{eval exec $cmd} err
]} {
2690 error_popup
"Failed to start gitk:\n\n$err"
2692 set ui_status_value
$starting_gitk_msg
2694 if {$ui_status_value eq
$starting_gitk_msg} {
2695 set ui_status_value
{Ready.
}
2702 set w
[new_console
{gc
} {Compressing the object database
}]
2703 console_exec
$w {git gc
}
2706 proc do_fsck_objects
{} {
2707 set w
[new_console
{fsck-objects
} \
2708 {Verifying the object database with fsck-objects
}]
2709 set cmd
[list git fsck-objects
]
2712 lappend cmd
--strict
2713 console_exec
$w $cmd
2719 global ui_comm is_quitting repo_config commit_type
2721 if {$is_quitting} return
2724 # -- Stash our current commit buffer.
2726 set save
[gitdir GITGUI_MSG
]
2727 set msg
[string trim
[$ui_comm get
0.0 end
]]
2728 if {![string match amend
* $commit_type]
2729 && [$ui_comm edit modified
]
2732 set fd
[open
$save w
]
2733 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2737 catch
{file delete
$save}
2740 # -- Stash our current window geometry into this repository.
2742 set cfg_geometry
[list
]
2743 lappend cfg_geometry
[wm geometry .
]
2744 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2745 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2746 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2749 if {$cfg_geometry ne
$rc_geometry} {
2750 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2757 rescan
{set ui_status_value
{Ready.
}}
2760 proc unstage_helper
{txt paths
} {
2761 global file_states current_diff_path
2763 if {![lock_index begin-update
]} return
2767 foreach path
$paths {
2768 switch
-glob -- [lindex
$file_states($path) 0] {
2772 lappend pathList
$path
2773 if {$path eq
$current_diff_path} {
2774 set after
{reshow_diff
;}
2779 if {$pathList eq
{}} {
2785 [concat
$after {set ui_status_value
{Ready.
}}]
2789 proc do_unstage_selection
{} {
2790 global current_diff_path selected_paths
2792 if {[array size selected_paths
] > 0} {
2794 {Unstaging selected files from commit
} \
2795 [array names selected_paths
]
2796 } elseif
{$current_diff_path ne
{}} {
2798 "Unstaging [short_path $current_diff_path] from commit" \
2799 [list
$current_diff_path]
2803 proc add_helper
{txt paths
} {
2804 global file_states current_diff_path
2806 if {![lock_index begin-update
]} return
2810 foreach path
$paths {
2811 switch
-glob -- [lindex
$file_states($path) 0] {
2816 lappend pathList
$path
2817 if {$path eq
$current_diff_path} {
2818 set after
{reshow_diff
;}
2823 if {$pathList eq
{}} {
2829 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2833 proc do_add_selection
{} {
2834 global current_diff_path selected_paths
2836 if {[array size selected_paths
] > 0} {
2838 {Adding selected files
} \
2839 [array names selected_paths
]
2840 } elseif
{$current_diff_path ne
{}} {
2842 "Adding [short_path $current_diff_path]" \
2843 [list
$current_diff_path]
2847 proc do_add_all
{} {
2851 foreach path
[array names file_states
] {
2852 switch
-glob -- [lindex
$file_states($path) 0] {
2855 ?D
{lappend paths
$path}
2858 add_helper
{Adding all changed files
} $paths
2861 proc revert_helper
{txt paths
} {
2862 global file_states current_diff_path
2864 if {![lock_index begin-update
]} return
2868 foreach path
$paths {
2869 switch
-glob -- [lindex
$file_states($path) 0] {
2873 lappend pathList
$path
2874 if {$path eq
$current_diff_path} {
2875 set after
{reshow_diff
;}
2881 set n
[llength
$pathList]
2885 } elseif
{$n == 1} {
2886 set s
"[short_path [lindex $pathList]]"
2888 set s
"these $n files"
2891 set reply
[tk_dialog \
2893 "[appname] ([reponame])" \
2894 "Revert changes in $s?
2896 Any unadded changes will be permanently lost by the revert." \
2906 [concat
$after {set ui_status_value
{Ready.
}}]
2912 proc do_revert_selection
{} {
2913 global current_diff_path selected_paths
2915 if {[array size selected_paths
] > 0} {
2917 {Reverting selected files
} \
2918 [array names selected_paths
]
2919 } elseif
{$current_diff_path ne
{}} {
2921 "Reverting [short_path $current_diff_path]" \
2922 [list
$current_diff_path]
2926 proc do_signoff
{} {
2929 set me
[committer_ident
]
2930 if {$me eq
{}} return
2932 set sob
"Signed-off-by: $me"
2933 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
2934 if {$last ne
$sob} {
2935 $ui_comm edit separator
2937 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
2938 $ui_comm insert end
"\n"
2940 $ui_comm insert end
"\n$sob"
2941 $ui_comm edit separator
2946 proc do_select_commit_type
{} {
2947 global commit_type selected_commit_type
2949 if {$selected_commit_type eq
{new
}
2950 && [string match amend
* $commit_type]} {
2952 } elseif
{$selected_commit_type eq
{amend
}
2953 && ![string match amend
* $commit_type]} {
2956 # The amend request was rejected...
2958 if {![string match amend
* $commit_type]} {
2959 set selected_commit_type new
2969 global appvers copyright
2970 global tcl_patchLevel tk_patchLevel
2974 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2976 label
$w.header
-text "About [appname]" \
2978 pack
$w.header
-side top
-fill x
2981 button
$w.buttons.close
-text {Close
} \
2983 -command [list destroy
$w]
2984 pack
$w.buttons.close
-side right
2985 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2988 -text "[appname] - a commit creation tool for Git.
2996 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
2999 append v
"[appname] version $appvers\n"
3000 append v
"[exec git version]\n"
3002 if {$tcl_patchLevel eq
$tk_patchLevel} {
3003 append v
"Tcl/Tk version $tcl_patchLevel"
3005 append v
"Tcl version $tcl_patchLevel"
3006 append v
", Tk version $tk_patchLevel"
3017 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
3019 menu
$w.ctxm
-tearoff 0
3020 $w.ctxm add
command \
3025 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
3028 bind $w <Visibility
> "grab $w; focus $w"
3029 bind $w <Key-Escape
> "destroy $w"
3030 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3031 wm title
$w "About [appname]"
3035 proc do_options
{} {
3036 global repo_config global_config font_descs
3037 global repo_config_new global_config_new
3039 array
unset repo_config_new
3040 array
unset global_config_new
3041 foreach name
[array names repo_config
] {
3042 set repo_config_new
($name) $repo_config($name)
3045 foreach name
[array names repo_config
] {
3047 gui.diffcontext
{continue}
3049 set repo_config_new
($name) $repo_config($name)
3051 foreach name
[array names global_config
] {
3052 set global_config_new
($name) $global_config($name)
3055 set w .options_editor
3057 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3059 label
$w.header
-text "[appname] Options" \
3061 pack
$w.header
-side top
-fill x
3064 button
$w.buttons.restore
-text {Restore Defaults
} \
3066 -command do_restore_defaults
3067 pack
$w.buttons.restore
-side left
3068 button
$w.buttons.save
-text Save \
3071 catch {eval \[bind \[focus -displayof $w\] <FocusOut>\]}
3074 pack
$w.buttons.save
-side right
3075 button
$w.buttons.cancel
-text {Cancel
} \
3077 -command [list destroy
$w]
3078 pack
$w.buttons.cancel
-side right
-padx 5
3079 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3081 labelframe
$w.repo
-text "[reponame] Repository" \
3083 -relief raised
-borderwidth 2
3084 labelframe
$w.global
-text {Global
(All Repositories
)} \
3086 -relief raised
-borderwidth 2
3087 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3088 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3091 {b pullsummary
{Show Pull Summary
}}
3092 {b trustmtime
{Trust File Modification Timestamps
}}
3093 {i diffcontext
{Number of Diff Context Lines
}}
3094 {t newbranchtemplate
{New Branch Name Template
}}
3096 set type [lindex
$option 0]
3097 set name
[lindex
$option 1]
3098 set text
[lindex
$option 2]
3099 foreach f
{repo global
} {
3102 checkbutton
$w.
$f.
$name -text $text \
3103 -variable ${f}_config_new
(gui.
$name) \
3107 pack
$w.
$f.
$name -side top
-anchor w
3111 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3112 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
3113 spinbox
$w.
$f.
$name.v \
3114 -textvariable ${f}_config_new
(gui.
$name) \
3115 -from 1 -to 99 -increment 1 \
3118 bind $w.
$f.
$name.v
<FocusIn
> {%W selection range
0 end
}
3119 pack
$w.
$f.
$name.v
-side right
-anchor e
-padx 5
3120 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3124 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3125 text
$w.
$f.
$name.v \
3131 $w.
$f.
$name.v insert
0.0 [set ${f}_config_new
(gui.
$name)]
3132 bind $w.
$f.
$name.v
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
3133 bind $w.
$f.
$name.v
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
3134 bind $w.
$f.
$name.v
<Key-Return
> break
3135 bind $w.
$f.
$name.v
<FocusIn
> "$w.$f.$name.v tag add sel 0.0 end"
3136 bind $w.
$f.
$name.v
<FocusOut
> "
3137 set ${f}_config_new(gui.$name) \
3138 \[string trim \[$w.$f.$name.v get 0.0 end\]\]
3140 pack
$w.
$f.
$name.l
-side left
-anchor w
3141 pack
$w.
$f.
$name.v
-side left
-anchor w \
3144 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3150 set all_fonts
[lsort
[font families
]]
3151 foreach option
$font_descs {
3152 set name
[lindex
$option 0]
3153 set font
[lindex
$option 1]
3154 set text
[lindex
$option 2]
3156 set global_config_new
(gui.
$font^^family
) \
3157 [font configure
$font -family]
3158 set global_config_new
(gui.
$font^^size
) \
3159 [font configure
$font -size]
3161 frame
$w.global.
$name
3162 label
$w.global.
$name.l
-text "$text:" -font font_ui
3163 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3164 eval tk_optionMenu
$w.global.
$name.family \
3165 global_config_new
(gui.
$font^^family
) \
3167 spinbox
$w.global.
$name.size \
3168 -textvariable global_config_new
(gui.
$font^^size
) \
3169 -from 2 -to 80 -increment 1 \
3172 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3173 pack
$w.global.
$name.size
-side right
-anchor e
3174 pack
$w.global.
$name.family
-side right
-anchor e
3175 pack
$w.global.
$name -side top
-anchor w
-fill x
3178 bind $w <Visibility
> "grab $w; focus $w"
3179 bind $w <Key-Escape
> "destroy $w"
3180 wm title
$w "[appname] ([reponame]): Options"
3184 proc do_restore_defaults
{} {
3185 global font_descs default_config repo_config
3186 global repo_config_new global_config_new
3188 foreach name
[array names default_config
] {
3189 set repo_config_new
($name) $default_config($name)
3190 set global_config_new
($name) $default_config($name)
3193 foreach option
$font_descs {
3194 set name
[lindex
$option 0]
3195 set repo_config
(gui.
$name) $default_config(gui.
$name)
3199 foreach option
$font_descs {
3200 set name
[lindex
$option 0]
3201 set font
[lindex
$option 1]
3202 set global_config_new
(gui.
$font^^family
) \
3203 [font configure
$font -family]
3204 set global_config_new
(gui.
$font^^size
) \
3205 [font configure
$font -size]
3209 proc do_save_config
{w
} {
3210 if {[catch
{save_config
} err
]} {
3211 error_popup
"Failed to completely save options:\n\n$err"
3217 proc do_windows_shortcut
{} {
3221 set desktop
[exec cygpath \
3229 set fn
[tk_getSaveFile \
3231 -title "[appname] ([reponame]): Create Desktop Icon" \
3232 -initialdir $desktop \
3233 -initialfile "Git [reponame].bat"]
3237 set sh
[exec cygpath \
3241 set me
[exec cygpath \
3245 set gd
[exec cygpath \
3249 set gw
[exec cygpath \
3252 [file dirname [gitdir
]]]
3253 regsub
-all ' $me "'\\''" me
3254 regsub -all ' $gd "'\\''" gd
3255 puts $fd "@ECHO Entering $gw"
3256 puts $fd "@ECHO Starting git-gui... please wait..."
3257 puts -nonewline $fd "@\"$sh\" --login -c \""
3258 puts -nonewline $fd "GIT_DIR='$gd'"
3259 puts -nonewline $fd " '$me'"
3263 error_popup "Cannot write script:\n\n$err"
3268 proc do_macosx_app {} {
3271 set fn [tk_getSaveFile \
3273 -title "[appname] ([reponame]): Create Desktop Icon" \
3274 -initialdir [file join $env(HOME) Desktop] \
3275 -initialfile "Git [reponame].app"]
3278 set Contents [file join $fn Contents]
3279 set MacOS [file join $Contents MacOS]
3280 set exe [file join $MacOS git-gui]
3284 set fd [open [file join $Contents Info.plist] w]
3285 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3286 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3287 <plist version="1.0">
3289 <key>CFBundleDevelopmentRegion</key>
3290 <string>English</string>
3291 <key>CFBundleExecutable</key>
3292 <string>git-gui</string>
3293 <key>CFBundleIdentifier</key>
3294 <string>org.spearce.git-gui</string>
3295 <key>CFBundleInfoDictionaryVersion</key>
3296 <string>6.0</string>
3297 <key>CFBundlePackageType</key>
3298 <string>APPL</string>
3299 <key>CFBundleSignature</key>
3300 <string>????</string>
3301 <key>CFBundleVersion</key>
3302 <string>1.0</string>
3303 <key>NSPrincipalClass</key>
3304 <string>NSApplication</string>
3309 set fd [open $exe w]
3310 set gd [file normalize [gitdir]]
3311 set ep [file normalize [exec git --exec-path]]
3312 regsub -all ' $gd "'\\''" gd
3313 regsub
-all ' $ep "'\\''" ep
3314 puts $fd "#!/bin/sh"
3315 foreach name
[array names env
] {
3316 if {[string match GIT_
* $name]} {
3317 regsub
-all ' $env($name) "'\\''" v
3318 puts $fd "export $name='$v'"
3321 puts $fd "export PATH
='$ep':\
$PATH"
3322 puts $fd "export GIT_DIR
='$gd'"
3323 puts $fd "exec [file normalize
$argv0]"
3326 file attributes $exe -permissions u+x,g+x,o+x
3328 error_popup "Cannot
write icon
:\n\n$err"
3333 proc toggle_or_diff {w x y} {
3334 global file_states file_lists current_diff_path ui_index ui_workdir
3335 global last_clicked selected_paths
3337 set pos [split [$w index @$x,$y] .]
3338 set lno [lindex $pos 0]
3339 set col [lindex $pos 1]
3340 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3346 set last_clicked [list $w $lno]
3347 array unset selected_paths
3348 $ui_index tag remove in_sel 0.0 end
3349 $ui_workdir tag remove in_sel 0.0 end
3352 if {$current_diff_path eq $path} {
3353 set after {reshow_diff;}
3357 if {$w eq $ui_index} {
3359 "Unstaging
[short_path
$path] from commit
" \
3361 [concat $after {set ui_status_value {Ready.}}]
3362 } elseif {$w eq $ui_workdir} {
3364 "Adding
[short_path
$path]" \
3366 [concat $after {set ui_status_value {Ready.}}]
3369 show_diff $path $w $lno
3373 proc add_one_to_selection {w x y} {
3374 global file_lists last_clicked selected_paths
3376 set lno [lindex [split [$w index @$x,$y] .] 0]
3377 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3383 if {$last_clicked ne {}
3384 && [lindex $last_clicked 0] ne $w} {
3385 array unset selected_paths
3386 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3389 set last_clicked [list $w $lno]
3390 if {[catch {set in_sel $selected_paths($path)}]} {
3394 unset selected_paths($path)
3395 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3397 set selected_paths($path) 1
3398 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3402 proc add_range_to_selection {w x y} {
3403 global file_lists last_clicked selected_paths
3405 if {[lindex $last_clicked 0] ne $w} {
3406 toggle_or_diff $w $x $y
3410 set lno [lindex [split [$w index @$x,$y] .] 0]
3411 set lc [lindex $last_clicked 1]
3420 foreach path [lrange $file_lists($w) \
3421 [expr {$begin - 1}] \
3422 [expr {$end - 1}]] {
3423 set selected_paths($path) 1
3425 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3428 ######################################################################
3432 set cursor_ptr arrow
3433 font create font_diff -family Courier -size 10
3437 eval font configure font_ui [font actual [.dummy cget -font]]
3441 font create font_uibold
3442 font create font_diffbold
3447 } elseif {[is_MacOSX]} {
3455 proc apply_config {} {
3456 global repo_config font_descs
3458 foreach option $font_descs {
3459 set name [lindex $option 0]
3460 set font [lindex $option 1]
3462 foreach {cn cv} $repo_config(gui.$name) {
3463 font configure $font $cn $cv
3466 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3468 foreach {cn cv} [font configure $font] {
3469 font configure ${font}bold $cn $cv
3471 font configure ${font}bold -weight bold
3475 set default_config(gui.trustmtime) false
3476 set default_config(gui.pullsummary) true
3477 set default_config(gui.diffcontext) 5
3478 set default_config(gui.newbranchtemplate) {}
3479 set default_config(gui.fontui) [font configure font_ui]
3480 set default_config(gui.fontdiff) [font configure font_diff]
3482 {fontui font_ui {Main Font}}
3483 {fontdiff font_diff {Diff/Console Font}}
3488 ######################################################################
3494 menu .mbar -tearoff 0
3495 .mbar add cascade -label Repository -menu .mbar.repository
3496 .mbar add cascade -label Edit -menu .mbar.edit
3497 if {!$single_commit} {
3498 .mbar add cascade -label Branch -menu .mbar.branch
3500 .mbar add cascade -label Commit -menu .mbar.commit
3501 if {!$single_commit} {
3502 .mbar add cascade -label Fetch -menu .mbar.fetch
3503 .mbar add cascade -label Pull -menu .mbar.pull
3504 .mbar add cascade -label Push -menu .mbar.push
3506 . configure -menu .mbar
3508 # -- Repository Menu
3510 menu .mbar.repository
3511 .mbar.repository add command \
3512 -label {Visualize Current Branch} \
3513 -command {do_gitk {}} \
3516 .mbar.repository add command \
3517 -label {Visualize All Branches} \
3518 -command {do_gitk {--all}} \
3521 .mbar.repository add separator
3523 if {!$single_commit} {
3524 .mbar.repository add command -label {Compress Database} \
3528 .mbar.repository add command -label {Verify Database} \
3529 -command do_fsck_objects \
3532 .mbar.repository add separator
3535 .mbar.repository add command \
3536 -label {Create Desktop Icon} \
3537 -command do_windows_shortcut \
3539 } elseif {[is_MacOSX]} {
3540 .mbar.repository add command \
3541 -label {Create Desktop Icon} \
3542 -command do_macosx_app \
3547 .mbar.repository add command -label Quit \
3549 -accelerator $M1T-Q \
3555 .mbar.edit add command -label Undo \
3556 -command {catch {[focus] edit undo}} \
3557 -accelerator $M1T-Z \
3559 .mbar.edit add command -label Redo \
3560 -command {catch {[focus] edit redo}} \
3561 -accelerator $M1T-Y \
3563 .mbar.edit add separator
3564 .mbar.edit add command -label Cut \
3565 -command {catch {tk_textCut [focus]}} \
3566 -accelerator $M1T-X \
3568 .mbar.edit add command -label Copy \
3569 -command {catch {tk_textCopy [focus]}} \
3570 -accelerator $M1T-C \
3572 .mbar.edit add command -label Paste \
3573 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3574 -accelerator $M1T-V \
3576 .mbar.edit add command -label Delete \
3577 -command {catch {[focus] delete sel.first sel.last}} \
3580 .mbar.edit add separator
3581 .mbar.edit add command -label {Select All} \
3582 -command {catch {[focus] tag add sel 0.0 end}} \
3583 -accelerator $M1T-A \
3588 if {!$single_commit} {
3591 .mbar.branch add command -label {Create...} \
3592 -command do_create_branch \
3593 -accelerator $M1T-N \
3595 lappend disable_on_lock [list .mbar.branch entryconf \
3596 [.mbar.branch index last] -state]
3598 .mbar.branch add command -label {Delete...} \
3599 -command do_delete_branch \
3601 lappend disable_on_lock [list .mbar.branch entryconf \
3602 [.mbar.branch index last] -state]
3609 .mbar.commit add radiobutton \
3610 -label {New Commit} \
3611 -command do_select_commit_type \
3612 -variable selected_commit_type \
3615 lappend disable_on_lock \
3616 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3618 .mbar.commit add radiobutton \
3619 -label {Amend Last Commit} \
3620 -command do_select_commit_type \
3621 -variable selected_commit_type \
3624 lappend disable_on_lock \
3625 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3627 .mbar.commit add separator
3629 .mbar.commit add command -label Rescan \
3630 -command do_rescan \
3633 lappend disable_on_lock \
3634 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3636 .mbar.commit add command -label {Add To Commit} \
3637 -command do_add_selection \
3639 lappend disable_on_lock \
3640 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3642 .mbar.commit add command -label {Add All To Commit} \
3643 -command do_add_all \
3644 -accelerator $M1T-I \
3646 lappend disable_on_lock \
3647 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3649 .mbar.commit add command -label {Unstage From Commit} \
3650 -command do_unstage_selection \
3652 lappend disable_on_lock \
3653 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3655 .mbar.commit add command -label {Revert Changes} \
3656 -command do_revert_selection \
3658 lappend disable_on_lock \
3659 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3661 .mbar.commit add separator
3663 .mbar.commit add command -label {Sign Off} \
3664 -command do_signoff \
3665 -accelerator $M1T-S \
3668 .mbar.commit add command -label Commit \
3669 -command do_commit \
3670 -accelerator $M1T-Return \
3672 lappend disable_on_lock \
3673 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3675 # -- Transport menus
3677 if {!$single_commit} {
3684 # -- Apple Menu (Mac OS X only)
3686 .mbar add cascade -label Apple -menu .mbar.apple
3689 .mbar.apple add command -label "About
[appname
]" \
3692 .mbar.apple add command -label "[appname
] Options...
" \
3693 -command do_options \
3698 .mbar.edit add separator
3699 .mbar.edit add command -label {Options...} \
3700 -command do_options \
3705 if {[file exists /usr/local/miga/lib/gui-miga]
3706 && [file exists .pvcsrc]} {
3708 global ui_status_value
3709 if {![lock_index update]} return
3710 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3711 set miga_fd [open "|
$cmd" r]
3712 fconfigure $miga_fd -blocking 0
3713 fileevent $miga_fd readable [list miga_done $miga_fd]
3714 set ui_status_value {Running miga...}
3716 proc miga_done {fd} {
3721 rescan [list set ui_status_value {Ready.}]
3724 .mbar add cascade -label Tools -menu .mbar.tools
3726 .mbar.tools add command -label "Migrate
" \
3729 lappend disable_on_lock \
3730 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3735 .mbar add cascade -label Help -menu .mbar.help
3738 .mbar.help add command -label "About
[appname
]" \
3750 -text {Current Branch:} \
3755 -textvariable current_branch \
3759 pack .branch.l1 -side left
3760 pack .branch.cb -side left -fill x
3761 pack .branch -side top -fill x
3763 # -- Main Window Layout
3765 panedwindow .vpane -orient vertical
3766 panedwindow .vpane.files -orient horizontal
3767 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3768 pack .vpane -anchor n -side top -fill both -expand 1
3770 # -- Index File List
3772 frame .vpane.files.index -height 100 -width 200
3773 label .vpane.files.index.title -text {Changes To Be Committed} \
3776 text $ui_index -background white -borderwidth 0 \
3777 -width 20 -height 10 \
3780 -cursor $cursor_ptr \
3781 -xscrollcommand {.vpane.files.index.sx set} \
3782 -yscrollcommand {.vpane.files.index.sy set} \
3784 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3785 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3786 pack .vpane.files.index.title -side top -fill x
3787 pack .vpane.files.index.sx -side bottom -fill x
3788 pack .vpane.files.index.sy -side right -fill y
3789 pack $ui_index -side left -fill both -expand 1
3790 .vpane.files add .vpane.files.index -sticky nsew
3792 # -- Working Directory File List
3794 frame .vpane.files.workdir -height 100 -width 200
3795 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3798 text $ui_workdir -background white -borderwidth 0 \
3799 -width 20 -height 10 \
3802 -cursor $cursor_ptr \
3803 -xscrollcommand {.vpane.files.workdir.sx set} \
3804 -yscrollcommand {.vpane.files.workdir.sy set} \
3806 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3807 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3808 pack .vpane.files.workdir.title -side top -fill x
3809 pack .vpane.files.workdir.sx -side bottom -fill x
3810 pack .vpane.files.workdir.sy -side right -fill y
3811 pack $ui_workdir -side left -fill both -expand 1
3812 .vpane.files add .vpane.files.workdir -sticky nsew
3814 foreach i [list $ui_index $ui_workdir] {
3815 $i tag conf in_diff -font font_uibold
3816 $i tag conf in_sel \
3817 -background [$i cget -foreground] \
3818 -foreground [$i cget -background]
3822 # -- Diff and Commit Area
3824 frame .vpane.lower -height 300 -width 400
3825 frame .vpane.lower.commarea
3826 frame .vpane.lower.diff -relief sunken -borderwidth 1
3827 pack .vpane.lower.commarea -side top -fill x
3828 pack .vpane.lower.diff -side bottom -fill both -expand 1
3829 .vpane add .vpane.lower -stick nsew
3831 # -- Commit Area Buttons
3833 frame .vpane.lower.commarea.buttons
3834 label .vpane.lower.commarea.buttons.l -text {} \
3838 pack .vpane.lower.commarea.buttons.l -side top -fill x
3839 pack .vpane.lower.commarea.buttons -side left -fill y
3841 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3842 -command do_rescan \
3844 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3845 lappend disable_on_lock \
3846 {.vpane.lower.commarea.buttons.rescan conf -state}
3848 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3849 -command do_add_all \
3851 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3852 lappend disable_on_lock \
3853 {.vpane.lower.commarea.buttons.incall conf -state}
3855 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3856 -command do_signoff \
3858 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3860 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3861 -command do_commit \
3863 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3864 lappend disable_on_lock \
3865 {.vpane.lower.commarea.buttons.commit conf -state}
3867 # -- Commit Message Buffer
3869 frame .vpane.lower.commarea.buffer
3870 frame .vpane.lower.commarea.buffer.header
3871 set ui_comm .vpane.lower.commarea.buffer.t
3872 set ui_coml .vpane.lower.commarea.buffer.header.l
3873 radiobutton .vpane.lower.commarea.buffer.header.new \
3874 -text {New Commit} \
3875 -command do_select_commit_type \
3876 -variable selected_commit_type \
3879 lappend disable_on_lock \
3880 [list .vpane.lower.commarea.buffer.header.new conf -state]
3881 radiobutton .vpane.lower.commarea.buffer.header.amend \
3882 -text {Amend Last Commit} \
3883 -command do_select_commit_type \
3884 -variable selected_commit_type \
3887 lappend disable_on_lock \
3888 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3893 proc trace_commit_type {varname args} {
3894 global ui_coml commit_type
3895 switch -glob -- $commit_type {
3896 initial {set txt {Initial Commit Message:}}
3897 amend {set txt {Amended Commit Message:}}
3898 amend-initial {set txt {Amended Initial Commit Message:}}
3899 amend-merge {set txt {Amended Merge Commit Message:}}
3900 merge {set txt {Merge Commit Message:}}
3901 * {set txt {Commit Message:}}
3903 $ui_coml conf -text $txt
3905 trace add variable commit_type write trace_commit_type
3906 pack $ui_coml -side left -fill x
3907 pack .vpane.lower.commarea.buffer.header.amend -side right
3908 pack .vpane.lower.commarea.buffer.header.new -side right
3910 text $ui_comm -background white -borderwidth 1 \
3913 -autoseparators true \
3915 -width 75 -height 9 -wrap none \
3917 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3918 scrollbar .vpane.lower.commarea.buffer.sby \
3919 -command [list $ui_comm yview]
3920 pack .vpane.lower.commarea.buffer.header -side top -fill x
3921 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3922 pack $ui_comm -side left -fill y
3923 pack .vpane.lower.commarea.buffer -side left -fill y
3925 # -- Commit Message Buffer Context Menu
3927 set ctxm .vpane.lower.commarea.buffer.ctxm
3928 menu $ctxm -tearoff 0
3932 -command {tk_textCut $ui_comm}
3936 -command {tk_textCopy $ui_comm}
3940 -command {tk_textPaste $ui_comm}
3944 -command {$ui_comm delete sel.first sel.last}
3947 -label {Select All} \
3949 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3954 $ui_comm tag add sel 0.0 end
3955 tk_textCopy $ui_comm
3956 $ui_comm tag remove sel 0.0 end
3963 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
3967 set current_diff_path {}
3968 set diff_actions [list]
3969 proc trace_current_diff_path {varname args} {
3970 global current_diff_path diff_actions file_states
3971 if {$current_diff_path eq {}} {
3977 set p $current_diff_path
3978 set s [mapdesc [lindex $file_states($p) 0] $p]
3980 set p [escape_path $p]
3984 .vpane.lower.diff.header.status configure -text $s
3985 .vpane.lower.diff.header.file configure -text $f
3986 .vpane.lower.diff.header.path configure -text $p
3987 foreach w $diff_actions {
3991 trace add variable current_diff_path write trace_current_diff_path
3993 frame .vpane.lower.diff.header -background orange
3994 label .vpane.lower.diff.header.status \
3995 -background orange \
3996 -width $max_status_desc \
4000 label .vpane.lower.diff.header.file \
4001 -background orange \
4005 label .vpane.lower.diff.header.path \
4006 -background orange \
4010 pack .vpane.lower.diff.header.status -side left
4011 pack .vpane.lower.diff.header.file -side left
4012 pack .vpane.lower.diff.header.path -fill x
4013 set ctxm .vpane.lower.diff.header.ctxm
4014 menu $ctxm -tearoff 0
4023 -- $current_diff_path
4025 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4026 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
4030 frame .vpane.lower.diff.body
4031 set ui_diff .vpane.lower.diff.body.t
4032 text $ui_diff -background white -borderwidth 0 \
4033 -width 80 -height 15 -wrap none \
4035 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4036 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4038 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4039 -command [list $ui_diff xview]
4040 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4041 -command [list $ui_diff yview]
4042 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4043 pack .vpane.lower.diff.body.sby -side right -fill y
4044 pack $ui_diff -side left -fill both -expand 1
4045 pack .vpane.lower.diff.header -side top -fill x
4046 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4048 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4049 $ui_diff tag conf d_+ -foreground {#00a000}
4050 $ui_diff tag conf d_- -foreground red
4052 $ui_diff tag conf d_++ -foreground {#00a000}
4053 $ui_diff tag conf d_-- -foreground red
4054 $ui_diff tag conf d_+s \
4055 -foreground {#00a000} \
4056 -background {#e2effa}
4057 $ui_diff tag conf d_-s \
4059 -background {#e2effa}
4060 $ui_diff tag conf d_s+ \
4061 -foreground {#00a000} \
4063 $ui_diff tag conf d_s- \
4067 $ui_diff tag conf d<<<<<<< \
4068 -foreground orange \
4070 $ui_diff tag conf d======= \
4071 -foreground orange \
4073 $ui_diff tag conf d>>>>>>> \
4074 -foreground orange \
4077 $ui_diff tag raise sel
4079 # -- Diff Body Context Menu
4081 set ctxm .vpane.lower.diff.body.ctxm
4082 menu $ctxm -tearoff 0
4086 -command reshow_diff
4090 -command {tk_textCopy $ui_diff}
4091 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4093 -label {Select All} \
4095 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4096 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4101 $ui_diff tag add sel 0.0 end
4102 tk_textCopy $ui_diff
4103 $ui_diff tag remove sel 0.0 end
4105 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4108 -label {Decrease Font Size} \
4110 -command {incr_font_size font_diff -1}
4111 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4113 -label {Increase Font Size} \
4115 -command {incr_font_size font_diff 1}
4116 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4119 -label {Show Less Context} \
4121 -command {if {$repo_config(gui.diffcontext) >= 2} {
4122 incr repo_config(gui.diffcontext) -1
4125 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4127 -label {Show More Context} \
4130 incr repo_config(gui.diffcontext)
4133 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4135 $ctxm add command -label {Options...} \
4138 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
4142 set ui_status_value {Initializing...}
4143 label .status -textvariable ui_status_value \
4149 pack .status -anchor w -side bottom -fill x
4154 set gm $repo_config(gui.geometry)
4155 wm geometry . [lindex $gm 0]
4156 .vpane sash place 0 \
4157 [lindex [.vpane sash coord 0] 0] \
4159 .vpane.files sash place 0 \
4161 [lindex [.vpane.files sash coord 0] 1]
4167 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4168 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4169 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4170 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4171 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4172 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4173 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4174 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4175 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4176 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4177 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4179 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4180 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4181 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4182 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4183 bind $ui_diff <$M1B-Key-v> {break}
4184 bind $ui_diff <$M1B-Key-V> {break}
4185 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4186 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4187 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4188 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4189 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4190 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4192 if {!$single_commit} {
4193 bind . <$M1B-Key-n> do_create_branch
4194 bind . <$M1B-Key-N> do_create_branch
4197 bind . <Destroy> do_quit
4198 bind all <Key-F5> do_rescan
4199 bind all <$M1B-Key-r> do_rescan
4200 bind all <$M1B-Key-R> do_rescan
4201 bind . <$M1B-Key-s> do_signoff
4202 bind . <$M1B-Key-S> do_signoff
4203 bind . <$M1B-Key-i> do_add_all
4204 bind . <$M1B-Key-I> do_add_all
4205 bind . <$M1B-Key-Return> do_commit
4206 bind all <$M1B-Key-q> do_quit
4207 bind all <$M1B-Key-Q> do_quit
4208 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4209 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4210 foreach i [list $ui_index $ui_workdir] {
4211 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4212 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4213 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4217 set file_lists($ui_index) [list]
4218 set file_lists($ui_workdir) [list]
4222 set MERGE_HEAD [list]
4225 set current_branch {}
4226 set current_diff_path {}
4227 set selected_commit_type new
4229 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4230 focus -force $ui_comm
4232 # -- Warn the user about environmental problems. Cygwin's Tcl
4233 # does *not* pass its env array onto any processes it spawns.
4234 # This means that git processes get none of our environment.
4239 set msg "Possible environment issues exist.
4241 The following environment variables are probably
4242 going to be ignored by any Git subprocess run
4246 foreach name [array names env] {
4247 switch -regexp -- $name {
4248 {^GIT_INDEX_FILE$} -
4249 {^GIT_OBJECT_DIRECTORY$} -
4250 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4252 {^GIT_EXTERNAL_DIFF$} -
4256 {^GIT_CONFIG_LOCAL$} -
4257 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4258 append msg " - $name\n"
4261 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4262 append msg " - $name\n"
4264 set suggest_user $name
4268 if {$ignored_env > 0} {
4270 This is due to a known issue with the
4271 Tcl binary distributed by Cygwin.
"
4273 if {$suggest_user ne {}} {
4276 A good replacement
for $suggest_user
4277 is placing values
for the user.name and
4278 user.email settings into your personal
4284 unset ignored_env msg suggest_user name
4287 # -- Only initialize complex UI if we are going to stay running.
4289 if {!$single_commit} {
4293 populate_branch_menu
4294 populate_fetch_menu .mbar.fetch
4295 populate_pull_menu .mbar.pull
4296 populate_push_menu .mbar.push
4299 # -- Only suggest a gc run if we are going to stay running.
4301 if {!$single_commit} {
4302 set object_limit 2000
4303 if {[is_Windows]} {set object_limit 200}
4304 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4305 if {$objects_current >= $object_limit} {
4307 "This repository currently has
$objects_current loose objects.
4309 To maintain optimal performance it is strongly
4310 recommended that you
compress the database
4311 when
more than
$object_limit loose objects exist.
4313 Compress the database now?
"] eq yes} {
4317 unset object_limit _junk objects_current
4320 lock_index begin-read