set disable_on_lock [list]
set index_lock_type none
-set HEAD {}
-set PARENT {}
-set commit_type {}
-set empty_tree {}
-
proc lock_index {type} {
global index_lock_type disable_on_lock
uplevel #0 $w disabled
}
return 1
- } elseif {$index_lock_type eq {begin-update} && $type eq {update}} {
+ } elseif {$index_lock_type eq "begin-$type"} {
set index_lock_type $type
return 1
}
incr z2 -1
display_file \
[string range $buf_rdi $z1 $z2] \
- [string index $buf_rdi [expr {$z1 - 2}]]_
+ [string index $buf_rdi [expr {$z1 - 2}]]?
incr c
}
if {$c < $n} {
incr z2 -1
display_file \
[string range $buf_rdf $z1 $z2] \
- _[string index $buf_rdf [expr {$z1 - 2}]]
+ ?[string index $buf_rdf [expr {$z1 - 2}]]
incr c
}
if {$c < $n} {
set pck [split $buf_rlo "\0"]
set buf_rlo [lindex $pck end]
foreach p [lrange $pck 0 end-1] {
- display_file $p _O
+ display_file $p ?O
}
rescan_done $fd buf_rlo $after
}
rescan {set ui_status_value {Ready.}}
}
+proc create_new_commit {} {
+ global commit_type ui_comm
+
+ set commit_type normal
+ $ui_comm delete 0.0 end
+ $ui_comm edit modified false
+ $ui_comm edit reset
+ rescan {set ui_status_value {Ready.}}
+}
+
+set GIT_COMMITTER_IDENT {}
+
+proc committer_ident {} {
+ global GIT_COMMITTER_IDENT
+
+ if {$GIT_COMMITTER_IDENT eq {}} {
+ if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
+ error_popup "Unable to obtain your identity:\n\n$err"
+ return {}
+ }
+ if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
+ $me me GIT_COMMITTER_IDENT]} {
+ error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
+ return {}
+ }
+ }
+
+ return $GIT_COMMITTER_IDENT
+}
+
proc commit_tree {} {
global HEAD commit_type file_states ui_comm repo_config
if {![lock_index update]} return
+ if {[committer_ident] eq {}} return
# -- Our in memory state should match the repository.
#
&& $cur_type eq {normal}
&& $curHEAD eq $HEAD} {
} elseif {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
- error_popup {Last scanned state does not match repository state.
+ info_popup {Last scanned state does not match repository state.
-Its highly likely that another Git program modified the
-repository since the last scan. A rescan is required
-before committing.
+Another Git program has modified this repository
+since the last scan. A rescan must be performed
+before another commit can be created.
-A rescan will be automatically started now.
+The rescan will be automatically started now.
}
unlock_index
rescan {set ui_status_value {Ready.}}
proc commit_committree {fd_wt curHEAD msg} {
global single_commit gitdir HEAD PARENT commit_type tcl_platform
- global ui_status_value ui_comm
+ global ui_status_value ui_comm selected_commit_type
global file_states selected_paths
gets $fd_wt tree_id
# -- Update status without invoking any git commands.
#
set commit_type normal
+ set selected_commit_type new
set HEAD $cmt_id
set PARENT $cmt_id
}
proc post_pull_remote {remote branch success} {
- global HEAD PARENT commit_type
+ global HEAD PARENT commit_type selected_commit_type
global ui_status_value
unlock_index
if {$success} {
repository_state HEAD commit_type
set PARENT $HEAD
+ set selected_commit_type new
set $ui_status_value "Pulling $branch from $remote complete."
} else {
set m "Conflicts detected while pulling $branch from $remote."
set icon [lindex $info 1]
}
- if {$s0 eq {_}} {
+ if {$s0 eq {?}} {
set s0 [string index $state 0]
- } elseif {$s0 eq {*}} {
+ } elseif {$s0 eq {_}} {
set s0 _
}
- if {$s1 eq {_}} {
+ if {$s1 eq {?}} {
set s1 [string index $state 1]
- } elseif {$s1 eq {*}} {
+ } elseif {$s1 eq {_}} {
set s1 _
}
switch -glob -- [lindex $file_states($path) 0] {
AD -
MD -
- _D {set new D*}
+ _D {set new D_}
_M -
MM -
- M_ {set new M*}
+ M_ {set new M_}
_O -
AM -
- A_ {set new A*}
+ A_ {set new A_}
?? {continue}
}
rescan {set ui_status_value {Ready.}}
}
-proc do_include_all {} {
+proc include_helper {txt paths} {
global file_states current_diff
if {![lock_index begin-update]} return
set pathList [list]
set after {}
- foreach path [array names file_states] {
+ foreach path $paths {
switch -- [lindex $file_states($path) 0] {
AM -
+ AD -
MM -
+ UM -
+ U_ -
_M -
- _D {
+ _D -
+ _O {
lappend pathList $path
if {$path eq $current_diff} {
set after {reshow_diff;}
unlock_index
} else {
update_index \
- "Including all modified files" \
+ $txt \
$pathList \
[concat $after {set ui_status_value {Ready to commit.}}]
}
}
-set GIT_COMMITTER_IDENT {}
+proc do_include_selection {} {
+ global current_diff selected_paths
-proc do_signoff {} {
- global ui_comm GIT_COMMITTER_IDENT
+ if {[array size selected_paths] > 0} {
+ include_helper \
+ {Including selected files} \
+ [array names selected_paths]
+ } elseif {$current_diff ne {}} {
+ include_helper \
+ "Including [short_path $current_diff]" \
+ [list $current_diff]
+ }
+}
- if {$GIT_COMMITTER_IDENT eq {}} {
- if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
- error_popup "Unable to obtain your identity:\n\n$err"
- return
- }
- if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
- $me me GIT_COMMITTER_IDENT]} {
- error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
- return
+proc do_include_all {} {
+ global file_states
+
+ set paths [list]
+ foreach path [array names file_states] {
+ switch -- [lindex $file_states($path) 0] {
+ AM -
+ AD -
+ MM -
+ _M -
+ _D {lappend paths $path}
}
}
+ include_helper \
+ {Including all modified files} \
+ $paths
+}
+
+proc do_signoff {} {
+ global ui_comm
+
+ set me [committer_ident]
+ if {$me eq {}} return
- set sob "Signed-off-by: $GIT_COMMITTER_IDENT"
+ set sob "Signed-off-by: $me"
set last [$ui_comm get {end -1c linestart} {end -1c}]
if {$last ne $sob} {
$ui_comm edit separator
}
}
-proc do_amend_last {} {
- load_last_commit
+proc do_select_commit_type {} {
+ global commit_type selected_commit_type
+
+ if {$selected_commit_type eq {new}
+ && [string match amend* $commit_type]} {
+ create_new_commit
+ } elseif {$selected_commit_type eq {amend}
+ && ![string match amend* $commit_type]} {
+ load_last_commit
+
+ # The amend request was rejected...
+ #
+ if {![string match amend* $commit_type]} {
+ set selected_commit_type new
+ }
+ }
}
proc do_commit {} {
## ui construction
# -- Menu Bar
+#
menu .mbar -tearoff 0
.mbar add cascade -label Project -menu .mbar.project
.mbar add cascade -label Edit -menu .mbar.edit
. configure -menu .mbar
# -- Project Menu
+#
menu .mbar.project
.mbar.project add command -label Visualize \
-command do_gitk \
-font font_ui
# -- Commit Menu
+#
menu .mbar.commit
+
+.mbar.commit add radiobutton \
+ -label {New Commit} \
+ -command do_select_commit_type \
+ -variable selected_commit_type \
+ -value new \
+ -font font_ui
+lappend disable_on_lock \
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
+
+.mbar.commit add radiobutton \
+ -label {Amend Last Commit} \
+ -command do_select_commit_type \
+ -variable selected_commit_type \
+ -value amend \
+ -font font_ui
+lappend disable_on_lock \
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
+
+.mbar.commit add separator
+
.mbar.commit add command -label Rescan \
-command do_rescan \
-accelerator F5 \
-font font_ui
lappend disable_on_lock \
[list .mbar.commit entryconf [.mbar.commit index last] -state]
-.mbar.commit add command -label {Amend Last Commit} \
- -command do_amend_last \
+
+.mbar.commit add command -label {Include Selected Files} \
+ -command do_include_selection \
-font font_ui
lappend disable_on_lock \
[list .mbar.commit entryconf [.mbar.commit index last] -state]
+
.mbar.commit add command -label {Include All Files} \
-command do_include_all \
-accelerator $M1T-I \
-font font_ui
lappend disable_on_lock \
[list .mbar.commit entryconf [.mbar.commit index last] -state]
+
.mbar.commit add command -label {Sign Off} \
-command do_signoff \
-accelerator $M1T-S \
-font font_ui
+
.mbar.commit add command -label Commit \
-command do_commit \
-accelerator $M1T-Return \
lappend disable_on_lock \
[list .mbar.commit entryconf [.mbar.commit index last] -state]
+# -- Transport menus
+#
if {!$single_commit} {
- # -- Fetch Menu
menu .mbar.fetch
-
- # -- Pull Menu
menu .mbar.pull
-
- # -- Push Menu
menu .mbar.push
}
# -- Main Window Layout
+#
panedwindow .vpane -orient vertical
panedwindow .vpane.files -orient horizontal
.vpane add .vpane.files -sticky nsew -height 100 -width 400
pack .vpane -anchor n -side top -fill both -expand 1
# -- Index File List
+#
frame .vpane.files.index -height 100 -width 400
label .vpane.files.index.title -text {Modified Files} \
-background green \
.vpane.files add .vpane.files.index -sticky nsew
# -- Other (Add) File List
+#
frame .vpane.files.other -height 100 -width 100
label .vpane.files.other.title -text {Untracked Files} \
-background red \
unset i
# -- Diff and Commit Area
+#
frame .vpane.lower -height 300 -width 400
frame .vpane.lower.commarea
frame .vpane.lower.diff -relief sunken -borderwidth 1
.vpane add .vpane.lower -stick nsew
# -- Commit Area Buttons
+#
frame .vpane.lower.commarea.buttons
label .vpane.lower.commarea.buttons.l -text {} \
-anchor w \
lappend disable_on_lock \
{.vpane.lower.commarea.buttons.rescan conf -state}
-button .vpane.lower.commarea.buttons.amend -text {Amend Last} \
- -command do_amend_last \
- -font font_ui
-pack .vpane.lower.commarea.buttons.amend -side top -fill x
-lappend disable_on_lock \
- {.vpane.lower.commarea.buttons.amend conf -state}
-
button .vpane.lower.commarea.buttons.incall -text {Include All} \
-command do_include_all \
-font font_ui
{.vpane.lower.commarea.buttons.commit conf -state}
# -- Commit Message Buffer
+#
frame .vpane.lower.commarea.buffer
+frame .vpane.lower.commarea.buffer.header
set ui_comm .vpane.lower.commarea.buffer.t
-set ui_coml .vpane.lower.commarea.buffer.l
-label $ui_coml -text {Commit Message:} \
+set ui_coml .vpane.lower.commarea.buffer.header.l
+radiobutton .vpane.lower.commarea.buffer.header.new \
+ -text {New Commit} \
+ -command do_select_commit_type \
+ -variable selected_commit_type \
+ -value new \
+ -font font_ui
+lappend disable_on_lock \
+ [list .vpane.lower.commarea.buffer.header.new conf -state]
+radiobutton .vpane.lower.commarea.buffer.header.amend \
+ -text {Amend Last Commit} \
+ -command do_select_commit_type \
+ -variable selected_commit_type \
+ -value amend \
+ -font font_ui
+lappend disable_on_lock \
+ [list .vpane.lower.commarea.buffer.header.amend conf -state]
+label $ui_coml \
-anchor w \
-justify left \
-font font_ui
$ui_coml conf -text $txt
}
trace add variable commit_type write trace_commit_type
+pack $ui_coml -side left -fill x
+pack .vpane.lower.commarea.buffer.header.amend -side right
+pack .vpane.lower.commarea.buffer.header.new -side right
+
text $ui_comm -background white -borderwidth 1 \
-undo true \
-maxundo 20 \
-yscrollcommand {.vpane.lower.commarea.buffer.sby set}
scrollbar .vpane.lower.commarea.buffer.sby \
-command [list $ui_comm yview]
-pack $ui_coml -side top -fill x
+pack .vpane.lower.commarea.buffer.header -side top -fill x
pack .vpane.lower.commarea.buffer.sby -side right -fill y
pack $ui_comm -side left -fill y
pack .vpane.lower.commarea.buffer -side left -fill y
bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
# -- Diff Header
+#
set current_diff {}
set diff_actions [list]
proc trace_current_diff {varname args} {
bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
# -- Diff Body
+#
frame .vpane.lower.diff.body
set ui_diff .vpane.lower.diff.body.t
text $ui_diff -background white -borderwidth 0 \
set file_lists($ui_index) [list]
set file_lists($ui_other) [list]
+
+set HEAD {}
+set PARENT {}
+set commit_type {}
+set empty_tree {}
set current_diff {}
+set selected_commit_type new
wm title . "$appname ([file normalize [file dirname $gitdir]])"
focus -force $ui_comm
populate_pull_menu .mbar.pull
populate_push_menu .mbar.push
}
+lock_index begin-read
after 1 do_rescan