# [PATCH] fix for incorrect index update

3 messages from 2009-05-09 to 2009-05-10. Participants: Dave O, Junio C Hamano, Dave Olszewski.
Thread: https://gitlist.dev/t/19259

## Dave O, 2009-05-09 21:49

Subject: [PATCH] fix for incorrect index update
Message-ID: <alpine.DEB.2.00.0905091356070.21000@narbuckle.genericorp.net>
URL: https://gitlist.dev/e/alpine.DEB.2.00.0905091356070.21000%40narbuckle.genericorp.net

```
call_depth > 0 requires trees to be constructed from the files with
conflicts, therefore the stages thusly must not be updated

Signed-off-by: Dave Olszewski <cxreg@pobox.com>
---
  merge-recursive.c          |   11 +++--
  t/t3031-merge-criscross.sh |   95 ++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 101 insertions(+), 5 deletions(-)
  create mode 100644 t/t3031-merge-criscross.sh

diff --git a/merge-recursive.c b/merge-recursive.c
index a3721ef..f5df9b9 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -933,11 +933,12 @@ static int process_renames(struct merge_options *o,
  				       ren1_src, ren1_dst, branch1,
  				       branch2);
  				update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
-				update_stages(ren1_dst, NULL,
-						branch1 == o->branch1 ?
-						ren1->pair->two : NULL,
-						branch1 == o->branch1 ?
-						NULL : ren1->pair->two, 1);
+				if (!o->call_depth)
+					update_stages(ren1_dst, NULL,
+							branch1 == o->branch1 ?
+							ren1->pair->two : NULL,
+							branch1 == o->branch1 ?
+							NULL : ren1->pair->two, 1);
  			} else if (!sha_eq(dst_other.sha1, null_sha1)) {
  				const char *new_path;
  				clean_merge = 0;
diff --git a/t/t3031-merge-criscross.sh b/t/t3031-merge-criscross.sh
new file mode 100644
index 0000000..cbfd95b
--- /dev/null
+++ b/t/t3031-merge-criscross.sh
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+test_description='merge-recursive backend test'
+
+. ./test-lib.sh
+
+#         A      <- create some files
+#        / \
+#       B   C    <- cause rename/delete conflicts between B and C
+#      /     \
+#     |\     /|
+#     | D   E |
+#     |  \ /  |
+#     |   X   |
+#     |  / \  |
+#     | /   \ |
+#     |/     \|
+#     F       G  <- merge E into B, D into C
+#      \     /
+#       \   /
+#        \ /
+#         H      <- recursive merge crashes
+#
+
+# initialize
+test_expect_success 'setup repo with criss-cross history' '
+	mkdir data &&
+
+	test_debug create a bunch of files &&
+	n=1 &&
+	while test $n -le 10
+	do
+		echo $n > data/$n &&
+		n=$(($n+1)) ||
+		break
+	done &&
+
+	test_debug check them in &&
+	git add data &&
+	git commit -m A &&
+	git branch A &&
+
+	test_debug a file in one branch &&
+	git checkout -b B A &&
+	git rm data/9 &&
+	git add data &&
+	git commit -m B &&
+
+	test_debug with a branch off of it &&
+	git branch D &&
+
+	test_debug put some commits on D &&
+	git checkout D &&
+	echo testD > data/testD &&
+	git add data &&
+	git commit -m D &&
+
+	test_debug back up to the top, create another branch and cause a rename  &&
+	test_debug conflict with the file we deleted earlier &&
+	git checkout -b C A &&
+	git mv data/9 data/new-9 &&
+	git add data &&
+	git commit -m C &&
+
+	test_debug with a branch off of it &&
+	git branch E &&
+
+	test_debug put a commit on E &&
+	git checkout E &&
+	echo testE > data/testE &&
+	git add data &&
+	git commit -m E &&
+
+	test_debug now, merge E into B &&
+	git checkout B &&
+	test_must_fail git merge E &&
+	test_debug force-resolve &&
+	git add data &&
+	git commit -m F &&
+	git branch F &&
+
+	test_debug and merge D into C &&
+	git checkout C &&
+	test_must_fail git merge D &&
+	test_debug force-resolve &&
+	git add data &&
+	git commit -m G &&
+	git branch G
+'
+
+test_expect_failure 'recursive merge between F and G, causes segfault' '
+	git merge F
+'
+
+test_done
-- 
1.6.2.4

```

## Junio C Hamano, 2009-05-10 04:22

Subject: Re: [PATCH] fix for incorrect index update
Message-ID: <7vskjd4mfh.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vskjd4mfh.fsf%40alter.siamese.dyndns.org
In-Reply-To: <alpine.DEB.2.00.0905091356070.21000@narbuckle.genericorp.net>

```
Dave O <cxreg@pobox.com> writes:

> call_depth > 0 requires trees to be constructed from the files with
> conflicts, therefore the stages thusly must not be updated
>
> Signed-off-by: Dave Olszewski <cxreg@pobox.com>
> ---

Thanks.  I'd add:

	From: Dave Olszewski <cxreg@pobox.com>

at the beginning, so you would not be shown as "Dave O" in "git shortlog"
and friends.

>  merge-recursive.c          |   11 +++--
>  t/t3031-merge-criscross.sh |   95 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 101 insertions(+), 5 deletions(-)
>  create mode 100644 t/t3031-merge-criscross.sh

> diff --git a/t/t3031-merge-criscross.sh b/t/t3031-merge-criscross.sh
> new file mode 100644

That should have been 100755 (I'll fix-up myself; no need to resend).

> index 0000000..cbfd95b
> --- /dev/null
> +++ b/t/t3031-merge-criscross.sh
> @@ -0,0 +1,95 @@
> +#!/bin/sh
> +
> +test_description='merge-recursive backend test'
> +
> +. ./test-lib.sh
> +
> +#         A      <- create some files
> +#        / \
> +#       B   C    <- cause rename/delete conflicts between B and C
> +#      /     \
> +#     |\     /|
> +#     | D   E |
> +#     |  \ /  |
> +#     |   X   |
> +#     |  / \  |
> +#     | /   \ |
> +#     |/     \|
> +#     F       G  <- merge E into B, D into C
> +#      \     /
> +#       \   /
> +#        \ /
> +#         H      <- recursive merge crashes
> +#

Much nicer than Dscho's ;-)

> +# initialize
> +test_expect_success 'setup repo with criss-cross history' '
> +	mkdir data &&
> +
> +	test_debug create a bunch of files &&

You inherited a bug from Dscho's patch, it seems.  Have you tried running
the test with debug option?

This could have been

	test_debug "echo create a bunch of files" &&

but I'd say we just make them into comments.

```

## Dave Olszewski, 2009-05-10 04:46

Subject: Re: [PATCH] fix for incorrect index update
Message-ID: <alpine.DEB.2.00.0905092139050.21000@narbuckle.genericorp.net>
URL: https://gitlist.dev/e/alpine.DEB.2.00.0905092139050.21000%40narbuckle.genericorp.net
In-Reply-To: <7vskjd4mfh.fsf@alter.siamese.dyndns.org>

```
On Sat, 9 May 2009, Junio C Hamano wrote:

> Thanks.  I'd add:
>
> 	From: Dave Olszewski <cxreg@pobox.com>
>
> at the beginning, so you would not be shown as "Dave O" in "git shortlog"
> and friends.

Ok, sounds good.  Thanks for the explanation of the issue.  Much of the
git internals are still mysterious but that's slowly changing :-)

> Much nicer than Dscho's ;-)

Well, it was mine first, can't fault him for that!

> You inherited a bug from Dscho's patch, it seems.  Have you tried running
> the test with debug option?
>
> This could have been
>
> 	test_debug "echo create a bunch of files" &&
>
> but I'd say we just make them into comments.

I didn't, sorry for that.  Making them comments seems ok to me.

Thanks once again.

     Dave Olszewski

```
