worktree: extract basename computation to new function