3737#include "packfile.h"
3838#include "tag.h"
3939#include "alias.h"
40+ #include "branch.h"
4041#include "commit-reach.h"
4142#include "wt-status.h"
4243
@@ -73,6 +74,7 @@ static int option_renormalize;
7374static int verbosity ;
7475static int allow_rerere_auto ;
7576static int abort_current_merge ;
77+ static int quit_current_merge ;
7678static int continue_current_merge ;
7779static int allow_unrelated_histories ;
7880static int show_progress = -1 ;
@@ -274,6 +276,8 @@ static struct option builtin_merge_options[] = {
274276 OPT__VERBOSITY (& verbosity ),
275277 OPT_BOOL (0 , "abort" , & abort_current_merge ,
276278 N_ ("abort the current in-progress merge" )),
279+ OPT_BOOL (0 , "quit" , & quit_current_merge ,
280+ N_ ("--abort but leave index and working tree alone" )),
277281 OPT_BOOL (0 , "continue" , & continue_current_merge ,
278282 N_ ("continue the current in-progress merge" )),
279283 OPT_BOOL (0 , "allow-unrelated-histories" , & allow_unrelated_histories ,
@@ -287,14 +291,6 @@ static struct option builtin_merge_options[] = {
287291 OPT_END ()
288292};
289293
290- /* Cleans up metadata that is uninteresting after a succeeded merge. */
291- static void drop_save (void )
292- {
293- unlink (git_path_merge_head (the_repository ));
294- unlink (git_path_merge_msg (the_repository ));
295- unlink (git_path_merge_mode (the_repository ));
296- }
297-
298294static int save_state (struct object_id * stash )
299295{
300296 int len ;
@@ -388,7 +384,7 @@ static void finish_up_to_date(const char *msg)
388384{
389385 if (verbosity >= 0 )
390386 printf ("%s%s\n" , squash ? _ (" (nothing to squash)" ) : "" , msg );
391- drop_save ( );
387+ remove_merge_branch_state ( the_repository );
392388}
393389
394390static void squash_message (struct commit * commit , struct commit_list * remoteheads )
@@ -881,7 +877,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
881877 & result_commit , NULL , sign_commit ))
882878 die (_ ("failed to write commit object" ));
883879 finish (head , remoteheads , & result_commit , "In-index merge" );
884- drop_save ( );
880+ remove_merge_branch_state ( the_repository );
885881 return 0 ;
886882}
887883
@@ -907,7 +903,7 @@ static int finish_automerge(struct commit *head,
907903 strbuf_addf (& buf , "Merge made by the '%s' strategy." , wt_strategy );
908904 finish (head , remoteheads , & result_commit , buf .buf );
909905 strbuf_release (& buf );
910- drop_save ( );
906+ remove_merge_branch_state ( the_repository );
911907 return 0 ;
912908}
913909
@@ -1289,6 +1285,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12891285 goto done ;
12901286 }
12911287
1288+ if (quit_current_merge ) {
1289+ if (orig_argc != 2 )
1290+ usage_msg_opt (_ ("--quit expects no arguments" ),
1291+ builtin_merge_usage ,
1292+ builtin_merge_options );
1293+
1294+ remove_merge_branch_state (the_repository );
1295+ goto done ;
1296+ }
1297+
12921298 if (continue_current_merge ) {
12931299 int nargc = 1 ;
12941300 const char * nargv [] = {"commit" , NULL };
@@ -1495,7 +1501,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14951501 }
14961502
14971503 finish (head_commit , remoteheads , & commit -> object .oid , msg .buf );
1498- drop_save ( );
1504+ remove_merge_branch_state ( the_repository );
14991505 goto done ;
15001506 } else if (!remoteheads -> next && common -> next )
15011507 ;
0 commit comments