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!
630 set fd
[open
$path r
]
631 set content
[read $fd]
636 set ui_status_value
"Unable to display [escape_path $path]"
637 error_popup
"Error loading file:\n\n$err"
640 if {[string first
"\0" [string range
$content 0 8000]] != -1} {
641 set content
{* Binary
file (not showing content
).
}
643 $ui_diff conf
-state normal
644 $ui_diff insert end
$content
645 $ui_diff conf
-state disabled
648 set ui_status_value
{Ready.
}
653 if {$w eq
$ui_index} {
654 lappend cmd diff-index
656 } elseif
{$w eq
$ui_workdir} {
657 if {[string index
$m 0] eq
{U
}} {
660 lappend cmd diff-files
665 lappend cmd
--no-color
666 if {$repo_config(gui.diffcontext
) > 0} {
667 lappend cmd
"-U$repo_config(gui.diffcontext)"
669 if {$w eq
$ui_index} {
675 if {[catch
{set fd
[open
$cmd r
]} err
]} {
678 set ui_status_value
"Unable to display [escape_path $path]"
679 error_popup
"Error loading diff:\n\n$err"
683 fconfigure
$fd -blocking 0 -translation auto
684 fileevent
$fd readable
[list read_diff
$fd]
687 proc read_diff
{fd
} {
688 global ui_diff ui_status_value is_3way_diff diff_active
690 $ui_diff conf
-state normal
691 while {[gets
$fd line
] >= 0} {
692 # -- Cleanup uninteresting diff header lines.
694 if {[string match
{diff --git *} $line]} continue
695 if {[string match
{diff --cc *} $line]} continue
696 if {[string match
{diff --combined *} $line]} continue
697 if {[string match
{--- *} $line]} continue
698 if {[string match
{+++ *} $line]} continue
699 if {$line eq
{deleted
file mode
120000}} {
700 set line
"deleted symlink"
703 # -- Automatically detect if this is a 3 way diff.
705 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
707 if {[string match
{index
*} $line]
708 ||
[string match
{mode
*} $line]
709 ||
[string match
{new
file *} $line]
710 ||
[string match
{deleted
file *} $line]
711 ||
$line eq
{\ No newline
at end of
file}
712 ||
[regexp
{^\
* Unmerged path
} $line]} {
714 } elseif
{$is_3way_diff} {
715 set op
[string range
$line 0 1]
725 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
726 set line
[string replace
$line 0 1 { }]
733 puts
"error: Unhandled 3 way diff marker: {$op}"
738 set op
[string index
$line 0]
744 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
745 set line
[string replace
$line 0 0 { }]
752 puts
"error: Unhandled 2 way diff marker: {$op}"
757 $ui_diff insert end
$line $tags
758 $ui_diff insert end
"\n" $tags
760 $ui_diff conf
-state disabled
766 set ui_status_value
{Ready.
}
768 if {[$ui_diff index end
] eq
{2.0}} {
774 ######################################################################
778 proc load_last_commit
{} {
779 global HEAD PARENT MERGE_HEAD commit_type ui_comm
781 if {[llength
$PARENT] == 0} {
782 error_popup
{There is nothing to amend.
784 You are about to create the initial commit.
785 There is no commit before this to amend.
790 repository_state curType curHEAD curMERGE_HEAD
791 if {$curType eq
{merge
}} {
792 error_popup
{Cannot amend
while merging.
794 You are currently
in the middle of a merge that
795 has not been fully completed. You cannot amend
796 the prior commit unless you first abort the
797 current merge activity.
805 set fd
[open
"| git cat-file commit $curHEAD" r
]
806 while {[gets
$fd line
] > 0} {
807 if {[string match
{parent
*} $line]} {
808 lappend parents
[string range
$line 7 end
]
811 set msg
[string trim
[read $fd]]
814 error_popup
"Error loading commit data for amend:\n\n$err"
820 set MERGE_HEAD
[list
]
821 switch
-- [llength
$parents] {
822 0 {set commit_type amend-initial
}
823 1 {set commit_type amend
}
824 default
{set commit_type amend-merge
}
827 $ui_comm delete
0.0 end
828 $ui_comm insert end
$msg
830 $ui_comm edit modified false
831 rescan
{set ui_status_value
{Ready.
}}
834 proc create_new_commit
{} {
835 global commit_type ui_comm
837 set commit_type normal
838 $ui_comm delete
0.0 end
840 $ui_comm edit modified false
841 rescan
{set ui_status_value
{Ready.
}}
844 set GIT_COMMITTER_IDENT
{}
846 proc committer_ident
{} {
847 global GIT_COMMITTER_IDENT
849 if {$GIT_COMMITTER_IDENT eq
{}} {
850 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
851 error_popup
"Unable to obtain your identity:\n\n$err"
854 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
855 $me me GIT_COMMITTER_IDENT
]} {
856 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
861 return $GIT_COMMITTER_IDENT
864 proc commit_tree
{} {
865 global HEAD commit_type file_states ui_comm repo_config
866 global ui_status_value pch_error
868 if {![lock_index update
]} return
869 if {[committer_ident
] eq
{}} return
871 # -- Our in memory state should match the repository.
873 repository_state curType curHEAD curMERGE_HEAD
874 if {[string match amend
* $commit_type]
875 && $curType eq
{normal
}
876 && $curHEAD eq
$HEAD} {
877 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
878 info_popup
{Last scanned state does not match repository state.
880 Another Git program has modified this repository
881 since the last scan. A rescan must be performed
882 before another commit can be created.
884 The rescan will be automatically started now.
887 rescan
{set ui_status_value
{Ready.
}}
891 # -- At least one file should differ in the index.
894 foreach path
[array names file_states
] {
895 switch
-glob -- [lindex
$file_states($path) 0] {
899 M?
{set files_ready
1}
901 error_popup
"Unmerged files cannot be committed.
903 File [short_path $path] has merge conflicts.
904 You must resolve them and add the file before committing.
910 error_popup
"Unknown file state [lindex $s 0] detected.
912 File [short_path $path] cannot be committed by this program.
918 info_popup
{No changes to commit.
920 You must add
at least
1 file before you can commit.
926 # -- A message is required.
928 set msg
[string trim
[$ui_comm get
1.0 end
]]
930 error_popup
{Please supply a commit message.
932 A good commit message has the following format
:
934 - First line
: Describe
in one sentance what you did.
936 - Remaining lines
: Describe why this change is good.
942 # -- Run the pre-commit hook.
944 set pchook
[gitdir hooks pre-commit
]
946 # On Cygwin [file executable] might lie so we need to ask
947 # the shell if the hook is executable. Yes that's annoying.
949 if {[is_Windows
] && [file isfile
$pchook]} {
950 set pchook
[list sh
-c [concat \
951 "if test -x \"$pchook\";" \
952 "then exec \"$pchook\" 2>&1;" \
954 } elseif
{[file executable
$pchook]} {
955 set pchook
[list
$pchook |
& cat]
957 commit_writetree
$curHEAD $msg
961 set ui_status_value
{Calling pre-commit hook...
}
963 set fd_ph
[open
"| $pchook" r
]
964 fconfigure
$fd_ph -blocking 0 -translation binary
965 fileevent
$fd_ph readable \
966 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
969 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
970 global pch_error ui_status_value
972 append pch_error
[read $fd_ph]
973 fconfigure
$fd_ph -blocking 1
975 if {[catch
{close
$fd_ph}]} {
976 set ui_status_value
{Commit declined by pre-commit hook.
}
977 hook_failed_popup pre-commit
$pch_error
980 commit_writetree
$curHEAD $msg
985 fconfigure
$fd_ph -blocking 0
988 proc commit_writetree
{curHEAD msg
} {
989 global ui_status_value
991 set ui_status_value
{Committing changes...
}
992 set fd_wt
[open
"| git write-tree" r
]
993 fileevent
$fd_wt readable \
994 [list commit_committree
$fd_wt $curHEAD $msg]
997 proc commit_committree
{fd_wt curHEAD msg
} {
998 global HEAD PARENT MERGE_HEAD commit_type
999 global single_commit all_heads current_branch
1000 global ui_status_value ui_comm selected_commit_type
1001 global file_states selected_paths rescan_active
1004 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1005 error_popup
"write-tree failed:\n\n$err"
1006 set ui_status_value
{Commit failed.
}
1011 # -- Create the commit.
1013 set cmd
[list git commit-tree
$tree_id]
1014 set parents
[concat
$PARENT $MERGE_HEAD]
1015 if {[llength
$parents] > 0} {
1016 foreach p
$parents {
1020 # git commit-tree writes to stderr during initial commit.
1021 lappend cmd
2>/dev
/null
1024 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1025 error_popup
"commit-tree failed:\n\n$err"
1026 set ui_status_value
{Commit failed.
}
1031 # -- Update the HEAD ref.
1034 if {$commit_type ne
{normal
}} {
1035 append reflogm
" ($commit_type)"
1037 set i
[string first
"\n" $msg]
1039 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1041 append reflogm
{: } $msg
1043 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1044 if {[catch
{eval exec $cmd} err
]} {
1045 error_popup
"update-ref failed:\n\n$err"
1046 set ui_status_value
{Commit failed.
}
1051 # -- Make sure our current branch exists.
1053 if {$commit_type eq
{initial
}} {
1054 lappend all_heads
$current_branch
1055 set all_heads
[lsort
-unique $all_heads]
1056 populate_branch_menu
1059 # -- Cleanup after ourselves.
1061 catch
{file delete
[gitdir MERGE_HEAD
]}
1062 catch
{file delete
[gitdir MERGE_MSG
]}
1063 catch
{file delete
[gitdir SQUASH_MSG
]}
1064 catch
{file delete
[gitdir GITGUI_MSG
]}
1066 # -- Let rerere do its thing.
1068 if {[file isdirectory
[gitdir rr-cache
]]} {
1069 catch
{exec git rerere
}
1072 # -- Run the post-commit hook.
1074 set pchook
[gitdir hooks post-commit
]
1075 if {[is_Windows
] && [file isfile
$pchook]} {
1076 set pchook
[list sh
-c [concat \
1077 "if test -x \"$pchook\";" \
1078 "then exec \"$pchook\";" \
1080 } elseif
{![file executable
$pchook]} {
1083 if {$pchook ne
{}} {
1084 catch
{exec $pchook &}
1087 $ui_comm delete
0.0 end
1089 $ui_comm edit modified false
1091 if {$single_commit} do_quit
1093 # -- Update in memory status
1095 set selected_commit_type new
1096 set commit_type normal
1099 set MERGE_HEAD
[list
]
1101 foreach path
[array names file_states
] {
1102 set s
$file_states($path)
1104 switch
-glob -- $m {
1112 unset file_states
($path)
1113 catch
{unset selected_paths
($path)}
1116 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1122 set file_states
($path) [list \
1123 _
[string index
$m 1] \
1134 set ui_status_value \
1135 "Changes committed as [string range $cmt_id 0 7]."
1138 ######################################################################
1142 proc fetch_from
{remote
} {
1143 set w
[new_console
"fetch $remote" \
1144 "Fetching new changes from $remote"]
1145 set cmd
[list git fetch
]
1147 console_exec
$w $cmd
1150 proc pull_remote
{remote branch
} {
1151 global HEAD commit_type file_states repo_config
1153 if {![lock_index update
]} return
1155 # -- Our in memory state should match the repository.
1157 repository_state curType curHEAD curMERGE_HEAD
1158 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1159 info_popup
{Last scanned state does not match repository state.
1161 Another Git program has modified this repository
1162 since the last scan. A rescan must be performed
1163 before a pull operation can be started.
1165 The rescan will be automatically started now.
1168 rescan
{set ui_status_value
{Ready.
}}
1172 # -- No differences should exist before a pull.
1174 if {[array size file_states
] != 0} {
1175 error_popup
{Uncommitted but modified files are present.
1177 You should not perform a pull with unmodified
1178 files
in your working directory as Git will be
1179 unable to recover from an incorrect merge.
1181 You should commit or revert all changes before
1182 starting a pull operation.
1188 set w
[new_console
"pull $remote $branch" \
1189 "Pulling new changes from branch $branch in $remote"]
1190 set cmd
[list git pull
]
1191 if {$repo_config(gui.pullsummary
) eq
{false
}} {
1192 lappend cmd
--no-summary
1196 console_exec
$w $cmd [list post_pull_remote
$remote $branch]
1199 proc post_pull_remote
{remote branch success
} {
1200 global HEAD PARENT MERGE_HEAD commit_type selected_commit_type
1201 global ui_status_value
1205 repository_state commit_type HEAD MERGE_HEAD
1207 set selected_commit_type new
1208 set ui_status_value
"Pulling $branch from $remote complete."
1210 rescan
[list
set ui_status_value \
1211 "Conflicts detected while pulling $branch from $remote."]
1215 proc push_to
{remote
} {
1216 set w
[new_console
"push $remote" \
1217 "Pushing changes to $remote"]
1218 set cmd
[list git push
]
1220 console_exec
$w $cmd
1223 ######################################################################
1227 proc mapicon
{w state path
} {
1230 if {[catch
{set r
$all_icons($state$w)}]} {
1231 puts
"error: no icon for $w state={$state} $path"
1237 proc mapdesc
{state path
} {
1240 if {[catch
{set r
$all_descs($state)}]} {
1241 puts
"error: no desc for state={$state} $path"
1247 proc escape_path
{path
} {
1248 regsub
-all "\n" $path "\\n" path
1252 proc short_path
{path
} {
1253 return [escape_path
[lindex
[file split $path] end
]]
1257 set null_sha1
[string repeat
0 40]
1259 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1260 global file_states next_icon_id null_sha1
1262 set s0
[string index
$new_state 0]
1263 set s1
[string index
$new_state 1]
1265 if {[catch
{set info
$file_states($path)}]} {
1267 set icon n
[incr next_icon_id
]
1269 set state
[lindex
$info 0]
1270 set icon
[lindex
$info 1]
1271 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1272 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1275 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1276 elseif
{$s0 eq
{_
}} {set s0 _
}
1278 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1279 elseif
{$s1 eq
{_
}} {set s1 _
}
1281 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1282 set head_info
[list
0 $null_sha1]
1283 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1284 && $head_info eq
{}} {
1285 set head_info
$index_info
1288 set file_states
($path) [list
$s0$s1 $icon \
1289 $head_info $index_info \
1294 proc display_file_helper
{w path icon_name old_m new_m
} {
1297 if {$new_m eq
{_
}} {
1298 set lno
[lsearch
-sorted $file_lists($w) $path]
1300 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1302 $w conf
-state normal
1303 $w delete
$lno.0 [expr {$lno + 1}].0
1304 $w conf
-state disabled
1306 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1307 lappend file_lists
($w) $path
1308 set file_lists
($w) [lsort
-unique $file_lists($w)]
1309 set lno
[lsearch
-sorted $file_lists($w) $path]
1311 $w conf
-state normal
1312 $w image create
$lno.0 \
1313 -align center
-padx 5 -pady 1 \
1315 -image [mapicon
$w $new_m $path]
1316 $w insert
$lno.1 "[escape_path $path]\n"
1317 $w conf
-state disabled
1318 } elseif
{$old_m ne
$new_m} {
1319 $w conf
-state normal
1320 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1321 $w conf
-state disabled
1325 proc display_file
{path state
} {
1326 global file_states selected_paths
1327 global ui_index ui_workdir
1329 set old_m
[merge_state
$path $state]
1330 set s
$file_states($path)
1331 set new_m
[lindex
$s 0]
1332 set icon_name
[lindex
$s 1]
1334 set o
[string index
$old_m 0]
1335 set n
[string index
$new_m 0]
1342 display_file_helper
$ui_index $path $icon_name $o $n
1344 if {[string index
$old_m 0] eq
{U
}} {
1347 set o
[string index
$old_m 1]
1349 if {[string index
$new_m 0] eq
{U
}} {
1352 set n
[string index
$new_m 1]
1354 display_file_helper
$ui_workdir $path $icon_name $o $n
1356 if {$new_m eq
{__
}} {
1357 unset file_states
($path)
1358 catch
{unset selected_paths
($path)}
1362 proc display_all_files_helper
{w path icon_name m
} {
1365 lappend file_lists
($w) $path
1366 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1367 $w image create end \
1368 -align center
-padx 5 -pady 1 \
1370 -image [mapicon
$w $m $path]
1371 $w insert end
"[escape_path $path]\n"
1374 proc display_all_files
{} {
1375 global ui_index ui_workdir
1376 global file_states file_lists
1379 $ui_index conf
-state normal
1380 $ui_workdir conf
-state normal
1382 $ui_index delete
0.0 end
1383 $ui_workdir delete
0.0 end
1386 set file_lists
($ui_index) [list
]
1387 set file_lists
($ui_workdir) [list
]
1389 foreach path
[lsort
[array names file_states
]] {
1390 set s
$file_states($path)
1392 set icon_name
[lindex
$s 1]
1394 set s
[string index
$m 0]
1395 if {$s ne
{U
} && $s ne
{_
}} {
1396 display_all_files_helper
$ui_index $path \
1400 if {[string index
$m 0] eq
{U
}} {
1403 set s
[string index
$m 1]
1406 display_all_files_helper
$ui_workdir $path \
1411 $ui_index conf
-state disabled
1412 $ui_workdir conf
-state disabled
1415 proc update_indexinfo
{msg pathList after
} {
1416 global update_index_cp ui_status_value
1418 if {![lock_index update
]} return
1420 set update_index_cp
0
1421 set pathList
[lsort
$pathList]
1422 set totalCnt
[llength
$pathList]
1423 set batch [expr {int
($totalCnt * .01) + 1}]
1424 if {$batch > 25} {set batch 25}
1426 set ui_status_value
[format \
1427 "$msg... %i/%i files (%.2f%%)" \
1431 set fd
[open
"| git update-index -z --index-info" w
]
1437 fileevent
$fd writable
[list \
1438 write_update_indexinfo \
1448 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1449 global update_index_cp ui_status_value
1450 global file_states current_diff_path
1452 if {$update_index_cp >= $totalCnt} {
1459 for {set i
$batch} \
1460 {$update_index_cp < $totalCnt && $i > 0} \
1462 set path
[lindex
$pathList $update_index_cp]
1463 incr update_index_cp
1465 set s
$file_states($path)
1466 switch
-glob -- [lindex
$s 0] {
1473 set info
[lindex
$s 2]
1474 if {$info eq
{}} continue
1476 puts
-nonewline $fd "$info\t$path\0"
1477 display_file
$path $new
1480 set ui_status_value
[format \
1481 "$msg... %i/%i files (%.2f%%)" \
1484 [expr {100.0 * $update_index_cp / $totalCnt}]]
1487 proc update_index
{msg pathList after
} {
1488 global update_index_cp ui_status_value
1490 if {![lock_index update
]} return
1492 set update_index_cp
0
1493 set pathList
[lsort
$pathList]
1494 set totalCnt
[llength
$pathList]
1495 set batch [expr {int
($totalCnt * .01) + 1}]
1496 if {$batch > 25} {set batch 25}
1498 set ui_status_value
[format \
1499 "$msg... %i/%i files (%.2f%%)" \
1503 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1509 fileevent
$fd writable
[list \
1510 write_update_index \
1520 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1521 global update_index_cp ui_status_value
1522 global file_states current_diff_path
1524 if {$update_index_cp >= $totalCnt} {
1531 for {set i
$batch} \
1532 {$update_index_cp < $totalCnt && $i > 0} \
1534 set path
[lindex
$pathList $update_index_cp]
1535 incr update_index_cp
1537 switch
-glob -- [lindex
$file_states($path) 0] {
1543 if {[file exists
$path]} {
1552 puts
-nonewline $fd "$path\0"
1553 display_file
$path $new
1556 set ui_status_value
[format \
1557 "$msg... %i/%i files (%.2f%%)" \
1560 [expr {100.0 * $update_index_cp / $totalCnt}]]
1563 proc checkout_index
{msg pathList after
} {
1564 global update_index_cp ui_status_value
1566 if {![lock_index update
]} return
1568 set update_index_cp
0
1569 set pathList
[lsort
$pathList]
1570 set totalCnt
[llength
$pathList]
1571 set batch [expr {int
($totalCnt * .01) + 1}]
1572 if {$batch > 25} {set batch 25}
1574 set ui_status_value
[format \
1575 "$msg... %i/%i files (%.2f%%)" \
1579 set cmd
[list git checkout-index
]
1585 set fd
[open
"| $cmd " w
]
1591 fileevent
$fd writable
[list \
1592 write_checkout_index \
1602 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1603 global update_index_cp ui_status_value
1604 global file_states current_diff_path
1606 if {$update_index_cp >= $totalCnt} {
1613 for {set i
$batch} \
1614 {$update_index_cp < $totalCnt && $i > 0} \
1616 set path
[lindex
$pathList $update_index_cp]
1617 incr update_index_cp
1618 switch
-glob -- [lindex
$file_states($path) 0] {
1622 puts
-nonewline $fd "$path\0"
1623 display_file
$path ?_
1628 set ui_status_value
[format \
1629 "$msg... %i/%i files (%.2f%%)" \
1632 [expr {100.0 * $update_index_cp / $totalCnt}]]
1635 ######################################################################
1637 ## branch management
1639 proc is_tracking_branch
{name
} {
1640 global tracking_branches
1642 if {![catch
{set info
$tracking_branches($name)}]} {
1645 foreach t
[array names tracking_branches
] {
1646 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1653 proc load_all_heads
{} {
1656 set all_heads
[list
]
1657 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1658 while {[gets
$fd line
] > 0} {
1659 if {[is_tracking_branch
$line]} continue
1660 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1661 lappend all_heads
$name
1665 set all_heads
[lsort
$all_heads]
1668 proc populate_branch_menu
{} {
1669 global all_heads disable_on_lock
1672 set last
[$m index last
]
1673 for {set i
0} {$i <= $last} {incr i
} {
1674 if {[$m type $i] eq
{separator
}} {
1677 foreach a
$disable_on_lock {
1678 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1682 set disable_on_lock
$new_dol
1688 foreach b
$all_heads {
1689 $m add radiobutton \
1691 -command [list switch_branch
$b] \
1692 -variable current_branch \
1695 lappend disable_on_lock \
1696 [list
$m entryconf
[$m index last
] -state]
1700 proc all_tracking_branches
{} {
1701 global tracking_branches
1703 set all_trackings
{}
1705 foreach name
[array names tracking_branches
] {
1706 if {[regsub
{/\
*$
} $name {} name
]} {
1709 regsub ^refs
/(heads|remotes
)/ $name {} name
1710 lappend all_trackings
$name
1715 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1716 while {[gets
$fd name
] > 0} {
1717 regsub ^refs
/(heads|remotes
)/ $name {} name
1718 lappend all_trackings
$name
1723 return [lsort
-unique $all_trackings]
1726 proc do_create_branch_action
{w
} {
1727 global all_heads null_sha1 repo_config
1728 global create_branch_checkout create_branch_revtype
1729 global create_branch_head create_branch_trackinghead
1731 set newbranch
[string trim
[$w.desc.name_t get
0.0 end
]]
1732 if {$newbranch eq
{}
1733 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1737 -title [wm title
$w] \
1739 -message "Please supply a branch name."
1740 focus
$w.desc.name_t
1743 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1747 -title [wm title
$w] \
1749 -message "Branch '$newbranch' already exists."
1750 focus
$w.desc.name_t
1753 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1757 -title [wm title
$w] \
1759 -message "We do not like '$newbranch' as a branch name."
1760 focus
$w.desc.name_t
1765 switch
-- $create_branch_revtype {
1766 head {set rev $create_branch_head}
1767 tracking
{set rev $create_branch_trackinghead}
1768 expression
{set rev [string trim
[$w.from.exp_t get
0.0 end
]]}
1770 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1774 -title [wm title
$w] \
1776 -message "Invalid starting revision: $rev"
1779 set cmd
[list git update-ref
]
1781 lappend cmd
"branch: Created from $rev"
1782 lappend cmd
"refs/heads/$newbranch"
1784 lappend cmd
$null_sha1
1785 if {[catch
{eval exec $cmd} err
]} {
1789 -title [wm title
$w] \
1791 -message "Failed to create '$newbranch'.\n\n$err"
1795 lappend all_heads
$newbranch
1796 set all_heads
[lsort
$all_heads]
1797 populate_branch_menu
1799 if {$create_branch_checkout} {
1800 switch_branch
$newbranch
1804 proc radio_selector
{varname value args
} {
1805 upvar
#0 $varname var
1809 trace add variable create_branch_head
write \
1810 [list radio_selector create_branch_revtype
head]
1811 trace add variable create_branch_trackinghead
write \
1812 [list radio_selector create_branch_revtype tracking
]
1814 trace add variable delete_branch_head
write \
1815 [list radio_selector delete_branch_checktype
head]
1816 trace add variable delete_branch_trackinghead
write \
1817 [list radio_selector delete_branch_checktype tracking
]
1819 proc do_create_branch
{} {
1820 global all_heads current_branch repo_config
1821 global create_branch_checkout create_branch_revtype
1822 global create_branch_head create_branch_trackinghead
1824 set w .branch_editor
1826 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1828 label
$w.header
-text {Create New Branch
} \
1830 pack
$w.header
-side top
-fill x
1833 button
$w.buttons.create
-text Create \
1836 -command [list do_create_branch_action
$w]
1837 pack
$w.buttons.create
-side right
1838 button
$w.buttons.cancel
-text {Cancel
} \
1840 -command [list destroy
$w]
1841 pack
$w.buttons.cancel
-side right
-padx 5
1842 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1844 labelframe
$w.desc \
1845 -text {Branch Description
} \
1847 label
$w.desc.name_l
-text {Name
:} -font font_ui
1848 text
$w.desc.name_t \
1854 $w.desc.name_t insert
0.0 $repo_config(gui.newbranchtemplate
)
1855 grid
$w.desc.name_l
$w.desc.name_t
-stick we
-padx {0 5}
1856 bind $w.desc.name_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1857 bind $w.desc.name_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1858 bind $w.desc.name_t
<Key-Return
> "do_create_branch_action $w;break"
1859 bind $w.desc.name_t
<Key
> {
1860 if {{%K
} ne
{BackSpace
}
1863 && {%K
} ne
{Return
}} {
1865 if {[string first
%A
{~^
:?
*[}] >= 0} break
1868 grid columnconfigure
$w.desc
1 -weight 1
1869 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
1871 labelframe
$w.from \
1872 -text {Starting Revision
} \
1874 radiobutton
$w.from.head_r \
1875 -text {Local Branch
:} \
1877 -variable create_branch_revtype \
1879 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
1880 grid
$w.from.head_r
$w.from.head_m
-sticky w
1881 set all_trackings
[all_tracking_branches
]
1882 if {$all_trackings ne
{}} {
1883 set create_branch_trackinghead
[lindex
$all_trackings 0]
1884 radiobutton
$w.from.tracking_r \
1885 -text {Tracking Branch
:} \
1887 -variable create_branch_revtype \
1889 eval tk_optionMenu
$w.from.tracking_m \
1890 create_branch_trackinghead \
1892 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
1894 radiobutton
$w.from.exp_r \
1895 -text {Revision Expression
:} \
1897 -variable create_branch_revtype \
1899 text
$w.from.exp_t \
1905 grid
$w.from.exp_r
$w.from.exp_t
-stick we
-padx {0 5}
1906 bind $w.from.exp_t
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
1907 bind $w.from.exp_t
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
1908 bind $w.from.exp_t
<Key-Return
> "do_create_branch_action $w;break"
1909 bind $w.from.exp_t
<Key-space
> break
1910 bind $w.from.exp_t
<Key
> {set create_branch_revtype expression
}
1911 grid columnconfigure
$w.from
1 -weight 1
1912 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1914 labelframe
$w.postActions \
1915 -text {Post Creation Actions
} \
1917 checkbutton
$w.postActions.checkout \
1918 -text {Checkout after creation
} \
1919 -variable create_branch_checkout \
1921 pack
$w.postActions.checkout
-anchor nw
1922 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
1924 set create_branch_checkout
1
1925 set create_branch_head
$current_branch
1926 set create_branch_revtype
head
1928 bind $w <Visibility
> "grab $w; focus $w.desc.name_t"
1929 bind $w <Key-Escape
> "destroy $w"
1930 bind $w <Key-Return
> "do_create_branch_action $w;break"
1931 wm title
$w "[appname] ([reponame]): Create Branch"
1935 proc do_delete_branch_action
{w
} {
1937 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
1940 switch
-- $delete_branch_checktype {
1941 head {set check_rev
$delete_branch_head}
1942 tracking
{set check_rev
$delete_branch_trackinghead}
1943 always
{set check_rev
{:none
}}
1945 if {$check_rev eq
{:none
}} {
1947 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
1951 -title [wm title
$w] \
1953 -message "Invalid check revision: $check_rev"
1957 set to_delete
[list
]
1958 set not_merged
[list
]
1959 foreach i
[$w.list.l curselection
] {
1960 set b
[$w.list.l get
$i]
1961 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
1962 if {$check_cmt ne
{}} {
1963 if {$b eq
$check_rev} continue
1964 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
1966 lappend not_merged
$b
1970 lappend to_delete
[list
$b $o]
1972 if {$not_merged ne
{}} {
1973 set msg
"The following branches are not completely merged into $check_rev:
1975 - [join $not_merged "\n - "]"
1979 -title [wm title
$w] \
1983 if {$to_delete eq
{}} return
1984 if {$delete_branch_checktype eq
{always
}} {
1985 set msg
{Recovering deleted branches is difficult.
1987 Delete the selected branches?
}
1988 if {[tk_messageBox \
1991 -title [wm title
$w] \
1993 -message $msg] ne
yes} {
1999 foreach i
$to_delete {
2002 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2003 append failed
" - $b: $err\n"
2005 set x
[lsearch
-sorted $all_heads $b]
2007 set all_heads
[lreplace
$all_heads $x $x]
2012 if {$failed ne
{}} {
2016 -title [wm title
$w] \
2018 -message "Failed to delete branches:\n$failed"
2021 set all_heads
[lsort
$all_heads]
2022 populate_branch_menu
2026 proc do_delete_branch
{} {
2027 global all_heads tracking_branches current_branch
2028 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2030 set w .branch_editor
2032 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2034 label
$w.header
-text {Delete Local Branch
} \
2036 pack
$w.header
-side top
-fill x
2039 button
$w.buttons.create
-text Delete \
2041 -command [list do_delete_branch_action
$w]
2042 pack
$w.buttons.create
-side right
2043 button
$w.buttons.cancel
-text {Cancel
} \
2045 -command [list destroy
$w]
2046 pack
$w.buttons.cancel
-side right
-padx 5
2047 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2049 labelframe
$w.list \
2050 -text {Local Branches
} \
2055 -selectmode extended \
2057 foreach h
$all_heads {
2058 if {$h ne
$current_branch} {
2059 $w.list.l insert end
$h
2062 pack
$w.list.l
-fill both
-pady 5 -padx 5
2063 pack
$w.list
-fill both
-pady 5 -padx 5
2065 labelframe
$w.validate \
2066 -text {Delete Only If
} \
2068 radiobutton
$w.validate.head_r \
2069 -text {Merged Into Local Branch
:} \
2071 -variable delete_branch_checktype \
2073 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2074 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2075 set all_trackings
[all_tracking_branches
]
2076 if {$all_trackings ne
{}} {
2077 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2078 radiobutton
$w.validate.tracking_r \
2079 -text {Merged Into Tracking Branch
:} \
2081 -variable delete_branch_checktype \
2083 eval tk_optionMenu
$w.validate.tracking_m \
2084 delete_branch_trackinghead \
2086 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2088 radiobutton
$w.validate.always_r \
2089 -text {Always
(Do not perform merge checks
)} \
2091 -variable delete_branch_checktype \
2093 grid
$w.validate.always_r
-columnspan 2 -sticky w
2094 grid columnconfigure
$w.validate
1 -weight 1
2095 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2097 set delete_branch_head
$current_branch
2098 set delete_branch_checktype
head
2100 bind $w <Visibility
> "grab $w; focus $w"
2101 bind $w <Key-Escape
> "destroy $w"
2102 wm title
$w "[appname] ([reponame]): Delete Branch"
2106 proc switch_branch
{b
} {
2107 global HEAD commit_type file_states current_branch
2108 global selected_commit_type ui_comm
2110 if {![lock_index switch
]} return
2112 # -- Backup the selected branch (repository_state resets it)
2114 set new_branch
$current_branch
2116 # -- Our in memory state should match the repository.
2118 repository_state curType curHEAD curMERGE_HEAD
2119 if {[string match amend
* $commit_type]
2120 && $curType eq
{normal
}
2121 && $curHEAD eq
$HEAD} {
2122 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2123 info_popup
{Last scanned state does not match repository state.
2125 Another Git program has modified this repository
2126 since the last scan. A rescan must be performed
2127 before the current branch can be changed.
2129 The rescan will be automatically started now.
2132 rescan
{set ui_status_value
{Ready.
}}
2136 # -- Toss the message buffer if we are in amend mode.
2138 if {[string match amend
* $curType]} {
2139 $ui_comm delete
0.0 end
2141 $ui_comm edit modified false
2144 set selected_commit_type new
2145 set current_branch
$new_branch
2148 error
"NOT FINISHED"
2151 ######################################################################
2153 ## remote management
2155 proc load_all_remotes
{} {
2157 global all_remotes tracking_branches
2159 set all_remotes
[list
]
2160 array
unset tracking_branches
2162 set rm_dir
[gitdir remotes
]
2163 if {[file isdirectory
$rm_dir]} {
2164 set all_remotes
[glob \
2168 -directory $rm_dir *]
2170 foreach name
$all_remotes {
2172 set fd
[open
[file join $rm_dir $name] r
]
2173 while {[gets
$fd line
] >= 0} {
2174 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2175 $line line src dst
]} continue
2176 if {![regexp ^refs
/ $dst]} {
2177 set dst
"refs/heads/$dst"
2179 set tracking_branches
($dst) [list
$name $src]
2186 foreach line
[array names repo_config remote.
*.url
] {
2187 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2188 lappend all_remotes
$name
2190 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2194 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2195 if {![regexp ^refs
/ $dst]} {
2196 set dst
"refs/heads/$dst"
2198 set tracking_branches
($dst) [list
$name $src]
2202 set all_remotes
[lsort
-unique $all_remotes]
2205 proc populate_fetch_menu
{m
} {
2206 global all_remotes repo_config
2208 foreach r
$all_remotes {
2210 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2211 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2216 set fd
[open
[gitdir remotes
$r] r
]
2217 while {[gets
$fd n
] >= 0} {
2218 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2229 -label "Fetch from $r..." \
2230 -command [list fetch_from
$r] \
2236 proc populate_push_menu
{m
} {
2237 global all_remotes repo_config
2239 foreach r
$all_remotes {
2241 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2242 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2247 set fd
[open
[gitdir remotes
$r] r
]
2248 while {[gets
$fd n
] >= 0} {
2249 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2260 -label "Push to $r..." \
2261 -command [list push_to
$r] \
2267 proc populate_pull_menu
{m
} {
2268 global repo_config all_remotes disable_on_lock
2270 foreach remote
$all_remotes {
2272 if {[array get repo_config remote.
$remote.url
] ne
{}} {
2273 if {[array get repo_config remote.
$remote.fetch
] ne
{}} {
2274 foreach line
$repo_config(remote.
$remote.fetch
) {
2275 if {[regexp
{^
([^
:]+):} $line line rb
]} {
2282 set fd
[open
[gitdir remotes
$remote] r
]
2283 while {[gets
$fd line
] >= 0} {
2284 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $line line rb
]} {
2292 foreach rb
$rb_list {
2293 regsub ^refs
/heads
/ $rb {} rb_short
2295 -label "Branch $rb_short from $remote..." \
2296 -command [list pull_remote
$remote $rb] \
2298 lappend disable_on_lock \
2299 [list
$m entryconf
[$m index last
] -state]
2304 ######################################################################
2309 #define mask_width 14
2310 #define mask_height 15
2311 static unsigned char mask_bits
[] = {
2312 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2313 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2314 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2317 image create bitmap file_plain
-background white
-foreground black
-data {
2318 #define plain_width 14
2319 #define plain_height 15
2320 static unsigned char plain_bits
[] = {
2321 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2322 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2323 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2324 } -maskdata $filemask
2326 image create bitmap file_mod
-background white
-foreground blue
-data {
2327 #define mod_width 14
2328 #define mod_height 15
2329 static unsigned char mod_bits
[] = {
2330 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2331 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2332 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2333 } -maskdata $filemask
2335 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2336 #define file_fulltick_width 14
2337 #define file_fulltick_height 15
2338 static unsigned char file_fulltick_bits
[] = {
2339 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2340 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2341 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2342 } -maskdata $filemask
2344 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2345 #define parttick_width 14
2346 #define parttick_height 15
2347 static unsigned char parttick_bits
[] = {
2348 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2349 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2350 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2351 } -maskdata $filemask
2353 image create bitmap file_question
-background white
-foreground black
-data {
2354 #define file_question_width 14
2355 #define file_question_height 15
2356 static unsigned char file_question_bits
[] = {
2357 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2358 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2359 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2360 } -maskdata $filemask
2362 image create bitmap file_removed
-background white
-foreground red
-data {
2363 #define file_removed_width 14
2364 #define file_removed_height 15
2365 static unsigned char file_removed_bits
[] = {
2366 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2367 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2368 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2369 } -maskdata $filemask
2371 image create bitmap file_merge
-background white
-foreground blue
-data {
2372 #define file_merge_width 14
2373 #define file_merge_height 15
2374 static unsigned char file_merge_bits
[] = {
2375 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2376 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2377 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2378 } -maskdata $filemask
2380 set ui_index .vpane.files.index.list
2381 set ui_workdir .vpane.files.workdir.list
2383 set all_icons
(_
$ui_index) file_plain
2384 set all_icons
(A
$ui_index) file_fulltick
2385 set all_icons
(M
$ui_index) file_fulltick
2386 set all_icons
(D
$ui_index) file_removed
2387 set all_icons
(U
$ui_index) file_merge
2389 set all_icons
(_
$ui_workdir) file_plain
2390 set all_icons
(M
$ui_workdir) file_mod
2391 set all_icons
(D
$ui_workdir) file_question
2392 set all_icons
(U
$ui_workdir) file_merge
2393 set all_icons
(O
$ui_workdir) file_plain
2395 set max_status_desc
0
2399 {_M
"Modified, not staged"}
2400 {M_
"Staged for commit"}
2401 {MM
"Portions staged for commit"}
2402 {MD
"Staged for commit, missing"}
2404 {_O
"Untracked, not staged"}
2405 {A_
"Staged for commit"}
2406 {AM
"Portions staged for commit"}
2407 {AD
"Staged for commit, missing"}
2410 {D_
"Staged for removal"}
2411 {DO
"Staged for removal, still present"}
2413 {U_
"Requires merge resolution"}
2414 {UU
"Requires merge resolution"}
2415 {UM
"Requires merge resolution"}
2416 {UD
"Requires merge resolution"}
2418 if {$max_status_desc < [string length
[lindex
$i 1]]} {
2419 set max_status_desc
[string length
[lindex
$i 1]]
2421 set all_descs
([lindex
$i 0]) [lindex
$i 1]
2425 ######################################################################
2430 global tcl_platform tk_library
2431 if {[tk windowingsystem
] eq
{aqua
}} {
2437 proc is_Windows
{} {
2439 if {$tcl_platform(platform
) eq
{windows
}} {
2445 proc bind_button3
{w cmd
} {
2446 bind $w <Any-Button-3
> $cmd
2448 bind $w <Control-Button-1
> $cmd
2452 proc incr_font_size
{font
{amt
1}} {
2453 set sz
[font configure
$font -size]
2455 font configure
$font -size $sz
2456 font configure
${font}bold
-size $sz
2459 proc hook_failed_popup
{hook msg
} {
2464 label
$w.m.l1
-text "$hook hook failed:" \
2469 -background white
-borderwidth 1 \
2471 -width 80 -height 10 \
2473 -yscrollcommand [list
$w.m.sby
set]
2475 -text {You must correct the above errors before committing.
} \
2479 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2480 pack
$w.m.l1
-side top
-fill x
2481 pack
$w.m.l2
-side bottom
-fill x
2482 pack
$w.m.sby
-side right
-fill y
2483 pack
$w.m.t
-side left
-fill both
-expand 1
2484 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2486 $w.m.t insert
1.0 $msg
2487 $w.m.t conf
-state disabled
2489 button
$w.ok
-text OK \
2492 -command "destroy $w"
2493 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2495 bind $w <Visibility
> "grab $w; focus $w"
2496 bind $w <Key-Return
> "destroy $w"
2497 wm title
$w "[appname] ([reponame]): error"
2501 set next_console_id
0
2503 proc new_console
{short_title long_title
} {
2504 global next_console_id console_data
2505 set w .console
[incr next_console_id
]
2506 set console_data
($w) [list
$short_title $long_title]
2507 return [console_init
$w]
2510 proc console_init
{w
} {
2511 global console_cr console_data M1B
2513 set console_cr
($w) 1.0
2516 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
2521 -background white
-borderwidth 1 \
2523 -width 80 -height 10 \
2526 -yscrollcommand [list
$w.m.sby
set]
2527 label
$w.m.s
-text {Working... please
wait...
} \
2531 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
2532 pack
$w.m.l1
-side top
-fill x
2533 pack
$w.m.s
-side bottom
-fill x
2534 pack
$w.m.sby
-side right
-fill y
2535 pack
$w.m.t
-side left
-fill both
-expand 1
2536 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
2538 menu
$w.ctxm
-tearoff 0
2539 $w.ctxm add
command -label "Copy" \
2541 -command "tk_textCopy $w.m.t"
2542 $w.ctxm add
command -label "Select All" \
2544 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
2545 $w.ctxm add
command -label "Copy All" \
2548 $w.m.t tag add sel 0.0 end
2550 $w.m.t tag remove sel 0.0 end
2553 button
$w.ok
-text {Close
} \
2556 -command "destroy $w"
2557 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
2559 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
2560 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
2561 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
2562 bind $w <Visibility
> "focus $w"
2563 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
2567 proc console_exec
{w cmd
{after
{}}} {
2568 # -- Windows tosses the enviroment when we exec our child.
2569 # But most users need that so we have to relogin. :-(
2572 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
2575 # -- Tcl won't let us redirect both stdout and stderr to
2576 # the same pipe. So pass it through cat...
2578 set cmd
[concat |
$cmd |
& cat]
2580 set fd_f
[open
$cmd r
]
2581 fconfigure
$fd_f -blocking 0 -translation binary
2582 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
2585 proc console_read
{w fd after
} {
2586 global console_cr console_data
2590 if {![winfo exists
$w]} {console_init
$w}
2591 $w.m.t conf
-state normal
2593 set n
[string length
$buf]
2595 set cr
[string first
"\r" $buf $c]
2596 set lf
[string first
"\n" $buf $c]
2597 if {$cr < 0} {set cr
[expr {$n + 1}]}
2598 if {$lf < 0} {set lf
[expr {$n + 1}]}
2601 $w.m.t insert end
[string range
$buf $c $lf]
2602 set console_cr
($w) [$w.m.t index
{end
-1c}]
2606 $w.m.t delete
$console_cr($w) end
2607 $w.m.t insert end
"\n"
2608 $w.m.t insert end
[string range
$buf $c $cr]
2613 $w.m.t conf
-state disabled
2617 fconfigure
$fd -blocking 1
2619 if {[catch
{close
$fd}]} {
2620 if {![winfo exists
$w]} {console_init
$w}
2621 $w.m.s conf
-background red
-text {Error
: Command Failed
}
2622 $w.ok conf
-state normal
2624 } elseif
{[winfo exists
$w]} {
2625 $w.m.s conf
-background green
-text {Success
}
2626 $w.ok conf
-state normal
2629 array
unset console_cr
$w
2630 array
unset console_data
$w
2632 uplevel
#0 $after $ok
2636 fconfigure
$fd -blocking 0
2639 ######################################################################
2643 set starting_gitk_msg
{Starting gitk... please
wait...
}
2645 proc do_gitk
{revs
} {
2646 global ui_status_value starting_gitk_msg
2654 set cmd
"sh -c \"exec $cmd\""
2658 if {[catch
{eval exec $cmd} err
]} {
2659 error_popup
"Failed to start gitk:\n\n$err"
2661 set ui_status_value
$starting_gitk_msg
2663 if {$ui_status_value eq
$starting_gitk_msg} {
2664 set ui_status_value
{Ready.
}
2671 set w
[new_console
{gc
} {Compressing the object database
}]
2672 console_exec
$w {git gc
}
2675 proc do_fsck_objects
{} {
2676 set w
[new_console
{fsck-objects
} \
2677 {Verifying the object database with fsck-objects
}]
2678 set cmd
[list git fsck-objects
]
2681 lappend cmd
--strict
2682 console_exec
$w $cmd
2688 global ui_comm is_quitting repo_config commit_type
2690 if {$is_quitting} return
2693 # -- Stash our current commit buffer.
2695 set save
[gitdir GITGUI_MSG
]
2696 set msg
[string trim
[$ui_comm get
0.0 end
]]
2697 if {![string match amend
* $commit_type]
2698 && [$ui_comm edit modified
]
2701 set fd
[open
$save w
]
2702 puts
$fd [string trim
[$ui_comm get
0.0 end
]]
2706 catch
{file delete
$save}
2709 # -- Stash our current window geometry into this repository.
2711 set cfg_geometry
[list
]
2712 lappend cfg_geometry
[wm geometry .
]
2713 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
2714 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
2715 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
2718 if {$cfg_geometry ne
$rc_geometry} {
2719 catch
{exec git repo-config gui.geometry
$cfg_geometry}
2726 rescan
{set ui_status_value
{Ready.
}}
2729 proc unstage_helper
{txt paths
} {
2730 global file_states current_diff_path
2732 if {![lock_index begin-update
]} return
2736 foreach path
$paths {
2737 switch
-glob -- [lindex
$file_states($path) 0] {
2741 lappend pathList
$path
2742 if {$path eq
$current_diff_path} {
2743 set after
{reshow_diff
;}
2748 if {$pathList eq
{}} {
2754 [concat
$after {set ui_status_value
{Ready.
}}]
2758 proc do_unstage_selection
{} {
2759 global current_diff_path selected_paths
2761 if {[array size selected_paths
] > 0} {
2763 {Unstaging selected files from commit
} \
2764 [array names selected_paths
]
2765 } elseif
{$current_diff_path ne
{}} {
2767 "Unstaging [short_path $current_diff_path] from commit" \
2768 [list
$current_diff_path]
2772 proc add_helper
{txt paths
} {
2773 global file_states current_diff_path
2775 if {![lock_index begin-update
]} return
2779 foreach path
$paths {
2780 switch
-glob -- [lindex
$file_states($path) 0] {
2785 lappend pathList
$path
2786 if {$path eq
$current_diff_path} {
2787 set after
{reshow_diff
;}
2792 if {$pathList eq
{}} {
2798 [concat
$after {set ui_status_value
{Ready to commit.
}}]
2802 proc do_add_selection
{} {
2803 global current_diff_path selected_paths
2805 if {[array size selected_paths
] > 0} {
2807 {Adding selected files
} \
2808 [array names selected_paths
]
2809 } elseif
{$current_diff_path ne
{}} {
2811 "Adding [short_path $current_diff_path]" \
2812 [list
$current_diff_path]
2816 proc do_add_all
{} {
2820 foreach path
[array names file_states
] {
2821 switch
-glob -- [lindex
$file_states($path) 0] {
2824 ?D
{lappend paths
$path}
2827 add_helper
{Adding all changed files
} $paths
2830 proc revert_helper
{txt paths
} {
2831 global file_states current_diff_path
2833 if {![lock_index begin-update
]} return
2837 foreach path
$paths {
2838 switch
-glob -- [lindex
$file_states($path) 0] {
2842 lappend pathList
$path
2843 if {$path eq
$current_diff_path} {
2844 set after
{reshow_diff
;}
2850 set n
[llength
$pathList]
2854 } elseif
{$n == 1} {
2855 set s
"[short_path [lindex $pathList]]"
2857 set s
"these $n files"
2860 set reply
[tk_dialog \
2862 "[appname] ([reponame])" \
2863 "Revert changes in $s?
2865 Any unadded changes will be permanently lost by the revert." \
2875 [concat
$after {set ui_status_value
{Ready.
}}]
2881 proc do_revert_selection
{} {
2882 global current_diff_path selected_paths
2884 if {[array size selected_paths
] > 0} {
2886 {Reverting selected files
} \
2887 [array names selected_paths
]
2888 } elseif
{$current_diff_path ne
{}} {
2890 "Reverting [short_path $current_diff_path]" \
2891 [list
$current_diff_path]
2895 proc do_signoff
{} {
2898 set me
[committer_ident
]
2899 if {$me eq
{}} return
2901 set sob
"Signed-off-by: $me"
2902 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
2903 if {$last ne
$sob} {
2904 $ui_comm edit separator
2906 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
2907 $ui_comm insert end
"\n"
2909 $ui_comm insert end
"\n$sob"
2910 $ui_comm edit separator
2915 proc do_select_commit_type
{} {
2916 global commit_type selected_commit_type
2918 if {$selected_commit_type eq
{new
}
2919 && [string match amend
* $commit_type]} {
2921 } elseif
{$selected_commit_type eq
{amend
}
2922 && ![string match amend
* $commit_type]} {
2925 # The amend request was rejected...
2927 if {![string match amend
* $commit_type]} {
2928 set selected_commit_type new
2938 global appvers copyright
2939 global tcl_patchLevel tk_patchLevel
2943 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2945 label
$w.header
-text "About [appname]" \
2947 pack
$w.header
-side top
-fill x
2950 button
$w.buttons.close
-text {Close
} \
2952 -command [list destroy
$w]
2953 pack
$w.buttons.close
-side right
2954 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2957 -text "[appname] - a commit creation tool for Git.
2965 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
2968 append v
"[appname] version $appvers\n"
2969 append v
"[exec git version]\n"
2971 if {$tcl_patchLevel eq
$tk_patchLevel} {
2972 append v
"Tcl/Tk version $tcl_patchLevel"
2974 append v
"Tcl version $tcl_patchLevel"
2975 append v
", Tk version $tk_patchLevel"
2986 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
2988 menu
$w.ctxm
-tearoff 0
2989 $w.ctxm add
command \
2994 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
2997 bind $w <Visibility
> "grab $w; focus $w"
2998 bind $w <Key-Escape
> "destroy $w"
2999 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3000 wm title
$w "About [appname]"
3004 proc do_options
{} {
3005 global repo_config global_config font_descs
3006 global repo_config_new global_config_new
3008 array
unset repo_config_new
3009 array
unset global_config_new
3010 foreach name
[array names repo_config
] {
3011 set repo_config_new
($name) $repo_config($name)
3014 foreach name
[array names repo_config
] {
3016 gui.diffcontext
{continue}
3018 set repo_config_new
($name) $repo_config($name)
3020 foreach name
[array names global_config
] {
3021 set global_config_new
($name) $global_config($name)
3024 set w .options_editor
3026 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3028 label
$w.header
-text "[appname] Options" \
3030 pack
$w.header
-side top
-fill x
3033 button
$w.buttons.restore
-text {Restore Defaults
} \
3035 -command do_restore_defaults
3036 pack
$w.buttons.restore
-side left
3037 button
$w.buttons.save
-text Save \
3040 catch {eval \[bind \[focus -displayof $w\] <FocusOut>\]}
3043 pack
$w.buttons.save
-side right
3044 button
$w.buttons.cancel
-text {Cancel
} \
3046 -command [list destroy
$w]
3047 pack
$w.buttons.cancel
-side right
-padx 5
3048 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3050 labelframe
$w.repo
-text "[reponame] Repository" \
3052 -relief raised
-borderwidth 2
3053 labelframe
$w.global
-text {Global
(All Repositories
)} \
3055 -relief raised
-borderwidth 2
3056 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3057 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3060 {b pullsummary
{Show Pull Summary
}}
3061 {b trustmtime
{Trust File Modification Timestamps
}}
3062 {i diffcontext
{Number of Diff Context Lines
}}
3063 {t newbranchtemplate
{New Branch Name Template
}}
3065 set type [lindex
$option 0]
3066 set name
[lindex
$option 1]
3067 set text
[lindex
$option 2]
3068 foreach f
{repo global
} {
3071 checkbutton
$w.
$f.
$name -text $text \
3072 -variable ${f}_config_new
(gui.
$name) \
3076 pack
$w.
$f.
$name -side top
-anchor w
3080 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3081 pack
$w.
$f.
$name.l
-side left
-anchor w
-fill x
3082 spinbox
$w.
$f.
$name.v \
3083 -textvariable ${f}_config_new
(gui.
$name) \
3084 -from 1 -to 99 -increment 1 \
3087 bind $w.
$f.
$name.v
<FocusIn
> {%W selection range
0 end
}
3088 pack
$w.
$f.
$name.v
-side right
-anchor e
-padx 5
3089 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3093 label
$w.
$f.
$name.l
-text "$text:" -font font_ui
3094 text
$w.
$f.
$name.v \
3100 $w.
$f.
$name.v insert
0.0 [set ${f}_config_new
(gui.
$name)]
3101 bind $w.
$f.
$name.v
<Shift-Key-Tab
> {focus
[tk_focusPrev
%W
];break}
3102 bind $w.
$f.
$name.v
<Key-Tab
> {focus
[tk_focusNext
%W
];break}
3103 bind $w.
$f.
$name.v
<Key-Return
> break
3104 bind $w.
$f.
$name.v
<FocusIn
> "$w.$f.$name.v tag add sel 0.0 end"
3105 bind $w.
$f.
$name.v
<FocusOut
> "
3106 set ${f}_config_new(gui.$name) \
3107 \[string trim \[$w.$f.$name.v get 0.0 end\]\]
3109 pack
$w.
$f.
$name.l
-side left
-anchor w
3110 pack
$w.
$f.
$name.v
-side left
-anchor w \
3113 pack
$w.
$f.
$name -side top
-anchor w
-fill x
3119 set all_fonts
[lsort
[font families
]]
3120 foreach option
$font_descs {
3121 set name
[lindex
$option 0]
3122 set font
[lindex
$option 1]
3123 set text
[lindex
$option 2]
3125 set global_config_new
(gui.
$font^^family
) \
3126 [font configure
$font -family]
3127 set global_config_new
(gui.
$font^^size
) \
3128 [font configure
$font -size]
3130 frame
$w.global.
$name
3131 label
$w.global.
$name.l
-text "$text:" -font font_ui
3132 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3133 eval tk_optionMenu
$w.global.
$name.family \
3134 global_config_new
(gui.
$font^^family
) \
3136 spinbox
$w.global.
$name.size \
3137 -textvariable global_config_new
(gui.
$font^^size
) \
3138 -from 2 -to 80 -increment 1 \
3141 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3142 pack
$w.global.
$name.size
-side right
-anchor e
3143 pack
$w.global.
$name.family
-side right
-anchor e
3144 pack
$w.global.
$name -side top
-anchor w
-fill x
3147 bind $w <Visibility
> "grab $w; focus $w"
3148 bind $w <Key-Escape
> "destroy $w"
3149 wm title
$w "[appname] ([reponame]): Options"
3153 proc do_restore_defaults
{} {
3154 global font_descs default_config repo_config
3155 global repo_config_new global_config_new
3157 foreach name
[array names default_config
] {
3158 set repo_config_new
($name) $default_config($name)
3159 set global_config_new
($name) $default_config($name)
3162 foreach option
$font_descs {
3163 set name
[lindex
$option 0]
3164 set repo_config
(gui.
$name) $default_config(gui.
$name)
3168 foreach option
$font_descs {
3169 set name
[lindex
$option 0]
3170 set font
[lindex
$option 1]
3171 set global_config_new
(gui.
$font^^family
) \
3172 [font configure
$font -family]
3173 set global_config_new
(gui.
$font^^size
) \
3174 [font configure
$font -size]
3178 proc do_save_config
{w
} {
3179 if {[catch
{save_config
} err
]} {
3180 error_popup
"Failed to completely save options:\n\n$err"
3186 proc do_windows_shortcut
{} {
3190 set desktop
[exec cygpath \
3198 set fn
[tk_getSaveFile \
3200 -title "[appname] ([reponame]): Create Desktop Icon" \
3201 -initialdir $desktop \
3202 -initialfile "Git [reponame].bat"]
3206 set sh
[exec cygpath \
3210 set me
[exec cygpath \
3214 set gd
[exec cygpath \
3218 set gw
[exec cygpath \
3221 [file dirname [gitdir
]]]
3222 regsub
-all ' $me "'\\''" me
3223 regsub -all ' $gd "'\\''" gd
3224 puts $fd "@ECHO Entering $gw"
3225 puts $fd "@ECHO Starting git-gui... please wait..."
3226 puts -nonewline $fd "@\"$sh\" --login -c \""
3227 puts -nonewline $fd "GIT_DIR='$gd'"
3228 puts -nonewline $fd " '$me'"
3232 error_popup "Cannot write script:\n\n$err"
3237 proc do_macosx_app {} {
3240 set fn [tk_getSaveFile \
3242 -title "[appname] ([reponame]): Create Desktop Icon" \
3243 -initialdir [file join $env(HOME) Desktop] \
3244 -initialfile "Git [reponame].app"]
3247 set Contents [file join $fn Contents]
3248 set MacOS [file join $Contents MacOS]
3249 set exe [file join $MacOS git-gui]
3253 set fd [open [file join $Contents Info.plist] w]
3254 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3255 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3256 <plist version="1.0">
3258 <key>CFBundleDevelopmentRegion</key>
3259 <string>English</string>
3260 <key>CFBundleExecutable</key>
3261 <string>git-gui</string>
3262 <key>CFBundleIdentifier</key>
3263 <string>org.spearce.git-gui</string>
3264 <key>CFBundleInfoDictionaryVersion</key>
3265 <string>6.0</string>
3266 <key>CFBundlePackageType</key>
3267 <string>APPL</string>
3268 <key>CFBundleSignature</key>
3269 <string>????</string>
3270 <key>CFBundleVersion</key>
3271 <string>1.0</string>
3272 <key>NSPrincipalClass</key>
3273 <string>NSApplication</string>
3278 set fd [open $exe w]
3279 set gd [file normalize [gitdir]]
3280 set ep [file normalize [exec git --exec-path]]
3281 regsub -all ' $gd "'\\''" gd
3282 regsub
-all ' $ep "'\\''" ep
3283 puts $fd "#!/bin/sh"
3284 foreach name
[array names env
] {
3285 if {[string match GIT_
* $name]} {
3286 regsub
-all ' $env($name) "'\\''" v
3287 puts $fd "export $name='$v'"
3290 puts $fd "export PATH
='$ep':\
$PATH"
3291 puts $fd "export GIT_DIR
='$gd'"
3292 puts $fd "exec [file normalize
$argv0]"
3295 file attributes $exe -permissions u+x,g+x,o+x
3297 error_popup "Cannot
write icon
:\n\n$err"
3302 proc toggle_or_diff {w x y} {
3303 global file_states file_lists current_diff_path ui_index ui_workdir
3304 global last_clicked selected_paths
3306 set pos [split [$w index @$x,$y] .]
3307 set lno [lindex $pos 0]
3308 set col [lindex $pos 1]
3309 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3315 set last_clicked [list $w $lno]
3316 array unset selected_paths
3317 $ui_index tag remove in_sel 0.0 end
3318 $ui_workdir tag remove in_sel 0.0 end
3321 if {$current_diff_path eq $path} {
3322 set after {reshow_diff;}
3326 if {$w eq $ui_index} {
3328 "Unstaging
[short_path
$path] from commit
" \
3330 [concat $after {set ui_status_value {Ready.}}]
3331 } elseif {$w eq $ui_workdir} {
3333 "Adding
[short_path
$path]" \
3335 [concat $after {set ui_status_value {Ready.}}]
3338 show_diff $path $w $lno
3342 proc add_one_to_selection {w x y} {
3343 global file_lists last_clicked selected_paths
3345 set lno [lindex [split [$w index @$x,$y] .] 0]
3346 set path [lindex $file_lists($w) [expr {$lno - 1}]]
3352 if {$last_clicked ne {}
3353 && [lindex $last_clicked 0] ne $w} {
3354 array unset selected_paths
3355 [lindex $last_clicked 0] tag remove in_sel 0.0 end
3358 set last_clicked [list $w $lno]
3359 if {[catch {set in_sel $selected_paths($path)}]} {
3363 unset selected_paths($path)
3364 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
3366 set selected_paths($path) 1
3367 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
3371 proc add_range_to_selection {w x y} {
3372 global file_lists last_clicked selected_paths
3374 if {[lindex $last_clicked 0] ne $w} {
3375 toggle_or_diff $w $x $y
3379 set lno [lindex [split [$w index @$x,$y] .] 0]
3380 set lc [lindex $last_clicked 1]
3389 foreach path [lrange $file_lists($w) \
3390 [expr {$begin - 1}] \
3391 [expr {$end - 1}]] {
3392 set selected_paths($path) 1
3394 $w tag add in_sel $begin.0 [expr {$end + 1}].0
3397 ######################################################################
3401 set cursor_ptr arrow
3402 font create font_diff -family Courier -size 10
3406 eval font configure font_ui [font actual [.dummy cget -font]]
3410 font create font_uibold
3411 font create font_diffbold
3416 } elseif {[is_MacOSX]} {
3424 proc apply_config {} {
3425 global repo_config font_descs
3427 foreach option $font_descs {
3428 set name [lindex $option 0]
3429 set font [lindex $option 1]
3431 foreach {cn cv} $repo_config(gui.$name) {
3432 font configure $font $cn $cv
3435 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
3437 foreach {cn cv} [font configure $font] {
3438 font configure ${font}bold $cn $cv
3440 font configure ${font}bold -weight bold
3444 set default_config(gui.trustmtime) false
3445 set default_config(gui.pullsummary) true
3446 set default_config(gui.diffcontext) 5
3447 set default_config(gui.newbranchtemplate) {}
3448 set default_config(gui.fontui) [font configure font_ui]
3449 set default_config(gui.fontdiff) [font configure font_diff]
3451 {fontui font_ui {Main Font}}
3452 {fontdiff font_diff {Diff/Console Font}}
3457 ######################################################################
3463 menu .mbar -tearoff 0
3464 .mbar add cascade -label Repository -menu .mbar.repository
3465 .mbar add cascade -label Edit -menu .mbar.edit
3466 if {!$single_commit} {
3467 .mbar add cascade -label Branch -menu .mbar.branch
3469 .mbar add cascade -label Commit -menu .mbar.commit
3470 if {!$single_commit} {
3471 .mbar add cascade -label Fetch -menu .mbar.fetch
3472 .mbar add cascade -label Pull -menu .mbar.pull
3473 .mbar add cascade -label Push -menu .mbar.push
3475 . configure -menu .mbar
3477 # -- Repository Menu
3479 menu .mbar.repository
3480 .mbar.repository add command \
3481 -label {Visualize Current Branch} \
3482 -command {do_gitk {}} \
3485 .mbar.repository add command \
3486 -label {Visualize All Branches} \
3487 -command {do_gitk {--all}} \
3490 .mbar.repository add separator
3492 if {!$single_commit} {
3493 .mbar.repository add command -label {Compress Database} \
3497 .mbar.repository add command -label {Verify Database} \
3498 -command do_fsck_objects \
3501 .mbar.repository add separator
3504 .mbar.repository add command \
3505 -label {Create Desktop Icon} \
3506 -command do_windows_shortcut \
3508 } elseif {[is_MacOSX]} {
3509 .mbar.repository add command \
3510 -label {Create Desktop Icon} \
3511 -command do_macosx_app \
3516 .mbar.repository add command -label Quit \
3518 -accelerator $M1T-Q \
3524 .mbar.edit add command -label Undo \
3525 -command {catch {[focus] edit undo}} \
3526 -accelerator $M1T-Z \
3528 .mbar.edit add command -label Redo \
3529 -command {catch {[focus] edit redo}} \
3530 -accelerator $M1T-Y \
3532 .mbar.edit add separator
3533 .mbar.edit add command -label Cut \
3534 -command {catch {tk_textCut [focus]}} \
3535 -accelerator $M1T-X \
3537 .mbar.edit add command -label Copy \
3538 -command {catch {tk_textCopy [focus]}} \
3539 -accelerator $M1T-C \
3541 .mbar.edit add command -label Paste \
3542 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
3543 -accelerator $M1T-V \
3545 .mbar.edit add command -label Delete \
3546 -command {catch {[focus] delete sel.first sel.last}} \
3549 .mbar.edit add separator
3550 .mbar.edit add command -label {Select All} \
3551 -command {catch {[focus] tag add sel 0.0 end}} \
3552 -accelerator $M1T-A \
3557 if {!$single_commit} {
3560 .mbar.branch add command -label {Create...} \
3561 -command do_create_branch \
3562 -accelerator $M1T-N \
3564 lappend disable_on_lock [list .mbar.branch entryconf \
3565 [.mbar.branch index last] -state]
3567 .mbar.branch add command -label {Delete...} \
3568 -command do_delete_branch \
3570 lappend disable_on_lock [list .mbar.branch entryconf \
3571 [.mbar.branch index last] -state]
3578 .mbar.commit add radiobutton \
3579 -label {New Commit} \
3580 -command do_select_commit_type \
3581 -variable selected_commit_type \
3584 lappend disable_on_lock \
3585 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3587 .mbar.commit add radiobutton \
3588 -label {Amend Last Commit} \
3589 -command do_select_commit_type \
3590 -variable selected_commit_type \
3593 lappend disable_on_lock \
3594 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3596 .mbar.commit add separator
3598 .mbar.commit add command -label Rescan \
3599 -command do_rescan \
3602 lappend disable_on_lock \
3603 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3605 .mbar.commit add command -label {Add To Commit} \
3606 -command do_add_selection \
3608 lappend disable_on_lock \
3609 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3611 .mbar.commit add command -label {Add All To Commit} \
3612 -command do_add_all \
3613 -accelerator $M1T-I \
3615 lappend disable_on_lock \
3616 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3618 .mbar.commit add command -label {Unstage From Commit} \
3619 -command do_unstage_selection \
3621 lappend disable_on_lock \
3622 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3624 .mbar.commit add command -label {Revert Changes} \
3625 -command do_revert_selection \
3627 lappend disable_on_lock \
3628 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3630 .mbar.commit add separator
3632 .mbar.commit add command -label {Sign Off} \
3633 -command do_signoff \
3634 -accelerator $M1T-S \
3637 .mbar.commit add command -label Commit \
3638 -command do_commit \
3639 -accelerator $M1T-Return \
3641 lappend disable_on_lock \
3642 [list .mbar.commit entryconf [.mbar.commit index last] -state]
3644 # -- Transport menus
3646 if {!$single_commit} {
3653 # -- Apple Menu (Mac OS X only)
3655 .mbar add cascade -label Apple -menu .mbar.apple
3658 .mbar.apple add command -label "About
[appname
]" \
3661 .mbar.apple add command -label "[appname
] Options...
" \
3662 -command do_options \
3667 .mbar.edit add separator
3668 .mbar.edit add command -label {Options...} \
3669 -command do_options \
3674 if {[file exists /usr/local/miga/lib/gui-miga]
3675 && [file exists .pvcsrc]} {
3677 global ui_status_value
3678 if {![lock_index update]} return
3679 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
3680 set miga_fd [open "|
$cmd" r]
3681 fconfigure $miga_fd -blocking 0
3682 fileevent $miga_fd readable [list miga_done $miga_fd]
3683 set ui_status_value {Running miga...}
3685 proc miga_done {fd} {
3690 rescan [list set ui_status_value {Ready.}]
3693 .mbar add cascade -label Tools -menu .mbar.tools
3695 .mbar.tools add command -label "Migrate
" \
3698 lappend disable_on_lock \
3699 [list .mbar.tools entryconf [.mbar.tools index last] -state]
3704 .mbar add cascade -label Help -menu .mbar.help
3707 .mbar.help add command -label "About
[appname
]" \
3719 -text {Current Branch:} \
3724 -textvariable current_branch \
3728 pack .branch.l1 -side left
3729 pack .branch.cb -side left -fill x
3730 pack .branch -side top -fill x
3732 # -- Main Window Layout
3734 panedwindow .vpane -orient vertical
3735 panedwindow .vpane.files -orient horizontal
3736 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3737 pack .vpane -anchor n -side top -fill both -expand 1
3739 # -- Index File List
3741 frame .vpane.files.index -height 100 -width 200
3742 label .vpane.files.index.title -text {Changes To Be Committed} \
3745 text $ui_index -background white -borderwidth 0 \
3746 -width 20 -height 10 \
3749 -cursor $cursor_ptr \
3750 -xscrollcommand {.vpane.files.index.sx set} \
3751 -yscrollcommand {.vpane.files.index.sy set} \
3753 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3754 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3755 pack .vpane.files.index.title -side top -fill x
3756 pack .vpane.files.index.sx -side bottom -fill x
3757 pack .vpane.files.index.sy -side right -fill y
3758 pack $ui_index -side left -fill both -expand 1
3759 .vpane.files add .vpane.files.index -sticky nsew
3761 # -- Working Directory File List
3763 frame .vpane.files.workdir -height 100 -width 200
3764 label .vpane.files.workdir.title -text {Changed But Not Updated} \
3767 text $ui_workdir -background white -borderwidth 0 \
3768 -width 20 -height 10 \
3771 -cursor $cursor_ptr \
3772 -xscrollcommand {.vpane.files.workdir.sx set} \
3773 -yscrollcommand {.vpane.files.workdir.sy set} \
3775 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3776 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3777 pack .vpane.files.workdir.title -side top -fill x
3778 pack .vpane.files.workdir.sx -side bottom -fill x
3779 pack .vpane.files.workdir.sy -side right -fill y
3780 pack $ui_workdir -side left -fill both -expand 1
3781 .vpane.files add .vpane.files.workdir -sticky nsew
3783 foreach i [list $ui_index $ui_workdir] {
3784 $i tag conf in_diff -font font_uibold
3785 $i tag conf in_sel \
3786 -background [$i cget -foreground] \
3787 -foreground [$i cget -background]
3791 # -- Diff and Commit Area
3793 frame .vpane.lower -height 300 -width 400
3794 frame .vpane.lower.commarea
3795 frame .vpane.lower.diff -relief sunken -borderwidth 1
3796 pack .vpane.lower.commarea -side top -fill x
3797 pack .vpane.lower.diff -side bottom -fill both -expand 1
3798 .vpane add .vpane.lower -stick nsew
3800 # -- Commit Area Buttons
3802 frame .vpane.lower.commarea.buttons
3803 label .vpane.lower.commarea.buttons.l -text {} \
3807 pack .vpane.lower.commarea.buttons.l -side top -fill x
3808 pack .vpane.lower.commarea.buttons -side left -fill y
3810 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
3811 -command do_rescan \
3813 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3814 lappend disable_on_lock \
3815 {.vpane.lower.commarea.buttons.rescan conf -state}
3817 button .vpane.lower.commarea.buttons.incall -text {Add All} \
3818 -command do_add_all \
3820 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3821 lappend disable_on_lock \
3822 {.vpane.lower.commarea.buttons.incall conf -state}
3824 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
3825 -command do_signoff \
3827 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3829 button .vpane.lower.commarea.buttons.commit -text {Commit} \
3830 -command do_commit \
3832 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3833 lappend disable_on_lock \
3834 {.vpane.lower.commarea.buttons.commit conf -state}
3836 # -- Commit Message Buffer
3838 frame .vpane.lower.commarea.buffer
3839 frame .vpane.lower.commarea.buffer.header
3840 set ui_comm .vpane.lower.commarea.buffer.t
3841 set ui_coml .vpane.lower.commarea.buffer.header.l
3842 radiobutton .vpane.lower.commarea.buffer.header.new \
3843 -text {New Commit} \
3844 -command do_select_commit_type \
3845 -variable selected_commit_type \
3848 lappend disable_on_lock \
3849 [list .vpane.lower.commarea.buffer.header.new conf -state]
3850 radiobutton .vpane.lower.commarea.buffer.header.amend \
3851 -text {Amend Last Commit} \
3852 -command do_select_commit_type \
3853 -variable selected_commit_type \
3856 lappend disable_on_lock \
3857 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3862 proc trace_commit_type {varname args} {
3863 global ui_coml commit_type
3864 switch -glob -- $commit_type {
3865 initial {set txt {Initial Commit Message:}}
3866 amend {set txt {Amended Commit Message:}}
3867 amend-initial {set txt {Amended Initial Commit Message:}}
3868 amend-merge {set txt {Amended Merge Commit Message:}}
3869 merge {set txt {Merge Commit Message:}}
3870 * {set txt {Commit Message:}}
3872 $ui_coml conf -text $txt
3874 trace add variable commit_type write trace_commit_type
3875 pack $ui_coml -side left -fill x
3876 pack .vpane.lower.commarea.buffer.header.amend -side right
3877 pack .vpane.lower.commarea.buffer.header.new -side right
3879 text $ui_comm -background white -borderwidth 1 \
3882 -autoseparators true \
3884 -width 75 -height 9 -wrap none \
3886 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3887 scrollbar .vpane.lower.commarea.buffer.sby \
3888 -command [list $ui_comm yview]
3889 pack .vpane.lower.commarea.buffer.header -side top -fill x
3890 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3891 pack $ui_comm -side left -fill y
3892 pack .vpane.lower.commarea.buffer -side left -fill y
3894 # -- Commit Message Buffer Context Menu
3896 set ctxm .vpane.lower.commarea.buffer.ctxm
3897 menu $ctxm -tearoff 0
3901 -command {tk_textCut $ui_comm}
3905 -command {tk_textCopy $ui_comm}
3909 -command {tk_textPaste $ui_comm}
3913 -command {$ui_comm delete sel.first sel.last}
3916 -label {Select All} \
3918 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3923 $ui_comm tag add sel 0.0 end
3924 tk_textCopy $ui_comm
3925 $ui_comm tag remove sel 0.0 end
3932 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
3936 set current_diff_path {}
3937 set diff_actions [list]
3938 proc trace_current_diff_path {varname args} {
3939 global current_diff_path diff_actions file_states
3940 if {$current_diff_path eq {}} {
3946 set p $current_diff_path
3947 set s [mapdesc [lindex $file_states($p) 0] $p]
3949 set p [escape_path $p]
3953 .vpane.lower.diff.header.status configure -text $s
3954 .vpane.lower.diff.header.file configure -text $f
3955 .vpane.lower.diff.header.path configure -text $p
3956 foreach w $diff_actions {
3960 trace add variable current_diff_path write trace_current_diff_path
3962 frame .vpane.lower.diff.header -background orange
3963 label .vpane.lower.diff.header.status \
3964 -background orange \
3965 -width $max_status_desc \
3969 label .vpane.lower.diff.header.file \
3970 -background orange \
3974 label .vpane.lower.diff.header.path \
3975 -background orange \
3979 pack .vpane.lower.diff.header.status -side left
3980 pack .vpane.lower.diff.header.file -side left
3981 pack .vpane.lower.diff.header.path -fill x
3982 set ctxm .vpane.lower.diff.header.ctxm
3983 menu $ctxm -tearoff 0
3992 -- $current_diff_path
3994 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3995 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
3999 frame .vpane.lower.diff.body
4000 set ui_diff .vpane.lower.diff.body.t
4001 text $ui_diff -background white -borderwidth 0 \
4002 -width 80 -height 15 -wrap none \
4004 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4005 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4007 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4008 -command [list $ui_diff xview]
4009 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4010 -command [list $ui_diff yview]
4011 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4012 pack .vpane.lower.diff.body.sby -side right -fill y
4013 pack $ui_diff -side left -fill both -expand 1
4014 pack .vpane.lower.diff.header -side top -fill x
4015 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4017 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4018 $ui_diff tag conf d_+ -foreground {#00a000}
4019 $ui_diff tag conf d_- -foreground red
4021 $ui_diff tag conf d_++ -foreground {#00a000}
4022 $ui_diff tag conf d_-- -foreground red
4023 $ui_diff tag conf d_+s \
4024 -foreground {#00a000} \
4025 -background {#e2effa}
4026 $ui_diff tag conf d_-s \
4028 -background {#e2effa}
4029 $ui_diff tag conf d_s+ \
4030 -foreground {#00a000} \
4032 $ui_diff tag conf d_s- \
4036 $ui_diff tag conf d<<<<<<< \
4037 -foreground orange \
4039 $ui_diff tag conf d======= \
4040 -foreground orange \
4042 $ui_diff tag conf d>>>>>>> \
4043 -foreground orange \
4046 $ui_diff tag raise sel
4048 # -- Diff Body Context Menu
4050 set ctxm .vpane.lower.diff.body.ctxm
4051 menu $ctxm -tearoff 0
4055 -command reshow_diff
4059 -command {tk_textCopy $ui_diff}
4060 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4062 -label {Select All} \
4064 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4065 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4070 $ui_diff tag add sel 0.0 end
4071 tk_textCopy $ui_diff
4072 $ui_diff tag remove sel 0.0 end
4074 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4077 -label {Decrease Font Size} \
4079 -command {incr_font_size font_diff -1}
4080 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4082 -label {Increase Font Size} \
4084 -command {incr_font_size font_diff 1}
4085 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4088 -label {Show Less Context} \
4090 -command {if {$repo_config(gui.diffcontext) >= 2} {
4091 incr repo_config(gui.diffcontext) -1
4094 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4096 -label {Show More Context} \
4099 incr repo_config(gui.diffcontext)
4102 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4104 $ctxm add command -label {Options...} \
4107 bind_button3 $ui_diff "tk_popup
$ctxm %X
%Y
"
4111 set ui_status_value {Initializing...}
4112 label .status -textvariable ui_status_value \
4118 pack .status -anchor w -side bottom -fill x
4123 set gm $repo_config(gui.geometry)
4124 wm geometry . [lindex $gm 0]
4125 .vpane sash place 0 \
4126 [lindex [.vpane sash coord 0] 0] \
4128 .vpane.files sash place 0 \
4130 [lindex [.vpane.files sash coord 0] 1]
4136 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4137 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4138 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4139 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4140 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4141 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4142 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4143 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4144 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4145 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4146 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4148 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4149 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4150 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4151 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4152 bind $ui_diff <$M1B-Key-v> {break}
4153 bind $ui_diff <$M1B-Key-V> {break}
4154 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4155 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4156 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4157 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4158 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4159 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4161 if {!$single_commit} {
4162 bind . <$M1B-Key-n> do_create_branch
4163 bind . <$M1B-Key-N> do_create_branch
4166 bind . <Destroy> do_quit
4167 bind all <Key-F5> do_rescan
4168 bind all <$M1B-Key-r> do_rescan
4169 bind all <$M1B-Key-R> do_rescan
4170 bind . <$M1B-Key-s> do_signoff
4171 bind . <$M1B-Key-S> do_signoff
4172 bind . <$M1B-Key-i> do_add_all
4173 bind . <$M1B-Key-I> do_add_all
4174 bind . <$M1B-Key-Return> do_commit
4175 bind all <$M1B-Key-q> do_quit
4176 bind all <$M1B-Key-Q> do_quit
4177 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4178 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4179 foreach i [list $ui_index $ui_workdir] {
4180 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4181 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4182 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4186 set file_lists($ui_index) [list]
4187 set file_lists($ui_workdir) [list]
4191 set MERGE_HEAD [list]
4194 set current_branch {}
4195 set current_diff_path {}
4196 set selected_commit_type new
4198 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4199 focus -force $ui_comm
4201 # -- Warn the user about environmental problems. Cygwin's Tcl
4202 # does *not* pass its env array onto any processes it spawns.
4203 # This means that git processes get none of our environment.
4208 set msg "Possible environment issues exist.
4210 The following environment variables are probably
4211 going to be ignored by any Git subprocess run
4215 foreach name [array names env] {
4216 switch -regexp -- $name {
4217 {^GIT_INDEX_FILE$} -
4218 {^GIT_OBJECT_DIRECTORY$} -
4219 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4221 {^GIT_EXTERNAL_DIFF$} -
4225 {^GIT_CONFIG_LOCAL$} -
4226 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4227 append msg " - $name\n"
4230 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4231 append msg " - $name\n"
4233 set suggest_user $name
4237 if {$ignored_env > 0} {
4239 This is due to a known issue with the
4240 Tcl binary distributed by Cygwin.
"
4242 if {$suggest_user ne {}} {
4245 A good replacement
for $suggest_user
4246 is placing values
for the user.name and
4247 user.email settings into your personal
4253 unset ignored_env msg suggest_user name
4256 # -- Only initialize complex UI if we are going to stay running.
4258 if {!$single_commit} {
4262 populate_branch_menu
4263 populate_fetch_menu .mbar.fetch
4264 populate_pull_menu .mbar.pull
4265 populate_push_menu .mbar.push
4268 # -- Only suggest a gc run if we are going to stay running.
4270 if {!$single_commit} {
4271 set object_limit 2000
4272 if {[is_Windows]} {set object_limit 200}
4273 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
4274 if {$objects_current >= $object_limit} {
4276 "This repository currently has
$objects_current loose objects.
4278 To maintain optimal performance it is strongly
4279 recommended that you
compress the database
4280 when
more than
$object_limit loose objects exist.
4282 Compress the database now?
"] eq yes} {
4286 unset object_limit _junk objects_current
4289 lock_index begin-read