+proc load_last_commit {} {
+ global HEAD PARENT commit_type ui_comm
+
+ if {$commit_type == {amend}} return
+ if {$commit_type != {normal}} {
+ error_popup "Can't amend a $commit_type commit."
+ return
+ }
+
+ set msg {}
+ set parent {}
+ set parent_count 0
+ if {[catch {
+ set fd [open "| git cat-file commit $HEAD" r]
+ while {[gets $fd line] > 0} {
+ if {[string match {parent *} $line]} {
+ set parent [string range $line 7 end]
+ incr parent_count
+ }
+ }
+ set msg [string trim [read $fd]]
+ close $fd
+ } err]} {
+ error_popup "Error loading commit data for amend:\n$err"
+ return
+ }
+
+ if {$parent_count == 0} {
+ set commit_type amend
+ set HEAD {}
+ set PARENT {}
+ update_status
+ } elseif {$parent_count == 1} {
+ set commit_type amend
+ set PARENT $parent
+ $ui_comm delete 0.0 end
+ $ui_comm insert end $msg
+ $ui_comm edit modified false
+ update_status
+ } else {
+ error_popup {You can't amend a merge commit.}
+ return
+ }
+}
+