Skip to content

Commit

Permalink
Merge branch 'mv/maint-merge-fix' into maint
Browse files Browse the repository at this point in the history
* mv/maint-merge-fix:
  merge: fix numerus bugs around "trivial merge" area
  • Loading branch information
Junio C Hamano committed Aug 24, 2008
2 parents ab54cd6 + 446247d commit 97e5f49
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
16 changes: 9 additions & 7 deletions builtin-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
struct dir_struct dir;
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));

if (read_cache_unmerged())
die("you need to resolve your current index first");
refresh_cache(REFRESH_QUIET);

fd = hold_locked_index(lock_file, 1);
Expand Down Expand Up @@ -651,13 +649,15 @@ static void add_strategies(const char *string, unsigned attr)
static int merge_trivial(void)
{
unsigned char result_tree[20], result_commit[20];
struct commit_list parent;
struct commit_list *parent = xmalloc(sizeof(struct commit_list *));

write_tree_trivial(result_tree);
printf("Wonderful.\n");
parent.item = remoteheads->item;
parent.next = NULL;
commit_tree(merge_msg.buf, result_tree, &parent, result_commit);
parent->item = lookup_commit(head);
parent->next = xmalloc(sizeof(struct commit_list *));
parent->next->item = remoteheads->item;
parent->next->next = NULL;
commit_tree(merge_msg.buf, result_tree, parent, result_commit);
finish(result_commit, "In-index merge");
drop_save();
return 0;
Expand Down Expand Up @@ -743,6 +743,7 @@ static int evaluate_result(void)
int cnt = 0;
struct rev_info rev;

discard_cache();
if (read_cache() < 0)
die("failed to read the cache");

Expand Down Expand Up @@ -776,7 +777,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
struct commit_list **remotes = &remoteheads;

setup_work_tree();
if (unmerged_cache())
if (read_cache_unmerged())
die("You are in the middle of a conflicted merge.");

/*
Expand Down Expand Up @@ -1073,6 +1074,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}

/* Automerge succeeded. */
discard_cache();
write_tree_trivial(result_tree);
automerge_was_ok = 1;
break;
Expand Down
11 changes: 11 additions & 0 deletions t/t3030-merge-recursive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ test_expect_success 'merge-recursive result' '
'

test_expect_success 'fail if the index has unresolved entries' '
rm -fr [abcd] &&
git checkout -f "$c1" &&
test_must_fail git merge "$c5" &&
test_must_fail git merge "$c5" 2> out &&
grep "You are in the middle of a conflicted merge" out
'

test_expect_success 'merge-recursive remove conflict' '
rm -fr [abcd] &&
Expand Down
9 changes: 9 additions & 0 deletions t/t7600-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,13 @@ test_expect_success 'merge fast-forward in a dirty tree' '

test_debug 'gitk --all'

test_expect_success 'in-index merge' '
git reset --hard c0 &&
git merge --no-ff -s resolve c1 > out &&
grep "Wonderful." out &&
verify_parents $c0 $c1
'

test_debug 'gitk --all'

test_done
4 changes: 3 additions & 1 deletion t/t7605-merge-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ test_expect_success 'merge c1 to c2' '
git diff --exit-code &&
test -f c0.c &&
test -f c1.c &&
test -f c2.c
test -f c2.c &&
test 3 = $(git ls-tree -r HEAD | wc -l) &&
test 3 = $(git ls-files | wc -l)
'

test_expect_success 'merge c2 to c3 (fails)' '
Expand Down

0 comments on commit 97e5f49

Please sign in to comment.