Merge branch 'nd/merge-quit'

"git merge" learned "--quit" option that cleans up the in-progress
merge while leaving the working tree and the index still in a mess.

* nd/merge-quit:
  merge: add --quit
  merge: remove drop_save() in favor of remove_merge_branch_state()
This commit is contained in:
Junio C Hamano 2019-06-13 13:19:41 -07:00
commit c4a38d161c
5 changed files with 61 additions and 14 deletions

View File

@ -100,6 +100,10 @@ commit or stash your changes before running 'git merge'.
'git merge --abort' is equivalent to 'git reset --merge' when
`MERGE_HEAD` is present.
--quit::
Forget about the current merge in progress. Leave the index
and the working tree as-is.
--continue::
After a 'git merge' stops due to conflicts you can conclude the
merge by running 'git merge --continue' (see "HOW TO RESOLVE

View File

@ -338,14 +338,19 @@ void create_branch(struct repository *r,
free(real_ref);
}
void remove_branch_state(struct repository *r)
void remove_merge_branch_state(struct repository *r)
{
sequencer_post_commit_cleanup(r);
unlink(git_path_merge_head(r));
unlink(git_path_merge_rr(r));
unlink(git_path_merge_msg(r));
unlink(git_path_merge_mode(r));
}
void remove_branch_state(struct repository *r)
{
sequencer_post_commit_cleanup(r);
unlink(git_path_squash_msg(r));
remove_merge_branch_state(r);
}
void die_if_checked_out(const char *branch, int ignore_current_worktree)

View File

@ -60,6 +60,12 @@ int validate_branchname(const char *name, struct strbuf *ref);
*/
int validate_new_branchname(const char *name, struct strbuf *ref, int force);
/*
* Remove information about the merge state on the current
* branch. (E.g., MERGE_HEAD)
*/
void remove_merge_branch_state(struct repository *r);
/*
* Remove information about the state of working on the current
* branch. (E.g., MERGE_HEAD)

View File

@ -37,6 +37,7 @@
#include "packfile.h"
#include "tag.h"
#include "alias.h"
#include "branch.h"
#include "commit-reach.h"
#include "wt-status.h"
@ -73,6 +74,7 @@ static int option_renormalize;
static int verbosity;
static int allow_rerere_auto;
static int abort_current_merge;
static int quit_current_merge;
static int continue_current_merge;
static int allow_unrelated_histories;
static int show_progress = -1;
@ -274,6 +276,8 @@ static struct option builtin_merge_options[] = {
OPT__VERBOSITY(&verbosity),
OPT_BOOL(0, "abort", &abort_current_merge,
N_("abort the current in-progress merge")),
OPT_BOOL(0, "quit", &quit_current_merge,
N_("--abort but leave index and working tree alone")),
OPT_BOOL(0, "continue", &continue_current_merge,
N_("continue the current in-progress merge")),
OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories,
@ -287,14 +291,6 @@ static struct option builtin_merge_options[] = {
OPT_END()
};
/* Cleans up metadata that is uninteresting after a succeeded merge. */
static void drop_save(void)
{
unlink(git_path_merge_head(the_repository));
unlink(git_path_merge_msg(the_repository));
unlink(git_path_merge_mode(the_repository));
}
static int save_state(struct object_id *stash)
{
int len;
@ -388,7 +384,7 @@ static void finish_up_to_date(const char *msg)
{
if (verbosity >= 0)
printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
drop_save();
remove_merge_branch_state(the_repository);
}
static 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)
&result_commit, NULL, sign_commit))
die(_("failed to write commit object"));
finish(head, remoteheads, &result_commit, "In-index merge");
drop_save();
remove_merge_branch_state(the_repository);
return 0;
}
@ -907,7 +903,7 @@ static int finish_automerge(struct commit *head,
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
finish(head, remoteheads, &result_commit, buf.buf);
strbuf_release(&buf);
drop_save();
remove_merge_branch_state(the_repository);
return 0;
}
@ -1289,6 +1285,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
goto done;
}
if (quit_current_merge) {
if (orig_argc != 2)
usage_msg_opt(_("--quit expects no arguments"),
builtin_merge_usage,
builtin_merge_options);
remove_merge_branch_state(the_repository);
goto done;
}
if (continue_current_merge) {
int nargc = 1;
const char *nargv[] = {"commit", NULL};
@ -1495,7 +1501,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}
finish(head_commit, remoteheads, &commit->object.oid, msg.buf);
drop_save();
remove_merge_branch_state(the_repository);
goto done;
} else if (!remoteheads->next && common->next)
;

View File

@ -867,4 +867,30 @@ test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue'
verify_parents $c0 $c1
'
test_expect_success 'merge --quit' '
git init merge-quit &&
(
cd merge-quit &&
test_commit base &&
echo one >>base.t &&
git commit -am one &&
git branch one &&
git checkout base &&
echo two >>base.t &&
git commit -am two &&
test_must_fail git -c rerere.enabled=true merge one &&
test_path_is_file .git/MERGE_HEAD &&
test_path_is_file .git/MERGE_MODE &&
test_path_is_file .git/MERGE_MSG &&
git rerere status >rerere.before &&
git merge --quit &&
test_path_is_missing .git/MERGE_HEAD &&
test_path_is_missing .git/MERGE_MODE &&
test_path_is_missing .git/MERGE_MSG &&
git rerere status >rerere.after &&
test_must_be_empty rerere.after &&
! test_cmp rerere.after rerere.before
)
'
test_done