# git mergetool from next not working in subdirectory

8 messages from 2009-01-30 to 2009-01-30. Participants: Jonas Flodén, Johannes Gilger, Charles Bailey.
Thread: https://gitlist.dev/t/17457

## Jonas Flodén, 2009-01-30 13:05

Subject: git mergetool from next not working in subdirectory
Message-ID: <glutv9$4b1$1@ger.gmane.org>
URL: https://gitlist.dev/e/glutv9%244b1%241%40ger.gmane.org

```
Hi,

I just upgraded to the current 'next' version of git
(v1.6.1.2-418-gd79e69c). When I run git mergetool from
a subdirectory in my workspace I get the following output:
(with obfuscated output..)

~/src/rep/subdir $ git mergetool
Merging the files: a/b/file.c

git checkout-index: subdir/subdir/a/b/file.c is not in the cache
git checkout-index: subdir/subdir/a/b/file.c is not in the cache
git checkout-index: subdir/subdir/a/b/file.c is not in the cache
Normal merge conflict for 'a/b/file.c':
  {local}: modified

  {remote}: modified

Hit return to start merge resolution tool (kdiff3):

When I hit enter the merge resolution finishes right away
and the file ends up empty.

Note how subdir is duplicated in the output above.

This works perfectly fine with the 'master' version (1.6.1.2-253-ga34a).

Regards,
Jonas

```

## Johannes Gilger, 2009-01-30 13:50

Subject: Re: git mergetool from next not working in subdirectory
Message-ID: <glv0jl$cbl$1@ger.gmane.org>
URL: https://gitlist.dev/e/glv0jl%24cbl%241%40ger.gmane.org
In-Reply-To: <glutv9$4b1$1@ger.gmane.org>

```
On 2009-01-30, Jonas Flodén <jonas.floden@gmail.com> wrote:
> I just upgraded to the current 'next' version of git
> ...
> This works perfectly fine with the 'master' version (1.6.1.2-253-ga34a).

Hi,

as you're running next you seem to be interested in the git development. 
That's why I suggest you try to bisect the commit that causes this. 
Fixing it is another problem entirely, but this way you'd at least take 
the tedious of work of a. duplicating your setup b. finding the bug off 
of the git developers.

Greetings,
Jojo

-- 
Johannes Gilger <heipei@hackvalue.de>
http://hackvalue.de/heipei/
GPG-Key: 0x42F6DE81
GPG-Fingerprint: BB49 F967 775E BB52 3A81  882C 58EE B178 42F6 DE81

```

## Charles Bailey, 2009-01-30 14:06

Subject: Re: git mergetool from next not working in subdirectory
Message-ID: <20090130140615.GA26321@hashpling.org>
URL: https://gitlist.dev/e/20090130140615.GA26321%40hashpling.org
In-Reply-To: <glutv9$4b1$1@ger.gmane.org>

```
On Fri, Jan 30, 2009 at 02:05:45PM +0100, Jonas Flodén wrote:
> ~/src/rep/subdir $ git mergetool
> Merging the files: a/b/file.c
> 
> git checkout-index: subdir/subdir/a/b/file.c is not in the cache
> git checkout-index: subdir/subdir/a/b/file.c is not in the cache
> git checkout-index: subdir/subdir/a/b/file.c is not in the cache
> Normal merge conflict for 'a/b/file.c':
>   {local}: modified
> 
>   {remote}: modified


Oh bother. I know exactly what this is. ls-files -u shows paths
relative to the work tree root, whereas checkout-index responds to
relative paths. Essentially the "$prefix" needs to come out of the
calls to the new checkout_staged_file shell function.

This is the bad commit 0ec7b6c26dad51f690cd985d4a5357634123c4b7

I can patch this (and more importantly add a test for this) tonight if
nobody beats me to it.

-- 
Charles Bailey
http://ccgi.hashpling.plus.com/blog/

```

## Charles Bailey, 2009-01-30 14:22

Subject: [PATCH] Quick and dirty mergetool fix
Message-ID: <1233325351-31496-1-git-send-email-charles@hashpling.org>
URL: https://gitlist.dev/e/1233325351-31496-1-git-send-email-charles%40hashpling.org
In-Reply-To: <20090130140615.GA26321@hashpling.org>

```
---
 git-mergetool.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index aefdca7..db9ef43 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -161,9 +161,9 @@ merge_file () {
     local_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}'`
     remote_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}'`
 
-    base_present   && checkout_staged_file 1 "$prefix$MERGED" "$BASE"
-    local_present  && checkout_staged_file 2 "$prefix$MERGED" "$LOCAL"
-    remote_present && checkout_staged_file 3 "$prefix$MERGED" "$REMOTE"
+    base_present   && checkout_staged_file 1 "$MERGED" "$BASE"
+    local_present  && checkout_staged_file 2 "$MERGED" "$LOCAL"
+    remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE"
 
     if test -z "$local_mode" -o -z "$remote_mode"; then
 	echo "Deleted merge conflict for '$MERGED':"
-- 
1.6.1.235.gc9d403

```

## Jonas Flodén, 2009-01-30 16:00

Subject: Re: [PATCH] Quick and dirty mergetool fix
Message-ID: <4983241B.6020208@gmail.com>
URL: https://gitlist.dev/e/4983241B.6020208%40gmail.com
In-Reply-To: <1233325351-31496-1-git-send-email-charles@hashpling.org>

```
Hmm, with that patch I get get this instead:

mv: cannot stat `.merge_file_Yg2IIs': No such file or directory
mv: cannot stat `.merge_file_4xGT8t': No such file or directory
mv: cannot stat `.merge_file_4XAVAt': No such file or directory

Which seems to be a problem in checkout_staged_file()

The .merge_file_* files exists in the repository root (the dir with
.git) but I don't know how to fix that..

Thanks!

// Jonas

```

## Charles Bailey, 2009-01-30 16:16

Subject: [PATCH] Quick and dirty mergetool fix - take 2
Message-ID: <1233332166-14300-1-git-send-email-charles@hashpling.org>
URL: https://gitlist.dev/e/1233332166-14300-1-git-send-email-charles%40hashpling.org
In-Reply-To: <4983241B.6020208@gmail.com>

```
---
 git-mergetool.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index aefdca7..d495a6b 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -131,7 +131,7 @@ checkout_staged_file () {
     tmpfile=$(expr "$(git checkout-index --temp --stage="$1" "$2")" : '\([^	]*\)	')
 
     if test $? -eq 0 -a -n "$tmpfile" ; then
-	mv -- "$tmpfile" "$3"
+	mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3"
     fi
 }
 
@@ -161,9 +161,9 @@ merge_file () {
     local_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}'`
     remote_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}'`
 
-    base_present   && checkout_staged_file 1 "$prefix$MERGED" "$BASE"
-    local_present  && checkout_staged_file 2 "$prefix$MERGED" "$LOCAL"
-    remote_present && checkout_staged_file 3 "$prefix$MERGED" "$REMOTE"
+    base_present   && checkout_staged_file 1 "$MERGED" "$BASE"
+    local_present  && checkout_staged_file 2 "$MERGED" "$LOCAL"
+    remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE"
 
     if test -z "$local_mode" -o -z "$remote_mode"; then
 	echo "Deleted merge conflict for '$MERGED':"
-- 
1.6.1.235.gc9d403

```

## Charles Bailey, 2009-01-30 16:18

Subject: Re: [PATCH] Quick and dirty mergetool fix - take 2
Message-ID: <20090130161850.GB26321@hashpling.org>
URL: https://gitlist.dev/e/20090130161850.GB26321%40hashpling.org
In-Reply-To: <1233332166-14300-1-git-send-email-charles@hashpling.org>

```
On Fri, Jan 30, 2009 at 04:16:06PM +0000, Charles Bailey wrote:

Sorry, I meant to add this comment to the last patch.

I have a test so I'm more confident about this version. It's not
signed off yet as I want to clean up the new test and make sure I've
considered everything - well more things - but it should at least work
now.

-- 
Charles Bailey
http://ccgi.hashpling.plus.com/blog/

```

## Jonas Flodén, 2009-01-30 16:22

Subject: Re: [PATCH] Quick and dirty mergetool fix - take 2
Message-ID: <4983293E.9070401@gmail.com>
URL: https://gitlist.dev/e/4983293E.9070401%40gmail.com
In-Reply-To: <1233332166-14300-1-git-send-email-charles@hashpling.org>

```
Charles Bailey wrote:
> ---
>  git-mergetool.sh |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index aefdca7..d495a6b 100755
> --- a/git-mergetool.sh
> +++ b/git-mergetool.sh
> @@ -131,7 +131,7 @@ checkout_staged_file () {
>      tmpfile=$(expr "$(git checkout-index --temp --stage="$1" "$2")" : '\([^	]*\)	')
>  
>      if test $? -eq 0 -a -n "$tmpfile" ; then
> -	mv -- "$tmpfile" "$3"
> +	mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3"
>      fi
>  }
>  
> @@ -161,9 +161,9 @@ merge_file () {
>      local_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}'`
>      remote_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}'`
>  
> -    base_present   && checkout_staged_file 1 "$prefix$MERGED" "$BASE"
> -    local_present  && checkout_staged_file 2 "$prefix$MERGED" "$LOCAL"
> -    remote_present && checkout_staged_file 3 "$prefix$MERGED" "$REMOTE"
> +    base_present   && checkout_staged_file 1 "$MERGED" "$BASE"
> +    local_present  && checkout_staged_file 2 "$MERGED" "$LOCAL"
> +    remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE"
>  
>      if test -z "$local_mode" -o -z "$remote_mode"; then
>  	echo "Deleted merge conflict for '$MERGED':"

Yes, I was just about to propose a similar patch.

This solution works for me!

You might want to remove $prefix from the top of the
file since it's not used any more.

Thanks!

// Jonas

```
