All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
To: Alan Blotz <work@blotz.org>
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: git difftool: No such file or directory
Date: Thu, 1 Jul 2021 07:35:54 +0700	[thread overview]
Message-ID: <YN0N6tUeSJM1EBHD@danh.dev> (raw)
In-Reply-To: <176caa21-0232-9f21-7a8d-af136754e354@blotz.org>

On 2021-06-30 11:38:21+0200, Alan Blotz <work@blotz.org> wrote:

> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> mkdir broken-diff
> cd broken-diff
> git init
> mkdir dir1
> mkdir dir2
> touch dir1/orig
> cd dir2/
> ln -s ../dir1/orig sym
> cd ..
> git add dir*
> git ci -m "init"
> git checkout -b b
> git rm dir2/sym 
> git ci -m "remove"
> git difftool -d master HEAD
> 
> What did you expect to happen? (Expected behavior)
> 
> git difftool shall compare both branches.
> 
> What happened instead? (Actual behavior)
> 
> git difftool prints an error:
> 
> fatal: could not open '/tmp/git-difftool.l4UM7e/left/dir2/sym' for writing: No such file or directory

It looks like this behaviour was there from the time difftool was
re-written in C in 03831ef7b5, (difftool: implement the functionality
in the builtin, 2017-01-19). The perl version didn't have this
problem.

The perl version create a file in place of that symlink and write the
symlink's target into that file. The C version tries to write (and
follow?) the symlink.

This hack can fix the problem but I'm not sure it's correct:
----8<---

diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2115e548a5..737ebb5b1a 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -492,12 +492,14 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 		if (*entry->left) {
 			add_path(&ldir, ldir_len, entry->path);
 			ensure_leading_directories(ldir.buf);
-			write_file(ldir.buf, "%s", entry->left);
+			unlink(ldir.buf);
+			write_file_buf(ldir.buf, entry->left, strlen(entry->left));
 		}
 		if (*entry->right) {
 			add_path(&rdir, rdir_len, entry->path);
 			ensure_leading_directories(rdir.buf);
-			write_file(rdir.buf, "%s", entry->right);
+			unlink(rdir.buf);
+			write_file_buf(rdir.buf, entry->right, strlen(entry->right));
 		}
 	}
---->8----- 

+Cc: Dscho, who wrote the C version.

-- 
Danh

  reply	other threads:[~2021-07-01  0:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  9:38 git difftool: No such file or directory Alan Blotz
2021-07-01  0:35 ` Đoàn Trần Công Danh [this message]
2021-08-30  0:32   ` David Aguilar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YN0N6tUeSJM1EBHD@danh.dev \
    --to=congdanhqx@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=work@blotz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.