worktree: add relative cli/config options to move command

This teaches the `worktree move` command to respect the
`--[no-]relative-paths` CLI option and `worktree.useRelativePaths`
config setting. If an existing worktree is moved with `--relative-paths`
the new path will be relative (and visa-versa).

Signed-off-by: Caleb White <cdwhite3@pm.me>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Caleb White
2024-11-29 22:23:03 +00:00
committed by Junio C Hamano
parent b7016344f1
commit 298d2917e2
4 changed files with 39 additions and 16 deletions

View File

@ -247,4 +247,29 @@ test_expect_success 'not remove a repo with initialized submodule' '
)
'
test_expect_success 'move worktree with absolute path to relative path' '
test_config worktree.useRelativePaths false &&
git worktree add ./absolute &&
git worktree move --relative-paths absolute relative &&
echo "gitdir: ../.git/worktrees/absolute" >expect &&
test_cmp expect relative/.git &&
echo "../../../relative/.git" >expect &&
test_cmp expect .git/worktrees/absolute/gitdir &&
test_config worktree.useRelativePaths true &&
git worktree move relative relative2 &&
echo "gitdir: ../.git/worktrees/absolute" >expect &&
test_cmp expect relative2/.git &&
echo "../../../relative2/.git" >expect &&
test_cmp expect .git/worktrees/absolute/gitdir
'
test_expect_success 'move worktree with relative path to absolute path' '
test_config worktree.useRelativePaths true &&
git worktree move --no-relative-paths relative2 absolute &&
echo "gitdir: $(pwd)/.git/worktrees/absolute" >expect &&
test_cmp expect absolute/.git &&
echo "$(pwd)/absolute/.git" >expect &&
test_cmp expect .git/worktrees/absolute/gitdir
'
test_done