summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2019-06-13 13:19:41 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-06-13 13:19:41 -0700
commitc4a38d161cbd3308825d7871d0f84f769aad04ab (patch)
tree7c2ea40857b1242030eff1a3cc4548941a152def
parentMerge branch 'ab/fail-prereqs-in-test' (diff)
parentmerge: add --quit (diff)
downloadtgif-c4a38d161cbd3308825d7871d0f84f769aad04ab.tar.xz
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()
-rw-r--r--Documentation/git-merge.txt4
-rw-r--r--branch.c9
-rw-r--r--branch.h6
-rw-r--r--builtin/merge.c30
-rwxr-xr-xt/t7600-merge.sh26
5 files changed, 61 insertions, 14 deletions
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 6294dbc09d..c01cfa6595 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -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
diff --git a/branch.c b/branch.c
index a594cc23e2..e70838fb87 100644
--- a/branch.c
+++ b/branch.c
@@ -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)
diff --git a/branch.h b/branch.h
index 6f38db14e9..064ee576f2 100644
--- a/branch.h
+++ b/branch.h
@@ -61,6 +61,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)
*/
diff --git a/builtin/merge.c b/builtin/merge.c
index e96f72af80..5c83f89cc6 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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)
;
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 7f9c68cbe7..3e16aaed3b 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -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