git/list[1] front-page[2] threads[3] people[4] search[5] about
 

difftool fails with dangling symlinks, writes to targets outside of the repository

From
PPhilippe <bqobctqyemmeacqxbrsaury3l4ka@quarantine.de>
Date
Nov 22, 2019, 12:37 UTC
Message-ID
<7e04799d-c03c-ac28-604d-ec4d30029d44@quarantine.de>
Hi all,

I'm using a git repository for configuration management which contains several dangling symlinks (which only make sense on the to be deployed system, fwiw). Now, using git 2.23, I ran into a problem regarding the difftool, which fails when such a symlink is involved in a changeset.

The best way to describe that problem is probably to provide an example.
Show 16 quoted lines
> #!/bin/bash
> tmp=$(mktemp -d)
> trap "rm -rf ${tmp}" 0 1 2 15
> 
> set -x
> 
> cd ${tmp}
> git init
> ln -s ../doesnot/exist myfile
> git add myfile ; git commit -m "initial checkin" myfile
> 
> git checkout -b mybranch
> rm -f myfile ; echo "foo" > myfile
> git commit -am "typechange"
> 
> git difftool -d master..mybranch
The last call fails with:
> fatal: could not open '/tmp/git-difftool.2wHaR9/left/myfile' for writing: No such file or directory
Neither specifying "--symlinks" nor "--no-symlinks" resolves that.

Playing around with this issue lead me to another strange behaviour. Difftool might overwrite symlink targets that are not part of the repository. Please take a look at the following script:

Show 21 quoted lines
> #!/bin/bash
> tmp=$(mktemp -d)
> trap "rm -rf ${tmp}" 0 1 2 15
> 
> set -x
> 
> echo "hello world" > /tmp/testfile
> cat /tmp/testfile
> 
> cd ${tmp}
> git init
> ln -s /tmp/testfile myfile
> git add myfile ; git commit -m "initial checkin" myfile
> 
> git checkout -b mybranch
> rm -f myfile ; echo "foo" > myfile
> git commit -am "typechange"
> 
> git difftool -d master..mybranch
> 
> cat /tmp/testfile

Here, difftool overwrites the /tmp/testfile's content "hello world" with "/tmp/testfile".

Did I run into a bug or is it a layer 8 problem?
Regards,
Philippe
Next: Philippe
Message 1 of 2 in “difftool fails with dangling symlinks, writes to targets outside of the repository”
  1. PhilippeNov 22, 2019
  2. PhilippeDec 2, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.