Commit 4448accf authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Fix (ish) a relative path issue in worktrees

parent eeb581ec
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -163,15 +163,15 @@ new_worktree()
	WT_REPO=".git/worktrees/$WORKTREE"
	mkdir -p -- "$WORKTREE" "$WT_REPO"
	PREFIX=gitdir gitlink $WT_GIT $WT_REPO
	REL=.git gitlink "$WT_REPO/gitdir" "$WT_GIT"
	gitlink "$WT_REPO/commondir" .git
	gitlink "$WT_REPO/gitdir" "$WT_GIT"
	echo "ref: refs/heads/$NAME" > "$WT_REPO/HEAD"
}

gitlink()
{
	printf "${PREFIX+$PREFIX: }"
	realpath --relative-to=$(dirname $1) $2
	realpath --relative-to=${REL-$(dirname $1)} $2
} > $1


@@ -350,7 +350,10 @@ action_rm()
	if is_subdirectory "$BRANCH"; then
		local BRANCH_NAME=$(GIT_DIR="$BRANCH/.git" git rev-parse --abbrev-ref HEAD)
		rm -r "$BRANCH"
		(
			cd $(git rev-parse --git-common-dir)
			git worktree prune
		)
	else
		arg_error "The first argument must be a worktree name"
	fi