Code

Status view: special case revert of unmerged entries with no physical file
authorJonas Fonseca <fonseca@diku.dk>
Thu, 19 Nov 2009 03:02:45 +0000 (22:02 -0500)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 19 Nov 2009 03:03:29 +0000 (22:03 -0500)
tig.c

diff --git a/tig.c b/tig.c
index 9e76ea0c21afb2b3987c94677588685f752b7dd6..222b3698de6bcc60395ab74519b4c9048e2e5ed6 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -5814,9 +5814,8 @@ status_revert(struct status *status, enum line_type type, bool has_none)
                } else {
                        report("Cannot revert changes to multiple files");
                }
-               return FALSE;
 
-       } else {
+       } else if (prompt_yesno("Are you sure you want to revert changes?")) {
                char mode[10] = "100644";
                const char *reset_argv[] = {
                        "git", "update-index", "--cacheinfo", mode,
@@ -5826,12 +5825,25 @@ status_revert(struct status *status, enum line_type type, bool has_none)
                        "git", "checkout", "--", status->old.name, NULL
                };
 
-               if (!prompt_yesno("Are you sure you want to overwrite any changes?"))
-                       return FALSE;
-               string_format(mode, "%o", status->old.mode);
-               return (status->status != 'U' || run_io_fg(reset_argv, opt_cdup)) &&
-                       run_io_fg(checkout_argv, opt_cdup);
+               if (status->status == 'U') {
+                       string_format(mode, "%5o", status->old.mode);
+
+                       if (status->old.mode == 0 && status->new.mode == 0) {
+                               reset_argv[2] = "--force-remove";
+                               reset_argv[3] = status->old.name;
+                               reset_argv[4] = NULL;
+                       }
+
+                       if (!run_io_fg(reset_argv, opt_cdup))
+                               return FALSE;
+                       if (status->old.mode == 0 && status->new.mode == 0)
+                               return TRUE;
+               }
+
+               return run_io_fg(checkout_argv, opt_cdup);
        }
+
+       return FALSE;
 }
 
 static enum request