Skip to content

Commit

Permalink
Relativize absolute symlinks to within the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Alcaro committed Aug 31, 2021
1 parent d73aa9c commit 09610b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,9 @@ class path_handler {
if (!target_is_in_repo) return ""; // if it'd point outside the repo, it's not a link
if (link_force_inline(path)) return ""; // if GITBSLR_FOLLOW says inline, it's not a link

// if the link's realpath is not in the work dir, but the target is, ignore readlink and create a new path
if (!newpath_abs.startswith(work_tree))
// if the link's target is absolute, or the realpath is not in the work dir but the target is,
// ignore readlink and create a new path
if (path_linktarget[0]=='/' || !newpath_abs.startswith(work_tree))
{
// path is virtual path to link
// path_abs is real path to link, including work tree
Expand Down
14 changes: 13 additions & 1 deletion test4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cd $(dirname $0)
. ./testlib.sh

#This script tests some rarer stuff, like ls-files and symlinks to symlinks.
#This script tests some rarer stuff, like ls-files, symlinks to symlinks, and symlinks to absolute paths in the repo.

# ls-files
mkdir test/repo/
Expand Down Expand Up @@ -61,6 +61,18 @@ mkdir test/expected/sub/to_subdir
ln_sr test/repo/sub/file test/subdir/to_file
ln_sr test/expected/sub/file test/expected/sub/to_subdir/to_file

# absolute symlinks into repo
mkdir test/repo/sub2/
mkdir test/expected/sub2/
echo test > test/repo/sub2/file2
echo test > test/expected/sub2/file2
ln -s $(realpath test/repo/sub2/) test/repo/to_sub2
ln_sr test/expected/sub2/ test/expected/to_sub2
ln -s $(realpath test/repo/sub2/) test/repo/sub/to_sub2
ln_sr test/expected/sub2/ test/expected/sub/to_sub2
ln -s $(realpath test/repo/sub/file) test/repo/sub/to_subfile
ln_sr test/expected/sub/file test/expected/sub/to_subfile

#TODO: figure out what to do with links to nonexistent in-repo, or out-of-repo, targets


Expand Down

0 comments on commit 09610b9

Please sign in to comment.