@matheusbsbs / matheus-bagliano / commits / ce9735dfbd
Fork 0

git-gui: Let users abort with `reset --hard` type logic.

If you get into the middle of a merge that turns out to be horrible and just not something you want to do right now, odds are you need to run `git reset --hard` to recover your working directory to a pre-merge state. We now offer Merge->Abort Merge for exactly this purpose, however its also useful to thow away a non-merge, as its basically the same logic as `git reset --hard`. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 26, 2007 at 03:54 UTC ce9735dfbd77ab7cbcb97ba8749b2f6eaa7f2527
1 file changed +61
git-gui.sh
+61
@@ -2786,6 +2786,61 @@ proc do_local_merge {} {
2786 tkwait window $w
2787 }
2788
2789 +proc do_reset_hard {} {
2790 + global HEAD commit_type file_states
2791 +
2792 + if {[string match amend* $commit_type]} {
2793 + info_popup {Cannot abort while amending.
2794 +
2795 +You must finish amending this commit.
2796 +}
2797 + return
2798 + }
2799 +
2800 + if {![lock_index abort]} return
2801 +
2802 + if {[string match *merge* $commit_type]} {
2803 + set op merge
2804 + } else {
2805 + set op commit
2806 + }
2807 +
2808 + if {[ask_popup "Abort $op?
2809 +
2810 +Aborting the current $op will cause
2811 +*ALL* uncommitted changes to be lost.
2812 +
2813 +Continue with aborting the current $op?"] eq {yes}} {
2814 + set fd [open "| git read-tree --reset -u HEAD" r]
2815 + fconfigure $fd -blocking 0 -translation binary
2816 + fileevent $fd readable [list reset_hard_wait $fd]
2817 + set ui_status_value {Aborting... please wait...}
2818 + } else {
2819 + unlock_index
2820 + }
2821 +}
2822 +
2823 +proc reset_hard_wait {fd} {
2824 + global ui_comm
2825 +
2826 + read $fd
2827 + if {[eof $fd]} {
2828 + close $fd
2829 + unlock_index
2830 +
2831 + $ui_comm delete 0.0 end
2832 + $ui_comm edit modified false
2833 +
2834 + catch {file delete [gitdir MERGE_HEAD]}
2835 + catch {file delete [gitdir rr-cache MERGE_RR]}
2836 + catch {file delete [gitdir SQUASH_MSG]}
2837 + catch {file delete [gitdir MERGE_MSG]}
2838 + catch {file delete [gitdir GITGUI_MSG]}
2839 +
2840 + rescan {set ui_status_value {Abort completed. Ready.}}
2841 + }
2842 +}
2843 +
2844 ######################################################################
2845 ##
2846 ## icons
@@ -4322,6 +4377,12 @@ if {!$single_commit} {
4377 -font font_ui
4378 lappend disable_on_lock \
4379 [list .mbar.merge entryconf [.mbar.merge index last] -state]
4380 + .mbar.merge add command -label {Abort Merge...} \
4381 + -command do_reset_hard \
4382 + -font font_ui
4383 + lappend disable_on_lock \
4384 + [list .mbar.merge entryconf [.mbar.merge index last] -state]
4385 +
4386
4387 menu .mbar.fetch
4388