cmd_merge(): Parse options before checking MERGE_HEAD
Reorder the initial part of builtin/merge.c:cmd_merge() so that command-line options are parsed _before_ we load the index and check for MERGE_HEAD (and exits if it exists). This does not change the behaviour of 'git merge', but is needed in preparation for the implementation of 'git merge --abort' (which requires MERGE_HEAD to be present). This patch has been improved by the following contributions: - Junio C Hamano: fixup minor style issues Thanks-to: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Nov 9, 2010 at 22:49 UTC
2a22c1b35d6110e72d86a2fac4b68dbad0905adb
1 file changed
+17
-16
builtin/merge.c
+17
-16
@@ -895,22 +895,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
895
const char *best_strategy = NULL, *wt_strategy = NULL;
896
struct commit_list **remotes = &remoteheads;
897
898
- if (read_cache_unmerged()) {
899
- die_resolve_conflict("merge");
900
- }
901
- if (file_exists(git_path("MERGE_HEAD"))) {
902
- /*
903
- * There is no unmerged entry, don't advise 'git
904
- * add/rm <file>', just 'git commit'.
905
- */
906
- if (advice_resolve_conflict)
907
- die("You have not concluded your merge (MERGE_HEAD exists).\n"
908
- "Please, commit your changes before you can merge.");
909
- else
910
- die("You have not concluded your merge (MERGE_HEAD exists).");
911
- }
912
-
913
- resolve_undo_clear();
898
/*
899
* Check if we are _not_ on a detached HEAD, i.e. if there is a
900
* current branch.
@@ -929,6 +913,23 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
913
914
argc = parse_options(argc, argv, prefix, builtin_merge_options,
915
builtin_merge_usage, 0);
916
+
917
+ if (read_cache_unmerged())
918
+ die_resolve_conflict("merge");
919
+
920
+ if (file_exists(git_path("MERGE_HEAD"))) {
921
+ /*
922
+ * There is no unmerged entry, don't advise 'git
923
+ * add/rm <file>', just 'git commit'.
924
+ */
925
+ if (advice_resolve_conflict)
926
+ die("You have not concluded your merge (MERGE_HEAD exists).\n"
927
+ "Please, commit your changes before you can merge.");
928
+ else
929
+ die("You have not concluded your merge (MERGE_HEAD exists).");
930
+ }
931
+ resolve_undo_clear();
932
+
933
if (verbosity < 0)
934
show_diffstat = 0;
935