Traditionally "git merge --no-commit" meant just that: do not create a new commit even when a merge succeeds. But this leads to confusion when the merged commit is a descendant of the current commit, in which case we succeed the merge by fast-forwarding and without creating a new commit. Also when the merged commit is already a part of the history, we succeeded without doing anything. Error out when --no-commit is given but the merge would result in a fast-forward or an up-to-date. Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- * This is the first alternative. I think it makes more sense than the other one, but I am unsure, as I obviously do not get confused when --no-commit becomes no-op due to a fast-forward nor an up-to-date and am rather happy with the current behaviour. builtin-merge.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/builtin-merge.c b/builtin-merge.c index b6b8428..4cfdf75 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -829,6 +829,12 @@ static int evaluate_result(void) return cnt; } +static void check_no_commit(const char *msg) +{ + if (!option_commit) + die("The merge will %s but --no-commit was given.", msg); +} + int cmd_merge(int argc, const char **argv, const char *prefix) { unsigned char result_tree[20]; @@ -996,6 +1002,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * If head can reach all the merge then we are up to date. * but first the most common case of merging one remote. */ + check_no_commit("be a no-op because you are up-to-date"); finish_up_to_date("Already up-to-date."); return 0; } else if (allow_fast_forward && !remoteheads->next && @@ -1006,6 +1013,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) struct object *o; char hex[41]; + if (allow_fast_forward) + check_no_commit("fast forward"); + strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV)); if (verbosity >= 0) @@ -1074,6 +1084,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } } if (up_to_date) { + check_no_commit("fast forward"); finish_up_to_date("Already up-to-date. Yeeah!"); return 0; } -- 1.6.5.1.107.gba912 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html