205
set HEAD {}
206
set PARENT {}
207
set commit_type {}
208
+set empty_tree {}
209
210
proc lock_index {type} {
211
global index_lock_type disable_on_lock
241
upvar $hdvar hd $ctvar ct
242
243
if {[catch {set hd [exec git rev-parse --verify HEAD]}]} {
244
+ set hd {}
245
set ct initial
246
} elseif {[file exists [file join $gitdir MERGE_HEAD]]} {
247
set ct merge
250
}
251
}
252
253
+proc PARENT {} {
254
+ global PARENT empty_tree
255
+
256
+ if {$PARENT ne {}} {
257
+ return $PARENT
258
+ }
259
+ if {$empty_tree eq {}} {
260
+ set empty_tree [exec git mktree << {}]
261
+ }
262
+ return $empty_tree
263
+}
264
+
265
proc rescan {after} {
266
global HEAD PARENT commit_type
267
global ui_index ui_other ui_status_value ui_comm
271
if {$rescan_active > 0 || ![lock_index read]} return
272
273
repository_state new_HEAD new_type
260
- if {$commit_type eq {amend}
274
+ if {[string match amend* $commit_type]
275
&& $new_type eq {normal}
276
&& $new_HEAD eq $HEAD} {
277
} else {
310
}
311
312
proc rescan_stage2 {fd after} {
299
- global gitdir PARENT commit_type
300
- global ui_index ui_other ui_status_value ui_comm
301
- global rescan_active
302
- global buf_rdi buf_rdf buf_rlo
313
+ global gitdir ui_status_value
314
+ global rescan_active buf_rdi buf_rdf buf_rlo
315
316
if {$fd ne {}} {
317
read $fd
332
333
set rescan_active 3
334
set ui_status_value {Scanning for modified files ...}
323
- set fd_di [open "| git diff-index --cached -z $PARENT" r]
335
+ set fd_di [open "| git diff-index --cached -z [PARENT]" r]
336
set fd_df [open "| git diff-files -z" r]
337
set fd_lo [open $ls_others r]
338
544
545
proc show_diff {path {w {}} {lno {}}} {
546
global file_states file_lists
535
- global PARENT diff_3way diff_active repo_config
547
+ global diff_3way diff_active repo_config
548
global ui_diff current_diff ui_status_value
549
550
if {$diff_active || ![lock_index read]} return
603
}
604
}
605
594
- lappend cmd $PARENT
606
+ lappend cmd [PARENT]
607
lappend cmd --
608
lappend cmd $path
609
683
proc load_last_commit {} {
684
global HEAD PARENT commit_type ui_comm
685
674
- if {$commit_type eq {amend}} return
686
+ if {[string match amend* $commit_type]} return
687
if {$commit_type ne {normal}} {
688
error_popup "Can't amend a $commit_type commit."
689
return
707
return
708
}
709
710
+ if {$parent_count > 1} {
711
+ error_popup {Can't amend a merge commit.}
712
+ return
713
+ }
714
+
715
if {$parent_count == 0} {
699
- set commit_type amend
700
- set HEAD {}
716
+ set commit_type amend-initial
717
set PARENT {}
702
- rescan {set ui_status_value {Ready.}}
718
} elseif {$parent_count == 1} {
719
set commit_type amend
720
set PARENT $parent
706
- $ui_comm delete 0.0 end
707
- $ui_comm insert end $msg
708
- $ui_comm edit modified false
709
- $ui_comm edit reset
710
- rescan {set ui_status_value {Ready.}}
711
- } else {
712
- error_popup {You can't amend a merge commit.}
713
- return
721
}
722
+
723
+ $ui_comm delete 0.0 end
724
+ $ui_comm insert end $msg
725
+ $ui_comm edit modified false
726
+ $ui_comm edit reset
727
+ rescan {set ui_status_value {Ready.}}
728
}
729
730
proc commit_tree {} {
735
# -- Our in memory state should match the repository.
736
#
737
repository_state curHEAD cur_type
725
- if {$commit_type eq {amend}
738
+ if {[string match amend* $commit_type]
739
&& $cur_type eq {normal}
740
&& $curHEAD eq $HEAD} {
741
} elseif {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
2572
-anchor w \
2573
-justify left \
2574
-font font_ui
2562
-trace add variable commit_type write {uplevel #0 {
2563
- switch -glob $commit_type \
2564
- initial {$ui_coml conf -text {Initial Commit Message:}} \
2565
- amend {$ui_coml conf -text {Amended Commit Message:}} \
2566
- merge {$ui_coml conf -text {Merge Commit Message:}} \
2567
- * {$ui_coml conf -text {Commit Message:}}
2568
-}}
2575
+proc trace_commit_type {varname args} {
2576
+ global ui_coml commit_type
2577
+ switch -glob -- $commit_type {
2578
+ initial {set txt {Initial Commit Message:}}
2579
+ amend {set txt {Amended Commit Message:}}
2580
+ amend-initial {set txt {Amended Initial Commit Message:}}
2581
+ merge {set txt {Merge Commit Message:}}
2582
+ * {set txt {Commit Message:}}
2583
+ }
2584
+ $ui_coml conf -text $txt
2585
+}
2586
+trace add variable commit_type write trace_commit_type
2587
text $ui_comm -background white -borderwidth 1 \
2588
-undo true \
2589
-maxundo 20 \