From 09610b934c5d752ef56e32781736723d4dbbbe7e Mon Sep 17 00:00:00 2001 From: Alcaro Date: Tue, 31 Aug 2021 13:15:12 +0200 Subject: [PATCH] Relativize absolute symlinks to within the repo --- main.cpp | 5 +++-- test4.sh | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 4bc205c..41437ba 100644 --- a/main.cpp +++ b/main.cpp @@ -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 diff --git a/test4.sh b/test4.sh index 578d62e..0c7665c 100755 --- a/test4.sh +++ b/test4.sh @@ -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/ @@ -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