{"thread":{"id":"52312","subject":"difftool fails with dangling symlinks, writes to targets outside of the repository","startedAt":"2019-11-22T12:45:23Z","lastAt":"2019-12-02T12:23:06Z","messageCount":2,"participants":["Philippe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"386817","messageId":"7e04799d-c03c-ac28-604d-ec4d30029d44@quarantine.de","threadId":"52312","inReplyTo":null,"subject":"difftool fails with dangling symlinks, writes to targets outside of the repository","fromName":"Philippe","fromEmail":"bqobctqyemmeacqxbrsaury3l4ka@quarantine.de","sentAt":"2019-11-22T12:37:32Z","receivedAt":"2019-11-22T12:45:23Z","isPatch":false,"sender":{"key":"bqobctqyemmeacqxbrsaury3l4ka@quarantine.de","avatar":null},"body":"Hi all,\n\n\nI'm using a git repository for configuration management which contains\nseveral dangling symlinks (which only make sense on the to be deployed\nsystem, fwiw). Now, using git 2.23, I ran into a problem regarding the\ndifftool, which fails when such a symlink is involved in a changeset.\n\nThe best way to describe that problem is probably to provide an example.\n\n> #!/bin/bash\n> tmp=$(mktemp -d)\n> trap \"rm -rf ${tmp}\" 0 1 2 15\n> \n> set -x\n> \n> cd ${tmp}\n> git init\n> ln -s ../doesnot/exist myfile\n> git add myfile ; git commit -m \"initial checkin\" myfile\n> \n> git checkout -b mybranch\n> rm -f myfile ; echo \"foo\" > myfile\n> git commit -am \"typechange\"\n> \n> git difftool -d master..mybranch\n\nThe last call fails with:\n\n> fatal: could not open '/tmp/git-difftool.2wHaR9/left/myfile' for writing: No such file or directory\n\nNeither specifying \"--symlinks\" nor \"--no-symlinks\" resolves that.\n\nPlaying around with this issue lead me to another strange behaviour.\nDifftool might overwrite symlink targets that are not part of the\nrepository. Please take a look at the following script:\n\n> #!/bin/bash\n> tmp=$(mktemp -d)\n> trap \"rm -rf ${tmp}\" 0 1 2 15\n> \n> set -x\n> \n> echo \"hello world\" > /tmp/testfile\n> cat /tmp/testfile\n> \n> cd ${tmp}\n> git init\n> ln -s /tmp/testfile myfile\n> git add myfile ; git commit -m \"initial checkin\" myfile\n> \n> git checkout -b mybranch\n> rm -f myfile ; echo \"foo\" > myfile\n> git commit -am \"typechange\"\n> \n> git difftool -d master..mybranch\n> \n> cat /tmp/testfile\n\nHere, difftool overwrites the /tmp/testfile's content \"hello world\" with\n\"/tmp/testfile\".\n\nDid I run into a bug or is it a layer 8 problem?\n\n\nRegards,\n\nPhilippe\n"},{"id":"387396","messageId":"c23d23d8-8a08-9ee7-d148-77b1f4611606@quarantine.de","threadId":"52312","inReplyTo":"7e04799d-c03c-ac28-604d-ec4d30029d44@quarantine.de","subject":"Re: difftool fails with dangling symlinks, writes to targets outside of the repository","fromName":"Philippe","fromEmail":"bqobctqyemmeacqxbrsaury3l4ka@quarantine.de","sentAt":"2019-12-02T12:23:00Z","receivedAt":"2019-12-02T12:23:06Z","isPatch":false,"sender":{"key":"bqobctqyemmeacqxbrsaury3l4ka@quarantine.de","avatar":null},"body":"Hi all,\n\nsince that \"difftool overwrites files outside of the git\nrepository\"-thingy is apparently not considered a bug, could you please\npoint me to the correct usage of difftool or a workaround?\n\nTo recall the situation:\n- git repo contains a symlink pointing outside of the repository to a\nnon-existing file\n- that symlink gets replaced by a regular file\n- using 'git difftool -d ${oldstate}..${newstate}' overwrites the file\nthe symlink was pointing to (which might fail if the target is not writable)\n\nKind regards\n\nPhilippe\n"}]}