threads / discuss / 17457

git mergetool from next not working in subdirectory

Subject: git mergetool from next not working in subdirectory

## tl;dr

8 messages between Jan 30, 2009 and Jan 30, 2009.

replies: 7people: 3as markdown or json

Jonas Flodén· Jan 30, 2009, 13:05 UTC · lore
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· Jan 30, 2009, 13:50 UTC · re: Jonas Flodén · lore

Re: git mergetool from next not working in subdirectory

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· Jan 30, 2009, 14:06 UTC · re: Jonas Flodén · lore

Re: git mergetool from next not working in subdirectory

On Fri, Jan 30, 2009 at 02:05:45PM +0100, Jonas Flodén wrote:
Show 10 quoted lines
> ~/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· Jan 30, 2009, 14:22 UTC · re: Charles Bailey · lore

[PATCH] Quick and dirty mergetool fix

---
 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· Jan 30, 2009, 16:00 UTC · re: Charles Bailey · lore

Re: [PATCH] Quick and dirty mergetool fix

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· Jan 30, 2009, 16:16 UTC · re: Jonas Flodén · lore

[PATCH] Quick and dirty mergetool fix - take 2

---
 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· Jan 30, 2009, 16:18 UTC · re: Charles Bailey · lore

Re: [PATCH] Quick and dirty mergetool fix - take 2

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· Jan 30, 2009, 16:22 UTC · re: Charles Bailey · lore

Re: [PATCH] Quick and dirty mergetool fix - take 2

Charles Bailey wrote:
Show 30 quoted lines
> ---
>  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

← back to recent threads