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
414 fconfigure
$fd_df -blocking 0 -translation binary
415 fconfigure
$fd_lo -blocking 0 -translation binary
416 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
417 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
418 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
421 proc load_message
{file} {
425 if {[file isfile
$f]} {
426 if {[catch
{set fd
[open
$f r
]}]} {
429 set content
[string trim
[read $fd]]
431 $ui_comm delete
0.0 end
432 $ui_comm insert end
$content
438 proc read_diff_index
{fd after
} {
441 append buf_rdi
[read $fd]
443 set n
[string length
$buf_rdi]
445 set z1
[string first
"\0" $buf_rdi $c]
448 set z2
[string first
"\0" $buf_rdi $z1]
452 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
454 [string range
$buf_rdi $z1 [expr {$z2 - 1}]] \
456 [list
[lindex
$i 0] [lindex
$i 2]] \
462 set buf_rdi
[string range
$buf_rdi $c end
]
467 rescan_done
$fd buf_rdi
$after
470 proc read_diff_files
{fd after
} {
473 append buf_rdf
[read $fd]
475 set n
[string length
$buf_rdf]
477 set z1
[string first
"\0" $buf_rdf $c]
480 set z2
[string first
"\0" $buf_rdf $z1]
484 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
486 [string range
$buf_rdf $z1 [expr {$z2 - 1}]] \
489 [list
[lindex
$i 0] [lindex
$i 2]]
494 set buf_rdf
[string range
$buf_rdf $c end
]
499 rescan_done
$fd buf_rdf
$after
502 proc read_ls_others
{fd after
} {
505 append buf_rlo
[read $fd]
506 set pck
[split $buf_rlo "\0"]
507 set buf_rlo
[lindex
$pck end
]
508 foreach p
[lrange
$pck 0 end-1
] {
511 rescan_done
$fd buf_rlo
$after
514 proc rescan_done
{fd buf after
} {
516 global file_states repo_config
519 if {![eof
$fd]} return
522 if {[incr rescan_active
-1] > 0} return
531 proc prune_selection
{} {
532 global file_states selected_paths
534 foreach path
[array names selected_paths
] {
535 if {[catch
{set still_here
$file_states($path)}]} {
536 unset selected_paths
($path)
541 ######################################################################
546 global ui_diff current_diff_path ui_index ui_workdir
548 $ui_diff conf
-state normal
549 $ui_diff delete
0.0 end
550 $ui_diff conf
-state disabled
552 set current_diff_path
{}
554 $ui_index tag remove in_diff
0.0 end
555 $ui_workdir tag remove in_diff
0.0 end
558 proc reshow_diff
{} {
559 global ui_status_value file_states file_lists
560 global current_diff_path current_diff_side
562 set p
$current_diff_path
564 ||
$current_diff_side eq
{}
565 ||
[catch
{set s
$file_states($p)}]
566 ||
[lsearch
-sorted $file_lists($current_diff_side) $p] == -1} {
569 show_diff
$p $current_diff_side
573 proc handle_empty_diff
{} {
574 global current_diff_path file_states file_lists
576 set path
$current_diff_path
577 set s
$file_states($path)
578 if {[lindex
$s 0] ne
{_M
}} return
580 info_popup
"No differences detected.
582 [short_path $path] has no changes.
584 The modification date of this file was updated
585 by another application, but the content within
586 the file was not changed.
588 A rescan will be automatically started to find
589 other files which may have the same state."
592 display_file
$path __
593 rescan
{set ui_status_value
{Ready.
}} 0
596 proc show_diff
{path w
{lno
{}}} {
597 global file_states file_lists
598 global is_3way_diff diff_active repo_config
599 global ui_diff ui_status_value ui_index ui_workdir
600 global current_diff_path current_diff_side
602 if {$diff_active ||
![lock_index
read]} return
605 if {$w eq
{} ||
$lno == {}} {
606 foreach w
[array names file_lists
] {
607 set lno
[lsearch
-sorted $file_lists($w) $path]
614 if {$w ne
{} && $lno >= 1} {
615 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
618 set s
$file_states($path)
622 set current_diff_path
$path
623 set current_diff_side
$w
624 set ui_status_value
"Loading diff of [escape_path $path]..."
626 # - Git won't give us the diff, there's nothing to compare to!
629 set max_sz
[expr {128 * 1024}]
631 set fd
[open
$path r
]
632 set content
[read $fd $max_sz]
634 set sz
[file size
$path]
638 set ui_status_value
"Unable to display [escape_path $path]"
639 error_popup
"Error loading file:\n\n$err"
642 $ui_diff conf
-state normal
643 if {![catch
{set type [exec file $path]}]} {
644 set n
[string length
$path]
645 if {[string equal
-length $n $path $type]} {
646 set type [string range
$type $n end
]
647 regsub
{^
:?\s
*} $type {} type
649 $ui_diff insert end
"* $type\n" d_@
651 if {[string first
"\0" $content] != -1} {
652 $ui_diff insert end \
653 "* Binary file (not showing content)." \
657 $ui_diff insert end \
658 "* Untracked file is $sz bytes.
659 * Showing only first $max_sz bytes.
663 $ui_diff insert end
$content
665 $ui_diff insert end
"
666 * Untracked file clipped here by [appname].
667 * To see the entire file, use an external editor.
671 $ui_diff conf
-state disabled
674 set ui_status_value
{Ready.
}
679 if {$w eq
$ui_index} {
680 lappend cmd diff-index
682 } elseif
{$w eq
$ui_workdir} {
683 if {[string index
$m 0] eq
{U
}} {
686 lappend cmd diff-files
691 lappend cmd
--no-color
692 if {$repo_config(gui.diffcontext
) > 0} {
693 lappend cmd
"-U$repo_config(gui.diffcontext)"
695 if {$w eq
$ui_index} {
701 if {[catch
{set fd
[open
$cmd r
]} err
]} {
704 set ui_status_value
"Unable to display [escape_path $path]"
705 error_popup
"Error loading diff:\n\n$err"
709 fconfigure
$fd -blocking 0 -translation auto
710 fileevent
$fd readable
[list read_diff
$fd]
713 proc read_diff
{fd
} {
714 global ui_diff ui_status_value is_3way_diff diff_active
716 $ui_diff conf
-state normal
717 while {[gets
$fd line
] >= 0} {
718 # -- Cleanup uninteresting diff header lines.
720 if {[string match
{diff --git *} $line]} continue
721 if {[string match
{diff --cc *} $line]} continue
722 if {[string match
{diff --combined *} $line]} continue
723 if {[string match
{--- *} $line]} continue
724 if {[string match
{+++ *} $line]} continue
725 if {$line eq
{deleted
file mode
120000}} {
726 set line
"deleted symlink"
729 # -- Automatically detect if this is a 3 way diff.
731 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
733 if {[string match
{index
*} $line]
734 ||
[string match
{mode
*} $line]
735 ||
[string match
{new
file *} $line]
736 ||
[string match
{deleted
file *} $line]
737 ||
[string match
{Binary files
* and
* differ
} $line]
738 ||
$line eq
{\ No newline
at end of
file}
739 ||
[regexp
{^\
* Unmerged path
} $line]} {
741 } elseif
{$is_3way_diff} {
742 set op
[string range
$line 0 1]
752 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
753 set line
[string replace
$line 0 1 { }]
760 puts
"error: Unhandled 3 way diff marker: {$op}"
765 set op
[string index
$line 0]
771 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
772 set line
[string replace
$line 0 0 { }]
779 puts
"error: Unhandled 2 way diff marker: {$op}"
784 $ui_diff insert end
$line $tags
785 $ui_diff insert end
"\n" $tags
787 $ui_diff conf
-state disabled
793 set ui_status_value
{Ready.
}
795 if {[$ui_diff index end
] eq
{2.0}} {
801 ######################################################################
805 proc load_last_commit
{} {
806 global HEAD PARENT MERGE_HEAD commit_type ui_comm
808 if {[llength
$PARENT] == 0} {
809 error_popup
{There is nothing to amend.
811 You are about to create the initial commit.
812 There is no commit before this to amend.
817 repository_state curType curHEAD curMERGE_HEAD
818 if {$curType eq
{merge
}} {
819 error_popup
{Cannot amend
while merging.
821 You are currently
in the middle of a merge that
822 has not been fully completed. You cannot amend
823 the prior commit unless you first abort the
824 current merge activity.
832 set fd
[open
"| git cat-file commit $curHEAD" r
]
833 while {[gets
$fd line
] > 0} {
834 if {[string match
{parent
*} $line]} {
835 lappend parents
[string range
$line 7 end
]
838 set msg
[string trim
[read $fd]]
841 error_popup
"Error loading commit data for amend:\n\n$err"
847 set MERGE_HEAD
[list
]
848 switch
-- [llength
$parents] {
849 0 {set commit_type amend-initial
}
850 1 {set commit_type amend
}
851 default
{set commit_type amend-merge
}
854 $ui_comm delete
0.0 end
855 $ui_comm insert end
$msg
857 $ui_comm edit modified false
858 rescan
{set ui_status_value
{Ready.
}}
861 proc create_new_commit
{} {
862 global commit_type ui_comm
864 set commit_type normal
865 $ui_comm delete
0.0 end
867 $ui_comm edit modified false
868 rescan
{set ui_status_value
{Ready.
}}
871 set GIT_COMMITTER_IDENT
{}
873 proc committer_ident
{} {
874 global GIT_COMMITTER_IDENT
876 if {$GIT_COMMITTER_IDENT eq
{}} {
877 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
878 error_popup
"Unable to obtain your identity:\n\n$err"
881 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
882 $me me GIT_COMMITTER_IDENT
]} {
883 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
888 return $GIT_COMMITTER_IDENT
891 proc commit_tree
{} {
892 global HEAD commit_type file_states ui_comm repo_config
893 global ui_status_value pch_error
895 if {![lock_index update
]} return
896 if {[committer_ident
] eq
{}} return
898 # -- Our in memory state should match the repository.
900 repository_state curType curHEAD curMERGE_HEAD
901 if {[string match amend
* $commit_type]
902 && $curType eq
{normal
}
903 && $curHEAD eq
$HEAD} {
904 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
905 info_popup
{Last scanned state does not match repository state.
907 Another Git program has modified this repository
908 since the last scan. A rescan must be performed
909 before another commit can be created.
911 The rescan will be automatically started now.
914 rescan
{set ui_status_value
{Ready.
}}
918 # -- At least one file should differ in the index.
921 foreach path
[array names file_states
] {
922 switch
-glob -- [lindex
$file_states($path) 0] {
926 M?
{set files_ready
1}
928 error_popup
"Unmerged files cannot be committed.
930 File [short_path $path] has merge conflicts.
931 You must resolve them and add the file before committing.
937 error_popup
"Unknown file state [lindex $s 0] detected.
939 File [short_path $path] cannot be committed by this program.
945 info_popup
{No changes to commit.
947 You must add
at least
1 file before you can commit.
953 # -- A message is required.
955 set msg
[string trim
[$ui_comm get
1.0 end
]]
957 error_popup
{Please supply a commit message.
959 A good commit message has the following format
:
961 - First line
: Describe
in one sentance what you did.
963 - Remaining lines
: Describe why this change is good.
969 # -- Run the pre-commit hook.
971 set pchook
[gitdir hooks pre-commit
]
973 # On Cygwin [file executable] might lie so we need to ask
974 # the shell if the hook is executable. Yes that's annoying.
976 if {[is_Windows
] && [file isfile
$pchook]} {
977 set pchook
[list sh
-c [concat \
978 "if test -x \"$pchook\";" \
979 "then exec \"$pchook\" 2>&1;" \
981 } elseif
{[file executable
$pchook]} {
982 set pchook
[list
$pchook |
& cat]
984 commit_writetree
$curHEAD $msg
988 set ui_status_value
{Calling pre-commit hook...
}
990 set fd_ph
[open
"| $pchook" r
]
991 fconfigure
$fd_ph -blocking 0 -translation binary
992 fileevent
$fd_ph readable \
993 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
996 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
997 global pch_error ui_status_value
999 append pch_error
[read $fd_ph]
1000 fconfigure
$fd_ph -blocking 1
1002 if {[catch
{close
$fd_ph}]} {
1003 set ui_status_value
{Commit declined by pre-commit hook.
}
1004 hook_failed_popup pre-commit
$pch_error
1007 commit_writetree
$curHEAD $msg
1012 fconfigure
$fd_ph -blocking 0
1015 proc commit_writetree
{curHEAD msg
} {
1016 global ui_status_value
1018 set ui_status_value
{Committing changes...
}
1019 set fd_wt
[open
"| git write-tree" r
]
1020 fileevent
$fd_wt readable \
1021 [list commit_committree
$fd_wt $curHEAD $msg]
1024 proc commit_committree
{fd_wt curHEAD msg
} {
1025 global HEAD PARENT MERGE_HEAD commit_type
1026 global single_commit all_heads current_branch
1027 global ui_status_value ui_comm selected_commit_type
1028 global file_states selected_paths rescan_active
1031 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1032 error_popup
"write-tree failed:\n\n$err"
1033 set ui_status_value
{Commit failed.
}
1038 # -- Create the commit.
1040 set cmd
[list git commit-tree
$tree_id]
1041 set parents
[concat
$PARENT $MERGE_HEAD]
1042 if {[llength
$parents] > 0} {
1043 foreach p
$parents {
1047 # git commit-tree writes to stderr during initial commit.
1048 lappend cmd
2>/dev
/null
1051 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1052 error_popup
"commit-tree failed:\n\n$err"
1053 set ui_status_value
{Commit failed.
}
1058 # -- Update the HEAD ref.
1061 if {$commit_type ne
{normal
}} {
1062 append reflogm
" ($commit_type)"
1064 set i
[string first
"\n" $msg]
1066 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1068 append reflogm
{: } $msg
1070 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1071 if {[catch
{eval exec $cmd} err
]} {
1072 error_popup
"update-ref failed:\n\n$err"
1073 set ui_status_value
{Commit failed.
}
1078 # -- Make sure our current branch exists.
1080 if {$commit_type eq
{initial
}} {
1081 lappend all_heads
$current_branch
1082 set all_heads
[lsort
-unique $all_heads]
1083 populate_branch_menu
1086 # -- Cleanup after ourselves.
1088 catch
{file delete
[gitdir MERGE_HEAD
]}
1089 catch
{file delete
[gitdir MERGE_MSG
]}
1090 catch
{file delete
[gitdir SQUASH_MSG
]}
1091 catch
{file delete
[gitdir GITGUI_MSG
]}
1093 # -- Let rerere do its thing.
1095 if {[file isdirectory
[gitdir rr-cache
]]} {
1096 catch
{exec git rerere
}
1099 # -- Run the post-commit hook.
1101 set pchook
[gitdir hooks post-commit
]
1102 if {[is_Windows
] && [file isfile
$pchook]} {
1103 set pchook
[list sh
-c [concat \
1104 "if test -x \"$pchook\";" \
1105 "then exec \"$pchook\";" \
1107 } elseif
{![file executable
$pchook]} {
1110 if {$pchook ne
{}} {
1111 catch
{exec $pchook &}
1114 $ui_comm delete
0.0 end
1116 $ui_comm edit modified false
1118 if {$single_commit} do_quit
1120 # -- Update in memory status
1122 set selected_commit_type new
1123 set commit_type normal
1126 set MERGE_HEAD
[list
]
1128 foreach path
[array names file_states
] {
1129 set s
$file_states($path)
1131 switch
-glob -- $m {
1139 unset file_states
($path)
1140 catch
{unset selected_paths
($path)}
1143 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1149 set file_states
($path) [list \
1150 _
[string index
$m 1] \
1161 set ui_status_value \
1162 "Changes committed as [string range $cmt_id 0 7]."
1165 ######################################################################
1169 proc fetch_from
{remote
} {
1170 set w
[new_console
"fetch $remote" \
1171 "Fetching new changes from $remote"]
1172 set cmd
[list git fetch
]
1174 console_exec
$w $cmd
1177 proc pull_remote
{remote branch
} {
1178 global HEAD commit_type file_states repo_config
1180 if {![lock_index update
]} return
1182 # -- Our in memory state should match the repository.
1184 repository_state curType curHEAD curMERGE_HEAD
1185 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1186 info_popup
{Last scanned state does not match repository state.
1188 Another Git program has modified this repository
1189 since the last scan. A rescan must be performed
1190 before a pull operation can be started.
1192 The rescan will be automatically started now.
1195 rescan
{set ui_status_value
{Ready.
}}
1199 # -- No differences should exist before a pull.
1201 if {[array size file_states
] != 0} {
1202 error_popup
{Uncommitted but modified files are present.
1204 You should not perform a pull with unmodified
1205 files
in your working directory as Git will be
1206 unable to recover from an incorrect merge.
1208 You should commit or revert all changes before
1209 starting a pull operation.
1215 set w
[new_console
"pull $remote $branch" \
1216 "Pulling new changes from branch $branch in $remote"]
1217 set cmd
[list git pull
]
1218 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1219 lappend cmd
--no-summary
1223 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1226 proc post_pull_remote
{remote branch success
} {
1227 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1228 global ui_status_value
1232 repository_state commit_type HEAD MERGE_HEAD
1234 set selected_commit_type new
1235 set ui_status_value
"Pulling $branch from $remote complete."
1237 rescan
[list
set ui_status_value \
1238 "Conflicts detected while pulling $branch from $remote."]
1242 proc push_to
{remote
} {
1243 set w
[new_console
"push $remote" \
1244 "Pushing changes to $remote"]
1245 set cmd
[list git push
]
1247 console_exec
$w $cmd
1250 ######################################################################
1254 proc mapicon
{w state path
} {
1257 if {[catch
{set r
$all_icons($state$w)}]} {
1258 puts
"error: no icon for $w state={$state} $path"
1264 proc mapdesc
{state path
} {
1267 if {[catch
{set r
$all_descs($state)}]} {
1268 puts
"error: no desc for state={$state} $path"
1274 proc escape_path
{path
} {
1275 regsub
-all "\n" $path "\\n" path
1279 proc short_path
{path
} {
1280 return [escape_path
[lindex
[file split $path] end
]]
1284 set null_sha1
[string repeat
0 40]
1286 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1287 global file_states next_icon_id null_sha1
1289 set s0
[string index
$new_state 0]
1290 set s1
[string index
$new_state 1]
1292 if {[catch
{set info
$file_states($path)}]} {
1294 set icon n
[incr next_icon_id
]
1296 set state
[lindex
$info 0]
1297 set icon
[lindex
$info 1]
1298 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1299 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1302 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1303 elseif
{$s0 eq
{_
}} {set s0 _
}
1305 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1306 elseif
{$s1 eq
{_
}} {set s1 _
}
1308 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1309 set head_info
[list
0 $null_sha1]
1310 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1311 && $head_info eq
{}} {
1312 set head_info
$index_info
1315 set file_states
($path) [list
$s0$s1 $icon \
1316 $head_info $index_info \
1321 proc display_file_helper
{w path icon_name old_m new_m
} {
1324 if {$new_m eq
{_
}} {
1325 set lno
[lsearch
-sorted $file_lists($w) $path]
1327 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1329 $w conf
-state normal
1330 $w delete
$lno.0 [expr {$lno + 1}].0
1331 $w conf
-state disabled
1333 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1334 lappend file_lists
($w) $path
1335 set file_lists
($w) [lsort
-unique $file_lists($w)]
1336 set lno
[lsearch
-sorted $file_lists($w) $path]
1338 $w conf
-state normal
1339 $w image create
$lno.0 \
1340 -align center
-padx 5 -pady 1 \
1342 -image [mapicon
$w $new_m $path]
1343 $w insert
$lno.1 "[escape_path $path]\n"
1344 $w conf
-state disabled
1345 } elseif
{$old_m ne
$new_m} {
1346 $w conf
-state normal
1347 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1348 $w conf
-state disabled
1352 proc display_file
{path state
} {
1353 global file_states selected_paths
1354 global ui_index ui_workdir
1356 set old_m
[merge_state
$path $state]
1357 set s
$file_states($path)
1358 set new_m
[lindex
$s 0]
1359 set icon_name
[lindex
$s 1]
1361 set o
[string index
$old_m 0]
1362 set n
[string index
$new_m 0]
1369 display_file_helper
$ui_index $path $icon_name $o $n
1371 if {[string index
$old_m 0] eq
{U
}} {
1374 set o
[string index
$old_m 1]
1376 if {[string index
$new_m 0] eq
{U
}} {
1379 set n
[string index
$new_m 1]
1381 display_file_helper
$ui_workdir $path $icon_name $o $n
1383 if {$new_m eq
{__
}} {
1384 unset file_states
($path)
1385 catch
{unset selected_paths
($path)}
1389 proc display_all_files_helper
{w path icon_name m
} {
1392 lappend file_lists
($w) $path
1393 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1394 $w image create end \
1395 -align center
-padx 5 -pady 1 \
1397 -image [mapicon
$w $m $path]
1398 $w insert end
"[escape_path $path]\n"
1401 proc display_all_files
{} {
1402 global ui_index ui_workdir
1403 global file_states file_lists
1406 $ui_index conf
-state normal
1407 $ui_workdir conf
-state normal
1409 $ui_index delete
0.0 end
1410 $ui_workdir delete
0.0 end
1413 set file_lists
($ui_index) [list
]
1414 set file_lists
($ui_workdir) [list
]
1416 foreach path
[lsort
[array names file_states
]] {
1417 set s
$file_states($path)
1419 set icon_name
[lindex
$s 1]
1421 set s
[string index
$m 0]
1422 if {$s ne
{U
} && $s ne
{_
}} {
1423 display_all_files_helper
$ui_index $path \
1427 if {[string index
$m 0] eq
{U
}} {
1430 set s
[string index
$m 1]
1433 display_all_files_helper
$ui_workdir $path \
1438 $ui_index conf
-state disabled
1439 $ui_workdir conf
-state disabled
1442 proc update_indexinfo
{msg pathList after
} {
1443 global update_index_cp ui_status_value
1445 if {![lock_index update
]} return
1447 set update_index_cp
0
1448 set pathList
[lsort
$pathList]
1449 set totalCnt
[llength
$pathList]
1450 set batch [expr {int
($totalCnt * .01) + 1}]
1451 if {$batch > 25} {set batch 25}
1453 set ui_status_value
[format \
1454 "$msg... %i/%i files (%.2f%%)" \
1458 set fd
[open
"| git update-index -z --index-info" w
]
1464 fileevent
$fd writable
[list \
1465 write_update_indexinfo \
1475 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1476 global update_index_cp ui_status_value
1477 global file_states current_diff_path
1479 if {$update_index_cp >= $totalCnt} {
1486 for {set i
$batch} \
1487 {$update_index_cp < $totalCnt && $i > 0} \
1489 set path
[lindex
$pathList $update_index_cp]
1490 incr update_index_cp
1492 set s
$file_states($path)
1493 switch
-glob -- [lindex
$s 0] {
1500 set info
[lindex
$s 2]
1501 if {$info eq
{}} continue
1503 puts
-nonewline $fd "$info\t$path\0"
1504 display_file
$path $new
1507 set ui_status_value
[format \
1508 "$msg... %i/%i files (%.2f%%)" \
1511 [expr {100.0 * $update_index_cp / $totalCnt}]]
1514 proc update_index
{msg pathList after
} {
1515 global update_index_cp ui_status_value
1517 if {![lock_index update
]} return
1519 set update_index_cp
0
1520 set pathList
[lsort
$pathList]
1521 set totalCnt
[llength
$pathList]
1522 set batch [expr {int
($totalCnt * .01) + 1}]
1523 if {$batch > 25} {set batch 25}
1525 set ui_status_value
[format \
1526 "$msg... %i/%i files (%.2f%%)" \
1530 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1536 fileevent
$fd writable
[list \
1537 write_update_index \
1547 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1548 global update_index_cp ui_status_value
1549 global file_states current_diff_path
1551 if {$update_index_cp >= $totalCnt} {
1558 for {set i
$batch} \
1559 {$update_index_cp < $totalCnt && $i > 0} \
1561 set path
[lindex
$pathList $update_index_cp]
1562 incr update_index_cp
1564 switch
-glob -- [lindex
$file_states($path) 0] {
1570 if {[file exists
$path]} {
1579 puts
-nonewline $fd "$path\0"
1580 display_file
$path $new
1583 set ui_status_value
[format \
1584 "$msg... %i/%i files (%.2f%%)" \
1587 [expr {100.0 * $update_index_cp / $totalCnt}]]
1590 proc checkout_index
{msg pathList after
} {
1591 global update_index_cp ui_status_value
1593 if {![lock_index update
]} return
1595 set update_index_cp
0
1596 set pathList
[lsort
$pathList]
1597 set totalCnt
[llength
$pathList]
1598 set batch [expr {int
($totalCnt * .01) + 1}]
1599 if {$batch > 25} {set batch 25}
1601 set ui_status_value
[format \
1602 "$msg... %i/%i files (%.2f%%)" \
1606 set cmd
[list git checkout-index
]
1612 set fd
[open
"| $cmd " w
]
1618 fileevent
$fd writable
[list \
1619 write_checkout_index \
1629 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1630 global update_index_cp ui_status_value
1631 global file_states current_diff_path
1633 if {$update_index_cp >= $totalCnt} {
1640 for {set i
$batch} \
1641 {$update_index_cp < $totalCnt && $i > 0} \
1643 set path
[lindex
$pathList $update_index_cp]
1644 incr update_index_cp
1645 switch
-glob -- [lindex
$file_states($path) 0] {
1649 puts
-nonewline $fd "$path\0"
1650 display_file
$path ?_
1655 set ui_status_value
[format \
1656 "$msg... %i/%i files (%.2f%%)" \
1659 [expr {100.0 * $update_index_cp / $totalCnt}]]
1662 ######################################################################
1664 ## branch management
1666 proc is_tracking_branch
{name
} {
1667 global tracking_branches
1669 if {![catch
{set info
$tracking_branches($name)}]} {
1672 foreach t
[array names tracking_branches
] {
1673 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1680 proc load_all_heads
{} {
1683 set all_heads
[list
]
1684 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1685 while {[gets
$fd line
] > 0} {
1686 if {[is_tracking_branch
$line]} continue
1687 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1688 lappend all_heads
$name
1692 set all_heads
[lsort
$all_heads]
1695 proc populate_branch_menu
{} {
1696 global all_heads disable_on_lock
1699 set last
[$m index last
]
1700 for {set i
0} {$i <= $last} {incr i
} {
1701 if {[$m type $i] eq
{separator
}} {
1704 foreach a
$disable_on_lock {
1705 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1709 set disable_on_lock
$new_dol
1715 foreach b
$all_heads {
1716 $m add radiobutton \
1718 -command [list switch_branch
$b] \
1719 -variable current_branch \
1722 lappend disable_on_lock \
1723 [list
$m entryconf
[$m index last
] -state]
1727 proc all_tracking_branches
{} {
1728 global tracking_branches
1730 set all_trackings
{}
1732 foreach name
[array names tracking_branches
] {
1733 if {[regsub
{/\
*$
} $name {} name
]} {
1736 regsub ^refs
/(heads|remotes
)/ $name {} name
1737 lappend all_trackings
$name
1742 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1743 while {[gets
$fd name
] > 0} {
1744 regsub ^refs
/(heads|remotes
)/ $name {} name
1745 lappend all_trackings
$name
1750 return [lsort
-unique $all_trackings]
1753 proc do_create_branch_action
{w
} {
1754 global all_heads null_sha1 repo_config
1755 global create_branch_checkout create_branch_revtype
1756 global create_branch_head create_branch_trackinghead
1758 set newbranch
[string trim
[$w.desc.name_t get
0.0 end
]]
1759 if {$newbranch eq
{}
1760 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1764 -title [wm title
$w] \
1766 -message "Please supply a branch name."
1767 focus
$w.desc.name_t
1770 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1774 -title [wm title
$w] \
1776 -message "Branch '$newbranch' already exists."
1777 focus
$w.desc.name_t
1780 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1784 -title [wm title
$w] \
1786 -message "We do not like '$newbranch' as a branch name."
1787 focus
$w.desc.name_t
1792 switch
-- $create_branch_revtype {
1793 head {set rev $create_branch_head}
1794 tracking
{set rev $create_branch_trackinghead}
1795 expression
{set rev [string trim
[$w.from.exp_t get
0.0 end
]]}
1797 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1801 -title [wm title
$w] \
1803 -message "Invalid starting revision: $rev"
1806 set cmd
[list git update-ref
]
1808 lappend cmd
"branch: Created from $rev"
1809 lappend cmd
"refs/heads/$newbranch"
1811 lappend cmd
$null_sha1
1812 if {[catch
{eval exec $cmd} err
]} {
1816 -title [wm title
$w] \
1818 -message "Failed to create '$newbranch'.\n\n$err"
1822 lappend all_heads
$newbranch
1823 set all_heads
[lsort
$all_heads]
1824 populate_branch_menu
1826 if {$create_branch_checkout} {
1827 switch_branch
$newbranch
1831 proc radio_selector
{varname value args
} {
1832 upvar
#0 $varname var
1836 trace add variable create_branch_head
write \
1837 [list radio_selector create_branch_revtype
head]
1838 trace add variable create_branch_trackinghead
write \
1839 [list radio_selector create_branch_revtype tracking
]
1841 trace add variable delete_branch_head
write \
1842 [list radio_selector delete_branch_checktype
head]
1843 trace add variable delete_branch_trackinghead
write \
1844 [list radio_selector delete_branch_checktype tracking
]
1846 proc do_create_branch
{} {
1847 global all_heads current_branch repo_config
1848 global create_branch_checkout create_branch_revtype
1849 global create_branch_head create_branch_trackinghead
1851 set w .branch_editor
1853 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1855 label
$w.header
-text {Create New Branch
} \
1857 pack
$w.header
-side top
-fill x
1860 button
$w.buttons.create
-text Create \
1863 -command [list do_create_branch_action
$w]
1864 pack
$w.buttons.create
-side right
1865 button
$w.buttons.cancel
-text {Cancel
} \
1867 -command [list destroy
$w]
1868 pack
$w.buttons.cancel
-side right
-padx 5
1869 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1871 labelframe
$w.desc \
1872 -text {Branch Description
} \
1874 label
$w.desc.name_l
-text {Name
:} -font font_ui
1875 text
$w.desc.name_t \
1881 $w.desc.name_t insert
0.0 $repo_config(gui.newbranchtemplate
)
1882 grid
$w.desc.name_l
$w.desc.name_t
-stick we
-padx {0 5}
1883 bind $w.desc.name_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1884 bind $w.desc.name_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1885 bind $w.desc.name_t
<Key-Return
> "do_create_branch_action $w;break"
1886 bind $w.desc.name_t
<Key
> {
1887 if {{%K
} ne
{BackSpace
}
1890 && {%K
} ne
{Return
}} {
1892 if {[string first
%A
{~^
:?
*[}] >= 0} break
1895 grid columnconfigure
$w.desc
1 -weight 1
1896 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
1898 labelframe
$w.from \
1899 -text {Starting Revision
} \
1901 radiobutton
$w.from.head_r \
1902 -text {Local Branch
:} \
1904 -variable create_branch_revtype \
1906 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
1907 grid
$w.from.head_r
$w.from.head_m
-sticky w
1908 set all_trackings
[all_tracking_branches
]
1909 if {$all_trackings ne
{}} {
1910 set create_branch_trackinghead
[lindex
$all_trackings 0]
1911 radiobutton
$w.from.tracking_r \
1912 -text {Tracking Branch
:} \
1914 -variable create_branch_revtype \
1916 eval tk_optionMenu
$w.from.tracking_m \
1917 create_branch_trackinghead \
1919 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
1921 radiobutton
$w.from.exp_r \
1922 -text {Revision Expression
:} \
1924 -variable create_branch_revtype \
1926 text
$w.from.exp_t \
1932 grid
$w.from.exp_r
$w.from.exp_t
-stick we
-padx {0 5}
1933 bind $w.from.exp_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1934 bind $w.from.exp_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1935 bind $w.from.exp_t
<Key-Return
> "do_create_branch_action $w;break"
1936 bind $w.from.exp_t
<Key-space
> break
1937 bind $w.from.exp_t
<Key
> {set create_branch_revtype expression
}
1938 grid columnconfigure
$w.from
1 -weight 1
1939 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1941 labelframe
$w.postActions \
1942 -text {Post Creation Actions
} \
1944 checkbutton
$w.postActions.checkout \
1945 -text {Checkout after creation
} \
1946 -variable create_branch_checkout \
1948 pack
$w.postActions.checkout
-anchor nw
1949 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1951 set create_branch_checkout
1
1952 set create_branch_head
$current_branch
1953 set create_branch_revtype
head
1955 bind $w <Visibility
> "grab $w; focus $w.desc.name_t"
1956 bind $w <Key-Escape
> "destroy $w"
1957 bind $w <Key-Return
> "do_create_branch_action $w;break"
1958 wm title
$w "[appname] ([reponame]): Create Branch"
1962 proc do_delete_branch_action
{w
} {
1964 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
1967 switch
-- $delete_branch_checktype {
1968 head {set check_rev
$delete_branch_head}
1969 tracking
{set check_rev
$delete_branch_trackinghead}
1970 always
{set check_rev
{:none
}}
1972 if {$check_rev eq
{:none
}} {
1974 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
1978 -title [wm title
$w] \
1980 -message "Invalid check revision: $check_rev"
1984 set to_delete
[list
]
1985 set not_merged
[list
]
1986 foreach i
[$w.list.l curselection
] {
1987 set b
[$w.list.l get
$i]
1988 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
1989 if {$check_cmt ne
{}} {
1990 if {$b eq
$check_rev} continue
1991 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
1993 lappend not_merged
$b
1997 lappend to_delete
[list
$b $o]
1999 if {$not_merged ne
{}} {
2000 set msg
"The following branches are not completely merged into $check_rev:
2002 - [join $not_merged "\n - "]"
2006 -title [wm title
$w] \
2010 if {$to_delete eq
{}} return
2011 if {$delete_branch_checktype eq
{always
}} {
2012 set msg
{Recovering deleted branches is difficult.
2014 Delete the selected branches?
}
2015 if {[tk_messageBox \
2018 -title [wm title
$w] \
2020 -message $msg] ne
yes} {
2026 foreach i
$to_delete {
2029 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2030 append failed
" - $b: $err\n"
2032 set x
[lsearch
-sorted $all_heads $b]
2034 set all_heads
[lreplace
$all_heads $x $x]
2039 if {$failed ne
{}} {
2043 -title [wm title
$w] \
2045 -message "Failed to delete branches:\n$failed"
2048 set all_heads
[lsort
$all_heads]
2049 populate_branch_menu
2053 proc do_delete_branch
{} {
2054 global all_heads tracking_branches current_branch
2055 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2057 set w .branch_editor
2059 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2061 label
$w.header
-text {Delete Local Branch
} \
2063 pack
$w.header
-side top
-fill x
2066 button
$w.buttons.create
-text Delete \
2068 -command [list do_delete_branch_action
$w]
2069 pack
$w.buttons.create
-side right
2070 button
$w.buttons.cancel
-text {Cancel
} \
2072 -command [list destroy
$w]
2073 pack
$w.buttons.cancel
-side right
-padx 5
2074 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2076 labelframe
$w.list \
2077 -text {Local Branches
} \
2082 -selectmode extended \
2084 foreach h
$all_heads {
2085 if {$h ne
$current_branch} {
2086 $w.list.l insert end
$h
2089 pack
$w.list.l
-fill both
-pady 5 -padx 5
2090 pack
$w.list
-fill both
-pady 5 -padx 5
2092 labelframe
$w.validate \
2093 -text {Delete Only If
} \
2095 radiobutton
$w.validate.head_r \
2096 -text {Merged Into Local Branch
:} \
2098 -variable delete_branch_checktype \
2100 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2101 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2102 set all_trackings
[all_tracking_branches
]
2103 if {$all_trackings ne
{}} {
2104 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2105 radiobutton
$w.validate.tracking_r \
2106 -text {Merged Into Tracking Branch
:} \
2108 -variable delete_branch_checktype \
2110 eval tk_optionMenu
$w.validate.tracking_m \
2111 delete_branch_trackinghead \
2113 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2115 radiobutton
$w.validate.always_r \
2116 -text {Always
(Do not perform merge checks
)} \
2118 -variable delete_branch_checktype \
2120 grid
$w.validate.always_r
-columnspan 2 -sticky w
2121 grid columnconfigure
$w.validate
1 -weight 1
2122 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2124 set delete_branch_head
$current_branch
2125 set delete_branch_checktype
head
2127 bind $w <Visibility
> "grab $w; focus $w"
2128 bind $w <Key-Escape
> "destroy $w"
2129 wm title
$w "[appname] ([reponame]): Delete Branch"
2133 proc switch_branch
{b
} {
2134 global HEAD commit_type file_states current_branch
2135 global selected_commit_type ui_comm
2137 if {![lock_index switch
]} return
2139 # -- Backup the selected branch (repository_state resets it)
2141 set new_branch
$current_branch
2143 # -- Our in memory state should match the repository.
2145 repository_state curType curHEAD curMERGE_HEAD
2146 if {[string match amend
* $commit_type]
2147 && $curType eq
{normal
}
2148 && $curHEAD eq
$HEAD} {
2149 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2150 info_popup
{Last scanned state does not match repository state.
2152 Another Git program has modified this repository
2153 since the last scan. A rescan must be performed
2154 before the current branch can be changed.
2156 The rescan will be automatically started now.
2159 rescan
{set ui_status_value
{Ready.
}}
2163 # -- Toss the message buffer if we are in amend mode.
2165 if {[string match amend
* $curType]} {
2166 $ui_comm delete
0.0 end
2168 $ui_comm edit modified false
2171 set selected_commit_type new
2172 set current_branch
$new_branch
2175 error
"NOT FINISHED"
2178 ######################################################################
2180 ## remote management
2182 proc load_all_remotes
{} {
2184 global all_remotes tracking_branches
2186 set all_remotes
[list
]
2187 array
unset tracking_branches
2189 set rm_dir
[gitdir remotes
]
2190 if {[file isdirectory
$rm_dir]} {
2191 set all_remotes
[glob \
2195 -directory $rm_dir *]
2197 foreach name
$all_remotes {
2199 set fd
[open
[file join $rm_dir $name] r
]
2200 while {[gets
$fd line
] >= 0} {
2201 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2202 $line line src dst
]} continue
2203 if {![regexp ^refs
/ $dst]} {
2204 set dst
"refs/heads/$dst"
2206 set tracking_branches
($dst) [list
$name $src]
2213 foreach line
[array names repo_config remote.
*.url
] {
2214 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2215 lappend all_remotes
$name
2217 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2221 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2222 if {![regexp ^refs
/ $dst]} {
2223 set dst
"refs/heads/$dst"
2225 set tracking_branches
($dst) [list
$name $src]
2229 set all_remotes
[lsort
-unique $all_remotes]
2232 proc populate_fetch_menu
{m
} {
2233 global all_remotes repo_config
2235 foreach r
$all_remotes {
2237 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2238 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2243 set fd
[open
[gitdir remotes
$r] r
]
2244 while {[gets
$fd n
] >= 0} {
2245 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2256 -label "Fetch from $r..." \
2257 -command [list fetch_from
$r] \
2263 proc populate_push_menu
{m
} {
2264 global all_remotes repo_config
2266 foreach r
$all_remotes {
2268 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2269 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2274 set fd
[open
[gitdir remotes
$r] r
]
2275 while {[gets
$fd n
] >= 0} {
2276 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2287 -label "Push to $r..." \
2288 -command [list push_to
$r] \
2294 proc populate_pull_menu
{m
} {
2295 global repo_config all_remotes disable_on_lock
2297 foreach remote
$all_remotes {
2299 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2300 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2301 foreach line
$repo_config(remote.
$remote.fetch
) {
2302 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2309 set fd
[open
[gitdir remotes
$remote] r
]
2310 while {[gets
$fd line
] >= 0} {
2311 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2319 foreach rb
$rb_list {
2320 regsub ^refs
/heads
/ $rb {} rb_short
2322 -label "Branch $rb_short from $remote..." \
2323 -command [list pull_remote
$remote $rb] \
2325 lappend disable_on_lock \
2326 [list
$m entryconf
[$m index last
] -state]
2331 ######################################################################
2336 #define mask_width 14
2337 #define mask_height 15
2338 static unsigned char mask_bits
[] = {
2339 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2340 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2341 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2344 image create bitmap file_plain
-background white
-foreground black
-data {
2345 #define plain_width 14
2346 #define plain_height 15
2347 static unsigned char plain_bits
[] = {
2348 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2349 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2350 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2351 } -maskdata $filemask
2353 image create bitmap file_mod
-background white
-foreground blue
-data {
2354 #define mod_width 14
2355 #define mod_height 15
2356 static unsigned char mod_bits
[] = {
2357 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2358 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2359 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2360 } -maskdata $filemask
2362 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2363 #define file_fulltick_width 14
2364 #define file_fulltick_height 15
2365 static unsigned char file_fulltick_bits
[] = {
2366 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2367 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2368 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2369 } -maskdata $filemask
2371 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2372 #define parttick_width 14
2373 #define parttick_height 15
2374 static unsigned char parttick_bits
[] = {
2375 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2376 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2377 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2378 } -maskdata $filemask
2380 image create bitmap file_question
-background white
-foreground black
-data {
2381 #define file_question_width 14
2382 #define file_question_height 15
2383 static unsigned char file_question_bits
[] = {
2384 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2385 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2386 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2387 } -maskdata $filemask
2389 image create bitmap file_removed
-background white
-foreground red
-data {
2390 #define file_removed_width 14
2391 #define file_removed_height 15
2392 static unsigned char file_removed_bits
[] = {
2393 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2394 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2395 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2396 } -maskdata $filemask
2398 image create bitmap file_merge
-background white
-foreground blue
-data {
2399 #define file_merge_width 14
2400 #define file_merge_height 15
2401 static unsigned char file_merge_bits
[] = {
2402 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2403 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2404 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2405 } -maskdata $filemask
2407 set ui_index .vpane.files.index.list
2408 set ui_workdir .vpane.files.workdir.list
2410 set all_icons
(_
$ui_index) file_plain
2411 set all_icons
(A
$ui_index) file_fulltick
2412 set all_icons
(M
$ui_index) file_fulltick
2413 set all_icons
(D
$ui_index) file_removed
2414 set all_icons
(U
$ui_index) file_merge
2416 set all_icons
(_
$ui_workdir) file_plain
2417 set all_icons
(M
$ui_workdir) file_mod
2418 set all_icons
(D
$ui_workdir) file_question
2419 set all_icons
(U
$ui_workdir) file_merge
2420 set all_icons
(O
$ui_workdir) file_plain
2422 set max_status_desc
0
2426 {_M
"Modified, not staged"}
2427 {M_
"Staged for commit"}
2428 {MM
"Portions staged for commit"}
2429 {MD
"Staged for commit, missing"}
2431 {_O
"Untracked, not staged"}
2432 {A_
"Staged for commit"}
2433 {AM
"Portions staged for commit"}
2434 {AD
"Staged for commit, missing"}
2437 {D_
"Staged for removal"}
2438 {DO
"Staged for removal, still present"}
2440 {U_
"Requires merge resolution"}
2441 {UU
"Requires merge resolution"}
2442 {UM
"Requires merge resolution"}
2443 {UD
"Requires merge resolution"}
2445 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2446 set max_status_desc
[string length
[lindex
$i 1]]
2448 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2452 ######################################################################
2457 global tcl_platform tk_library
2458 if {[tk windowingsystem
] eq
{aqua
}} {
2464 proc is_Windows
{} {
2466 if {$tcl_platform(platform
) eq
{windows
}} {
2472 proc bind_button3
{w cmd
} {
2473 bind $w <Any-Button-3
> $cmd
2475 bind $w <Control-Button-1
> $cmd
2479 proc incr_font_size
{font
{amt
1}} {
2480 set sz
[font configure
$font -size]
2482 font configure
$font -size $sz
2483 font configure
${font}bold
-size $sz
2486 proc hook_failed_popup
{hook msg
} {
2491 label
$w.m.l1
-text "$hook hook failed:" \
2496 -background white
-borderwidth 1 \
2498 -width 80 -height 10 \
2500 -yscrollcommand [list
$w.m.sby
set]
2502 -text {You must correct the above errors before committing.
} \
2506 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2507 pack
$w.m.l1
-side top
-fill x
2508 pack
$w.m.l2
-side bottom
-fill x
2509 pack
$w.m.sby
-side right
-fill y
2510 pack
$w.m.t
-side left
-fill both
-expand 1
2511 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2513 $w.m.t insert
1.0 $msg
2514 $w.m.t conf
-state disabled
2516 button
$w.ok
-text OK \
2519 -command "destroy $w"
2520 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2522 bind $w <Visibility
> "grab $w; focus $w"
2523 bind $w <Key-Return
> "destroy $w"
2524 wm title
$w "[appname] ([reponame]): error"
2528 set next_console_id
0
2530 proc new_console
{short_title long_title
} {
2531 global next_console_id console_data
2532 set w .console
[incr next_console_id
]
2533 set console_data
($w) [list
$short_title $long_title]
2534 return [console_init
$w]
2537 proc console_init
{w
} {
2538 global console_cr console_data M1B
2540 set console_cr
($w) 1.0
2543 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2548 -background white
-borderwidth 1 \
2550 -width 80 -height 10 \
2553 -yscrollcommand [list
$w.m.sby
set]
2554 label
$w.m.s
-text {Working... please
wait...
} \
2558 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2559 pack
$w.m.l1
-side top
-fill x
2560 pack
$w.m.s
-side bottom
-fill x
2561 pack
$w.m.sby
-side right
-fill y
2562 pack
$w.m.t
-side left
-fill both
-expand 1
2563 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2565 menu
$w.ctxm
-tearoff 0
2566 $w.ctxm add
command -label "Copy" \
2568 -command "tk_textCopy $w.m.t"
2569 $w.ctxm add
command -label "Select All" \
2571 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
2572 $w.ctxm add
command -label "Copy All" \
2575 $w.m.t tag add sel 0.0 end
2577 $w.m.t tag remove sel 0.0 end
2580 button
$w.ok
-text {Close
} \
2583 -command "destroy $w"
2584 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2586 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2587 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2588 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2589 bind $w <Visibility
> "focus $w"
2590 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2594 proc console_exec
{w cmd
{after
{}}} {
2595 # -- Windows tosses the enviroment when we exec our child.
2596 # But most users need that so we have to relogin. :-(
2599 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2602 # -- Tcl won't let us redirect both stdout and stderr to
2603 # the same pipe. So pass it through cat...
2605 set cmd
[concat |
$cmd |
& cat]
2607 set fd_f
[open
$cmd r
]
2608 fconfigure
$fd_f -blocking 0 -translation binary
2609 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2612 proc console_read
{w fd after
} {
2613 global console_cr console_data
2617 if {![winfo exists
$w]} {console_init
$w}
2618 $w.m.t conf
-state normal
2620 set n
[string length
$buf]
2622 set cr
[string first
"\r" $buf $c]
2623 set lf
[string first
"\n" $buf $c]
2624 if {$cr < 0} {set cr
[expr {$n + 1}]}
2625 if {$lf < 0} {set lf
[expr {$n + 1}]}
2628 $w.m.t insert end
[string range
$buf $c $lf]
2629 set console_cr
($w) [$w.m.t index
{end
-1c}]
2633 $w.m.t delete
$console_cr($w) end
2634 $w.m.t insert end
"\n"
2635 $w.m.t insert end
[string range
$buf $c $cr]
2640 $w.m.t conf
-state disabled
2644 fconfigure
$fd -blocking 1
2646 if {[catch
{close
$fd}]} {
2647 if {![winfo exists
$w]} {console_init
$w}
2648 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2649 $w.ok conf
-state normal
2651 } elseif
{[winfo exists
$w]} {
2652 $w.m.s conf
-background green
-text {Success
}
2653 $w.ok conf
-state normal
2656 array
unset console_cr
$w
2657 array
unset console_data
$w
2659 uplevel
#0 $after $ok
2663 fconfigure
$fd -blocking 0
2666 ######################################################################
2670 set starting_gitk_msg
{Starting gitk... please
wait...
}
2672 proc do_gitk
{revs
} {
2673 global ui_status_value starting_gitk_msg
2681 set cmd
"sh -c \"exec $cmd\""
2685 if {[catch
{eval exec $cmd} err
]} {
2686 error_popup
"Failed to start gitk:\n\n$err"
2688 set ui_status_value
$starting_gitk_msg
2690 if {$ui_status_value eq
$starting_gitk_msg} {
2691 set ui_status_value
{Ready.
}
2698 set w
[new_console
{gc
} {Compressing the object database
}]
2699 console_exec
$w {git gc
}
2702 proc do_fsck_objects
{} {
2703 set w
[new_console
{fsck-objects
} \
2704 {Verifying the object database with fsck-objects
}]
2705 set cmd
[list git fsck-objects
]
2708 lappend cmd
--strict
2709 console_exec
$w $cmd
2715 global ui_comm is_quitting repo_config commit_type
2717 if {$is_quitting} return
2720 # -- Stash our current commit buffer.
2722 set save
[gitdir GITGUI_MSG
]
2723 set msg
[string trim
[$ui_comm get
0.0 end
]]
2724 if {![string match amend
* $commit_type]
2725 && [$ui_comm edit modified
]
2728 set fd
[open
$save w
]
2729 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2733 catch
{file delete
$save}
2736 # -- Stash our current window geometry into this repository.
2738 set cfg_geometry
[list
]
2739 lappend cfg_geometry
[wm geometry .
]
2740 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2741 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2742 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2745 if {$cfg_geometry ne
$rc_geometry} {
2746 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2753 rescan
{set ui_status_value
{Ready.
}}
2756 proc unstage_helper
{txt paths
} {
2757 global file_states current_diff_path
2759 if {![lock_index begin-update
]} return
2763 foreach path
$paths {
2764 switch
-glob -- [lindex
$file_states($path) 0] {
2768 lappend pathList
$path
2769 if {$path eq
$current_diff_path} {
2770 set after
{reshow_diff
;}
2775 if {$pathList eq
{}} {
2781 [concat
$after {set ui_status_value
{Ready.
}}]
2785 proc do_unstage_selection
{} {
2786 global current_diff_path selected_paths
2788 if {[array size selected_paths
] > 0} {
2790 {Unstaging selected files from commit
} \
2791 [array names selected_paths
]
2792 } elseif
{$current_diff_path ne
{}} {
2794 "Unstaging [short_path $current_diff_path] from commit" \
2795 [list
$current_diff_path]
2799 proc add_helper
{txt paths
} {
2800 global file_states current_diff_path
2802 if {![lock_index begin-update
]} return
2806 foreach path
$paths {
2807 switch
-glob -- [lindex
$file_states($path) 0] {
2812 lappend pathList
$path
2813 if {$path eq
$current_diff_path} {
2814 set after
{reshow_diff
;}
2819 if {$pathList eq
{}} {
2825 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2829 proc do_add_selection
{} {
2830 global current_diff_path selected_paths
2832 if {[array size selected_paths
] > 0} {
2834 {Adding selected files
} \
2835 [array names selected_paths
]
2836 } elseif
{$current_diff_path ne
{}} {
2838 "Adding [short_path $current_diff_path]" \
2839 [list
$current_diff_path]
2843 proc do_add_all
{} {
2847 foreach path
[array names file_states
] {
2848 switch
-glob -- [lindex
$file_states($path) 0] {
2851 ?D
{lappend paths
$path}
2854 add_helper
{Adding all changed files
} $paths
2857 proc revert_helper
{txt paths
} {
2858 global file_states current_diff_path
2860 if {![lock_index begin-update
]} return
2864 foreach path
$paths {
2865 switch
-glob -- [lindex
$file_states($path) 0] {
2869 lappend pathList
$path
2870 if {$path eq
$current_diff_path} {
2871 set after
{reshow_diff
;}
2877 set n
[llength
$pathList]
2881 } elseif
{$n == 1} {
2882 set s
"[short_path [lindex $pathList]]"
2884 set s
"these $n files"
2887 set reply
[tk_dialog \
2889 "[appname] ([reponame])" \
2890 "Revert changes in $s?
2892 Any unadded changes will be permanently lost by the revert." \
2902 [concat
$after {set ui_status_value
{Ready.
}}]
2908 proc do_revert_selection
{} {
2909 global current_diff_path selected_paths
2911 if {[array size selected_paths
] > 0} {
2913 {Reverting selected files
} \
2914 [array names selected_paths
]
2915 } elseif
{$current_diff_path ne
{}} {
2917 "Reverting [short_path $current_diff_path]" \
2918 [list
$current_diff_path]
2922 proc do_signoff
{} {
2925 set me
[committer_ident
]
2926 if {$me eq
{}} return
2928 set sob
"Signed-off-by: $me"
2929 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
2930 if {$last ne
$sob} {
2931 $ui_comm edit separator
2933 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
2934 $ui_comm insert end
"\n"
2936 $ui_comm insert end
"\n$sob"
2937 $ui_comm edit separator
2942 proc do_select_commit_type
{} {
2943 global commit_type selected_commit_type
2945 if {$selected_commit_type eq
{new
}
2946 && [string match amend
* $commit_type]} {
2948 } elseif
{$selected_commit_type eq
{amend
}
2949 && ![string match amend
* $commit_type]} {
2952 # The amend request was rejected...
2954 if {![string match amend
* $commit_type]} {
2955 set selected_commit_type new
2965 global appvers copyright
2966 global tcl_patchLevel tk_patchLevel
2970 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2972 label
$w.header
-text "About [appname]" \
2974 pack
$w.header
-side top
-fill x
2977 button
$w.buttons.close
-text {Close
} \
2979 -command [list destroy
$w]
2980 pack
$w.buttons.close
-side right
2981 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2984 -text "[appname] - a commit creation tool for Git.
2992 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
2995 append v
"[appname] version $appvers\n"
2996 append v
"[exec git version]\n"
2998 if {$tcl_patchLevel eq
$tk_patchLevel} {
2999 append v
"Tcl/Tk version $tcl_patchLevel"
3001 append v
"Tcl version $tcl_patchLevel"
3002 append v
", Tk version $tk_patchLevel"
3013 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
3015 menu
$w.ctxm
-tearoff 0
3016 $w.ctxm add
command \
3021 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
3024 bind $w <Visibility
> "grab $w; focus $w"
3025 bind $w <Key-Escape
> "destroy $w"
3026 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3027 wm title
$w "About [appname]"
3031 proc do_options
{} {
3032 global repo_config global_config font_descs
3033 global repo_config_new global_config_new
3035 array
unset repo_config_new
3036 array
unset global_config_new
3037 foreach name
[array names repo_config
] {
3038 set repo_config_new
($name) $repo_config($name)
3041 foreach name
[array names repo_config
] {
3043 gui.diffcontext
{continue}
3045 set repo_config_new
($name) $repo_config($name)
3047 foreach name
[array names global_config
] {
3048 set global_config_new
($name) $global_config($name)
3051 set w .options_editor
3053 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3055 label
$w.header
-text "[appname] Options" \
3057 pack
$w.header
-side top
-fill x
3060 button
$w.buttons.restore
-text {Restore Defaults
} \
3062 -command do_restore_defaults
3063 pack
$w.buttons.restore
-side left
3064 button
$w.buttons.save
-text Save \
3067 catch {eval \[bind \[focus -displayof $w\] <FocusOut>\]}
3070 pack
$w.buttons.save
-side right
3071 button
$w.buttons.cancel
-text {Cancel
} \
3073 -command [list destroy
$w]
3074 pack
$w.buttons.cancel
-side right
-padx 5
3075 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3077 labelframe
$w.repo
-text "[reponame] Repository" \
3079 -relief raised
-borderwidth 2
3080 labelframe
$w.global
-text {Global
(All Repositories
)} \
3082 -relief raised
-borderwidth 2
3083 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3084 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3087 {b pullsummary
{Show Pull Summary
}}
3088 {b trustmtime
{Trust File Modification Timestamps
}}
3089 {i diffcontext
{Number of Diff Context Lines
}}
3090 {t newbranchtemplate
{New Branch Name Template
}}
3092 set type [lindex
$option 0]
3093 set name
[lindex
$option 1]
3094 set text
[lindex
$option 2]
3095 foreach f
{repo global
} {
3098 checkbutton
$w.
$f.
$name -text $text \
3099 -variable ${f}_config_new
(gui.
$name) \
3103 pack
$w.
$f.
$name -side top
-anchor w
3107 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3108 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
3109 spinbox
$w.
$f.
$name.v \
3110 -textvariable ${f}_config_new
(gui.
$name) \
3111 -from 1 -to 99 -increment 1 \
3114 bind $w.
$f.
$name.v
<FocusIn
> {%W selection range
0 end
}
3115 pack
$w.
$f.
$name.v
-side right
-anchor e
-padx 5
3116 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3120 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3121 text
$w.
$f.
$name.v \
3127 $w.
$f.
$name.v insert
0.0 [set ${f}_config_new
(gui.
$name)]
3128 bind $w.
$f.
$name.v
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
3129 bind $w.
$f.
$name.v
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
3130 bind $w.
$f.
$name.v
<Key-Return
> break
3131 bind $w.
$f.
$name.v
<FocusIn
> "$w.$f.$name.v tag add sel 0.0 end"
3132 bind $w.
$f.
$name.v
<FocusOut
> "
3133 set ${f}_config_new(gui.$name) \
3134 \[string trim \[$w.$f.$name.v get 0.0 end\]\]
3136 pack
$w.
$f.
$name.l
-side left
-anchor w
3137 pack
$w.
$f.
$name.v
-side left
-anchor w \
3140 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3146 set all_fonts
[lsort
[font families
]]
3147 foreach option
$font_descs {
3148 set name
[lindex
$option 0]
3149 set font
[lindex
$option 1]
3150 set text
[lindex
$option 2]
3152 set global_config_new
(gui.
$font^^family
) \
3153 [font configure
$font -family]
3154 set global_config_new
(gui.
$font^^size
) \
3155 [font configure
$font -size]
3157 frame
$w.global.
$name
3158 label
$w.global.
$name.l
-text "$text:" -font font_ui
3159 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3160 eval tk_optionMenu
$w.global.
$name.family \
3161 global_config_new
(gui.
$font^^family
) \
3163 spinbox
$w.global.
$name.size \
3164 -textvariable global_config_new
(gui.
$font^^size
) \
3165 -from 2 -to 80 -increment 1 \
3168 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3169 pack
$w.global.
$name.size
-side right
-anchor e
3170 pack
$w.global.
$name.family
-side right
-anchor e
3171 pack
$w.global.
$name -side top
-anchor w
-fill x
3174 bind $w <Visibility
> "grab $w; focus $w"
3175 bind $w <Key-Escape
> "destroy $w"
3176 wm title
$w "[appname] ([reponame]): Options"
3180 proc do_restore_defaults
{} {
3181 global font_descs default_config repo_config
3182 global repo_config_new global_config_new
3184 foreach name
[array names default_config
] {
3185 set repo_config_new
($name) $default_config($name)
3186 set global_config_new
($name) $default_config($name)
3189 foreach option
$font_descs {
3190 set name
[lindex
$option 0]
3191 set repo_config
(gui.
$name) $default_config(gui.
$name)
3195 foreach option
$font_descs {
3196 set name
[lindex
$option 0]
3197 set font
[lindex
$option 1]
3198 set global_config_new
(gui.
$font^^family
) \
3199 [font configure
$font -family]
3200 set global_config_new
(gui.
$font^^size
) \
3201 [font configure
$font -size]
3205 proc do_save_config
{w
} {
3206 if {[catch
{save_config
} err
]} {
3207 error_popup
"Failed to completely save options:\n\n$err"
3213 proc do_windows_shortcut
{} {
3217 set desktop
[exec cygpath \
3225 set fn
[tk_getSaveFile \
3227 -title "[appname] ([reponame]): Create Desktop Icon" \
3228 -initialdir $desktop \
3229 -initialfile "Git [reponame].bat"]
3233 set sh
[exec cygpath \
3237 set me
[exec cygpath \
3241 set gd
[exec cygpath \
3245 set gw
[exec cygpath \
3248 [file dirname [gitdir
]]]
3249 regsub
-all ' $me "'\\''" me
3250 regsub -all ' $gd "'\\''" gd
3251 puts $fd "@ECHO Entering $gw"
3252 puts $fd "@ECHO Starting git-gui... please wait..."
3253 puts -nonewline $fd "@\"$sh\" --login -c \""
3254 puts -nonewline $fd "GIT_DIR='$gd'"
3255 puts -nonewline $fd " '$me'"
3259 error_popup "Cannot write script:\n\n$err"
3264 proc do_macosx_app {} {
3267 set fn [tk_getSaveFile \
3269 -title "[appname] ([reponame]): Create Desktop Icon" \
3270 -initialdir [file join $env(HOME) Desktop] \
3271 -initialfile "Git [reponame].app"]
3274 set Contents [file join $fn Contents]
3275 set MacOS [file join $Contents MacOS]
3276 set exe [file join $MacOS git-gui]
3280 set fd [open [file join $Contents Info.plist] w]
3281 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3282 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3283 <plist version="1.0">
3285 <key>CFBundleDevelopmentRegion</key>
3286 <string>English</string>
3287 <key>CFBundleExecutable</key>
3288 <string>git-gui</string>
3289 <key>CFBundleIdentifier</key>
3290 <string>org.spearce.git-gui</string>
3291 <key>CFBundleInfoDictionaryVersion</key>
3292 <string>6.0</string>
3293 <key>CFBundlePackageType</key>
3294 <string>APPL</string>
3295 <key>CFBundleSignature</key>
3296 <string>????</string>
3297 <key>CFBundleVersion</key>
3298 <string>1.0</string>
3299 <key>NSPrincipalClass</key>
3300 <string>NSApplication</string>
3305 set fd [open $exe w]
3306 set gd [file normalize [gitdir]]
3307 set ep [file normalize [exec git --exec-path]]
3308 regsub -all ' $gd "'\\''" gd
3309 regsub
-all ' $ep "'\\''" ep
3310 puts $fd "#!/bin/sh"
3311 foreach name
[array names env
] {
3312 if {[string match GIT_
* $name]} {
3313 regsub
-all ' $env($name) "'\\''" v
3314 puts $fd "export $name='$v'"
3317 puts $fd "export PATH
='$ep':\
$PATH"
3318 puts $fd "export GIT_DIR
='$gd'"
3319 puts $fd "exec [file normalize
$argv0]"
3322 file attributes $exe -permissions u+x,g+x,o+x
3324 error_popup "Cannot
write icon
:\n\n$err"
3329 proc toggle_or_diff {w x y} {
3330 global file_states file_lists current_diff_path ui_index ui_workdir
3331 global last_clicked selected_paths
3333 set pos [split [$w index @$x,$y] .]
3334 set lno [lindex $pos 0]
3335 set col [lindex $pos 1]
3336 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3342 set last_clicked [list $w $lno]
3343 array unset selected_paths
3344 $ui_index tag remove in_sel 0.0 end
3345 $ui_workdir tag remove in_sel 0.0 end
3348 if {$current_diff_path eq $path} {
3349 set after {reshow_diff;}
3353 if {$w eq $ui_index} {
3355 "Unstaging
[short_path
$path] from commit
" \
3357 [concat $after {set ui_status_value {Ready.}}]
3358 } elseif {$w eq $ui_workdir} {
3360 "Adding
[short_path
$path]" \
3362 [concat $after {set ui_status_value {Ready.}}]
3365 show_diff $path $w $lno
3369 proc add_one_to_selection {w x y} {
3370 global file_lists last_clicked selected_paths
3372 set lno [lindex [split [$w index @$x,$y] .] 0]
3373 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3379 if {$last_clicked ne {}
3380 && [lindex $last_clicked 0] ne $w} {
3381 array unset selected_paths
3382 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3385 set last_clicked [list $w $lno]
3386 if {[catch {set in_sel $selected_paths($path)}]} {
3390 unset selected_paths($path)
3391 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3393 set selected_paths($path) 1
3394 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3398 proc add_range_to_selection {w x y} {
3399 global file_lists last_clicked selected_paths
3401 if {[lindex $last_clicked 0] ne $w} {
3402 toggle_or_diff $w $x $y
3406 set lno [lindex [split [$w index @$x,$y] .] 0]
3407 set lc [lindex $last_clicked 1]
3416 foreach path [lrange $file_lists($w) \
3417 [expr {$begin - 1}] \
3418 [expr {$end - 1}]] {
3419 set selected_paths($path) 1
3421 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3424 ######################################################################
3428 set cursor_ptr arrow
3429 font create font_diff -family Courier -size 10
3433 eval font configure font_ui [font actual [.dummy cget -font]]
3437 font create font_uibold
3438 font create font_diffbold
3443 } elseif {[is_MacOSX]} {
3451 proc apply_config {} {
3452 global repo_config font_descs
3454 foreach option $font_descs {
3455 set name [lindex $option 0]
3456 set font [lindex $option 1]
3458 foreach {cn cv} $repo_config(gui.$name) {
3459 font configure $font $cn $cv
3462 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3464 foreach {cn cv} [font configure $font] {
3465 font configure ${font}bold $cn $cv
3467 font configure ${font}bold -weight bold
3471 set default_config(gui.trustmtime) false
3472 set default_config(gui.pullsummary) true
3473 set default_config(gui.diffcontext) 5
3474 set default_config(gui.newbranchtemplate) {}
3475 set default_config(gui.fontui) [font configure font_ui]
3476 set default_config(gui.fontdiff) [font configure font_diff]
3478 {fontui font_ui {Main Font}}
3479 {fontdiff font_diff {Diff/Console Font}}
3484 ######################################################################
3490 menu .mbar -tearoff 0
3491 .mbar add cascade -label Repository -menu .mbar.repository
3492 .mbar add cascade -label Edit -menu .mbar.edit
3493 if {!$single_commit} {
3494 .mbar add cascade -label Branch -menu .mbar.branch
3496 .mbar add cascade -label Commit -menu .mbar.commit
3497 if {!$single_commit} {
3498 .mbar add cascade -label Fetch -menu .mbar.fetch
3499 .mbar add cascade -label Pull -menu .mbar.pull
3500 .mbar add cascade -label Push -menu .mbar.push
3502 . configure -menu .mbar
3504 # -- Repository Menu
3506 menu .mbar.repository
3507 .mbar.repository add command \
3508 -label {Visualize Current Branch} \
3509 -command {do_gitk {}} \
3512 .mbar.repository add command \
3513 -label {Visualize All Branches} \
3514 -command {do_gitk {--all}} \
3517 .mbar.repository add separator
3519 if {!$single_commit} {
3520 .mbar.repository add command -label {Compress Database} \
3524 .mbar.repository add command -label {Verify Database} \
3525 -command do_fsck_objects \
3528 .mbar.repository add separator
3531 .mbar.repository add command \
3532 -label {Create Desktop Icon} \
3533 -command do_windows_shortcut \
3535 } elseif {[is_MacOSX]} {
3536 .mbar.repository add command \
3537 -label {Create Desktop Icon} \
3538 -command do_macosx_app \
3543 .mbar.repository add command -label Quit \
3545 -accelerator $M1T-Q \
3551 .mbar.edit add command -label Undo \
3552 -command {catch {[focus] edit undo}} \
3553 -accelerator $M1T-Z \
3555 .mbar.edit add command -label Redo \
3556 -command {catch {[focus] edit redo}} \
3557 -accelerator $M1T-Y \
3559 .mbar.edit add separator
3560 .mbar.edit add command -label Cut \
3561 -command {catch {tk_textCut [focus]}} \
3562 -accelerator $M1T-X \
3564 .mbar.edit add command -label Copy \
3565 -command {catch {tk_textCopy [focus]}} \
3566 -accelerator $M1T-C \
3568 .mbar.edit add command -label Paste \
3569 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3570 -accelerator $M1T-V \
3572 .mbar.edit add command -label Delete \
3573 -command {catch {[focus] delete sel.first sel.last}} \
3576 .mbar.edit add separator
3577 .mbar.edit add command -label {Select All} \
3578 -command {catch {[focus] tag add sel 0.0 end}} \
3579 -accelerator $M1T-A \
3584 if {!$single_commit} {
3587 .mbar.branch add command -label {Create...} \
3588 -command do_create_branch \
3589 -accelerator $M1T-N \
3591 lappend disable_on_lock [list .mbar.branch entryconf \
3592 [.mbar.branch index last] -state]
3594 .mbar.branch add command -label {Delete...} \
3595 -command do_delete_branch \
3597 lappend disable_on_lock [list .mbar.branch entryconf \
3598 [.mbar.branch index last] -state]
3605 .mbar.commit add radiobutton \
3606 -label {New Commit} \
3607 -command do_select_commit_type \
3608 -variable selected_commit_type \
3611 lappend disable_on_lock \
3612 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3614 .mbar.commit add radiobutton \
3615 -label {Amend Last Commit} \
3616 -command do_select_commit_type \
3617 -variable selected_commit_type \
3620 lappend disable_on_lock \
3621 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3623 .mbar.commit add separator
3625 .mbar.commit add command -label Rescan \
3626 -command do_rescan \
3629 lappend disable_on_lock \
3630 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3632 .mbar.commit add command -label {Add To Commit} \
3633 -command do_add_selection \
3635 lappend disable_on_lock \
3636 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3638 .mbar.commit add command -label {Add All To Commit} \
3639 -command do_add_all \
3640 -accelerator $M1T-I \
3642 lappend disable_on_lock \
3643 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3645 .mbar.commit add command -label {Unstage From Commit} \
3646 -command do_unstage_selection \
3648 lappend disable_on_lock \
3649 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3651 .mbar.commit add command -label {Revert Changes} \
3652 -command do_revert_selection \
3654 lappend disable_on_lock \
3655 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3657 .mbar.commit add separator
3659 .mbar.commit add command -label {Sign Off} \
3660 -command do_signoff \
3661 -accelerator $M1T-S \
3664 .mbar.commit add command -label Commit \
3665 -command do_commit \
3666 -accelerator $M1T-Return \
3668 lappend disable_on_lock \
3669 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3671 # -- Transport menus
3673 if {!$single_commit} {
3680 # -- Apple Menu (Mac OS X only)
3682 .mbar add cascade -label Apple -menu .mbar.apple
3685 .mbar.apple add command -label "About
[appname
]" \
3688 .mbar.apple add command -label "[appname
] Options...
" \
3689 -command do_options \
3694 .mbar.edit add separator
3695 .mbar.edit add command -label {Options...} \
3696 -command do_options \
3701 if {[file exists /usr/local/miga/lib/gui-miga]
3702 && [file exists .pvcsrc]} {
3704 global ui_status_value
3705 if {![lock_index update]} return
3706 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3707 set miga_fd [open "|
$cmd" r]
3708 fconfigure $miga_fd -blocking 0
3709 fileevent $miga_fd readable [list miga_done $miga_fd]
3710 set ui_status_value {Running miga...}
3712 proc miga_done {fd} {
3717 rescan [list set ui_status_value {Ready.}]
3720 .mbar add cascade -label Tools -menu .mbar.tools
3722 .mbar.tools add command -label "Migrate
" \
3725 lappend disable_on_lock \
3726 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3731 .mbar add cascade -label Help -menu .mbar.help
3734 .mbar.help add command -label "About
[appname
]" \
3746 -text {Current Branch:} \
3751 -textvariable current_branch \
3755 pack .branch.l1 -side left
3756 pack .branch.cb -side left -fill x
3757 pack .branch -side top -fill x
3759 # -- Main Window Layout
3761 panedwindow .vpane -orient vertical
3762 panedwindow .vpane.files -orient horizontal
3763 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3764 pack .vpane -anchor n -side top -fill both -expand 1
3766 # -- Index File List
3768 frame .vpane.files.index -height 100 -width 200
3769 label .vpane.files.index.title -text {Changes To Be Committed} \
3772 text $ui_index -background white -borderwidth 0 \
3773 -width 20 -height 10 \
3776 -cursor $cursor_ptr \
3777 -xscrollcommand {.vpane.files.index.sx set} \
3778 -yscrollcommand {.vpane.files.index.sy set} \
3780 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3781 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3782 pack .vpane.files.index.title -side top -fill x
3783 pack .vpane.files.index.sx -side bottom -fill x
3784 pack .vpane.files.index.sy -side right -fill y
3785 pack $ui_index -side left -fill both -expand 1
3786 .vpane.files add .vpane.files.index -sticky nsew
3788 # -- Working Directory File List
3790 frame .vpane.files.workdir -height 100 -width 200
3791 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3794 text $ui_workdir -background white -borderwidth 0 \
3795 -width 20 -height 10 \
3798 -cursor $cursor_ptr \
3799 -xscrollcommand {.vpane.files.workdir.sx set} \
3800 -yscrollcommand {.vpane.files.workdir.sy set} \
3802 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3803 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3804 pack .vpane.files.workdir.title -side top -fill x
3805 pack .vpane.files.workdir.sx -side bottom -fill x
3806 pack .vpane.files.workdir.sy -side right -fill y
3807 pack $ui_workdir -side left -fill both -expand 1
3808 .vpane.files add .vpane.files.workdir -sticky nsew
3810 foreach i [list $ui_index $ui_workdir] {
3811 $i tag conf in_diff -font font_uibold
3812 $i tag conf in_sel \
3813 -background [$i cget -foreground] \
3814 -foreground [$i cget -background]
3818 # -- Diff and Commit Area
3820 frame .vpane.lower -height 300 -width 400
3821 frame .vpane.lower.commarea
3822 frame .vpane.lower.diff -relief sunken -borderwidth 1
3823 pack .vpane.lower.commarea -side top -fill x
3824 pack .vpane.lower.diff -side bottom -fill both -expand 1
3825 .vpane add .vpane.lower -stick nsew
3827 # -- Commit Area Buttons
3829 frame .vpane.lower.commarea.buttons
3830 label .vpane.lower.commarea.buttons.l -text {} \
3834 pack .vpane.lower.commarea.buttons.l -side top -fill x
3835 pack .vpane.lower.commarea.buttons -side left -fill y
3837 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3838 -command do_rescan \
3840 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3841 lappend disable_on_lock \
3842 {.vpane.lower.commarea.buttons.rescan conf -state}
3844 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3845 -command do_add_all \
3847 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3848 lappend disable_on_lock \
3849 {.vpane.lower.commarea.buttons.incall conf -state}
3851 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3852 -command do_signoff \
3854 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3856 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3857 -command do_commit \
3859 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3860 lappend disable_on_lock \
3861 {.vpane.lower.commarea.buttons.commit conf -state}
3863 # -- Commit Message Buffer
3865 frame .vpane.lower.commarea.buffer
3866 frame .vpane.lower.commarea.buffer.header
3867 set ui_comm .vpane.lower.commarea.buffer.t
3868 set ui_coml .vpane.lower.commarea.buffer.header.l
3869 radiobutton .vpane.lower.commarea.buffer.header.new \
3870 -text {New Commit} \
3871 -command do_select_commit_type \
3872 -variable selected_commit_type \
3875 lappend disable_on_lock \
3876 [list .vpane.lower.commarea.buffer.header.new conf -state]
3877 radiobutton .vpane.lower.commarea.buffer.header.amend \
3878 -text {Amend Last Commit} \
3879 -command do_select_commit_type \
3880 -variable selected_commit_type \
3883 lappend disable_on_lock \
3884 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3889 proc trace_commit_type {varname args} {
3890 global ui_coml commit_type
3891 switch -glob -- $commit_type {
3892 initial {set txt {Initial Commit Message:}}
3893 amend {set txt {Amended Commit Message:}}
3894 amend-initial {set txt {Amended Initial Commit Message:}}
3895 amend-merge {set txt {Amended Merge Commit Message:}}
3896 merge {set txt {Merge Commit Message:}}
3897 * {set txt {Commit Message:}}
3899 $ui_coml conf -text $txt
3901 trace add variable commit_type write trace_commit_type
3902 pack $ui_coml -side left -fill x
3903 pack .vpane.lower.commarea.buffer.header.amend -side right
3904 pack .vpane.lower.commarea.buffer.header.new -side right
3906 text $ui_comm -background white -borderwidth 1 \
3909 -autoseparators true \
3911 -width 75 -height 9 -wrap none \
3913 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3914 scrollbar .vpane.lower.commarea.buffer.sby \
3915 -command [list $ui_comm yview]
3916 pack .vpane.lower.commarea.buffer.header -side top -fill x
3917 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3918 pack $ui_comm -side left -fill y
3919 pack .vpane.lower.commarea.buffer -side left -fill y
3921 # -- Commit Message Buffer Context Menu
3923 set ctxm .vpane.lower.commarea.buffer.ctxm
3924 menu $ctxm -tearoff 0
3928 -command {tk_textCut $ui_comm}
3932 -command {tk_textCopy $ui_comm}
3936 -command {tk_textPaste $ui_comm}
3940 -command {$ui_comm delete sel.first sel.last}
3943 -label {Select All} \
3945 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3950 $ui_comm tag add sel 0.0 end
3951 tk_textCopy $ui_comm
3952 $ui_comm tag remove sel 0.0 end
3959 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
3963 set current_diff_path {}
3964 set diff_actions [list]
3965 proc trace_current_diff_path {varname args} {
3966 global current_diff_path diff_actions file_states
3967 if {$current_diff_path eq {}} {
3973 set p $current_diff_path
3974 set s [mapdesc [lindex $file_states($p) 0] $p]
3976 set p [escape_path $p]
3980 .vpane.lower.diff.header.status configure -text $s
3981 .vpane.lower.diff.header.file configure -text $f
3982 .vpane.lower.diff.header.path configure -text $p
3983 foreach w $diff_actions {
3987 trace add variable current_diff_path write trace_current_diff_path
3989 frame .vpane.lower.diff.header -background orange
3990 label .vpane.lower.diff.header.status \
3991 -background orange \
3992 -width $max_status_desc \
3996 label .vpane.lower.diff.header.file \
3997 -background orange \
4001 label .vpane.lower.diff.header.path \
4002 -background orange \
4006 pack .vpane.lower.diff.header.status -side left
4007 pack .vpane.lower.diff.header.file -side left
4008 pack .vpane.lower.diff.header.path -fill x
4009 set ctxm .vpane.lower.diff.header.ctxm
4010 menu $ctxm -tearoff 0
4019 -- $current_diff_path
4021 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4022 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
4026 frame .vpane.lower.diff.body
4027 set ui_diff .vpane.lower.diff.body.t
4028 text $ui_diff -background white -borderwidth 0 \
4029 -width 80 -height 15 -wrap none \
4031 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4032 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4034 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4035 -command [list $ui_diff xview]
4036 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4037 -command [list $ui_diff yview]
4038 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4039 pack .vpane.lower.diff.body.sby -side right -fill y
4040 pack $ui_diff -side left -fill both -expand 1
4041 pack .vpane.lower.diff.header -side top -fill x
4042 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4044 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4045 $ui_diff tag conf d_+ -foreground {#00a000}
4046 $ui_diff tag conf d_- -foreground red
4048 $ui_diff tag conf d_++ -foreground {#00a000}
4049 $ui_diff tag conf d_-- -foreground red
4050 $ui_diff tag conf d_+s \
4051 -foreground {#00a000} \
4052 -background {#e2effa}
4053 $ui_diff tag conf d_-s \
4055 -background {#e2effa}
4056 $ui_diff tag conf d_s+ \
4057 -foreground {#00a000} \
4059 $ui_diff tag conf d_s- \
4063 $ui_diff tag conf d<<<<<<< \
4064 -foreground orange \
4066 $ui_diff tag conf d======= \
4067 -foreground orange \
4069 $ui_diff tag conf d>>>>>>> \
4070 -foreground orange \
4073 $ui_diff tag raise sel
4075 # -- Diff Body Context Menu
4077 set ctxm .vpane.lower.diff.body.ctxm
4078 menu $ctxm -tearoff 0
4082 -command reshow_diff
4086 -command {tk_textCopy $ui_diff}
4087 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4089 -label {Select All} \
4091 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4092 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4097 $ui_diff tag add sel 0.0 end
4098 tk_textCopy $ui_diff
4099 $ui_diff tag remove sel 0.0 end
4101 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4104 -label {Decrease Font Size} \
4106 -command {incr_font_size font_diff -1}
4107 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4109 -label {Increase Font Size} \
4111 -command {incr_font_size font_diff 1}
4112 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4115 -label {Show Less Context} \
4117 -command {if {$repo_config(gui.diffcontext) >= 2} {
4118 incr repo_config(gui.diffcontext) -1
4121 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4123 -label {Show More Context} \
4126 incr repo_config(gui.diffcontext)
4129 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4131 $ctxm add command -label {Options...} \
4134 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
4138 set ui_status_value {Initializing...}
4139 label .status -textvariable ui_status_value \
4145 pack .status -anchor w -side bottom -fill x
4150 set gm $repo_config(gui.geometry)
4151 wm geometry . [lindex $gm 0]
4152 .vpane sash place 0 \
4153 [lindex [.vpane sash coord 0] 0] \
4155 .vpane.files sash place 0 \
4157 [lindex [.vpane.files sash coord 0] 1]
4163 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4164 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4165 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4166 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4167 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4168 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4169 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4170 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4171 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4172 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4173 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4175 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4176 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4177 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4178 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4179 bind $ui_diff <$M1B-Key-v> {break}
4180 bind $ui_diff <$M1B-Key-V> {break}
4181 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4182 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4183 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4184 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4185 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4186 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4188 if {!$single_commit} {
4189 bind . <$M1B-Key-n> do_create_branch
4190 bind . <$M1B-Key-N> do_create_branch
4193 bind . <Destroy> do_quit
4194 bind all <Key-F5> do_rescan
4195 bind all <$M1B-Key-r> do_rescan
4196 bind all <$M1B-Key-R> do_rescan
4197 bind . <$M1B-Key-s> do_signoff
4198 bind . <$M1B-Key-S> do_signoff
4199 bind . <$M1B-Key-i> do_add_all
4200 bind . <$M1B-Key-I> do_add_all
4201 bind . <$M1B-Key-Return> do_commit
4202 bind all <$M1B-Key-q> do_quit
4203 bind all <$M1B-Key-Q> do_quit
4204 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4205 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4206 foreach i [list $ui_index $ui_workdir] {
4207 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4208 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4209 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4213 set file_lists($ui_index) [list]
4214 set file_lists($ui_workdir) [list]
4218 set MERGE_HEAD [list]
4221 set current_branch {}
4222 set current_diff_path {}
4223 set selected_commit_type new
4225 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4226 focus -force $ui_comm
4228 # -- Warn the user about environmental problems. Cygwin's Tcl
4229 # does *not* pass its env array onto any processes it spawns.
4230 # This means that git processes get none of our environment.
4235 set msg "Possible environment issues exist.
4237 The following environment variables are probably
4238 going to be ignored by any Git subprocess run
4242 foreach name [array names env] {
4243 switch -regexp -- $name {
4244 {^GIT_INDEX_FILE$} -
4245 {^GIT_OBJECT_DIRECTORY$} -
4246 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4248 {^GIT_EXTERNAL_DIFF$} -
4252 {^GIT_CONFIG_LOCAL$} -
4253 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4254 append msg " - $name\n"
4257 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4258 append msg " - $name\n"
4260 set suggest_user $name
4264 if {$ignored_env > 0} {
4266 This is due to a known issue with the
4267 Tcl binary distributed by Cygwin.
"
4269 if {$suggest_user ne {}} {
4272 A good replacement
for $suggest_user
4273 is placing values
for the user.name and
4274 user.email settings into your personal
4280 unset ignored_env msg suggest_user name
4283 # -- Only initialize complex UI if we are going to stay running.
4285 if {!$single_commit} {
4289 populate_branch_menu
4290 populate_fetch_menu .mbar.fetch
4291 populate_pull_menu .mbar.pull
4292 populate_push_menu .mbar.push
4295 # -- Only suggest a gc run if we are going to stay running.
4297 if {!$single_commit} {
4298 set object_limit 2000
4299 if {[is_Windows]} {set object_limit 200}
4300 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4301 if {$objects_current >= $object_limit} {
4303 "This repository currently has
$objects_current loose objects.
4305 To maintain optimal performance it is strongly
4306 recommended that you
compress the database
4307 when
more than
$object_limit loose objects exist.
4309 Compress the database now?
"] eq yes} {
4313 unset object_limit _junk objects_current
4316 lock_index begin-read