From fff1aa9fa4ae96800f1e557f2539582463ae654f Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 1 Nov 2024 10:11:24 -0400 Subject: [PATCH] YADM_WORK: allow for relative worktree paths --- test/test_alt.py | 6 +++++- yadm | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_alt.py b/test/test_alt.py index 138d609..c6d335b 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -56,10 +56,14 @@ def test_alt_source(runner, paths, tracked, encrypt, exclude, yadm_alt): @pytest.mark.usefixtures("ds1_copy") @pytest.mark.parametrize("yadm_alt", [True, False], ids=["alt", "worktree"]) -def test_relative_link(runner, paths, yadm_alt): +@pytest.mark.parametrize("rel_worktree", [True, False], ids=["relative_work", "absolute_work"]) +def test_relative_link(runner, paths, yadm_alt, yadm_cmd, rel_worktree): """Confirm links created are relative""" yadm_dir, yadm_data = setup_standard_yadm_dir(paths) + if rel_worktree: + runner(yadm_cmd("gitconfig", "core.worktree", "../../../..")) + utils.create_alt_files( paths, "##default", tracked=True, encrypt=False, exclude=False, yadm_alt=yadm_alt, yadm_dir=yadm_dir ) diff --git a/yadm b/yadm index 34d951c..04c5e9e 100755 --- a/yadm +++ b/yadm @@ -1793,7 +1793,12 @@ function configure_paths() { # obtain YADM_WORK from repo if it exists if [ -d "$GIT_DIR" ]; then local work + # It's possible this is a relative path, in which case it's relative to $GIT_DIR: + # https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreworktree work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)") + if [[ "$work" != /* ]]; then + work="$(cd "$GIT_DIR/$work" && pwd)" + fi [ -n "$work" ] && YADM_WORK="$work" fi