Skip to contentSkip to conversation

git mergetool from next not working in subdirectory

PATCH In review Jonas Flodén 3 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 10 lines · Jonas Flodén

~/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.

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
#2 lore raw

PATCH 1/1 Quick and dirty mergetool fix

---
 git-mergetool.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
git-mergetool.sh +3 -3
index aefdca7..db9ef43 100755
@@ -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':"
Signature · 1 line
1.6.1.235.gc9d403
#3 lore raw

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

#4 lore raw

PATCH 1/1 Quick and dirty mergetool fix - take 2

---
 git-mergetool.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
git-mergetool.sh +4 -4
index aefdca7..d495a6b 100755
@@ -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':"
Signature · 1 line
1.6.1.235.gc9d403
#5 lore raw

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.

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
#6 lore raw

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

In reply to Charles Bailey
Quoted 20 lines · Charles Bailey
---
 git-mergetool.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
git-mergetool.sh +1 -1
index aefdca7..d495a6b 100755
@@ -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;}'`

git-mergetool.sh merge_file () { · line 169

Quoted 10 lines
git-mergetool.sh +3 -3
 
-    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

#7 lore raw
In reply to Jonas Flodén
Quoted 3 lines · Jonas Flodén

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

Signature · 4 lines
Johannes Gilger <[email protected]>
http://hackvalue.de/heipei/
GPG-Key: 0x42F6DE81
GPG-Fingerprint: BB49 F967 775E BB52 3A81  882C 58EE B178 42F6 DE81