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 is_config_true
{name
} {
65 if {[catch
{set v
$repo_config($name)}]} {
67 } elseif
{$v eq
{true
} ||
$v eq
{1} ||
$v eq
{yes}} {
74 proc load_config
{include_global
} {
75 global repo_config global_config default_config
77 array
unset global_config
78 if {$include_global} {
80 set fd_rc
[open
"| git repo-config --global --list" r
]
81 while {[gets
$fd_rc line
] >= 0} {
82 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
83 if {[is_many_config
$name]} {
84 lappend global_config
($name) $value
86 set global_config
($name) $value
94 array
unset repo_config
96 set fd_rc
[open
"| git repo-config --list" r
]
97 while {[gets
$fd_rc line
] >= 0} {
98 if {[regexp
{^
([^
=]+)=(.
*)$
} $line line name value
]} {
99 if {[is_many_config
$name]} {
100 lappend repo_config
($name) $value
102 set repo_config
($name) $value
109 foreach name
[array names default_config
] {
110 if {[catch
{set v
$global_config($name)}]} {
111 set global_config
($name) $default_config($name)
113 if {[catch
{set v
$repo_config($name)}]} {
114 set repo_config
($name) $default_config($name)
119 proc save_config
{} {
120 global default_config font_descs
121 global repo_config global_config
122 global repo_config_new global_config_new
124 foreach option
$font_descs {
125 set name
[lindex
$option 0]
126 set font
[lindex
$option 1]
127 font configure
$font \
128 -family $global_config_new(gui.
$font^^family
) \
129 -size $global_config_new(gui.
$font^^size
)
130 font configure
${font}bold \
131 -family $global_config_new(gui.
$font^^family
) \
132 -size $global_config_new(gui.
$font^^size
)
133 set global_config_new
(gui.
$name) [font configure
$font]
134 unset global_config_new
(gui.
$font^^family
)
135 unset global_config_new
(gui.
$font^^size
)
138 foreach name
[array names default_config
] {
139 set value
$global_config_new($name)
140 if {$value ne
$global_config($name)} {
141 if {$value eq
$default_config($name)} {
142 catch
{exec git repo-config
--global --unset $name}
144 regsub
-all "\[{}\]" $value {"} value
145 exec git repo-config --global $name $value
147 set global_config($name) $value
148 if {$value eq $repo_config($name)} {
149 catch {exec git repo-config --unset $name}
150 set repo_config($name) $value
155 foreach name [array names default_config] {
156 set value $repo_config_new($name)
157 if {$value ne $repo_config($name)} {
158 if {$value eq $global_config($name)} {
159 catch {exec git repo-config --unset $name}
161 regsub -all "\
[{}\
]" $value {"} value
162 exec git repo-config
$name $value
164 set repo_config
($name) $value
169 proc error_popup
{msg
} {
171 if {[reponame
] ne
{}} {
172 append title
" ([reponame])"
174 set cmd
[list tk_messageBox \
177 -title "$title: error" \
179 if {[winfo ismapped .
]} {
180 lappend cmd
-parent .
185 proc warn_popup
{msg
} {
187 if {[reponame
] ne
{}} {
188 append title
" ([reponame])"
190 set cmd
[list tk_messageBox \
193 -title "$title: warning" \
195 if {[winfo ismapped .
]} {
196 lappend cmd
-parent .
201 proc info_popup
{msg
{parent .
}} {
203 if {[reponame
] ne
{}} {
204 append title
" ([reponame])"
214 proc ask_popup
{msg
} {
216 if {[reponame
] ne
{}} {
217 append title
" ([reponame])"
219 return [tk_messageBox \
227 ######################################################################
231 if { [catch
{set _gitdir
$env(GIT_DIR
)}]
232 && [catch
{set _gitdir
[exec git rev-parse
--git-dir]} err
]} {
233 catch
{wm withdraw .
}
234 error_popup
"Cannot find the git directory:\n\n$err"
237 if {![file isdirectory
$_gitdir]} {
238 catch
{wm withdraw .
}
239 error_popup
"Git directory not found:\n\n$_gitdir"
242 if {[lindex
[file split $_gitdir] end
] ne
{.git
}} {
243 catch
{wm withdraw .
}
244 error_popup
"Cannot use funny .git directory:\n\n$gitdir"
247 if {[catch
{cd [file dirname $_gitdir]} err
]} {
248 catch
{wm withdraw .
}
249 error_popup
"No working directory [file dirname $_gitdir]:\n\n$err"
252 set _reponame
[lindex
[file split \
253 [file normalize
[file dirname $_gitdir]]] \
257 if {[appname
] eq
{git-citool
}} {
261 ######################################################################
269 set disable_on_lock
[list
]
270 set index_lock_type none
272 proc lock_index
{type} {
273 global index_lock_type disable_on_lock
275 if {$index_lock_type eq
{none
}} {
276 set index_lock_type
$type
277 foreach w
$disable_on_lock {
278 uplevel
#0 $w disabled
281 } elseif
{$index_lock_type eq
"begin-$type"} {
282 set index_lock_type
$type
288 proc unlock_index
{} {
289 global index_lock_type disable_on_lock
291 set index_lock_type none
292 foreach w
$disable_on_lock {
297 ######################################################################
301 proc repository_state
{ctvar hdvar mhvar
} {
302 global current_branch
303 upvar
$ctvar ct
$hdvar hd
$mhvar mh
307 if {[catch
{set current_branch
[exec git symbolic-ref HEAD
]}]} {
308 set current_branch
{}
310 regsub ^refs
/((heads|tags|remotes
)/)? \
316 if {[catch
{set hd
[exec git rev-parse
--verify HEAD
]}]} {
322 set merge_head
[gitdir MERGE_HEAD
]
323 if {[file exists
$merge_head]} {
325 set fd_mh
[open
$merge_head r
]
326 while {[gets
$fd_mh line
] >= 0} {
337 global PARENT empty_tree
339 set p
[lindex
$PARENT 0]
343 if {$empty_tree eq
{}} {
344 set empty_tree
[exec git mktree
<< {}]
349 proc rescan
{after
{honor_trustmtime
1}} {
350 global HEAD PARENT MERGE_HEAD commit_type
351 global ui_index ui_workdir ui_status_value ui_comm
352 global rescan_active file_states
355 if {$rescan_active > 0 ||
![lock_index
read]} return
357 repository_state newType newHEAD newMERGE_HEAD
358 if {[string match amend
* $commit_type]
359 && $newType eq
{normal
}
360 && $newHEAD eq
$HEAD} {
364 set MERGE_HEAD
$newMERGE_HEAD
365 set commit_type
$newType
368 array
unset file_states
370 if {![$ui_comm edit modified
]
371 ||
[string trim
[$ui_comm get
0.0 end
]] eq
{}} {
372 if {[load_message GITGUI_MSG
]} {
373 } elseif
{[load_message MERGE_MSG
]} {
374 } elseif
{[load_message SQUASH_MSG
]} {
377 $ui_comm edit modified false
380 if {$honor_trustmtime && $repo_config(gui.trustmtime
) eq
{true
}} {
381 rescan_stage2
{} $after
384 set ui_status_value
{Refreshing
file status...
}
385 set cmd
[list git update-index
]
387 lappend cmd
--unmerged
388 lappend cmd
--ignore-missing
389 lappend cmd
--refresh
390 set fd_rf
[open
"| $cmd" r
]
391 fconfigure
$fd_rf -blocking 0 -translation binary
392 fileevent
$fd_rf readable \
393 [list rescan_stage2
$fd_rf $after]
397 proc rescan_stage2
{fd after
} {
398 global ui_status_value
399 global rescan_active buf_rdi buf_rdf buf_rlo
403 if {![eof
$fd]} return
407 set ls_others
[list | git ls-files
--others -z \
408 --exclude-per-directory=.gitignore
]
409 set info_exclude
[gitdir info exclude
]
410 if {[file readable
$info_exclude]} {
411 lappend ls_others
"--exclude-from=$info_exclude"
419 set ui_status_value
{Scanning
for modified files ...
}
420 set fd_di
[open
"| git diff-index --cached -z [PARENT]" r
]
421 set fd_df
[open
"| git diff-files -z" r
]
422 set fd_lo
[open
$ls_others r
]
424 fconfigure
$fd_di -blocking 0 -translation binary
-encoding binary
425 fconfigure
$fd_df -blocking 0 -translation binary
-encoding binary
426 fconfigure
$fd_lo -blocking 0 -translation binary
-encoding binary
427 fileevent
$fd_di readable
[list read_diff_index
$fd_di $after]
428 fileevent
$fd_df readable
[list read_diff_files
$fd_df $after]
429 fileevent
$fd_lo readable
[list read_ls_others
$fd_lo $after]
432 proc load_message
{file} {
436 if {[file isfile
$f]} {
437 if {[catch
{set fd
[open
$f r
]}]} {
440 set content
[string trim
[read $fd]]
442 regsub
-all -line {[ \r\t]+$
} $content {} content
443 $ui_comm delete
0.0 end
444 $ui_comm insert end
$content
450 proc read_diff_index
{fd after
} {
453 append buf_rdi
[read $fd]
455 set n
[string length
$buf_rdi]
457 set z1
[string first
"\0" $buf_rdi $c]
460 set z2
[string first
"\0" $buf_rdi $z1]
464 set i
[split [string range
$buf_rdi $c [expr {$z1 - 2}]] { }]
465 set p
[string range
$buf_rdi $z1 [expr {$z2 - 1}]]
467 [encoding convertfrom
$p] \
469 [list
[lindex
$i 0] [lindex
$i 2]] \
475 set buf_rdi
[string range
$buf_rdi $c end
]
480 rescan_done
$fd buf_rdi
$after
483 proc read_diff_files
{fd after
} {
486 append buf_rdf
[read $fd]
488 set n
[string length
$buf_rdf]
490 set z1
[string first
"\0" $buf_rdf $c]
493 set z2
[string first
"\0" $buf_rdf $z1]
497 set i
[split [string range
$buf_rdf $c [expr {$z1 - 2}]] { }]
498 set p
[string range
$buf_rdf $z1 [expr {$z2 - 1}]]
500 [encoding convertfrom
$p] \
503 [list
[lindex
$i 0] [lindex
$i 2]]
508 set buf_rdf
[string range
$buf_rdf $c end
]
513 rescan_done
$fd buf_rdf
$after
516 proc read_ls_others
{fd after
} {
519 append buf_rlo
[read $fd]
520 set pck
[split $buf_rlo "\0"]
521 set buf_rlo
[lindex
$pck end
]
522 foreach p
[lrange
$pck 0 end-1
] {
523 merge_state
[encoding convertfrom
$p] ?O
525 rescan_done
$fd buf_rlo
$after
528 proc rescan_done
{fd buf after
} {
530 global file_states repo_config
533 if {![eof
$fd]} return
536 if {[incr rescan_active
-1] > 0} return
545 proc prune_selection
{} {
546 global file_states selected_paths
548 foreach path
[array names selected_paths
] {
549 if {[catch
{set still_here
$file_states($path)}]} {
550 unset selected_paths
($path)
555 ######################################################################
560 global ui_diff current_diff_path current_diff_header
561 global ui_index ui_workdir
563 $ui_diff conf
-state normal
564 $ui_diff delete
0.0 end
565 $ui_diff conf
-state disabled
567 set current_diff_path
{}
568 set current_diff_header
{}
570 $ui_index tag remove in_diff
0.0 end
571 $ui_workdir tag remove in_diff
0.0 end
574 proc reshow_diff
{} {
575 global ui_status_value file_states file_lists
576 global current_diff_path current_diff_side
578 set p
$current_diff_path
580 ||
$current_diff_side eq
{}
581 ||
[catch
{set s
$file_states($p)}]
582 ||
[lsearch
-sorted -exact $file_lists($current_diff_side) $p] == -1} {
585 show_diff
$p $current_diff_side
589 proc handle_empty_diff
{} {
590 global current_diff_path file_states file_lists
592 set path
$current_diff_path
593 set s
$file_states($path)
594 if {[lindex
$s 0] ne
{_M
}} return
596 info_popup
"No differences detected.
598 [short_path $path] has no changes.
600 The modification date of this file was updated
601 by another application, but the content within
602 the file was not changed.
604 A rescan will be automatically started to find
605 other files which may have the same state."
608 display_file
$path __
609 rescan
{set ui_status_value
{Ready.
}} 0
612 proc show_diff
{path w
{lno
{}}} {
613 global file_states file_lists
614 global is_3way_diff diff_active repo_config
615 global ui_diff ui_status_value ui_index ui_workdir
616 global current_diff_path current_diff_side current_diff_header
618 if {$diff_active ||
![lock_index
read]} return
622 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
628 $w tag add in_diff
$lno.0 [expr {$lno + 1}].0
631 set s
$file_states($path)
635 set current_diff_path
$path
636 set current_diff_side
$w
637 set current_diff_header
{}
638 set ui_status_value
"Loading diff of [escape_path $path]..."
640 # - Git won't give us the diff, there's nothing to compare to!
643 set max_sz
[expr {128 * 1024}]
645 set fd
[open
$path r
]
646 set content
[read $fd $max_sz]
648 set sz
[file size
$path]
652 set ui_status_value
"Unable to display [escape_path $path]"
653 error_popup
"Error loading file:\n\n$err"
656 $ui_diff conf
-state normal
657 if {![catch
{set type [exec file $path]}]} {
658 set n
[string length
$path]
659 if {[string equal
-length $n $path $type]} {
660 set type [string range
$type $n end
]
661 regsub
{^
:?\s
*} $type {} type
663 $ui_diff insert end
"* $type\n" d_@
665 if {[string first
"\0" $content] != -1} {
666 $ui_diff insert end \
667 "* Binary file (not showing content)." \
671 $ui_diff insert end \
672 "* Untracked file is $sz bytes.
673 * Showing only first $max_sz bytes.
676 $ui_diff insert end
$content
678 $ui_diff insert end
"
679 * Untracked file clipped here by [appname].
680 * To see the entire file, use an external editor.
684 $ui_diff conf
-state disabled
687 set ui_status_value
{Ready.
}
692 if {$w eq
$ui_index} {
693 lappend cmd diff-index
695 } elseif
{$w eq
$ui_workdir} {
696 if {[string index
$m 0] eq
{U
}} {
699 lappend cmd diff-files
704 lappend cmd
--no-color
705 if {$repo_config(gui.diffcontext
) > 0} {
706 lappend cmd
"-U$repo_config(gui.diffcontext)"
708 if {$w eq
$ui_index} {
714 if {[catch
{set fd
[open
$cmd r
]} err
]} {
717 set ui_status_value
"Unable to display [escape_path $path]"
718 error_popup
"Error loading diff:\n\n$err"
726 fileevent
$fd readable
[list read_diff
$fd]
729 proc read_diff
{fd
} {
730 global ui_diff ui_status_value diff_active
731 global is_3way_diff current_diff_header
733 $ui_diff conf
-state normal
734 while {[gets
$fd line
] >= 0} {
735 # -- Cleanup uninteresting diff header lines.
737 if { [string match
{diff --git *} $line]
738 ||
[string match
{diff --cc *} $line]
739 ||
[string match
{diff --combined *} $line]
740 ||
[string match
{--- *} $line]
741 ||
[string match
{+++ *} $line]} {
742 append current_diff_header
$line "\n"
745 if {[string match
{index
*} $line]} continue
746 if {$line eq
{deleted
file mode
120000}} {
747 set line
"deleted symlink"
750 # -- Automatically detect if this is a 3 way diff.
752 if {[string match
{@@@
*} $line]} {set is_3way_diff
1}
754 if {[string match
{mode
*} $line]
755 ||
[string match
{new
file *} $line]
756 ||
[string match
{deleted
file *} $line]
757 ||
[string match
{Binary files
* and
* differ
} $line]
758 ||
$line eq
{\ No newline
at end of
file}
759 ||
[regexp
{^\
* Unmerged path
} $line]} {
761 } elseif
{$is_3way_diff} {
762 set op
[string range
$line 0 1]
772 if {[regexp
{^\
+\
+([<>]{7} |
={7})} $line _g op
]} {
773 set line
[string replace
$line 0 1 { }]
780 puts
"error: Unhandled 3 way diff marker: {$op}"
785 set op
[string index
$line 0]
791 if {[regexp
{^\
+([<>]{7} |
={7})} $line _g op
]} {
792 set line
[string replace
$line 0 0 { }]
799 puts
"error: Unhandled 2 way diff marker: {$op}"
804 $ui_diff insert end
$line $tags
805 if {[string index
$line end
] eq
"\r"} {
806 $ui_diff tag add d_cr
{end
- 2c
}
808 $ui_diff insert end
"\n" $tags
810 $ui_diff conf
-state disabled
816 set ui_status_value
{Ready.
}
818 if {[$ui_diff index end
] eq
{2.0}} {
824 proc apply_hunk
{x y
} {
825 global current_diff_path current_diff_header current_diff_side
826 global ui_diff ui_index file_states
828 if {$current_diff_path eq
{} ||
$current_diff_header eq
{}} return
829 if {![lock_index apply_hunk
]} return
831 set apply_cmd
{git apply
--cached --whitespace=nowarn
}
832 set mi
[lindex
$file_states($current_diff_path) 0]
833 if {$current_diff_side eq
$ui_index} {
835 lappend apply_cmd
--reverse
836 if {[string index
$mi 0] ne
{M
}} {
842 if {[string index
$mi 1] ne
{M
}} {
848 set s_lno
[lindex
[split [$ui_diff index @
$x,$y] .
] 0]
849 set s_lno
[$ui_diff search
-backwards -regexp ^@@
$s_lno.0 0.0]
855 set e_lno
[$ui_diff search
-forwards -regexp ^@@
"$s_lno + 1 lines" end
]
861 set p
[open
"| $apply_cmd" w
]
862 fconfigure
$p -translation binary
-encoding binary
863 puts
-nonewline $p $current_diff_header
864 puts
-nonewline $p [$ui_diff get
$s_lno $e_lno]
866 error_popup
"Failed to $mode selected hunk.\n\n$err"
871 $ui_diff conf
-state normal
872 $ui_diff delete
$s_lno $e_lno
873 $ui_diff conf
-state disabled
875 if {[$ui_diff get
1.0 end
] eq
"\n"} {
881 if {$current_diff_side eq
$ui_index} {
883 } elseif
{[string index
$mi 0] eq
{_
}} {
889 display_file
$current_diff_path $mi
895 ######################################################################
899 proc load_last_commit
{} {
900 global HEAD PARENT MERGE_HEAD commit_type ui_comm
903 if {[llength
$PARENT] == 0} {
904 error_popup
{There is nothing to amend.
906 You are about to create the initial commit.
907 There is no commit before this to amend.
912 repository_state curType curHEAD curMERGE_HEAD
913 if {$curType eq
{merge
}} {
914 error_popup
{Cannot amend
while merging.
916 You are currently
in the middle of a merge that
917 has not been fully completed. You cannot amend
918 the prior commit unless you first abort the
919 current merge activity.
927 set fd
[open
"| git cat-file commit $curHEAD" r
]
928 fconfigure
$fd -encoding binary
-translation lf
929 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
932 while {[gets
$fd line
] > 0} {
933 if {[string match
{parent
*} $line]} {
934 lappend parents
[string range
$line 7 end
]
935 } elseif
{[string match
{encoding
*} $line]} {
936 set enc
[string tolower
[string range
$line 9 end
]]
939 fconfigure
$fd -encoding $enc
940 set msg
[string trim
[read $fd]]
943 error_popup
"Error loading commit data for amend:\n\n$err"
949 set MERGE_HEAD
[list
]
950 switch
-- [llength
$parents] {
951 0 {set commit_type amend-initial
}
952 1 {set commit_type amend
}
953 default
{set commit_type amend-merge
}
956 $ui_comm delete
0.0 end
957 $ui_comm insert end
$msg
959 $ui_comm edit modified false
960 rescan
{set ui_status_value
{Ready.
}}
963 proc create_new_commit
{} {
964 global commit_type ui_comm
966 set commit_type normal
967 $ui_comm delete
0.0 end
969 $ui_comm edit modified false
970 rescan
{set ui_status_value
{Ready.
}}
973 set GIT_COMMITTER_IDENT
{}
975 proc committer_ident
{} {
976 global GIT_COMMITTER_IDENT
978 if {$GIT_COMMITTER_IDENT eq
{}} {
979 if {[catch
{set me
[exec git var GIT_COMMITTER_IDENT
]} err
]} {
980 error_popup
"Unable to obtain your identity:\n\n$err"
983 if {![regexp
{^
(.
*) [0-9]+ [-+0-9]+$
} \
984 $me me GIT_COMMITTER_IDENT
]} {
985 error_popup
"Invalid GIT_COMMITTER_IDENT:\n\n$me"
990 return $GIT_COMMITTER_IDENT
993 proc commit_tree
{} {
994 global HEAD commit_type file_states ui_comm repo_config
995 global ui_status_value pch_error
997 if {[committer_ident
] eq
{}} return
998 if {![lock_index update
]} return
1000 # -- Our in memory state should match the repository.
1002 repository_state curType curHEAD curMERGE_HEAD
1003 if {[string match amend
* $commit_type]
1004 && $curType eq
{normal
}
1005 && $curHEAD eq
$HEAD} {
1006 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
1007 info_popup
{Last scanned state does not match repository state.
1009 Another Git program has modified this repository
1010 since the last scan. A rescan must be performed
1011 before another commit can be created.
1013 The rescan will be automatically started now.
1016 rescan
{set ui_status_value
{Ready.
}}
1020 # -- At least one file should differ in the index.
1023 foreach path
[array names file_states
] {
1024 switch
-glob -- [lindex
$file_states($path) 0] {
1028 M?
{set files_ready
1}
1030 error_popup
"Unmerged files cannot be committed.
1032 File [short_path $path] has merge conflicts.
1033 You must resolve them and add the file before committing.
1039 error_popup
"Unknown file state [lindex $s 0] detected.
1041 File [short_path $path] cannot be committed by this program.
1046 if {!$files_ready} {
1047 info_popup
{No changes to commit.
1049 You must add
at least
1 file before you can commit.
1055 # -- A message is required.
1057 set msg
[string trim
[$ui_comm get
1.0 end
]]
1058 regsub
-all -line {[ \t\r]+$
} $msg {} msg
1060 error_popup
{Please supply a commit message.
1062 A good commit message has the following format
:
1064 - First line
: Describe
in one sentance what you did.
1065 - Second line
: Blank
1066 - Remaining lines
: Describe why this change is good.
1072 # -- Run the pre-commit hook.
1074 set pchook
[gitdir hooks pre-commit
]
1076 # On Cygwin [file executable] might lie so we need to ask
1077 # the shell if the hook is executable. Yes that's annoying.
1079 if {[is_Windows
] && [file isfile
$pchook]} {
1080 set pchook
[list sh
-c [concat \
1081 "if test -x \"$pchook\";" \
1082 "then exec \"$pchook\" 2>&1;" \
1084 } elseif
{[file executable
$pchook]} {
1085 set pchook
[list
$pchook |
& cat]
1087 commit_writetree
$curHEAD $msg
1091 set ui_status_value
{Calling pre-commit hook...
}
1093 set fd_ph
[open
"| $pchook" r
]
1094 fconfigure
$fd_ph -blocking 0 -translation binary
1095 fileevent
$fd_ph readable \
1096 [list commit_prehook_wait
$fd_ph $curHEAD $msg]
1099 proc commit_prehook_wait
{fd_ph curHEAD msg
} {
1100 global pch_error ui_status_value
1102 append pch_error
[read $fd_ph]
1103 fconfigure
$fd_ph -blocking 1
1105 if {[catch
{close
$fd_ph}]} {
1106 set ui_status_value
{Commit declined by pre-commit hook.
}
1107 hook_failed_popup pre-commit
$pch_error
1110 commit_writetree
$curHEAD $msg
1115 fconfigure
$fd_ph -blocking 0
1118 proc commit_writetree
{curHEAD msg
} {
1119 global ui_status_value
1121 set ui_status_value
{Committing changes...
}
1122 set fd_wt
[open
"| git write-tree" r
]
1123 fileevent
$fd_wt readable \
1124 [list commit_committree
$fd_wt $curHEAD $msg]
1127 proc commit_committree
{fd_wt curHEAD msg
} {
1128 global HEAD PARENT MERGE_HEAD commit_type
1129 global single_commit all_heads current_branch
1130 global ui_status_value ui_comm selected_commit_type
1131 global file_states selected_paths rescan_active
1135 if {$tree_id eq
{} ||
[catch
{close
$fd_wt} err
]} {
1136 error_popup
"write-tree failed:\n\n$err"
1137 set ui_status_value
{Commit failed.
}
1142 # -- Build the message.
1144 set msg_p
[gitdir COMMIT_EDITMSG
]
1145 set msg_wt
[open
$msg_p w
]
1146 if {[catch
{set enc
$repo_config(i18n.commitencoding
)}]} {
1149 fconfigure
$msg_wt -encoding $enc -translation binary
1150 puts
-nonewline $msg_wt $msg
1153 # -- Create the commit.
1155 set cmd
[list git commit-tree
$tree_id]
1156 set parents
[concat
$PARENT $MERGE_HEAD]
1157 if {[llength
$parents] > 0} {
1158 foreach p
$parents {
1162 # git commit-tree writes to stderr during initial commit.
1163 lappend cmd
2>/dev
/null
1166 if {[catch
{set cmt_id
[eval exec $cmd]} err
]} {
1167 error_popup
"commit-tree failed:\n\n$err"
1168 set ui_status_value
{Commit failed.
}
1173 # -- Update the HEAD ref.
1176 if {$commit_type ne
{normal
}} {
1177 append reflogm
" ($commit_type)"
1179 set i
[string first
"\n" $msg]
1181 append reflogm
{: } [string range
$msg 0 [expr {$i - 1}]]
1183 append reflogm
{: } $msg
1185 set cmd
[list git update-ref
-m $reflogm HEAD
$cmt_id $curHEAD]
1186 if {[catch
{eval exec $cmd} err
]} {
1187 error_popup
"update-ref failed:\n\n$err"
1188 set ui_status_value
{Commit failed.
}
1193 # -- Make sure our current branch exists.
1195 if {$commit_type eq
{initial
}} {
1196 lappend all_heads
$current_branch
1197 set all_heads
[lsort
-unique $all_heads]
1198 populate_branch_menu
1201 # -- Cleanup after ourselves.
1203 catch
{file delete
$msg_p}
1204 catch
{file delete
[gitdir MERGE_HEAD
]}
1205 catch
{file delete
[gitdir MERGE_MSG
]}
1206 catch
{file delete
[gitdir SQUASH_MSG
]}
1207 catch
{file delete
[gitdir GITGUI_MSG
]}
1209 # -- Let rerere do its thing.
1211 if {[file isdirectory
[gitdir rr-cache
]]} {
1212 catch
{exec git rerere
}
1215 # -- Run the post-commit hook.
1217 set pchook
[gitdir hooks post-commit
]
1218 if {[is_Windows
] && [file isfile
$pchook]} {
1219 set pchook
[list sh
-c [concat \
1220 "if test -x \"$pchook\";" \
1221 "then exec \"$pchook\";" \
1223 } elseif
{![file executable
$pchook]} {
1226 if {$pchook ne
{}} {
1227 catch
{exec $pchook &}
1230 $ui_comm delete
0.0 end
1232 $ui_comm edit modified false
1234 if {$single_commit} do_quit
1236 # -- Update in memory status
1238 set selected_commit_type new
1239 set commit_type normal
1242 set MERGE_HEAD
[list
]
1244 foreach path
[array names file_states
] {
1245 set s
$file_states($path)
1247 switch
-glob -- $m {
1255 unset file_states
($path)
1256 catch
{unset selected_paths
($path)}
1259 set file_states
($path) [list _O
[lindex
$s 1] {} {}]
1265 set file_states
($path) [list \
1266 _
[string index
$m 1] \
1277 set ui_status_value \
1278 "Changes committed as [string range $cmt_id 0 7]."
1281 ######################################################################
1285 proc fetch_from
{remote
} {
1286 set w
[new_console \
1288 "Fetching new changes from $remote"]
1289 set cmd
[list git fetch
]
1291 console_exec
$w $cmd console_done
1294 proc push_to
{remote
} {
1295 set w
[new_console \
1297 "Pushing changes to $remote"]
1298 set cmd
[list git push
]
1301 console_exec
$w $cmd console_done
1304 ######################################################################
1308 proc mapicon
{w state path
} {
1311 if {[catch
{set r
$all_icons($state$w)}]} {
1312 puts
"error: no icon for $w state={$state} $path"
1318 proc mapdesc
{state path
} {
1321 if {[catch
{set r
$all_descs($state)}]} {
1322 puts
"error: no desc for state={$state} $path"
1328 proc escape_path
{path
} {
1329 regsub
-all "\n" $path "\\n" path
1333 proc short_path
{path
} {
1334 return [escape_path
[lindex
[file split $path] end
]]
1338 set null_sha1
[string repeat
0 40]
1340 proc merge_state
{path new_state
{head_info
{}} {index_info
{}}} {
1341 global file_states next_icon_id null_sha1
1343 set s0
[string index
$new_state 0]
1344 set s1
[string index
$new_state 1]
1346 if {[catch
{set info
$file_states($path)}]} {
1348 set icon n
[incr next_icon_id
]
1350 set state
[lindex
$info 0]
1351 set icon
[lindex
$info 1]
1352 if {$head_info eq
{}} {set head_info
[lindex
$info 2]}
1353 if {$index_info eq
{}} {set index_info
[lindex
$info 3]}
1356 if {$s0 eq
{?
}} {set s0
[string index
$state 0]} \
1357 elseif
{$s0 eq
{_
}} {set s0 _
}
1359 if {$s1 eq
{?
}} {set s1
[string index
$state 1]} \
1360 elseif
{$s1 eq
{_
}} {set s1 _
}
1362 if {$s0 eq
{A
} && $s1 eq
{_
} && $head_info eq
{}} {
1363 set head_info
[list
0 $null_sha1]
1364 } elseif
{$s0 ne
{_
} && [string index
$state 0] eq
{_
}
1365 && $head_info eq
{}} {
1366 set head_info
$index_info
1369 set file_states
($path) [list
$s0$s1 $icon \
1370 $head_info $index_info \
1375 proc display_file_helper
{w path icon_name old_m new_m
} {
1378 if {$new_m eq
{_
}} {
1379 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1381 set file_lists
($w) [lreplace
$file_lists($w) $lno $lno]
1383 $w conf
-state normal
1384 $w delete
$lno.0 [expr {$lno + 1}].0
1385 $w conf
-state disabled
1387 } elseif
{$old_m eq
{_
} && $new_m ne
{_
}} {
1388 lappend file_lists
($w) $path
1389 set file_lists
($w) [lsort
-unique $file_lists($w)]
1390 set lno
[lsearch
-sorted -exact $file_lists($w) $path]
1392 $w conf
-state normal
1393 $w image create
$lno.0 \
1394 -align center
-padx 5 -pady 1 \
1396 -image [mapicon
$w $new_m $path]
1397 $w insert
$lno.1 "[escape_path $path]\n"
1398 $w conf
-state disabled
1399 } elseif
{$old_m ne
$new_m} {
1400 $w conf
-state normal
1401 $w image conf
$icon_name -image [mapicon
$w $new_m $path]
1402 $w conf
-state disabled
1406 proc display_file
{path state
} {
1407 global file_states selected_paths
1408 global ui_index ui_workdir
1410 set old_m
[merge_state
$path $state]
1411 set s
$file_states($path)
1412 set new_m
[lindex
$s 0]
1413 set icon_name
[lindex
$s 1]
1415 set o
[string index
$old_m 0]
1416 set n
[string index
$new_m 0]
1423 display_file_helper
$ui_index $path $icon_name $o $n
1425 if {[string index
$old_m 0] eq
{U
}} {
1428 set o
[string index
$old_m 1]
1430 if {[string index
$new_m 0] eq
{U
}} {
1433 set n
[string index
$new_m 1]
1435 display_file_helper
$ui_workdir $path $icon_name $o $n
1437 if {$new_m eq
{__
}} {
1438 unset file_states
($path)
1439 catch
{unset selected_paths
($path)}
1443 proc display_all_files_helper
{w path icon_name m
} {
1446 lappend file_lists
($w) $path
1447 set lno
[expr {[lindex
[split [$w index end
] .
] 0] - 1}]
1448 $w image create end \
1449 -align center
-padx 5 -pady 1 \
1451 -image [mapicon
$w $m $path]
1452 $w insert end
"[escape_path $path]\n"
1455 proc display_all_files
{} {
1456 global ui_index ui_workdir
1457 global file_states file_lists
1460 $ui_index conf
-state normal
1461 $ui_workdir conf
-state normal
1463 $ui_index delete
0.0 end
1464 $ui_workdir delete
0.0 end
1467 set file_lists
($ui_index) [list
]
1468 set file_lists
($ui_workdir) [list
]
1470 foreach path
[lsort
[array names file_states
]] {
1471 set s
$file_states($path)
1473 set icon_name
[lindex
$s 1]
1475 set s
[string index
$m 0]
1476 if {$s ne
{U
} && $s ne
{_
}} {
1477 display_all_files_helper
$ui_index $path \
1481 if {[string index
$m 0] eq
{U
}} {
1484 set s
[string index
$m 1]
1487 display_all_files_helper
$ui_workdir $path \
1492 $ui_index conf
-state disabled
1493 $ui_workdir conf
-state disabled
1496 proc update_indexinfo
{msg pathList after
} {
1497 global update_index_cp ui_status_value
1499 if {![lock_index update
]} return
1501 set update_index_cp
0
1502 set pathList
[lsort
$pathList]
1503 set totalCnt
[llength
$pathList]
1504 set batch [expr {int
($totalCnt * .01) + 1}]
1505 if {$batch > 25} {set batch 25}
1507 set ui_status_value
[format \
1508 "$msg... %i/%i files (%.2f%%)" \
1512 set fd
[open
"| git update-index -z --index-info" w
]
1519 fileevent
$fd writable
[list \
1520 write_update_indexinfo \
1530 proc write_update_indexinfo
{fd pathList totalCnt
batch msg after
} {
1531 global update_index_cp ui_status_value
1532 global file_states current_diff_path
1534 if {$update_index_cp >= $totalCnt} {
1541 for {set i
$batch} \
1542 {$update_index_cp < $totalCnt && $i > 0} \
1544 set path
[lindex
$pathList $update_index_cp]
1545 incr update_index_cp
1547 set s
$file_states($path)
1548 switch
-glob -- [lindex
$s 0] {
1555 set info
[lindex
$s 2]
1556 if {$info eq
{}} continue
1558 puts
-nonewline $fd "$info\t[encoding convertto $path]\0"
1559 display_file
$path $new
1562 set ui_status_value
[format \
1563 "$msg... %i/%i files (%.2f%%)" \
1566 [expr {100.0 * $update_index_cp / $totalCnt}]]
1569 proc update_index
{msg pathList after
} {
1570 global update_index_cp ui_status_value
1572 if {![lock_index update
]} return
1574 set update_index_cp
0
1575 set pathList
[lsort
$pathList]
1576 set totalCnt
[llength
$pathList]
1577 set batch [expr {int
($totalCnt * .01) + 1}]
1578 if {$batch > 25} {set batch 25}
1580 set ui_status_value
[format \
1581 "$msg... %i/%i files (%.2f%%)" \
1585 set fd
[open
"| git update-index --add --remove -z --stdin" w
]
1592 fileevent
$fd writable
[list \
1593 write_update_index \
1603 proc write_update_index
{fd pathList totalCnt
batch msg after
} {
1604 global update_index_cp ui_status_value
1605 global file_states current_diff_path
1607 if {$update_index_cp >= $totalCnt} {
1614 for {set i
$batch} \
1615 {$update_index_cp < $totalCnt && $i > 0} \
1617 set path
[lindex
$pathList $update_index_cp]
1618 incr update_index_cp
1620 switch
-glob -- [lindex
$file_states($path) 0] {
1626 if {[file exists
$path]} {
1635 puts
-nonewline $fd "[encoding convertto $path]\0"
1636 display_file
$path $new
1639 set ui_status_value
[format \
1640 "$msg... %i/%i files (%.2f%%)" \
1643 [expr {100.0 * $update_index_cp / $totalCnt}]]
1646 proc checkout_index
{msg pathList after
} {
1647 global update_index_cp ui_status_value
1649 if {![lock_index update
]} return
1651 set update_index_cp
0
1652 set pathList
[lsort
$pathList]
1653 set totalCnt
[llength
$pathList]
1654 set batch [expr {int
($totalCnt * .01) + 1}]
1655 if {$batch > 25} {set batch 25}
1657 set ui_status_value
[format \
1658 "$msg... %i/%i files (%.2f%%)" \
1662 set cmd
[list git checkout-index
]
1668 set fd
[open
"| $cmd " w
]
1675 fileevent
$fd writable
[list \
1676 write_checkout_index \
1686 proc write_checkout_index
{fd pathList totalCnt
batch msg after
} {
1687 global update_index_cp ui_status_value
1688 global file_states current_diff_path
1690 if {$update_index_cp >= $totalCnt} {
1697 for {set i
$batch} \
1698 {$update_index_cp < $totalCnt && $i > 0} \
1700 set path
[lindex
$pathList $update_index_cp]
1701 incr update_index_cp
1702 switch
-glob -- [lindex
$file_states($path) 0] {
1706 puts
-nonewline $fd "[encoding convertto $path]\0"
1707 display_file
$path ?_
1712 set ui_status_value
[format \
1713 "$msg... %i/%i files (%.2f%%)" \
1716 [expr {100.0 * $update_index_cp / $totalCnt}]]
1719 ######################################################################
1721 ## branch management
1723 proc is_tracking_branch
{name
} {
1724 global tracking_branches
1726 if {![catch
{set info
$tracking_branches($name)}]} {
1729 foreach t
[array names tracking_branches
] {
1730 if {[string match
{*/\
*} $t] && [string match
$t $name]} {
1737 proc load_all_heads
{} {
1740 set all_heads
[list
]
1741 set fd
[open
"| git for-each-ref --format=%(refname) refs/heads" r
]
1742 while {[gets
$fd line
] > 0} {
1743 if {[is_tracking_branch
$line]} continue
1744 if {![regsub ^refs
/heads
/ $line {} name
]} continue
1745 lappend all_heads
$name
1749 set all_heads
[lsort
$all_heads]
1752 proc populate_branch_menu
{} {
1753 global all_heads disable_on_lock
1756 set last
[$m index last
]
1757 for {set i
0} {$i <= $last} {incr i
} {
1758 if {[$m type $i] eq
{separator
}} {
1761 foreach a
$disable_on_lock {
1762 if {[lindex
$a 0] ne
$m ||
[lindex
$a 2] < $i} {
1766 set disable_on_lock
$new_dol
1771 if {$all_heads ne
{}} {
1774 foreach b
$all_heads {
1775 $m add radiobutton \
1777 -command [list switch_branch
$b] \
1778 -variable current_branch \
1781 lappend disable_on_lock \
1782 [list
$m entryconf
[$m index last
] -state]
1786 proc all_tracking_branches
{} {
1787 global tracking_branches
1789 set all_trackings
{}
1791 foreach name
[array names tracking_branches
] {
1792 if {[regsub
{/\
*$
} $name {} name
]} {
1795 regsub ^refs
/(heads|remotes
)/ $name {} name
1796 lappend all_trackings
$name
1801 set fd
[open
"| git for-each-ref --format=%(refname) $cmd" r
]
1802 while {[gets
$fd name
] > 0} {
1803 regsub ^refs
/(heads|remotes
)/ $name {} name
1804 lappend all_trackings
$name
1809 return [lsort
-unique $all_trackings]
1812 proc do_create_branch_action
{w
} {
1813 global all_heads null_sha1 repo_config
1814 global create_branch_checkout create_branch_revtype
1815 global create_branch_head create_branch_trackinghead
1816 global create_branch_name create_branch_revexp
1818 set newbranch
$create_branch_name
1819 if {$newbranch eq
{}
1820 ||
$newbranch eq
$repo_config(gui.newbranchtemplate
)} {
1824 -title [wm title
$w] \
1826 -message "Please supply a branch name."
1827 focus
$w.desc.name_t
1830 if {![catch
{exec git show-ref
--verify -- "refs/heads/$newbranch"}]} {
1834 -title [wm title
$w] \
1836 -message "Branch '$newbranch' already exists."
1837 focus
$w.desc.name_t
1840 if {[catch
{exec git check-ref-format
"heads/$newbranch"}]} {
1844 -title [wm title
$w] \
1846 -message "We do not like '$newbranch' as a branch name."
1847 focus
$w.desc.name_t
1852 switch
-- $create_branch_revtype {
1853 head {set rev $create_branch_head}
1854 tracking
{set rev $create_branch_trackinghead}
1855 expression
{set rev $create_branch_revexp}
1857 if {[catch
{set cmt
[exec git rev-parse
--verify "${rev}^0"]}]} {
1861 -title [wm title
$w] \
1863 -message "Invalid starting revision: $rev"
1866 set cmd
[list git update-ref
]
1868 lappend cmd
"branch: Created from $rev"
1869 lappend cmd
"refs/heads/$newbranch"
1871 lappend cmd
$null_sha1
1872 if {[catch
{eval exec $cmd} err
]} {
1876 -title [wm title
$w] \
1878 -message "Failed to create '$newbranch'.\n\n$err"
1882 lappend all_heads
$newbranch
1883 set all_heads
[lsort
$all_heads]
1884 populate_branch_menu
1886 if {$create_branch_checkout} {
1887 switch_branch
$newbranch
1891 proc radio_selector
{varname value args
} {
1892 upvar
#0 $varname var
1896 trace add variable create_branch_head
write \
1897 [list radio_selector create_branch_revtype
head]
1898 trace add variable create_branch_trackinghead
write \
1899 [list radio_selector create_branch_revtype tracking
]
1901 trace add variable delete_branch_head
write \
1902 [list radio_selector delete_branch_checktype
head]
1903 trace add variable delete_branch_trackinghead
write \
1904 [list radio_selector delete_branch_checktype tracking
]
1906 proc do_create_branch
{} {
1907 global all_heads current_branch repo_config
1908 global create_branch_checkout create_branch_revtype
1909 global create_branch_head create_branch_trackinghead
1910 global create_branch_name create_branch_revexp
1912 set w .branch_editor
1914 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
1916 label
$w.header
-text {Create New Branch
} \
1918 pack
$w.header
-side top
-fill x
1921 button
$w.buttons.create
-text Create \
1924 -command [list do_create_branch_action
$w]
1925 pack
$w.buttons.create
-side right
1926 button
$w.buttons.cancel
-text {Cancel
} \
1928 -command [list destroy
$w]
1929 pack
$w.buttons.cancel
-side right
-padx 5
1930 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
1932 labelframe
$w.desc \
1933 -text {Branch Description
} \
1935 label
$w.desc.name_l
-text {Name
:} -font font_ui
1936 entry
$w.desc.name_t \
1940 -textvariable create_branch_name \
1944 if {%d
== 1 && [regexp
{[~^
:?
*\
[\
0- ]} %S
]} {return 0}
1947 grid
$w.desc.name_l
$w.desc.name_t
-sticky we
-padx {0 5}
1948 grid columnconfigure
$w.desc
1 -weight 1
1949 pack
$w.desc
-anchor nw
-fill x
-pady 5 -padx 5
1951 labelframe
$w.from \
1952 -text {Starting Revision
} \
1954 radiobutton
$w.from.head_r \
1955 -text {Local Branch
:} \
1957 -variable create_branch_revtype \
1959 eval tk_optionMenu
$w.from.head_m create_branch_head
$all_heads
1960 grid
$w.from.head_r
$w.from.head_m
-sticky w
1961 set all_trackings
[all_tracking_branches
]
1962 if {$all_trackings ne
{}} {
1963 set create_branch_trackinghead
[lindex
$all_trackings 0]
1964 radiobutton
$w.from.tracking_r \
1965 -text {Tracking Branch
:} \
1967 -variable create_branch_revtype \
1969 eval tk_optionMenu
$w.from.tracking_m \
1970 create_branch_trackinghead \
1972 grid
$w.from.tracking_r
$w.from.tracking_m
-sticky w
1974 radiobutton
$w.from.exp_r \
1975 -text {Revision Expression
:} \
1977 -variable create_branch_revtype \
1979 entry
$w.from.exp_t \
1983 -textvariable create_branch_revexp \
1987 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
1988 if {%d
== 1 && [string length
%S
] > 0} {
1989 set create_branch_revtype expression
1993 grid
$w.from.exp_r
$w.from.exp_t
-sticky we
-padx {0 5}
1994 grid columnconfigure
$w.from
1 -weight 1
1995 pack
$w.from
-anchor nw
-fill x
-pady 5 -padx 5
1997 labelframe
$w.postActions \
1998 -text {Post Creation Actions
} \
2000 checkbutton
$w.postActions.checkout \
2001 -text {Checkout after creation
} \
2002 -variable create_branch_checkout \
2004 pack
$w.postActions.checkout
-anchor nw
2005 pack
$w.postActions
-anchor nw
-fill x
-pady 5 -padx 5
2007 set create_branch_checkout
1
2008 set create_branch_head
$current_branch
2009 set create_branch_revtype
head
2010 set create_branch_name
$repo_config(gui.newbranchtemplate
)
2011 set create_branch_revexp
{}
2013 bind $w <Visibility
> "
2015 $w.desc.name_t icursor end
2016 focus $w.desc.name_t
2018 bind $w <Key-Escape
> "destroy $w"
2019 bind $w <Key-Return
> "do_create_branch_action $w;break"
2020 wm title
$w "[appname] ([reponame]): Create Branch"
2024 proc do_delete_branch_action
{w
} {
2026 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2029 switch
-- $delete_branch_checktype {
2030 head {set check_rev
$delete_branch_head}
2031 tracking
{set check_rev
$delete_branch_trackinghead}
2032 always
{set check_rev
{:none
}}
2034 if {$check_rev eq
{:none
}} {
2036 } elseif
{[catch
{set check_cmt
[exec git rev-parse
--verify "${check_rev}^0"]}]} {
2040 -title [wm title
$w] \
2042 -message "Invalid check revision: $check_rev"
2046 set to_delete
[list
]
2047 set not_merged
[list
]
2048 foreach i
[$w.list.l curselection
] {
2049 set b
[$w.list.l get
$i]
2050 if {[catch
{set o
[exec git rev-parse
--verify $b]}]} continue
2051 if {$check_cmt ne
{}} {
2052 if {$b eq
$check_rev} continue
2053 if {[catch
{set m
[exec git merge-base
$o $check_cmt]}]} continue
2055 lappend not_merged
$b
2059 lappend to_delete
[list
$b $o]
2061 if {$not_merged ne
{}} {
2062 set msg
"The following branches are not completely merged into $check_rev:
2064 - [join $not_merged "\n - "]"
2068 -title [wm title
$w] \
2072 if {$to_delete eq
{}} return
2073 if {$delete_branch_checktype eq
{always
}} {
2074 set msg
{Recovering deleted branches is difficult.
2076 Delete the selected branches?
}
2077 if {[tk_messageBox \
2080 -title [wm title
$w] \
2082 -message $msg] ne
yes} {
2088 foreach i
$to_delete {
2091 if {[catch
{exec git update-ref
-d "refs/heads/$b" $o} err
]} {
2092 append failed
" - $b: $err\n"
2094 set x
[lsearch
-sorted -exact $all_heads $b]
2096 set all_heads
[lreplace
$all_heads $x $x]
2101 if {$failed ne
{}} {
2105 -title [wm title
$w] \
2107 -message "Failed to delete branches:\n$failed"
2110 set all_heads
[lsort
$all_heads]
2111 populate_branch_menu
2115 proc do_delete_branch
{} {
2116 global all_heads tracking_branches current_branch
2117 global delete_branch_checktype delete_branch_head delete_branch_trackinghead
2119 set w .branch_editor
2121 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2123 label
$w.header
-text {Delete Local Branch
} \
2125 pack
$w.header
-side top
-fill x
2128 button
$w.buttons.create
-text Delete \
2130 -command [list do_delete_branch_action
$w]
2131 pack
$w.buttons.create
-side right
2132 button
$w.buttons.cancel
-text {Cancel
} \
2134 -command [list destroy
$w]
2135 pack
$w.buttons.cancel
-side right
-padx 5
2136 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2138 labelframe
$w.list \
2139 -text {Local Branches
} \
2144 -selectmode extended \
2145 -yscrollcommand [list
$w.list.sby
set] \
2147 foreach h
$all_heads {
2148 if {$h ne
$current_branch} {
2149 $w.list.l insert end
$h
2152 scrollbar
$w.list.sby
-command [list
$w.list.l yview
]
2153 pack
$w.list.sby
-side right
-fill y
2154 pack
$w.list.l
-side left
-fill both
-expand 1
2155 pack
$w.list
-fill both
-expand 1 -pady 5 -padx 5
2157 labelframe
$w.validate \
2158 -text {Delete Only If
} \
2160 radiobutton
$w.validate.head_r \
2161 -text {Merged Into Local Branch
:} \
2163 -variable delete_branch_checktype \
2165 eval tk_optionMenu
$w.validate.head_m delete_branch_head
$all_heads
2166 grid
$w.validate.head_r
$w.validate.head_m
-sticky w
2167 set all_trackings
[all_tracking_branches
]
2168 if {$all_trackings ne
{}} {
2169 set delete_branch_trackinghead
[lindex
$all_trackings 0]
2170 radiobutton
$w.validate.tracking_r \
2171 -text {Merged Into Tracking Branch
:} \
2173 -variable delete_branch_checktype \
2175 eval tk_optionMenu
$w.validate.tracking_m \
2176 delete_branch_trackinghead \
2178 grid
$w.validate.tracking_r
$w.validate.tracking_m
-sticky w
2180 radiobutton
$w.validate.always_r \
2181 -text {Always
(Do not perform merge checks
)} \
2183 -variable delete_branch_checktype \
2185 grid
$w.validate.always_r
-columnspan 2 -sticky w
2186 grid columnconfigure
$w.validate
1 -weight 1
2187 pack
$w.validate
-anchor nw
-fill x
-pady 5 -padx 5
2189 set delete_branch_head
$current_branch
2190 set delete_branch_checktype
head
2192 bind $w <Visibility
> "grab $w; focus $w"
2193 bind $w <Key-Escape
> "destroy $w"
2194 wm title
$w "[appname] ([reponame]): Delete Branch"
2198 proc switch_branch
{new_branch
} {
2199 global HEAD commit_type current_branch repo_config
2201 if {![lock_index switch
]} return
2203 # -- Our in memory state should match the repository.
2205 repository_state curType curHEAD curMERGE_HEAD
2206 if {[string match amend
* $commit_type]
2207 && $curType eq
{normal
}
2208 && $curHEAD eq
$HEAD} {
2209 } elseif
{$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2210 info_popup
{Last scanned state does not match repository state.
2212 Another Git program has modified this repository
2213 since the last scan. A rescan must be performed
2214 before the current branch can be changed.
2216 The rescan will be automatically started now.
2219 rescan
{set ui_status_value
{Ready.
}}
2223 # -- Don't do a pointless switch.
2225 if {$current_branch eq
$new_branch} {
2230 if {$repo_config(gui.trustmtime
) eq
{true
}} {
2231 switch_branch_stage2
{} $new_branch
2233 set ui_status_value
{Refreshing
file status...
}
2234 set cmd
[list git update-index
]
2236 lappend cmd
--unmerged
2237 lappend cmd
--ignore-missing
2238 lappend cmd
--refresh
2239 set fd_rf
[open
"| $cmd" r
]
2240 fconfigure
$fd_rf -blocking 0 -translation binary
2241 fileevent
$fd_rf readable \
2242 [list switch_branch_stage2
$fd_rf $new_branch]
2246 proc switch_branch_stage2
{fd_rf new_branch
} {
2247 global ui_status_value HEAD
2251 if {![eof
$fd_rf]} return
2255 set ui_status_value
"Updating working directory to '$new_branch'..."
2256 set cmd
[list git read-tree
]
2259 lappend cmd
--exclude-per-directory=.gitignore
2261 lappend cmd
$new_branch
2262 set fd_rt
[open
"| $cmd" r
]
2263 fconfigure
$fd_rt -blocking 0 -translation binary
2264 fileevent
$fd_rt readable \
2265 [list switch_branch_readtree_wait
$fd_rt $new_branch]
2268 proc switch_branch_readtree_wait
{fd_rt new_branch
} {
2269 global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
2270 global current_branch
2271 global ui_comm ui_status_value
2273 # -- We never get interesting output on stdout; only stderr.
2276 fconfigure
$fd_rt -blocking 1
2277 if {![eof
$fd_rt]} {
2278 fconfigure
$fd_rt -blocking 0
2282 # -- The working directory wasn't in sync with the index and
2283 # we'd have to overwrite something to make the switch. A
2284 # merge is required.
2286 if {[catch
{close
$fd_rt} err
]} {
2287 regsub
{^fatal
: } $err {} err
2288 warn_popup
"File level merge required.
2292 Staying on branch '$current_branch'."
2293 set ui_status_value
"Aborted checkout of '$new_branch' (file level merging is required)."
2298 # -- Update the symbolic ref. Core git doesn't even check for failure
2299 # here, it Just Works(tm). If it doesn't we are in some really ugly
2300 # state that is difficult to recover from within git-gui.
2302 if {[catch
{exec git symbolic-ref HEAD
"refs/heads/$new_branch"} err
]} {
2303 error_popup
"Failed to set current branch.
2305 This working directory is only partially switched.
2306 We successfully updated your files, but failed to
2307 update an internal Git file.
2309 This should not have occurred. [appname] will now
2317 # -- Update our repository state. If we were previously in amend mode
2318 # we need to toss the current buffer and do a full rescan to update
2319 # our file lists. If we weren't in amend mode our file lists are
2320 # accurate and we can avoid the rescan.
2323 set selected_commit_type new
2324 if {[string match amend
* $commit_type]} {
2325 $ui_comm delete
0.0 end
2327 $ui_comm edit modified false
2328 rescan
{set ui_status_value
"Checked out branch '$current_branch'."}
2330 repository_state commit_type HEAD MERGE_HEAD
2332 set ui_status_value
"Checked out branch '$current_branch'."
2336 ######################################################################
2338 ## remote management
2340 proc load_all_remotes
{} {
2342 global all_remotes tracking_branches
2344 set all_remotes
[list
]
2345 array
unset tracking_branches
2347 set rm_dir
[gitdir remotes
]
2348 if {[file isdirectory
$rm_dir]} {
2349 set all_remotes
[glob \
2353 -directory $rm_dir *]
2355 foreach name
$all_remotes {
2357 set fd
[open
[file join $rm_dir $name] r
]
2358 while {[gets
$fd line
] >= 0} {
2359 if {![regexp
{^Pull
:[ ]*([^
:]+):(.
+)$
} \
2360 $line line src dst
]} continue
2361 if {![regexp ^refs
/ $dst]} {
2362 set dst
"refs/heads/$dst"
2364 set tracking_branches
($dst) [list
$name $src]
2371 foreach line
[array names repo_config remote.
*.url
] {
2372 if {![regexp ^remote\.
(.
*)\.url\$
$line line name
]} continue
2373 lappend all_remotes
$name
2375 if {[catch
{set fl
$repo_config(remote.
$name.fetch
)}]} {
2379 if {![regexp
{^
([^
:]+):(.
+)$
} $line line src dst
]} continue
2380 if {![regexp ^refs
/ $dst]} {
2381 set dst
"refs/heads/$dst"
2383 set tracking_branches
($dst) [list
$name $src]
2387 set all_remotes
[lsort
-unique $all_remotes]
2390 proc populate_fetch_menu
{} {
2391 global all_remotes repo_config
2394 foreach r
$all_remotes {
2396 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2397 if {![catch
{set a
$repo_config(remote.
$r.fetch
)}]} {
2402 set fd
[open
[gitdir remotes
$r] r
]
2403 while {[gets
$fd n
] >= 0} {
2404 if {[regexp
{^Pull
:[ \t]*([^
:]+):} $n]} {
2415 -label "Fetch from $r..." \
2416 -command [list fetch_from
$r] \
2422 proc populate_push_menu
{} {
2423 global all_remotes repo_config
2427 foreach r
$all_remotes {
2429 if {![catch
{set a
$repo_config(remote.
$r.url
)}]} {
2430 if {![catch
{set a
$repo_config(remote.
$r.push
)}]} {
2435 set fd
[open
[gitdir remotes
$r] r
]
2436 while {[gets
$fd n
] >= 0} {
2437 if {[regexp
{^Push
:[ \t]*([^
:]+):} $n]} {
2451 -label "Push to $r..." \
2452 -command [list push_to
$r] \
2459 proc start_push_anywhere_action
{w
} {
2460 global push_urltype push_remote push_url push_thin push_tags
2463 switch
-- $push_urltype {
2464 remote
{set r_url
$push_remote}
2465 url
{set r_url
$push_url}
2467 if {$r_url eq
{}} return
2469 set cmd
[list git push
]
2479 foreach i
[$w.
source.l curselection
] {
2480 set b
[$w.
source.l get
$i]
2481 lappend cmd
"refs/heads/$b:refs/heads/$b"
2486 } elseif
{$cnt == 1} {
2492 set cons
[new_console
"push $r_url" "Pushing $cnt $unit to $r_url"]
2493 console_exec
$cons $cmd console_done
2497 trace add variable push_remote
write \
2498 [list radio_selector push_urltype remote
]
2500 proc do_push_anywhere
{} {
2501 global all_heads all_remotes current_branch
2502 global push_urltype push_remote push_url push_thin push_tags
2506 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2508 label
$w.header
-text {Push Branches
} -font font_uibold
2509 pack
$w.header
-side top
-fill x
2512 button
$w.buttons.create
-text Push \
2514 -command [list start_push_anywhere_action
$w]
2515 pack
$w.buttons.create
-side right
2516 button
$w.buttons.cancel
-text {Cancel
} \
2518 -command [list destroy
$w]
2519 pack
$w.buttons.cancel
-side right
-padx 5
2520 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2522 labelframe
$w.
source \
2523 -text {Source Branches
} \
2525 listbox
$w.
source.l \
2528 -selectmode extended \
2529 -yscrollcommand [list
$w.
source.sby
set] \
2531 foreach h
$all_heads {
2532 $w.
source.l insert end
$h
2533 if {$h eq
$current_branch} {
2534 $w.
source.l
select set end
2537 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2538 pack
$w.
source.sby
-side right
-fill y
2539 pack
$w.
source.l
-side left
-fill both
-expand 1
2540 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2542 labelframe
$w.dest \
2543 -text {Destination Repository
} \
2545 if {$all_remotes ne
{}} {
2546 radiobutton
$w.dest.remote_r \
2549 -variable push_urltype \
2551 eval tk_optionMenu
$w.dest.remote_m push_remote
$all_remotes
2552 grid
$w.dest.remote_r
$w.dest.remote_m
-sticky w
2553 if {[lsearch
-sorted -exact $all_remotes origin
] != -1} {
2554 set push_remote origin
2556 set push_remote
[lindex
$all_remotes 0]
2558 set push_urltype remote
2560 set push_urltype url
2562 radiobutton
$w.dest.url_r \
2563 -text {Arbitrary URL
:} \
2565 -variable push_urltype \
2567 entry
$w.dest.url_t \
2571 -textvariable push_url \
2575 if {%d
== 1 && [regexp
{\s
} %S
]} {return 0}
2576 if {%d
== 1 && [string length
%S
] > 0} {
2577 set push_urltype url
2581 grid
$w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
2582 grid columnconfigure
$w.dest
1 -weight 1
2583 pack
$w.dest
-anchor nw
-fill x
-pady 5 -padx 5
2585 labelframe
$w.options \
2586 -text {Transfer Options
} \
2588 checkbutton
$w.options.thin \
2589 -text {Use thin pack
(for slow network connections
)} \
2590 -variable push_thin \
2592 grid
$w.options.thin
-columnspan 2 -sticky w
2593 checkbutton
$w.options.tags \
2594 -text {Include tags
} \
2595 -variable push_tags \
2597 grid
$w.options.tags
-columnspan 2 -sticky w
2598 grid columnconfigure
$w.options
1 -weight 1
2599 pack
$w.options
-anchor nw
-fill x
-pady 5 -padx 5
2605 bind $w <Visibility
> "grab $w"
2606 bind $w <Key-Escape
> "destroy $w"
2607 wm title
$w "[appname] ([reponame]): Push"
2611 ######################################################################
2616 global HEAD commit_type file_states
2618 if {[string match amend
* $commit_type]} {
2619 info_popup
{Cannot merge
while amending.
2621 You must finish amending this commit before
2622 starting any
type of merge.
2627 if {[committer_ident
] eq
{}} {return 0}
2628 if {![lock_index merge
]} {return 0}
2630 # -- Our in memory state should match the repository.
2632 repository_state curType curHEAD curMERGE_HEAD
2633 if {$commit_type ne
$curType ||
$HEAD ne
$curHEAD} {
2634 info_popup
{Last scanned state does not match repository state.
2636 Another Git program has modified this repository
2637 since the last scan. A rescan must be performed
2638 before a merge can be performed.
2640 The rescan will be automatically started now.
2643 rescan
{set ui_status_value
{Ready.
}}
2647 foreach path
[array names file_states
] {
2648 switch
-glob -- [lindex
$file_states($path) 0] {
2650 continue; # and pray it works!
2653 error_popup
"You are in the middle of a conflicted merge.
2655 File [short_path $path] has merge conflicts.
2657 You must resolve them, add the file, and commit to
2658 complete the current merge. Only then can you
2659 begin another merge.
2665 error_popup
"You are in the middle of a change.
2667 File [short_path $path] is modified.
2669 You should complete the current commit before
2670 starting a merge. Doing so will help you abort
2671 a failed merge, should the need arise.
2682 proc visualize_local_merge
{w
} {
2684 foreach i
[$w.
source.l curselection
] {
2685 lappend revs
[$w.
source.l get
$i]
2687 if {$revs eq
{}} return
2688 lappend revs
--not HEAD
2692 proc start_local_merge_action
{w
} {
2693 global HEAD ui_status_value current_branch
2695 set cmd
[list git merge
]
2698 foreach i
[$w.
source.l curselection
] {
2699 set b
[$w.
source.l get
$i]
2707 } elseif
{$revcnt == 1} {
2709 } elseif
{$revcnt <= 15} {
2715 -title [wm title
$w] \
2717 -message "Too many branches selected.
2719 You have requested to merge $revcnt branches
2720 in an octopus merge. This exceeds Git's
2721 internal limit of 15 branches per merge.
2723 Please select fewer branches. To merge more
2724 than 15 branches, merge the branches in batches.
2729 set msg
"Merging $current_branch, [join $names {, }]"
2730 set ui_status_value
"$msg..."
2731 set cons
[new_console
"Merge" $msg]
2732 console_exec
$cons $cmd [list finish_merge
$revcnt]
2733 bind $w <Destroy
> {}
2737 proc finish_merge
{revcnt w ok
} {
2740 set msg
{Merge completed successfully.
}
2743 info_popup
"Octopus merge failed.
2745 Your merge of $revcnt branches has failed.
2747 There are file-level conflicts between the
2748 branches which must be resolved manually.
2750 The working directory will now be reset.
2752 You can attempt this merge again
2753 by merging only one branch at a time." $w
2755 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2756 fconfigure
$fd -blocking 0 -translation binary
2757 fileevent
$fd readable
[list reset_hard_wait
$fd]
2758 set ui_status_value
{Aborting... please
wait...
}
2762 set msg
{Merge failed. Conflict resolution is required.
}
2765 rescan
[list
set ui_status_value
$msg]
2768 proc do_local_merge
{} {
2769 global current_branch
2771 if {![can_merge
]} return
2775 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
2778 -text "Merge Into $current_branch" \
2780 pack
$w.header
-side top
-fill x
2783 button
$w.buttons.visualize
-text Visualize \
2785 -command [list visualize_local_merge
$w]
2786 pack
$w.buttons.visualize
-side left
2787 button
$w.buttons.create
-text Merge \
2789 -command [list start_local_merge_action
$w]
2790 pack
$w.buttons.create
-side right
2791 button
$w.buttons.cancel
-text {Cancel
} \
2793 -command [list destroy
$w]
2794 pack
$w.buttons.cancel
-side right
-padx 5
2795 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
2797 labelframe
$w.
source \
2798 -text {Source Branches
} \
2800 listbox
$w.
source.l \
2803 -selectmode extended \
2804 -yscrollcommand [list
$w.
source.sby
set] \
2806 scrollbar
$w.
source.sby
-command [list
$w.
source.l yview
]
2807 pack
$w.
source.sby
-side right
-fill y
2808 pack
$w.
source.l
-side left
-fill both
-expand 1
2809 pack
$w.
source -fill both
-expand 1 -pady 5 -padx 5
2811 set cmd
[list git for-each-ref
]
2812 lappend cmd
{--format=%(objectname
) %(refname
)}
2813 lappend cmd refs
/heads
2814 lappend cmd refs
/remotes
2815 set fr_fd
[open
"| $cmd" r
]
2816 fconfigure
$fr_fd -translation binary
2817 while {[gets
$fr_fd line
] > 0} {
2818 set line
[split $line { }]
2819 set sha1
([lindex
$line 0]) [lindex
$line 1]
2824 set fr_fd
[open
"| git rev-list --all --not HEAD"]
2825 while {[gets
$fr_fd line
] > 0} {
2826 if {[catch
{set ref
$sha1($line)}]} continue
2827 regsub ^refs
/(heads|remotes
)/ $ref {} ref
2828 lappend to_show
$ref
2832 foreach ref
[lsort
-unique $to_show] {
2833 $w.
source.l insert end
$ref
2836 bind $w <Visibility
> "grab $w"
2837 bind $w <Key-Escape
> "unlock_index;destroy $w"
2838 bind $w <Destroy
> unlock_index
2839 wm title
$w "[appname] ([reponame]): Merge"
2843 proc do_reset_hard
{} {
2844 global HEAD commit_type file_states
2846 if {[string match amend
* $commit_type]} {
2847 info_popup
{Cannot abort
while amending.
2849 You must finish amending this commit.
2854 if {![lock_index abort
]} return
2856 if {[string match
*merge
* $commit_type]} {
2862 if {[ask_popup
"Abort $op?
2864 Aborting the current $op will cause
2865 *ALL* uncommitted changes to be lost.
2867 Continue with aborting the current $op?"] eq
{yes}} {
2868 set fd
[open
"| git read-tree --reset -u HEAD" r
]
2869 fconfigure
$fd -blocking 0 -translation binary
2870 fileevent
$fd readable
[list reset_hard_wait
$fd]
2871 set ui_status_value
{Aborting... please
wait...
}
2877 proc reset_hard_wait
{fd
} {
2885 $ui_comm delete
0.0 end
2886 $ui_comm edit modified false
2888 catch
{file delete
[gitdir MERGE_HEAD
]}
2889 catch
{file delete
[gitdir rr-cache MERGE_RR
]}
2890 catch
{file delete
[gitdir SQUASH_MSG
]}
2891 catch
{file delete
[gitdir MERGE_MSG
]}
2892 catch
{file delete
[gitdir GITGUI_MSG
]}
2894 rescan
{set ui_status_value
{Abort completed. Ready.
}}
2898 ######################################################################
2903 #define mask_width 14
2904 #define mask_height 15
2905 static unsigned char mask_bits
[] = {
2906 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2907 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
2908 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
2911 image create bitmap file_plain
-background white
-foreground black
-data {
2912 #define plain_width 14
2913 #define plain_height 15
2914 static unsigned char plain_bits
[] = {
2915 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2916 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
2917 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2918 } -maskdata $filemask
2920 image create bitmap file_mod
-background white
-foreground blue
-data {
2921 #define mod_width 14
2922 #define mod_height 15
2923 static unsigned char mod_bits
[] = {
2924 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2925 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2926 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2927 } -maskdata $filemask
2929 image create bitmap file_fulltick
-background white
-foreground "#007000" -data {
2930 #define file_fulltick_width 14
2931 #define file_fulltick_height 15
2932 static unsigned char file_fulltick_bits
[] = {
2933 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
2934 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
2935 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2936 } -maskdata $filemask
2938 image create bitmap file_parttick
-background white
-foreground "#005050" -data {
2939 #define parttick_width 14
2940 #define parttick_height 15
2941 static unsigned char parttick_bits
[] = {
2942 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
2943 0x7a, 0x14, 0x02, 0x16, 0x02, 0x13, 0x8a, 0x11, 0xda, 0x10, 0x72, 0x10,
2944 0x22, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2945 } -maskdata $filemask
2947 image create bitmap file_question
-background white
-foreground black
-data {
2948 #define file_question_width 14
2949 #define file_question_height 15
2950 static unsigned char file_question_bits
[] = {
2951 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
2952 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
2953 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
2954 } -maskdata $filemask
2956 image create bitmap file_removed
-background white
-foreground red
-data {
2957 #define file_removed_width 14
2958 #define file_removed_height 15
2959 static unsigned char file_removed_bits
[] = {
2960 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
2961 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
2962 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
2963 } -maskdata $filemask
2965 image create bitmap file_merge
-background white
-foreground blue
-data {
2966 #define file_merge_width 14
2967 #define file_merge_height 15
2968 static unsigned char file_merge_bits
[] = {
2969 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
2970 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
2971 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
2972 } -maskdata $filemask
2974 set ui_index .vpane.files.index.list
2975 set ui_workdir .vpane.files.workdir.list
2977 set all_icons
(_
$ui_index) file_plain
2978 set all_icons
(A
$ui_index) file_fulltick
2979 set all_icons
(M
$ui_index) file_fulltick
2980 set all_icons
(D
$ui_index) file_removed
2981 set all_icons
(U
$ui_index) file_merge
2983 set all_icons
(_
$ui_workdir) file_plain
2984 set all_icons
(M
$ui_workdir) file_mod
2985 set all_icons
(D
$ui_workdir) file_question
2986 set all_icons
(U
$ui_workdir) file_merge
2987 set all_icons
(O
$ui_workdir) file_plain
2989 set max_status_desc
0
2993 {_M
"Modified, not staged"}
2994 {M_
"Staged for commit"}
2995 {MM
"Portions staged for commit"}
2996 {MD
"Staged for commit, missing"}
2998 {_O
"Untracked, not staged"}
2999 {A_
"Staged for commit"}
3000 {AM
"Portions staged for commit"}
3001 {AD
"Staged for commit, missing"}
3004 {D_
"Staged for removal"}
3005 {DO
"Staged for removal, still present"}
3007 {U_
"Requires merge resolution"}
3008 {UU
"Requires merge resolution"}
3009 {UM
"Requires merge resolution"}
3010 {UD
"Requires merge resolution"}
3012 if {$max_status_desc < [string length
[lindex
$i 1]]} {
3013 set max_status_desc
[string length
[lindex
$i 1]]
3015 set all_descs
([lindex
$i 0]) [lindex
$i 1]
3019 ######################################################################
3024 global tcl_platform tk_library
3025 if {[tk windowingsystem
] eq
{aqua
}} {
3031 proc is_Windows
{} {
3033 if {$tcl_platform(platform
) eq
{windows
}} {
3039 proc bind_button3
{w cmd
} {
3040 bind $w <Any-Button-3
> $cmd
3042 bind $w <Control-Button-1
> $cmd
3046 proc incr_font_size
{font
{amt
1}} {
3047 set sz
[font configure
$font -size]
3049 font configure
$font -size $sz
3050 font configure
${font}bold
-size $sz
3053 proc hook_failed_popup
{hook msg
} {
3058 label
$w.m.l1
-text "$hook hook failed:" \
3063 -background white
-borderwidth 1 \
3065 -width 80 -height 10 \
3067 -yscrollcommand [list
$w.m.sby
set]
3069 -text {You must correct the above errors before committing.
} \
3073 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3074 pack
$w.m.l1
-side top
-fill x
3075 pack
$w.m.l2
-side bottom
-fill x
3076 pack
$w.m.sby
-side right
-fill y
3077 pack
$w.m.t
-side left
-fill both
-expand 1
3078 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3080 $w.m.t insert
1.0 $msg
3081 $w.m.t conf
-state disabled
3083 button
$w.ok
-text OK \
3086 -command "destroy $w"
3087 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3089 bind $w <Visibility
> "grab $w; focus $w"
3090 bind $w <Key-Return
> "destroy $w"
3091 wm title
$w "[appname] ([reponame]): error"
3095 set next_console_id
0
3097 proc new_console
{short_title long_title
} {
3098 global next_console_id console_data
3099 set w .console
[incr next_console_id
]
3100 set console_data
($w) [list
$short_title $long_title]
3101 return [console_init
$w]
3104 proc console_init
{w
} {
3105 global console_cr console_data M1B
3107 set console_cr
($w) 1.0
3110 label
$w.m.l1
-text "[lindex $console_data($w) 1]:" \
3115 -background white
-borderwidth 1 \
3117 -width 80 -height 10 \
3120 -yscrollcommand [list
$w.m.sby
set]
3121 label
$w.m.s
-text {Working... please
wait...
} \
3125 scrollbar
$w.m.sby
-command [list
$w.m.t yview
]
3126 pack
$w.m.l1
-side top
-fill x
3127 pack
$w.m.s
-side bottom
-fill x
3128 pack
$w.m.sby
-side right
-fill y
3129 pack
$w.m.t
-side left
-fill both
-expand 1
3130 pack
$w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
3132 menu
$w.ctxm
-tearoff 0
3133 $w.ctxm add
command -label "Copy" \
3135 -command "tk_textCopy $w.m.t"
3136 $w.ctxm add
command -label "Select All" \
3138 -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
3139 $w.ctxm add
command -label "Copy All" \
3142 $w.m.t tag add sel 0.0 end
3144 $w.m.t tag remove sel 0.0 end
3147 button
$w.ok
-text {Close
} \
3150 -command "destroy $w"
3151 pack
$w.ok
-side bottom
-anchor e
-pady 10 -padx 10
3153 bind_button3
$w.m.t
"tk_popup $w.ctxm %X %Y"
3154 bind $w.m.t
<$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
3155 bind $w.m.t
<$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
3156 bind $w <Visibility
> "focus $w"
3157 wm title
$w "[appname] ([reponame]): [lindex $console_data($w) 0]"
3161 proc console_exec
{w cmd after
} {
3162 # -- Windows tosses the enviroment when we exec our child.
3163 # But most users need that so we have to relogin. :-(
3166 set cmd
[list sh
--login -c "cd \"[pwd]\" && [join $cmd { }]"]
3169 # -- Tcl won't let us redirect both stdout and stderr to
3170 # the same pipe. So pass it through cat...
3172 set cmd
[concat |
$cmd |
& cat]
3174 set fd_f
[open
$cmd r
]
3175 fconfigure
$fd_f -blocking 0 -translation binary
3176 fileevent
$fd_f readable
[list console_read
$w $fd_f $after]
3179 proc console_read
{w fd after
} {
3184 if {![winfo exists
$w]} {console_init
$w}
3185 $w.m.t conf
-state normal
3187 set n
[string length
$buf]
3189 set cr
[string first
"\r" $buf $c]
3190 set lf
[string first
"\n" $buf $c]
3191 if {$cr < 0} {set cr
[expr {$n + 1}]}
3192 if {$lf < 0} {set lf
[expr {$n + 1}]}
3195 $w.m.t insert end
[string range
$buf $c $lf]
3196 set console_cr
($w) [$w.m.t index
{end
-1c}]
3200 $w.m.t delete
$console_cr($w) end
3201 $w.m.t insert end
"\n"
3202 $w.m.t insert end
[string range
$buf $c $cr]
3207 $w.m.t conf
-state disabled
3211 fconfigure
$fd -blocking 1
3213 if {[catch
{close
$fd}]} {
3218 uplevel
#0 $after $w $ok
3221 fconfigure
$fd -blocking 0
3224 proc console_chain
{cmdlist w
{ok
1}} {
3226 if {[llength
$cmdlist] == 0} {
3231 set cmd
[lindex
$cmdlist 0]
3232 set cmdlist
[lrange
$cmdlist 1 end
]
3234 if {[lindex
$cmd 0] eq
{console_exec
}} {
3237 [list console_chain
$cmdlist]
3239 uplevel
#0 $cmd $cmdlist $w $ok
3246 proc console_done
{args
} {
3247 global console_cr console_data
3249 switch
-- [llength
$args] {
3251 set w
[lindex
$args 0]
3252 set ok
[lindex
$args 1]
3255 set w
[lindex
$args 1]
3256 set ok
[lindex
$args 2]
3259 error
"wrong number of args: console_done ?ignored? w ok"
3264 if {[winfo exists
$w]} {
3265 $w.m.s conf
-background green
-text {Success
}
3266 $w.ok conf
-state normal
3269 if {![winfo exists
$w]} {
3272 $w.m.s conf
-background red
-text {Error
: Command Failed
}
3273 $w.ok conf
-state normal
3276 array
unset console_cr
$w
3277 array
unset console_data
$w
3280 ######################################################################
3284 set starting_gitk_msg
{Starting gitk... please
wait...
}
3286 proc do_gitk
{revs
} {
3287 global ui_status_value starting_gitk_msg
3295 set cmd
"sh -c \"exec $cmd\""
3299 if {[catch
{eval exec $cmd} err
]} {
3300 error_popup
"Failed to start gitk:\n\n$err"
3302 set ui_status_value
$starting_gitk_msg
3304 if {$ui_status_value eq
$starting_gitk_msg} {
3305 set ui_status_value
{Ready.
}
3312 set fd
[open
"| git count-objects -v" r
]
3313 while {[gets
$fd line
] > 0} {
3314 if {[regexp
{^
([^
:]+): (\d
+)$
} $line _ name value
]} {
3315 set stats
($name) $value
3321 foreach p
[glob
-directory [gitdir objects pack
] \
3324 incr packed_sz
[file size
$p]
3326 if {$packed_sz > 0} {
3327 set stats
(size-pack
) [expr {$packed_sz / 1024}]
3332 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3334 label
$w.header
-text {Database Statistics
} \
3336 pack
$w.header
-side top
-fill x
3338 frame
$w.buttons
-border 1
3339 button
$w.buttons.close
-text Close \
3341 -command [list destroy
$w]
3342 button
$w.buttons.gc
-text {Compress Database
} \
3344 -command "destroy $w;do_gc"
3345 pack
$w.buttons.close
-side right
3346 pack
$w.buttons.gc
-side left
3347 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3349 frame
$w.stat
-borderwidth 1 -relief solid
3351 {count
{Number of loose objects
}}
3352 {size
{Disk space used by loose objects
} { KiB
}}
3353 {in-pack
{Number of packed objects
}}
3354 {packs
{Number of packs
}}
3355 {size-pack
{Disk space used by packed objects
} { KiB
}}
3356 {prune-packable
{Packed objects waiting
for pruning
}}
3357 {garbage
{Garbage files
}}
3359 set name
[lindex
$s 0]
3360 set label
[lindex
$s 1]
3361 if {[catch
{set value
$stats($name)}]} continue
3362 if {[llength
$s] > 2} {
3363 set value
"$value[lindex $s 2]"
3366 label
$w.stat.l_
$name -text "$label:" -anchor w
-font font_ui
3367 label
$w.stat.v_
$name -text $value -anchor w
-font font_ui
3368 grid
$w.stat.l_
$name $w.stat.v_
$name -sticky we
-padx {0 5}
3370 pack
$w.stat
-pady 10 -padx 10
3372 bind $w <Visibility
> "grab $w; focus $w"
3373 bind $w <Key-Escape
> [list destroy
$w]
3374 bind $w <Key-Return
> [list destroy
$w]
3375 wm title
$w "[appname] ([reponame]): Database Statistics"
3380 set w
[new_console
{gc
} {Compressing the object database
}]
3382 {console_exec
{git pack-refs
--prune}}
3383 {console_exec
{git reflog expire
--all}}
3384 {console_exec
{git repack
-a -d -l}}
3385 {console_exec
{git rerere gc
}}
3389 proc do_fsck_objects
{} {
3390 set w
[new_console
{fsck-objects
} \
3391 {Verifying the object database with fsck-objects
}]
3392 set cmd
[list git fsck-objects
]
3395 lappend cmd
--strict
3396 console_exec
$w $cmd console_done
3402 global ui_comm is_quitting repo_config commit_type
3404 if {$is_quitting} return
3407 # -- Stash our current commit buffer.
3409 set save
[gitdir GITGUI_MSG
]
3410 set msg
[string trim
[$ui_comm get
0.0 end
]]
3411 regsub
-all -line {[ \r\t]+$
} $msg {} msg
3412 if {(![string match amend
* $commit_type]
3413 ||
[$ui_comm edit modified
])
3416 set fd
[open
$save w
]
3417 puts
-nonewline $fd $msg
3421 catch
{file delete
$save}
3424 # -- Stash our current window geometry into this repository.
3426 set cfg_geometry
[list
]
3427 lappend cfg_geometry
[wm geometry .
]
3428 lappend cfg_geometry
[lindex
[.vpane sash coord
0] 1]
3429 lappend cfg_geometry
[lindex
[.vpane.files sash coord
0] 0]
3430 if {[catch
{set rc_geometry
$repo_config(gui.geometry
)}]} {
3433 if {$cfg_geometry ne
$rc_geometry} {
3434 catch
{exec git repo-config gui.geometry
$cfg_geometry}
3441 rescan
{set ui_status_value
{Ready.
}}
3444 proc unstage_helper
{txt paths
} {
3445 global file_states current_diff_path
3447 if {![lock_index begin-update
]} return
3451 foreach path
$paths {
3452 switch
-glob -- [lindex
$file_states($path) 0] {
3456 lappend pathList
$path
3457 if {$path eq
$current_diff_path} {
3458 set after
{reshow_diff
;}
3463 if {$pathList eq
{}} {
3469 [concat
$after {set ui_status_value
{Ready.
}}]
3473 proc do_unstage_selection
{} {
3474 global current_diff_path selected_paths
3476 if {[array size selected_paths
] > 0} {
3478 {Unstaging selected files from commit
} \
3479 [array names selected_paths
]
3480 } elseif
{$current_diff_path ne
{}} {
3482 "Unstaging [short_path $current_diff_path] from commit" \
3483 [list
$current_diff_path]
3487 proc add_helper
{txt paths
} {
3488 global file_states current_diff_path
3490 if {![lock_index begin-update
]} return
3494 foreach path
$paths {
3495 switch
-glob -- [lindex
$file_states($path) 0] {
3500 lappend pathList
$path
3501 if {$path eq
$current_diff_path} {
3502 set after
{reshow_diff
;}
3507 if {$pathList eq
{}} {
3513 [concat
$after {set ui_status_value
{Ready to commit.
}}]
3517 proc do_add_selection
{} {
3518 global current_diff_path selected_paths
3520 if {[array size selected_paths
] > 0} {
3522 {Adding selected files
} \
3523 [array names selected_paths
]
3524 } elseif
{$current_diff_path ne
{}} {
3526 "Adding [short_path $current_diff_path]" \
3527 [list
$current_diff_path]
3531 proc do_add_all
{} {
3535 foreach path
[array names file_states
] {
3536 switch
-glob -- [lindex
$file_states($path) 0] {
3539 ?D
{lappend paths
$path}
3542 add_helper
{Adding all changed files
} $paths
3545 proc revert_helper
{txt paths
} {
3546 global file_states current_diff_path
3548 if {![lock_index begin-update
]} return
3552 foreach path
$paths {
3553 switch
-glob -- [lindex
$file_states($path) 0] {
3557 lappend pathList
$path
3558 if {$path eq
$current_diff_path} {
3559 set after
{reshow_diff
;}
3565 set n
[llength
$pathList]
3569 } elseif
{$n == 1} {
3570 set s
"[short_path [lindex $pathList]]"
3572 set s
"these $n files"
3575 set reply
[tk_dialog \
3577 "[appname] ([reponame])" \
3578 "Revert changes in $s?
3580 Any unadded changes will be permanently lost by the revert." \
3590 [concat
$after {set ui_status_value
{Ready.
}}]
3596 proc do_revert_selection
{} {
3597 global current_diff_path selected_paths
3599 if {[array size selected_paths
] > 0} {
3601 {Reverting selected files
} \
3602 [array names selected_paths
]
3603 } elseif
{$current_diff_path ne
{}} {
3605 "Reverting [short_path $current_diff_path]" \
3606 [list
$current_diff_path]
3610 proc do_signoff
{} {
3613 set me
[committer_ident
]
3614 if {$me eq
{}} return
3616 set sob
"Signed-off-by: $me"
3617 set last
[$ui_comm get
{end
-1c linestart
} {end
-1c}]
3618 if {$last ne
$sob} {
3619 $ui_comm edit separator
3621 && ![regexp
{^
[A-Z
][A-Za-z
]*-[A-Za-z-
]+: *} $last]} {
3622 $ui_comm insert end
"\n"
3624 $ui_comm insert end
"\n$sob"
3625 $ui_comm edit separator
3630 proc do_select_commit_type
{} {
3631 global commit_type selected_commit_type
3633 if {$selected_commit_type eq
{new
}
3634 && [string match amend
* $commit_type]} {
3636 } elseif
{$selected_commit_type eq
{amend
}
3637 && ![string match amend
* $commit_type]} {
3640 # The amend request was rejected...
3642 if {![string match amend
* $commit_type]} {
3643 set selected_commit_type new
3653 global appvers copyright
3654 global tcl_patchLevel tk_patchLevel
3658 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3660 label
$w.header
-text "About [appname]" \
3662 pack
$w.header
-side top
-fill x
3665 button
$w.buttons.close
-text {Close
} \
3667 -command [list destroy
$w]
3668 pack
$w.buttons.close
-side right
3669 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3672 -text "[appname] - a commit creation tool for Git.
3680 pack
$w.desc
-side top
-fill x
-padx 5 -pady 5
3683 append v
"[appname] version $appvers\n"
3684 append v
"[exec git version]\n"
3686 if {$tcl_patchLevel eq
$tk_patchLevel} {
3687 append v
"Tcl/Tk version $tcl_patchLevel"
3689 append v
"Tcl version $tcl_patchLevel"
3690 append v
", Tk version $tk_patchLevel"
3701 pack
$w.vers
-side top
-fill x
-padx 5 -pady 5
3703 menu
$w.ctxm
-tearoff 0
3704 $w.ctxm add
command \
3709 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
3712 bind $w <Visibility
> "grab $w; focus $w"
3713 bind $w <Key-Escape
> "destroy $w"
3714 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
3715 wm title
$w "About [appname]"
3719 proc do_options
{} {
3720 global repo_config global_config font_descs
3721 global repo_config_new global_config_new
3723 array
unset repo_config_new
3724 array
unset global_config_new
3725 foreach name
[array names repo_config
] {
3726 set repo_config_new
($name) $repo_config($name)
3729 foreach name
[array names repo_config
] {
3731 gui.diffcontext
{continue}
3733 set repo_config_new
($name) $repo_config($name)
3735 foreach name
[array names global_config
] {
3736 set global_config_new
($name) $global_config($name)
3739 set w .options_editor
3741 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
3743 label
$w.header
-text "[appname] Options" \
3745 pack
$w.header
-side top
-fill x
3748 button
$w.buttons.restore
-text {Restore Defaults
} \
3750 -command do_restore_defaults
3751 pack
$w.buttons.restore
-side left
3752 button
$w.buttons.save
-text Save \
3754 -command [list do_save_config
$w]
3755 pack
$w.buttons.save
-side right
3756 button
$w.buttons.cancel
-text {Cancel
} \
3758 -command [list destroy
$w]
3759 pack
$w.buttons.cancel
-side right
-padx 5
3760 pack
$w.buttons
-side bottom
-fill x
-pady 10 -padx 10
3762 labelframe
$w.repo
-text "[reponame] Repository" \
3764 labelframe
$w.global
-text {Global
(All Repositories
)} \
3766 pack
$w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
3767 pack
$w.global
-side right
-fill both
-expand 1 -pady 5 -padx 5
3771 {b merge.summary
{Summarize Merge Commits
}}
3772 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
3774 {b gui.trustmtime
{Trust File Modification Timestamps
}}
3775 {i-1.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
3776 {t gui.newbranchtemplate
{New Branch Name Template
}}
3778 set type [lindex
$option 0]
3779 set name
[lindex
$option 1]
3780 set text
[lindex
$option 2]
3782 foreach f
{repo global
} {
3783 switch
-glob -- $type {
3785 checkbutton
$w.
$f.
$optid -text $text \
3786 -variable ${f}_config_new
($name) \
3790 pack
$w.
$f.
$optid -side top
-anchor w
3793 regexp
-- {-(\d
+)\.\.
(\d
+)$
} $type _junk min max
3795 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
3796 pack
$w.
$f.
$optid.l
-side left
-anchor w
-fill x
3797 spinbox
$w.
$f.
$optid.v \
3798 -textvariable ${f}_config_new
($name) \
3802 -width [expr {1 + [string length
$max]}] \
3804 bind $w.
$f.
$optid.v
<FocusIn
> {%W selection range
0 end
}
3805 pack
$w.
$f.
$optid.v
-side right
-anchor e
-padx 5
3806 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
3810 label
$w.
$f.
$optid.l
-text "$text:" -font font_ui
3811 entry
$w.
$f.
$optid.v \
3815 -textvariable ${f}_config_new
($name) \
3817 pack
$w.
$f.
$optid.l
-side left
-anchor w
3818 pack
$w.
$f.
$optid.v
-side left
-anchor w \
3821 pack
$w.
$f.
$optid -side top
-anchor w
-fill x
3827 set all_fonts
[lsort
[font families
]]
3828 foreach option
$font_descs {
3829 set name
[lindex
$option 0]
3830 set font
[lindex
$option 1]
3831 set text
[lindex
$option 2]
3833 set global_config_new
(gui.
$font^^family
) \
3834 [font configure
$font -family]
3835 set global_config_new
(gui.
$font^^size
) \
3836 [font configure
$font -size]
3838 frame
$w.global.
$name
3839 label
$w.global.
$name.l
-text "$text:" -font font_ui
3840 pack
$w.global.
$name.l
-side left
-anchor w
-fill x
3841 eval tk_optionMenu
$w.global.
$name.family \
3842 global_config_new
(gui.
$font^^family
) \
3844 spinbox
$w.global.
$name.size \
3845 -textvariable global_config_new
(gui.
$font^^size
) \
3846 -from 2 -to 80 -increment 1 \
3849 bind $w.global.
$name.size
<FocusIn
> {%W selection range
0 end
}
3850 pack
$w.global.
$name.size
-side right
-anchor e
3851 pack
$w.global.
$name.family
-side right
-anchor e
3852 pack
$w.global.
$name -side top
-anchor w
-fill x
3855 bind $w <Visibility
> "grab $w; focus $w"
3856 bind $w <Key-Escape
> "destroy $w"
3857 wm title
$w "[appname] ([reponame]): Options"
3861 proc do_restore_defaults
{} {
3862 global font_descs default_config repo_config
3863 global repo_config_new global_config_new
3865 foreach name
[array names default_config
] {
3866 set repo_config_new
($name) $default_config($name)
3867 set global_config_new
($name) $default_config($name)
3870 foreach option
$font_descs {
3871 set name
[lindex
$option 0]
3872 set repo_config
(gui.
$name) $default_config(gui.
$name)
3876 foreach option
$font_descs {
3877 set name
[lindex
$option 0]
3878 set font
[lindex
$option 1]
3879 set global_config_new
(gui.
$font^^family
) \
3880 [font configure
$font -family]
3881 set global_config_new
(gui.
$font^^size
) \
3882 [font configure
$font -size]
3886 proc do_save_config
{w
} {
3887 if {[catch
{save_config
} err
]} {
3888 error_popup
"Failed to completely save options:\n\n$err"
3894 proc do_windows_shortcut
{} {
3898 set desktop
[exec cygpath \
3906 set fn
[tk_getSaveFile \
3908 -title "[appname] ([reponame]): Create Desktop Icon" \
3909 -initialdir $desktop \
3910 -initialfile "Git [reponame].bat"]
3914 set sh
[exec cygpath \
3918 set me
[exec cygpath \
3922 set gd
[exec cygpath \
3926 set gw
[exec cygpath \
3929 [file dirname [gitdir
]]]
3930 regsub
-all ' $me "'\\''" me
3931 regsub -all ' $gd "'\\''" gd
3932 puts $fd "@ECHO Entering $gw"
3933 puts $fd "@ECHO Starting git-gui... please wait..."
3934 puts -nonewline $fd "@\"$sh\" --login -c \""
3935 puts -nonewline $fd "GIT_DIR='$gd'"
3936 puts -nonewline $fd " '$me'"
3940 error_popup "Cannot write script:\n\n$err"
3945 proc do_macosx_app {} {
3948 set fn [tk_getSaveFile \
3950 -title "[appname] ([reponame]): Create Desktop Icon" \
3951 -initialdir [file join $env(HOME) Desktop] \
3952 -initialfile "Git [reponame].app"]
3955 set Contents [file join $fn Contents]
3956 set MacOS [file join $Contents MacOS]
3957 set exe [file join $MacOS git-gui]
3961 set fd [open [file join $Contents Info.plist] w]
3962 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
3963 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3964 <plist version="1.0">
3966 <key>CFBundleDevelopmentRegion</key>
3967 <string>English</string>
3968 <key>CFBundleExecutable</key>
3969 <string>git-gui</string>
3970 <key>CFBundleIdentifier</key>
3971 <string>org.spearce.git-gui</string>
3972 <key>CFBundleInfoDictionaryVersion</key>
3973 <string>6.0</string>
3974 <key>CFBundlePackageType</key>
3975 <string>APPL</string>
3976 <key>CFBundleSignature</key>
3977 <string>????</string>
3978 <key>CFBundleVersion</key>
3979 <string>1.0</string>
3980 <key>NSPrincipalClass</key>
3981 <string>NSApplication</string>
3986 set fd [open $exe w]
3987 set gd [file normalize [gitdir]]
3988 set ep [file normalize [exec git --exec-path]]
3989 regsub -all ' $gd "'\\''" gd
3990 regsub
-all ' $ep "'\\''" ep
3991 puts $fd "#!/bin/sh"
3992 foreach name
[array names env
] {
3993 if {[string match GIT_
* $name]} {
3994 regsub
-all ' $env($name) "'\\''" v
3995 puts $fd "export $name='$v'"
3998 puts $fd "export PATH
='$ep':\
$PATH"
3999 puts $fd "export GIT_DIR
='$gd'"
4000 puts $fd "exec [file normalize
$argv0]"
4003 file attributes $exe -permissions u+x,g+x,o+x
4005 error_popup "Cannot
write icon
:\n\n$err"
4010 proc toggle_or_diff {w x y} {
4011 global file_states file_lists current_diff_path ui_index ui_workdir
4012 global last_clicked selected_paths
4014 set pos [split [$w index @$x,$y] .]
4015 set lno [lindex $pos 0]
4016 set col [lindex $pos 1]
4017 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4023 set last_clicked [list $w $lno]
4024 array unset selected_paths
4025 $ui_index tag remove in_sel 0.0 end
4026 $ui_workdir tag remove in_sel 0.0 end
4029 if {$current_diff_path eq $path} {
4030 set after {reshow_diff;}
4034 if {$w eq $ui_index} {
4036 "Unstaging
[short_path
$path] from commit
" \
4038 [concat $after {set ui_status_value {Ready.}}]
4039 } elseif {$w eq $ui_workdir} {
4041 "Adding
[short_path
$path]" \
4043 [concat $after {set ui_status_value {Ready.}}]
4046 show_diff $path $w $lno
4050 proc add_one_to_selection {w x y} {
4051 global file_lists last_clicked selected_paths
4053 set lno [lindex [split [$w index @$x,$y] .] 0]
4054 set path [lindex $file_lists($w) [expr {$lno - 1}]]
4060 if {$last_clicked ne {}
4061 && [lindex $last_clicked 0] ne $w} {
4062 array unset selected_paths
4063 [lindex $last_clicked 0] tag remove in_sel 0.0 end
4066 set last_clicked [list $w $lno]
4067 if {[catch {set in_sel $selected_paths($path)}]} {
4071 unset selected_paths($path)
4072 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
4074 set selected_paths($path) 1
4075 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
4079 proc add_range_to_selection {w x y} {
4080 global file_lists last_clicked selected_paths
4082 if {[lindex $last_clicked 0] ne $w} {
4083 toggle_or_diff $w $x $y
4087 set lno [lindex [split [$w index @$x,$y] .] 0]
4088 set lc [lindex $last_clicked 1]
4097 foreach path [lrange $file_lists($w) \
4098 [expr {$begin - 1}] \
4099 [expr {$end - 1}]] {
4100 set selected_paths($path) 1
4102 $w tag add in_sel $begin.0 [expr {$end + 1}].0
4105 ######################################################################
4109 set cursor_ptr arrow
4110 font create font_diff -family Courier -size 10
4114 eval font configure font_ui [font actual [.dummy cget -font]]
4118 font create font_uibold
4119 font create font_diffbold
4124 } elseif {[is_MacOSX]} {
4132 proc apply_config {} {
4133 global repo_config font_descs
4135 foreach option $font_descs {
4136 set name [lindex $option 0]
4137 set font [lindex $option 1]
4139 foreach {cn cv} $repo_config(gui.$name) {
4140 font configure $font $cn $cv
4143 error_popup "Invalid font specified
in gui.
$name:\n\n$err"
4145 foreach {cn cv} [font configure $font] {
4146 font configure ${font}bold $cn $cv
4148 font configure ${font}bold -weight bold
4152 set default_config(merge.summary) false
4153 set default_config(merge.verbosity) 2
4154 set default_config(gui.trustmtime) false
4155 set default_config(gui.diffcontext) 5
4156 set default_config(gui.newbranchtemplate) {}
4157 set default_config(gui.fontui) [font configure font_ui]
4158 set default_config(gui.fontdiff) [font configure font_diff]
4160 {fontui font_ui {Main Font}}
4161 {fontdiff font_diff {Diff/Console Font}}
4166 ######################################################################
4172 menu .mbar -tearoff 0
4173 .mbar add cascade -label Repository -menu .mbar.repository
4174 .mbar add cascade -label Edit -menu .mbar.edit
4175 if {!$single_commit} {
4176 .mbar add cascade -label Branch -menu .mbar.branch
4178 .mbar add cascade -label Commit -menu .mbar.commit
4179 if {!$single_commit} {
4180 .mbar add cascade -label Merge -menu .mbar.merge
4181 .mbar add cascade -label Fetch -menu .mbar.fetch
4182 .mbar add cascade -label Push -menu .mbar.push
4184 . configure -menu .mbar
4186 # -- Repository Menu
4188 menu .mbar.repository
4189 .mbar.repository add command \
4190 -label {Visualize Current Branch} \
4191 -command {do_gitk {}} \
4193 .mbar.repository add command \
4194 -label {Visualize All Branches} \
4195 -command {do_gitk {--all}} \
4197 .mbar.repository add separator
4199 if {!$single_commit} {
4200 .mbar.repository add command -label {Database Statistics} \
4204 .mbar.repository add command -label {Compress Database} \
4208 .mbar.repository add command -label {Verify Database} \
4209 -command do_fsck_objects \
4212 .mbar.repository add separator
4215 .mbar.repository add command \
4216 -label {Create Desktop Icon} \
4217 -command do_windows_shortcut \
4219 } elseif {[is_MacOSX]} {
4220 .mbar.repository add command \
4221 -label {Create Desktop Icon} \
4222 -command do_macosx_app \
4227 .mbar.repository add command -label Quit \
4229 -accelerator $M1T-Q \
4235 .mbar.edit add command -label Undo \
4236 -command {catch {[focus] edit undo}} \
4237 -accelerator $M1T-Z \
4239 .mbar.edit add command -label Redo \
4240 -command {catch {[focus] edit redo}} \
4241 -accelerator $M1T-Y \
4243 .mbar.edit add separator
4244 .mbar.edit add command -label Cut \
4245 -command {catch {tk_textCut [focus]}} \
4246 -accelerator $M1T-X \
4248 .mbar.edit add command -label Copy \
4249 -command {catch {tk_textCopy [focus]}} \
4250 -accelerator $M1T-C \
4252 .mbar.edit add command -label Paste \
4253 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
4254 -accelerator $M1T-V \
4256 .mbar.edit add command -label Delete \
4257 -command {catch {[focus] delete sel.first sel.last}} \
4260 .mbar.edit add separator
4261 .mbar.edit add command -label {Select All} \
4262 -command {catch {[focus] tag add sel 0.0 end}} \
4263 -accelerator $M1T-A \
4268 if {!$single_commit} {
4271 .mbar.branch add command -label {Create...} \
4272 -command do_create_branch \
4273 -accelerator $M1T-N \
4275 lappend disable_on_lock [list .mbar.branch entryconf \
4276 [.mbar.branch index last] -state]
4278 .mbar.branch add command -label {Delete...} \
4279 -command do_delete_branch \
4281 lappend disable_on_lock [list .mbar.branch entryconf \
4282 [.mbar.branch index last] -state]
4289 .mbar.commit add radiobutton \
4290 -label {New Commit} \
4291 -command do_select_commit_type \
4292 -variable selected_commit_type \
4295 lappend disable_on_lock \
4296 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4298 .mbar.commit add radiobutton \
4299 -label {Amend Last Commit} \
4300 -command do_select_commit_type \
4301 -variable selected_commit_type \
4304 lappend disable_on_lock \
4305 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4307 .mbar.commit add separator
4309 .mbar.commit add command -label Rescan \
4310 -command do_rescan \
4313 lappend disable_on_lock \
4314 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4316 .mbar.commit add command -label {Add To Commit} \
4317 -command do_add_selection \
4319 lappend disable_on_lock \
4320 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4322 .mbar.commit add command -label {Add All To Commit} \
4323 -command do_add_all \
4324 -accelerator $M1T-I \
4326 lappend disable_on_lock \
4327 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4329 .mbar.commit add command -label {Unstage From Commit} \
4330 -command do_unstage_selection \
4332 lappend disable_on_lock \
4333 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4335 .mbar.commit add command -label {Revert Changes} \
4336 -command do_revert_selection \
4338 lappend disable_on_lock \
4339 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4341 .mbar.commit add separator
4343 .mbar.commit add command -label {Sign Off} \
4344 -command do_signoff \
4345 -accelerator $M1T-S \
4348 .mbar.commit add command -label Commit \
4349 -command do_commit \
4350 -accelerator $M1T-Return \
4352 lappend disable_on_lock \
4353 [list .mbar.commit entryconf [.mbar.commit index last] -state]
4356 # -- Apple Menu (Mac OS X only)
4358 .mbar add cascade -label Apple -menu .mbar.apple
4361 .mbar.apple add command -label "About
[appname
]" \
4364 .mbar.apple add command -label "[appname
] Options...
" \
4365 -command do_options \
4370 .mbar.edit add separator
4371 .mbar.edit add command -label {Options...} \
4372 -command do_options \
4377 if {[file exists /usr/local/miga/lib/gui-miga]
4378 && [file exists .pvcsrc]} {
4380 global ui_status_value
4381 if {![lock_index update]} return
4382 set cmd [list sh --login -c "/usr
/local
/miga
/lib
/gui-miga
\"[pwd]\""]
4383 set miga_fd [open "|
$cmd" r]
4384 fconfigure $miga_fd -blocking 0
4385 fileevent $miga_fd readable [list miga_done $miga_fd]
4386 set ui_status_value {Running miga...}
4388 proc miga_done {fd} {
4393 rescan [list set ui_status_value {Ready.}]
4396 .mbar add cascade -label Tools -menu .mbar.tools
4398 .mbar.tools add command -label "Migrate
" \
4401 lappend disable_on_lock \
4402 [list .mbar.tools entryconf [.mbar.tools index last] -state]
4407 .mbar add cascade -label Help -menu .mbar.help
4410 .mbar.help add command -label "About
[appname
]" \
4422 -text {Current Branch:} \
4427 -textvariable current_branch \
4431 pack .branch.l1 -side left
4432 pack .branch.cb -side left -fill x
4433 pack .branch -side top -fill x
4435 if {!$single_commit} {
4437 .mbar.merge add command -label {Local Merge...} \
4438 -command do_local_merge \
4440 lappend disable_on_lock \
4441 [list .mbar.merge entryconf [.mbar.merge index last] -state]
4442 .mbar.merge add command -label {Abort Merge...} \
4443 -command do_reset_hard \
4445 lappend disable_on_lock \
4446 [list .mbar.merge entryconf [.mbar.merge index last] -state]
4452 .mbar.push add command -label {Push...} \
4453 -command do_push_anywhere \
4457 # -- Main Window Layout
4459 panedwindow .vpane -orient vertical
4460 panedwindow .vpane.files -orient horizontal
4461 .vpane add .vpane.files -sticky nsew -height 100 -width 200
4462 pack .vpane -anchor n -side top -fill both -expand 1
4464 # -- Index File List
4466 frame .vpane.files.index -height 100 -width 200
4467 label .vpane.files.index.title -text {Changes To Be Committed} \
4470 text $ui_index -background white -borderwidth 0 \
4471 -width 20 -height 10 \
4474 -cursor $cursor_ptr \
4475 -xscrollcommand {.vpane.files.index.sx set} \
4476 -yscrollcommand {.vpane.files.index.sy set} \
4478 scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
4479 scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
4480 pack .vpane.files.index.title -side top -fill x
4481 pack .vpane.files.index.sx -side bottom -fill x
4482 pack .vpane.files.index.sy -side right -fill y
4483 pack $ui_index -side left -fill both -expand 1
4484 .vpane.files add .vpane.files.index -sticky nsew
4486 # -- Working Directory File List
4488 frame .vpane.files.workdir -height 100 -width 200
4489 label .vpane.files.workdir.title -text {Changed But Not Updated} \
4492 text $ui_workdir -background white -borderwidth 0 \
4493 -width 20 -height 10 \
4496 -cursor $cursor_ptr \
4497 -xscrollcommand {.vpane.files.workdir.sx set} \
4498 -yscrollcommand {.vpane.files.workdir.sy set} \
4500 scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
4501 scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
4502 pack .vpane.files.workdir.title -side top -fill x
4503 pack .vpane.files.workdir.sx -side bottom -fill x
4504 pack .vpane.files.workdir.sy -side right -fill y
4505 pack $ui_workdir -side left -fill both -expand 1
4506 .vpane.files add .vpane.files.workdir -sticky nsew
4508 foreach i [list $ui_index $ui_workdir] {
4509 $i tag conf in_diff -font font_uibold
4510 $i tag conf in_sel \
4511 -background [$i cget -foreground] \
4512 -foreground [$i cget -background]
4516 # -- Diff and Commit Area
4518 frame .vpane.lower -height 300 -width 400
4519 frame .vpane.lower.commarea
4520 frame .vpane.lower.diff -relief sunken -borderwidth 1
4521 pack .vpane.lower.commarea -side top -fill x
4522 pack .vpane.lower.diff -side bottom -fill both -expand 1
4523 .vpane add .vpane.lower -sticky nsew
4525 # -- Commit Area Buttons
4527 frame .vpane.lower.commarea.buttons
4528 label .vpane.lower.commarea.buttons.l -text {} \
4532 pack .vpane.lower.commarea.buttons.l -side top -fill x
4533 pack .vpane.lower.commarea.buttons -side left -fill y
4535 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
4536 -command do_rescan \
4538 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
4539 lappend disable_on_lock \
4540 {.vpane.lower.commarea.buttons.rescan conf -state}
4542 button .vpane.lower.commarea.buttons.incall -text {Add All} \
4543 -command do_add_all \
4545 pack .vpane.lower.commarea.buttons.incall -side top -fill x
4546 lappend disable_on_lock \
4547 {.vpane.lower.commarea.buttons.incall conf -state}
4549 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
4550 -command do_signoff \
4552 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
4554 button .vpane.lower.commarea.buttons.commit -text {Commit} \
4555 -command do_commit \
4557 pack .vpane.lower.commarea.buttons.commit -side top -fill x
4558 lappend disable_on_lock \
4559 {.vpane.lower.commarea.buttons.commit conf -state}
4561 # -- Commit Message Buffer
4563 frame .vpane.lower.commarea.buffer
4564 frame .vpane.lower.commarea.buffer.header
4565 set ui_comm .vpane.lower.commarea.buffer.t
4566 set ui_coml .vpane.lower.commarea.buffer.header.l
4567 radiobutton .vpane.lower.commarea.buffer.header.new \
4568 -text {New Commit} \
4569 -command do_select_commit_type \
4570 -variable selected_commit_type \
4573 lappend disable_on_lock \
4574 [list .vpane.lower.commarea.buffer.header.new conf -state]
4575 radiobutton .vpane.lower.commarea.buffer.header.amend \
4576 -text {Amend Last Commit} \
4577 -command do_select_commit_type \
4578 -variable selected_commit_type \
4581 lappend disable_on_lock \
4582 [list .vpane.lower.commarea.buffer.header.amend conf -state]
4587 proc trace_commit_type {varname args} {
4588 global ui_coml commit_type
4589 switch -glob -- $commit_type {
4590 initial {set txt {Initial Commit Message:}}
4591 amend {set txt {Amended Commit Message:}}
4592 amend-initial {set txt {Amended Initial Commit Message:}}
4593 amend-merge {set txt {Amended Merge Commit Message:}}
4594 merge {set txt {Merge Commit Message:}}
4595 * {set txt {Commit Message:}}
4597 $ui_coml conf -text $txt
4599 trace add variable commit_type write trace_commit_type
4600 pack $ui_coml -side left -fill x
4601 pack .vpane.lower.commarea.buffer.header.amend -side right
4602 pack .vpane.lower.commarea.buffer.header.new -side right
4604 text $ui_comm -background white -borderwidth 1 \
4607 -autoseparators true \
4609 -width 75 -height 9 -wrap none \
4611 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
4612 scrollbar .vpane.lower.commarea.buffer.sby \
4613 -command [list $ui_comm yview]
4614 pack .vpane.lower.commarea.buffer.header -side top -fill x
4615 pack .vpane.lower.commarea.buffer.sby -side right -fill y
4616 pack $ui_comm -side left -fill y
4617 pack .vpane.lower.commarea.buffer -side left -fill y
4619 # -- Commit Message Buffer Context Menu
4621 set ctxm .vpane.lower.commarea.buffer.ctxm
4622 menu $ctxm -tearoff 0
4626 -command {tk_textCut $ui_comm}
4630 -command {tk_textCopy $ui_comm}
4634 -command {tk_textPaste $ui_comm}
4638 -command {$ui_comm delete sel.first sel.last}
4641 -label {Select All} \
4643 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
4648 $ui_comm tag add sel 0.0 end
4649 tk_textCopy $ui_comm
4650 $ui_comm tag remove sel 0.0 end
4657 bind_button3 $ui_comm "tk_popup
$ctxm %X
%Y
"
4661 set current_diff_path {}
4662 set current_diff_side {}
4663 set diff_actions [list]
4664 proc trace_current_diff_path {varname args} {
4665 global current_diff_path diff_actions file_states
4666 if {$current_diff_path eq {}} {
4672 set p $current_diff_path
4673 set s [mapdesc [lindex $file_states($p) 0] $p]
4675 set p [escape_path $p]
4679 .vpane.lower.diff.header.status configure -text $s
4680 .vpane.lower.diff.header.file configure -text $f
4681 .vpane.lower.diff.header.path configure -text $p
4682 foreach w $diff_actions {
4686 trace add variable current_diff_path write trace_current_diff_path
4688 frame .vpane.lower.diff.header -background orange
4689 label .vpane.lower.diff.header.status \
4690 -background orange \
4691 -width $max_status_desc \
4695 label .vpane.lower.diff.header.file \
4696 -background orange \
4700 label .vpane.lower.diff.header.path \
4701 -background orange \
4705 pack .vpane.lower.diff.header.status -side left
4706 pack .vpane.lower.diff.header.file -side left
4707 pack .vpane.lower.diff.header.path -fill x
4708 set ctxm .vpane.lower.diff.header.ctxm
4709 menu $ctxm -tearoff 0
4718 -- $current_diff_path
4720 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4721 bind_button3 .vpane.lower.diff.header.path "tk_popup
$ctxm %X
%Y
"
4725 frame .vpane.lower.diff.body
4726 set ui_diff .vpane.lower.diff.body.t
4727 text $ui_diff -background white -borderwidth 0 \
4728 -width 80 -height 15 -wrap none \
4730 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
4731 -yscrollcommand {.vpane.lower.diff.body.sby set} \
4733 scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
4734 -command [list $ui_diff xview]
4735 scrollbar .vpane.lower.diff.body.sby -orient vertical \
4736 -command [list $ui_diff yview]
4737 pack .vpane.lower.diff.body.sbx -side bottom -fill x
4738 pack .vpane.lower.diff.body.sby -side right -fill y
4739 pack $ui_diff -side left -fill both -expand 1
4740 pack .vpane.lower.diff.header -side top -fill x
4741 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
4743 $ui_diff tag conf d_cr -elide true
4744 $ui_diff tag conf d_@ -foreground blue -font font_diffbold
4745 $ui_diff tag conf d_+ -foreground {#00a000}
4746 $ui_diff tag conf d_- -foreground red
4748 $ui_diff tag conf d_++ -foreground {#00a000}
4749 $ui_diff tag conf d_-- -foreground red
4750 $ui_diff tag conf d_+s \
4751 -foreground {#00a000} \
4752 -background {#e2effa}
4753 $ui_diff tag conf d_-s \
4755 -background {#e2effa}
4756 $ui_diff tag conf d_s+ \
4757 -foreground {#00a000} \
4759 $ui_diff tag conf d_s- \
4763 $ui_diff tag conf d<<<<<<< \
4764 -foreground orange \
4766 $ui_diff tag conf d======= \
4767 -foreground orange \
4769 $ui_diff tag conf d>>>>>>> \
4770 -foreground orange \
4773 $ui_diff tag raise sel
4775 # -- Diff Body Context Menu
4777 set ctxm .vpane.lower.diff.body.ctxm
4778 menu $ctxm -tearoff 0
4782 -command reshow_diff
4783 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4787 -command {tk_textCopy $ui_diff}
4788 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4790 -label {Select All} \
4792 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
4793 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4798 $ui_diff tag add sel 0.0 end
4799 tk_textCopy $ui_diff
4800 $ui_diff tag remove sel 0.0 end
4802 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4805 -label {Apply/Reverse Hunk} \
4807 -command {apply_hunk $cursorX $cursorY}
4808 set ui_diff_applyhunk [$ctxm index last]
4809 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
4812 -label {Decrease Font Size} \
4814 -command {incr_font_size font_diff -1}
4815 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4817 -label {Increase Font Size} \
4819 -command {incr_font_size font_diff 1}
4820 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4823 -label {Show Less Context} \
4825 -command {if {$repo_config(gui.diffcontext) >= 2} {
4826 incr repo_config(gui.diffcontext) -1
4829 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4831 -label {Show More Context} \
4834 incr repo_config(gui.diffcontext)
4837 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
4839 $ctxm add command -label {Options...} \
4842 bind_button3 $ui_diff "
4845 if {\
$ui_index eq \
$current_diff_side} {
4846 $ctxm entryconf
$ui_diff_applyhunk -label {Unstage Hunk From Commit
}
4848 $ctxm entryconf
$ui_diff_applyhunk -label {Stage Hunk For Commit
}
4850 tk_popup
$ctxm %X
%Y
4852 unset ui_diff_applyhunk
4856 set ui_status_value {Initializing...}
4857 label .status -textvariable ui_status_value \
4863 pack .status -anchor w -side bottom -fill x
4868 set gm $repo_config(gui.geometry)
4869 wm geometry . [lindex $gm 0]
4870 .vpane sash place 0 \
4871 [lindex [.vpane sash coord 0] 0] \
4873 .vpane.files sash place 0 \
4875 [lindex [.vpane.files sash coord 0] 1]
4881 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
4882 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
4883 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
4884 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
4885 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
4886 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
4887 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
4888 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
4889 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
4890 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4891 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4893 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
4894 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
4895 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
4896 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
4897 bind $ui_diff <$M1B-Key-v> {break}
4898 bind $ui_diff <$M1B-Key-V> {break}
4899 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
4900 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
4901 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
4902 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
4903 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
4904 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
4905 bind $ui_diff <Button-1> {focus %W}
4907 if {!$single_commit} {
4908 bind . <$M1B-Key-n> do_create_branch
4909 bind . <$M1B-Key-N> do_create_branch
4912 bind . <Destroy> do_quit
4913 bind all <Key-F5> do_rescan
4914 bind all <$M1B-Key-r> do_rescan
4915 bind all <$M1B-Key-R> do_rescan
4916 bind . <$M1B-Key-s> do_signoff
4917 bind . <$M1B-Key-S> do_signoff
4918 bind . <$M1B-Key-i> do_add_all
4919 bind . <$M1B-Key-I> do_add_all
4920 bind . <$M1B-Key-Return> do_commit
4921 bind all <$M1B-Key-q> do_quit
4922 bind all <$M1B-Key-Q> do_quit
4923 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
4924 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
4925 foreach i [list $ui_index $ui_workdir] {
4926 bind $i <Button-1> "toggle_or_diff
$i %x
%y
; break"
4927 bind $i <$M1B-Button-1> "add_one_to_selection
$i %x
%y
; break"
4928 bind $i <Shift-Button-1> "add_range_to_selection
$i %x
%y
; break"
4932 set file_lists($ui_index) [list]
4933 set file_lists($ui_workdir) [list]
4937 set MERGE_HEAD [list]
4940 set current_branch {}
4941 set current_diff_path {}
4942 set selected_commit_type new
4944 wm title . "[appname
] ([file normalize
[file dirname [gitdir
]]])"
4945 focus -force $ui_comm
4947 # -- Warn the user about environmental problems. Cygwin's Tcl
4948 # does *not* pass its env array onto any processes it spawns.
4949 # This means that git processes get none of our environment.
4954 set msg "Possible environment issues exist.
4956 The following environment variables are probably
4957 going to be ignored by any Git subprocess run
4961 foreach name [array names env] {
4962 switch -regexp -- $name {
4963 {^GIT_INDEX_FILE$} -
4964 {^GIT_OBJECT_DIRECTORY$} -
4965 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
4967 {^GIT_EXTERNAL_DIFF$} -
4971 {^GIT_CONFIG_LOCAL$} -
4972 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
4973 append msg " - $name\n"
4976 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
4977 append msg " - $name\n"
4979 set suggest_user $name
4983 if {$ignored_env > 0} {
4985 This is due to a known issue with the
4986 Tcl binary distributed by Cygwin.
"
4988 if {$suggest_user ne {}} {
4991 A good replacement
for $suggest_user
4992 is placing values
for the user.name and
4993 user.email settings into your personal
4999 unset ignored_env msg suggest_user name
5002 # -- Only initialize complex UI if we are going to stay running.
5004 if {!$single_commit} {
5008 populate_branch_menu
5013 # -- Only suggest a gc run if we are going to stay running.
5015 if {!$single_commit} {
5016 set object_limit 2000
5017 if {[is_Windows]} {set object_limit 200}
5018 regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
5019 if {$objects_current >= $object_limit} {
5021 "This repository currently has
$objects_current loose objects.
5023 To maintain optimal performance it is strongly
5024 recommended that you
compress the database
5025 when
more than
$object_limit loose objects exist.
5027 Compress the database now?
"] eq yes} {
5031 unset object_limit _junk objects_current
5034 lock_index begin-read