# and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version.
+set appname [lindex [file split $argv0] end]
+set gitdir {}
+
######################################################################
##
## config
set repo_config(gui.trustmtime) [list $cfg_trust_mtime]
}
- set cfg_geometry [list \
- [wm geometry .] \
- [.vpane sash coord 0] \
- [.vpane.files sash coord 0] \
- ]
+ set cfg_geometry [wm geometry .]
+ append cfg_geometry " [lindex [.vpane sash coord 0] 1]"
+ append cfg_geometry " [lindex [.vpane.files sash coord 0] 0]"
if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
set rc_geometry [list [list]]
}
}
}
+proc error_popup {msg} {
+ global gitdir appname
+
+ set title $appname
+ if {$gitdir != {}} {
+ append title { (}
+ append title [lindex \
+ [file split [file normalize [file dirname $gitdir]]] \
+ end]
+ append title {)}
+ }
+ tk_messageBox \
+ -parent . \
+ -icon error \
+ -type ok \
+ -title "$title: error" \
+ -message $msg
+}
+
######################################################################
##
## repository setup
-set appname [lindex [file split $argv0] end]
-set gitdir {}
-set GIT_COMMITTER_IDENT {}
-
-if {[catch {set cdup [exec git rev-parse --show-cdup]} err]} {
- show_msg {} . "Cannot find the git directory: $err"
+if { [catch {set cdup [exec git rev-parse --show-cdup]} err]
+ || [catch {set gitdir [exec git rev-parse --git-dir]} err]} {
+ catch {wm withdraw .}
+ error_popup "Cannot find the git directory:\n\n$err"
exit 1
}
if {$cdup != ""} {
}
unset cdup
-if {[catch {set gitdir [exec git rev-parse --git-dir]} err]} {
- show_msg {} . "Cannot find the git directory: $err"
- exit 1
-}
-
if {$appname == {git-citool}} {
set single_commit 1
}
set ui_status_value {Refreshing file status...}
set fd_rf [open "| git update-index -q --unmerged --refresh" r]
fconfigure $fd_rf -blocking 0 -translation binary
- fileevent $fd_rf readable [list update_status_stage2 $fd_rf $final]
+ fileevent $fd_rf readable \
+ [list update_status_stage2 $fd_rf $final]
}
}
set cmd [list | git diff-index -p $PARENT -- $path]
switch $m {
- AM {
- }
MM {
set cmd [list | git diff-index -p -c $PARENT $path]
}
set diff_active 0
unlock_index
set ui_status_value "Unable to display [escape_path $path]"
- error_popup "Error loading file:\n$err"
+ error_popup "Error loading file:\n\n$err"
return
}
$ui_diff conf -state normal
set diff_active 0
unlock_index
set ui_status_value "Unable to display [escape_path $path]"
- error_popup "Error loading diff:\n$err"
+ error_popup "Error loading diff:\n\n$err"
return
}
set msg [string trim [read $fd]]
close $fd
} err]} {
- error_popup "Error loading commit data for amend:\n$err"
+ error_popup "Error loading commit data for amend:\n\n$err"
return
}
global file_states
gets $fd_wt tree_id
- close $fd_wt
-
- if {$tree_id == {}} {
- error_popup "write-tree failed"
+ if {$tree_id == {} || [catch {close $fd_wt} err]} {
+ error_popup "write-tree failed:\n\n$err"
set commit_active 0
set ui_status_value {Commit failed.}
unlock_index
}
close $fd_mh
} err]} {
- error_popup "Loading MERGE_HEAD failed:\n$err"
+ error_popup "Loading MERGE_HEAD failed:\n\n$err"
set commit_active 0
set ui_status_value {Commit failed.}
unlock_index
}
lappend cmd << $msg
if {[catch {set cmt_id [eval exec $cmd]} err]} {
- error_popup "commit-tree failed:\n$err"
+ error_popup "commit-tree failed:\n\n$err"
set commit_active 0
set ui_status_value {Commit failed.}
unlock_index
}
set cmd [list git update-ref -m $reflogm HEAD $cmt_id $curHEAD]
if {[catch {eval exec $cmd} err]} {
- error_popup "update-ref failed:\n$err"
+ error_popup "update-ref failed:\n\n$err"
set commit_active 0
set ui_status_value {Commit failed.}
unlock_index
set PARENT $HEAD
set $ui_status_value {Ready.}
} else {
- update_status "Conflicts detected while pulling $branch from $remote."
+ update_status \
+ "Conflicts detected while pulling $branch from $remote."
}
}
}
proc populate_remote_menu {m pfx op} {
- global all_remotes mainfont
+ global all_remotes font_ui
foreach remote $all_remotes {
$m add command -label "$pfx $remote..." \
-command [list $op $remote] \
- -font $mainfont
+ -font $font_ui
}
}
proc populate_pull_menu {m} {
- global gitdir repo_config all_remotes mainfont disable_on_lock
+ global gitdir repo_config all_remotes font_ui disable_on_lock
foreach remote $all_remotes {
set rb {}
$m add command \
-label "Branch $rb_short from $remote..." \
-command [list pull_remote $remote $rb] \
- -font $mainfont
+ -font $font_ui
lappend disable_on_lock \
[list $m entryconf [$m index last] -state]
}
##
## util
-proc error_popup {msg} {
- set w .error
- toplevel $w
- wm transient $w .
- show_msg $w $w $msg
-}
-
-proc show_msg {w top msg} {
- global gitdir appname mainfont
-
- message $w.m -text $msg -justify left -aspect 400
- pack $w.m -side top -fill x -padx 5 -pady 10
- button $w.ok -text OK \
- -width 15 \
- -font $mainfont \
- -command "destroy $top"
- pack $w.ok -side bottom
- bind $top <Visibility> "grab $top; focus $top"
- bind $top <Key-Return> "destroy $top"
- wm title $w "$appname ([lindex [file split \
- [file normalize [file dirname $gitdir]]] \
- end]): error"
- tkwait window $top
-}
-
proc hook_failed_popup {hook msg} {
- global gitdir mainfont difffont appname
+ global gitdir font_ui font_diff appname
set w .hookfail
toplevel $w
label $w.m.l1 -text "$hook hook failed:" \
-anchor w \
-justify left \
- -font [concat $mainfont bold]
+ -font [concat $font_ui bold]
text $w.m.t \
-background white -borderwidth 1 \
-relief sunken \
-width 80 -height 10 \
- -font $difffont \
+ -font $font_diff \
-yscrollcommand [list $w.m.sby set]
label $w.m.l2 \
-text {You must correct the above errors before committing.} \
-anchor w \
-justify left \
- -font [concat $mainfont bold]
+ -font [concat $font_ui bold]
scrollbar $w.m.sby -command [list $w.m.t yview]
pack $w.m.l1 -side top -fill x
pack $w.m.l2 -side bottom -fill x
button $w.ok -text OK \
-width 15 \
- -font $mainfont \
+ -font $font_ui \
-command "destroy $w"
pack $w.ok -side bottom
proc console_init {w} {
global console_cr console_data
- global gitdir appname mainfont difffont
+ global gitdir appname font_ui font_diff
set console_cr($w) 1.0
toplevel $w
label $w.m.l1 -text "[lindex $console_data($w) 1]:" \
-anchor w \
-justify left \
- -font [concat $mainfont bold]
+ -font [concat $font_ui bold]
text $w.m.t \
-background white -borderwidth 1 \
-relief sunken \
-width 80 -height 10 \
- -font $difffont \
+ -font $font_diff \
-state disabled \
-yscrollcommand [list $w.m.sby set]
label $w.m.s -anchor w \
-justify left \
- -font [concat $mainfont bold]
+ -font [concat $font_ui bold]
scrollbar $w.m.sby -command [list $w.m.t yview]
pack $w.m.l1 -side top -fill x
pack $w.m.s -side bottom -fill x
button $w.ok -text {Running...} \
-width 15 \
- -font $mainfont \
+ -font $font_ui \
-state disabled \
-command "destroy $w"
pack $w.ok -side bottom
console_exec $w $cmd
}
+set quitting 0
+
proc do_quit {} {
- global gitdir ui_comm
+ global gitdir ui_comm quitting
+
+ if {$quitting} return
+ set quitting 1
set save [file join $gitdir GITGUI_MSG]
set msg [string trim [$ui_comm get 0.0 end]]
}
}
+set GIT_COMMITTER_IDENT {}
+
proc do_signoff {} {
global ui_comm GIT_COMMITTER_IDENT
if {$GIT_COMMITTER_IDENT == {}} {
if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
- error_popup "Unable to obtain your identity:\n$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$me"
+ error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
return
}
}
##
## ui init
-set mainfont {Helvetica 10}
-set difffont {Courier 10}
+set font_ui {Helvetica 10}
+set font_diff {Courier 10}
set maincursor [. cget -cursor]
switch -glob -- "$tcl_platform(platform),$tcl_platform(os)" {
windows,* {set M1B Control; set M1T Ctrl}
unix,Darwin {set M1B M1; set M1T Cmd}
-default {set M1B M1; set M1T M1}
+* {set M1B M1; set M1T M1}
}
# -- Menu Bar
menu .mbar.project
.mbar.project add command -label Visualize \
-command do_gitk \
- -font $mainfont
+ -font $font_ui
.mbar.project add command -label {Repack Database} \
-command do_repack \
- -font $mainfont
+ -font $font_ui
.mbar.project add command -label Quit \
-command do_quit \
-accelerator $M1T-Q \
- -font $mainfont
+ -font $font_ui
# -- Edit Menu
#
.mbar.edit add command -label Undo \
-command {catch {[focus] edit undo}} \
-accelerator $M1T-Z \
- -font $mainfont
+ -font $font_ui
.mbar.edit add command -label Redo \
-command {catch {[focus] edit redo}} \
-accelerator $M1T-Y \
- -font $mainfont
+ -font $font_ui
.mbar.edit add separator
.mbar.edit add command -label Cut \
-command {catch {tk_textCut [focus]}} \
-accelerator $M1T-X \
- -font $mainfont
+ -font $font_ui
.mbar.edit add command -label Copy \
-command {catch {tk_textCopy [focus]}} \
-accelerator $M1T-C \
- -font $mainfont
+ -font $font_ui
.mbar.edit add command -label Paste \
-command {catch {tk_textPaste [focus]; [focus] see insert}} \
-accelerator $M1T-V \
- -font $mainfont
+ -font $font_ui
.mbar.edit add command -label Delete \
-command {catch {[focus] delete sel.first sel.last}} \
-accelerator Del \
- -font $mainfont
+ -font $font_ui
.mbar.edit add separator
.mbar.edit add command -label {Select All} \
-command {catch {[focus] tag add sel 0.0 end}} \
-accelerator $M1T-A \
- -font $mainfont
+ -font $font_ui
# -- Commit Menu
menu .mbar.commit
.mbar.commit add command -label Rescan \
-command do_rescan \
-accelerator F5 \
- -font $mainfont
+ -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 \
- -font $mainfont
+ -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 $mainfont
+ -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 $mainfont
+ -font $font_ui
.mbar.commit add command -label Commit \
-command do_commit \
-accelerator $M1T-Return \
- -font $mainfont
+ -font $font_ui
lappend disable_on_lock \
[list .mbar.commit entryconf [.mbar.commit index last] -state]
frame .vpane.files.index -height 100 -width 400
label .vpane.files.index.title -text {Modified Files} \
-background green \
- -font $mainfont
+ -font $font_ui
text $ui_index -background white -borderwidth 0 \
-width 40 -height 10 \
- -font $mainfont \
+ -font $font_ui \
-yscrollcommand {.vpane.files.index.sb set} \
-cursor $maincursor \
-state disabled
frame .vpane.files.other -height 100 -width 100
label .vpane.files.other.title -text {Untracked Files} \
-background red \
- -font $mainfont
+ -font $font_ui
text $ui_other -background white -borderwidth 0 \
-width 40 -height 10 \
- -font $mainfont \
+ -font $font_ui \
-yscrollcommand {.vpane.files.other.sb set} \
-cursor $maincursor \
-state disabled
pack $ui_other -side left -fill both -expand 1
.vpane.files add .vpane.files.other -sticky nsew
-$ui_index tag conf in_diff -font [concat $mainfont bold]
-$ui_other tag conf in_diff -font [concat $mainfont bold]
+$ui_index tag conf in_diff -font [concat $font_ui bold]
+$ui_other tag conf in_diff -font [concat $font_ui bold]
# -- Diff and Commit Area
frame .vpane.lower -height 400 -width 400
label .vpane.lower.commarea.buttons.l -text {} \
-anchor w \
-justify left \
- -font $mainfont
+ -font $font_ui
pack .vpane.lower.commarea.buttons.l -side top -fill x
pack .vpane.lower.commarea.buttons -side left -fill y
button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
-command do_rescan \
- -font $mainfont
+ -font $font_ui
pack .vpane.lower.commarea.buttons.rescan -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.rescan conf -state}
+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 $mainfont
+ -font $font_ui
pack .vpane.lower.commarea.buttons.amend -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.amend conf -state}
+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 $mainfont
+ -font $font_ui
pack .vpane.lower.commarea.buttons.incall -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.incall conf -state}
+lappend disable_on_lock \
+ {.vpane.lower.commarea.buttons.incall conf -state}
button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
-command do_signoff \
- -font $mainfont
+ -font $font_ui
pack .vpane.lower.commarea.buttons.signoff -side top -fill x
button .vpane.lower.commarea.buttons.commit -text {Commit} \
-command do_commit \
- -font $mainfont
+ -font $font_ui
pack .vpane.lower.commarea.buttons.commit -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.commit conf -state}
+lappend disable_on_lock \
+ {.vpane.lower.commarea.buttons.commit conf -state}
# -- Commit Message Buffer
frame .vpane.lower.commarea.buffer
label $ui_coml -text {Commit Message:} \
-anchor w \
-justify left \
- -font $mainfont
+ -font $font_ui
trace add variable commit_type write {uplevel #0 {
switch -glob $commit_type \
initial {$ui_coml conf -text {Initial Commit Message:}} \
-autoseparators true \
-relief sunken \
-width 75 -height 9 -wrap none \
- -font $difffont \
+ -font $font_diff \
-yscrollcommand {.vpane.lower.commarea.buffer.sby set} \
-cursor $maincursor
-scrollbar .vpane.lower.commarea.buffer.sby -command [list $ui_comm yview]
+scrollbar .vpane.lower.commarea.buffer.sby \
+ -command [list $ui_comm yview]
pack $ui_coml -side top -fill x
pack .vpane.lower.commarea.buffer.sby -side right -fill y
pack $ui_comm -side left -fill y
frame .vpane.lower.diff.header -background orange
label .vpane.lower.diff.header.l1 -text {File:} \
-background orange \
- -font $mainfont
+ -font $font_ui
label .vpane.lower.diff.header.l2 -textvariable ui_fname_value \
-background orange \
-anchor w \
-justify left \
- -font $mainfont
+ -font $font_ui
label .vpane.lower.diff.header.l3 -text {Status:} \
-background orange \
- -font $mainfont
+ -font $font_ui
label .vpane.lower.diff.header.l4 -textvariable ui_fstatus_value \
-background orange \
-width $max_status_desc \
-anchor w \
-justify left \
- -font $mainfont
+ -font $font_ui
pack .vpane.lower.diff.header.l1 -side left
pack .vpane.lower.diff.header.l2 -side left -fill x
pack .vpane.lower.diff.header.l4 -side right
set ui_diff .vpane.lower.diff.body.t
text $ui_diff -background white -borderwidth 0 \
-width 80 -height 15 -wrap none \
- -font $difffont \
+ -font $font_diff \
-xscrollcommand {.vpane.lower.diff.body.sbx set} \
-yscrollcommand {.vpane.lower.diff.body.sby set} \
-cursor $maincursor \
$ui_diff tag conf dm -foreground red
$ui_diff tag conf dp -foreground blue
-$ui_diff tag conf da -font [concat $difffont bold]
+$ui_diff tag conf da -font [concat $font_diff bold]
$ui_diff tag conf di -foreground "#00a000"
$ui_diff tag conf dni -foreground "#a000a0"
-$ui_diff tag conf bold -font [concat $difffont bold]
+$ui_diff tag conf bold -font [concat $font_diff bold]
# -- Status Bar
set ui_status_value {Initializing...}
-justify left \
-borderwidth 1 \
-relief sunken \
- -font $mainfont
+ -font $font_ui
pack .status -anchor w -side bottom -fill x
# -- Load geometry
catch {
-wm geometry . [lindex $repo_config(gui.geometry) 0 0]
-eval .vpane sash place 0 [lindex $repo_config(gui.geometry) 0 1]
-eval .vpane.files sash place 0 [lindex $repo_config(gui.geometry) 0 2]
+set gm [lindex $repo_config(gui.geometry) 0]
+wm geometry . [lindex $gm 0]
+.vpane sash place 0 \
+ [lindex [.vpane sash coord 0] 0] \
+ [lindex $gm 1]
+.vpane.files sash place 0 \
+ [lindex $gm 2] \
+ [lindex [.vpane.files sash coord 0] 1]
+unset gm
}
# -- Key Bindings