1417
1418
proc do_quit {} {
1419
global ui_comm is_quitting repo_config commit_type
1420
+ global GITGUI_BCK_exists GITGUI_BCK_i
1421
1422
if {$is_quitting} return
1423
set is_quitting 1
1426
# -- Stash our current commit buffer.
1427
#
1428
set save [gitdir GITGUI_MSG]
1428
- set msg [string trim [$ui_comm get 0.0 end]]
1429
- regsub -all -line {[ \r\t]+$} $msg {} msg
1430
- if {(![string match amend* $commit_type]
1431
- || [$ui_comm edit modified])
1432
- && $msg ne {}} {
1433
- catch {
1434
- set fd [open $save w]
1435
- puts -nonewline $fd $msg
1436
- close $fd
1437
- }
1429
+ if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
1430
+ file rename -force [gitdir GITGUI_BCK] $save
1431
+ set GITGUI_BCK_exists 0
1432
} else {
1439
- catch {file delete $save}
1433
+ set msg [string trim [$ui_comm get 0.0 end]]
1434
+ regsub -all -line {[ \r\t]+$} $msg {} msg
1435
+ if {(![string match amend* $commit_type]
1436
+ || [$ui_comm edit modified])
1437
+ && $msg ne {}} {
1438
+ catch {
1439
+ set fd [open $save w]
1440
+ puts -nonewline $fd $msg
1441
+ close $fd
1442
+ }
1443
+ } else {
1444
+ catch {file delete $save}
1445
+ }
1446
+ }
1447
+
1448
+ # -- Remove our editor backup, its not needed.
1449
+ #
1450
+ after cancel $GITGUI_BCK_i
1451
+ if {$GITGUI_BCK_exists} {
1452
+ catch {file delete [gitdir GITGUI_BCK]}
1453
}
1454
1455
# -- Stash our current window geometry into this repository.
2611
populate_push_menu
2612
}
2613
2614
+if {[winfo exists $ui_comm]} {
2615
+ set GITGUI_BCK_exists [load_message GITGUI_BCK]
2616
+
2617
+ # -- If both our backup and message files exist use the
2618
+ # newer of the two files to initialize the buffer.
2619
+ #
2620
+ if {$GITGUI_BCK_exists} {
2621
+ set m [gitdir GITGUI_MSG]
2622
+ if {[file isfile $m]} {
2623
+ if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
2624
+ catch {file delete [gitdir GITGUI_MSG]}
2625
+ } else {
2626
+ $ui_comm delete 0.0 end
2627
+ $ui_comm edit reset
2628
+ $ui_comm edit modified false
2629
+ catch {file delete [gitdir GITGUI_BCK]}
2630
+ set GITGUI_BCK_exists 0
2631
+ }
2632
+ }
2633
+ unset m
2634
+ }
2635
+
2636
+ proc backup_commit_buffer {} {
2637
+ global ui_comm GITGUI_BCK_exists
2638
+
2639
+ set m [$ui_comm edit modified]
2640
+ if {$m || $GITGUI_BCK_exists} {
2641
+ set msg [string trim [$ui_comm get 0.0 end]]
2642
+ regsub -all -line {[ \r\t]+$} $msg {} msg
2643
+
2644
+ if {$msg eq {}} {
2645
+ if {$GITGUI_BCK_exists} {
2646
+ catch {file delete [gitdir GITGUI_BCK]}
2647
+ set GITGUI_BCK_exists 0
2648
+ }
2649
+ } elseif {$m} {
2650
+ catch {
2651
+ set fd [open [gitdir GITGUI_BCK] w]
2652
+ puts -nonewline $fd $msg
2653
+ close $fd
2654
+ set GITGUI_BCK_exists 1
2655
+ }
2656
+ }
2657
+
2658
+ $ui_comm edit modified false
2659
+ }
2660
+
2661
+ set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
2662
+ }
2663
+
2664
+ backup_commit_buffer
2665
+}
2666
+
2667
lock_index begin-read
2668
if {![winfo ismapped .]} {
2669
wm deiconify .