From: Edmundo Carmona Antoranz <eantoranz@gmail.com>
To: git@vger.kernel.org
Cc: Edmundo Carmona Antoranz <eantoranz@gmail.com>
Subject: [PATCH v2] builtin/merge: allow --squash to commit if there are no conflicts
Date: Fri, 12 Jul 2019 23:18:04 -0600 [thread overview]
Message-ID: <20190713051804.12893-1-eantoranz@gmail.com> (raw)
Using --squash made git stop regardless of conflicts so that the
user could finish the operation with a later call to git-commit.
Now --squash allows for the operation to finish with the new revision
if there are no conflicts (can still be controlled with --no-commit).
Option -m can be used to defined the message for the revision instead
of the default message that contains all squashed revisions info.
Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>
---
builtin/merge.c | 109 +++++++++++++++++++++++++-----------------------
1 file changed, 57 insertions(+), 52 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index aad5a9504c..66fd57de02 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -64,6 +64,7 @@ static int option_edit = -1;
static int allow_trivial = 1, have_message, verify_signatures;
static int overwrite_ignore = 1;
static struct strbuf merge_msg = STRBUF_INIT;
+static struct strbuf squash_msg = STRBUF_INIT;
static struct strategy **use_strategies;
static size_t use_strategies_nr, use_strategies_alloc;
static const char **xopts;
@@ -390,39 +391,38 @@ static void finish_up_to_date(const char *msg)
static void squash_message(struct commit *commit, struct commit_list *remoteheads)
{
struct rev_info rev;
- struct strbuf out = STRBUF_INIT;
struct commit_list *j;
struct pretty_print_context ctx = {0};
- printf(_("Squash commit -- not updating HEAD\n"));
-
- repo_init_revisions(the_repository, &rev, NULL);
- rev.ignore_merges = 1;
- rev.commit_format = CMIT_FMT_MEDIUM;
-
- commit->object.flags |= UNINTERESTING;
- add_pending_object(&rev, &commit->object, NULL);
-
- for (j = remoteheads; j; j = j->next)
- add_pending_object(&rev, &j->item->object, NULL);
-
- setup_revisions(0, NULL, &rev, NULL);
- if (prepare_revision_walk(&rev))
- die(_("revision walk setup failed"));
-
- ctx.abbrev = rev.abbrev;
- ctx.date_mode = rev.date_mode;
- ctx.fmt = rev.commit_format;
-
- strbuf_addstr(&out, "Squashed commit of the following:\n");
- while ((commit = get_revision(&rev)) != NULL) {
- strbuf_addch(&out, '\n');
- strbuf_addf(&out, "commit %s\n",
- oid_to_hex(&commit->object.oid));
- pretty_print_commit(&ctx, commit, &out);
+ if (merge_msg.len)
+ squash_msg = merge_msg;
+ else {
+ repo_init_revisions(the_repository, &rev, NULL);
+ rev.ignore_merges = 1;
+ rev.commit_format = CMIT_FMT_MEDIUM;
+
+ commit->object.flags |= UNINTERESTING;
+ add_pending_object(&rev, &commit->object, NULL);
+
+ for (j = remoteheads; j; j = j->next)
+ add_pending_object(&rev, &j->item->object, NULL);
+
+ setup_revisions(0, NULL, &rev, NULL);
+ if (prepare_revision_walk(&rev))
+ die(_("revision walk setup failed"));
+
+ ctx.abbrev = rev.abbrev;
+ ctx.date_mode = rev.date_mode;
+ ctx.fmt = rev.commit_format;
+
+ strbuf_addstr(&squash_msg, "Squashed commit of the following:\n");
+ while ((commit = get_revision(&rev)) != NULL) {
+ strbuf_addch(&squash_msg, '\n');
+ strbuf_addf(&squash_msg, "commit %s\n",
+ oid_to_hex(&commit->object.oid));
+ pretty_print_commit(&ctx, commit, &squash_msg);
+ }
}
- write_file_buf(git_path_squash_msg(the_repository), out.buf, out.len);
- strbuf_release(&out);
}
static void finish(struct commit *head_commit,
@@ -440,8 +440,11 @@ static void finish(struct commit *head_commit,
strbuf_addf(&reflog_message, "%s: %s",
getenv("GIT_REFLOG_ACTION"), msg);
}
- if (squash) {
+ if (squash && !squash_msg.len) {
squash_message(head_commit, remoteheads);
+ write_file_buf(git_path_squash_msg(the_repository), squash_msg.buf, squash_msg.len);
+ if (option_commit > 0)
+ printf(_("Squash conflicts -- not updating HEAD\n"));
} else {
if (verbosity >= 0 && !merge_msg.len)
printf(_("No merge message -- not updating HEAD\n"));
@@ -893,14 +896,23 @@ static int finish_automerge(struct commit *head,
struct object_id result_commit;
free_commit_list(common);
- parents = remoteheads;
- if (!head_subsumed || fast_forward == FF_NO)
- commit_list_insert(head, &parents);
- prepare_to_commit(remoteheads);
- if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
- &result_commit, NULL, sign_commit))
- die(_("failed to write commit object"));
- strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
+ if (squash) {
+ squash_message(head, remoteheads);
+ parents = commit_list_insert(head, &parents);
+ if (commit_tree(squash_msg.buf, squash_msg.len, result_tree, parents,
+ &result_commit, NULL, sign_commit))
+ die(_("failed to write commit object on squash"));
+ } else {
+ parents = remoteheads;
+ if (!head_subsumed || fast_forward == FF_NO)
+ commit_list_insert(head, &parents);
+ prepare_to_commit(remoteheads);
+ if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
+ &result_commit, NULL, sign_commit))
+ die(_("failed to write commit object"));
+ }
+ strbuf_addf(&buf, "Merge made by the '%s' strategy", wt_strategy);
+ strbuf_addstr(&buf, squash ? " (squashed)." : ".");
finish(head, remoteheads, &result_commit, buf.buf);
strbuf_release(&buf);
remove_merge_branch_state(the_repository);
@@ -1342,18 +1354,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (verbosity < 0)
show_diffstat = 0;
- if (squash) {
- if (fast_forward == FF_NO)
- die(_("You cannot combine --squash with --no-ff."));
- if (option_commit > 0)
- die(_("You cannot combine --squash with --commit."));
- /*
- * squash can now silently disable option_commit - this is not
- * a problem as it is only overriding the default, not a user
- * supplied option.
- */
- option_commit = 0;
- }
+ if (squash && fast_forward == FF_NO)
+ die(_("You cannot combine --squash with --no-ff."));
if (option_commit < 0)
option_commit = 1;
@@ -1682,8 +1684,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
write_merge_state(remoteheads);
if (merge_was_ok)
- fprintf(stderr, _("Automatic merge went well; "
- "stopped before committing as requested\n"));
+ if (!option_commit)
+ fprintf(stderr, _("Automatic merge went well; "
+ "stopped before committing as requested\n"));
+ else
+ ;
else
ret = suggest_conflicts();
--
2.20.1
next reply other threads:[~2019-07-13 5:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-13 5:18 Edmundo Carmona Antoranz [this message]
2019-07-13 5:27 ` [PATCH v2] builtin/merge: allow --squash to commit if there are no conflicts Edmundo Carmona Antoranz
2019-07-14 18:59 ` Junio C Hamano
2019-07-14 7:15 ` Edmundo Carmona Antoranz
2019-07-17 18:07 ` Junio C Hamano
2019-07-18 0:41 ` Edmundo Carmona Antoranz
2019-07-18 2:32 ` Edmundo Carmona Antoranz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190713051804.12893-1-eantoranz@gmail.com \
--to=eantoranz@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).