Fix clashing worktrees
This commit is contained in:
@@ -519,7 +519,7 @@ from_source() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove build directories and worktrees
|
# Remove all build directories and worktrees
|
||||||
if ((RESET)); then
|
if ((RESET)); then
|
||||||
if [[ -d "$BUILD_DIR" || -d "$worktree_meta" ]]; then
|
if [[ -d "$BUILD_DIR" || -d "$worktree_meta" ]]; then
|
||||||
execute git -C "$SRC_DIR" worktree remove --force --force "$BUILD_DIR"
|
execute git -C "$SRC_DIR" worktree remove --force --force "$BUILD_DIR"
|
||||||
@@ -538,22 +538,29 @@ from_source() {
|
|||||||
execute git clone "$src_url" "$SRC_DIR"
|
execute git clone "$src_url" "$SRC_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up orphaned worktree if needed
|
# Clean up orphaned or conflicting worktree if needed
|
||||||
if [[ ! -d "$BUILD_DIR" || ! -d "$worktree_meta" ]]; then
|
execute git -C "$SRC_DIR" worktree prune --verbose
|
||||||
[[ -d "$BUILD_DIR" ]] && execute rm -rf "$BUILD_DIR"
|
|
||||||
[[ -d "$worktree_meta" ]] && execute rm -rf "$worktree_meta"
|
# Remove build dir if it exists but is not a worktree
|
||||||
execute git -C "$SRC_DIR" worktree prune --verbose
|
if [[ -d "$BUILD_DIR" ]] && ! git -C "$SRC_DIR" worktree list | grep -q "$BUILD_DIR"; then
|
||||||
|
execute rm -rf "$BUILD_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove any worktree using this ref elsewhere
|
||||||
|
existing_worktree=$(git -C "$SRC_DIR" worktree list | awk "/\\[$ref\\]/ {print \$1}")
|
||||||
|
if [[ -n "$existing_worktree" && "$existing_worktree" != "$BUILD_DIR" ]]; then
|
||||||
|
echo "Removing conflicting worktree at $existing_worktree for ref $ref"
|
||||||
|
execute git -C "$SRC_DIR" worktree remove --force "$existing_worktree"
|
||||||
|
[[ -d "$existing_worktree" ]] && execute rm -rf "$existing_worktree"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add or update worktree
|
# Add or update worktree
|
||||||
if [[ -d "$BUILD_DIR" && -d "$worktree_meta" ]]; then
|
if [[ -d "$BUILD_DIR" ]] && git -C "$SRC_DIR" worktree list | grep -q "$BUILD_DIR"; then
|
||||||
execute git -C "$BUILD_DIR" checkout "$ref"
|
execute git -C "$BUILD_DIR" checkout "$ref"
|
||||||
# pull if ref is a branch
|
|
||||||
if git -C "$SRC_DIR" show-ref --verify --quiet "refs/heads/$ref"; then
|
if git -C "$SRC_DIR" show-ref --verify --quiet "refs/heads/$ref"; then
|
||||||
execute git -C "$BUILD_DIR" pull
|
execute git -C "$BUILD_DIR" pull
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# branch or tag?
|
|
||||||
if git -C "$SRC_DIR" show-ref --verify --quiet "refs/heads/$ref"; then
|
if git -C "$SRC_DIR" show-ref --verify --quiet "refs/heads/$ref"; then
|
||||||
execute git -C "$SRC_DIR" worktree add "$BUILD_DIR" "$ref"
|
execute git -C "$SRC_DIR" worktree add "$BUILD_DIR" "$ref"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user