@@ -892,6 +892,7 @@ static int finish_automerge(struct commit *head,
892
892
struct strbuf buf = STRBUF_INIT ;
893
893
struct object_id result_commit ;
894
894
895
+ write_tree_trivial (result_tree );
895
896
free_commit_list (common );
896
897
parents = remoteheads ;
897
898
if (!head_subsumed || fast_forward == FF_NO )
@@ -1586,8 +1587,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1586
1587
save_state (& stash ))
1587
1588
oidclr (& stash );
1588
1589
1589
- for (i = 0 ; i < use_strategies_nr ; i ++ ) {
1590
- int ret ;
1590
+ for (i = 0 ; ! merge_was_ok && i < use_strategies_nr ; i ++ ) {
1591
+ int ret , cnt ;
1591
1592
if (i ) {
1592
1593
printf (_ ("Rewinding the tree to pristine...\n" ));
1593
1594
restore_state (& head_commit -> object .oid , & stash );
@@ -1604,40 +1605,26 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1604
1605
ret = try_merge_strategy (use_strategies [i ]-> name ,
1605
1606
common , remoteheads ,
1606
1607
head_commit );
1607
- if (!option_commit && !ret ) {
1608
- merge_was_ok = 1 ;
1609
- /*
1610
- * This is necessary here just to avoid writing
1611
- * the tree, but later we will *not* exit with
1612
- * status code 1 because merge_was_ok is set.
1613
- */
1614
- ret = 1 ;
1615
- }
1616
-
1617
- if (ret ) {
1618
- /*
1619
- * The backend exits with 1 when conflicts are
1620
- * left to be resolved, with 2 when it does not
1621
- * handle the given merge at all.
1622
- */
1623
- if (ret == 1 ) {
1624
- int cnt = evaluate_result ();
1625
-
1626
- if (best_cnt <= 0 || cnt <= best_cnt ) {
1627
- best_strategy = use_strategies [i ]-> name ;
1628
- best_cnt = cnt ;
1608
+ /*
1609
+ * The backend exits with 1 when conflicts are
1610
+ * left to be resolved, with 2 when it does not
1611
+ * handle the given merge at all.
1612
+ */
1613
+ if (ret < 2 ) {
1614
+ if (!ret ) {
1615
+ if (option_commit ) {
1616
+ /* Automerge succeeded. */
1617
+ automerge_was_ok = 1 ;
1618
+ break ;
1629
1619
}
1620
+ merge_was_ok = 1 ;
1621
+ }
1622
+ cnt = evaluate_result ();
1623
+ if (best_cnt <= 0 || cnt <= best_cnt ) {
1624
+ best_strategy = use_strategies [i ]-> name ;
1625
+ best_cnt = cnt ;
1630
1626
}
1631
- if (merge_was_ok )
1632
- break ;
1633
- else
1634
- continue ;
1635
1627
}
1636
-
1637
- /* Automerge succeeded. */
1638
- write_tree_trivial (& result_tree );
1639
- automerge_was_ok = 1 ;
1640
- break ;
1641
1628
}
1642
1629
1643
1630
/*
0 commit comments