|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Verify worktree credentials |
| 5 | +# This test verifies that git credentials work in worktrees created after checkout |
| 6 | +# Usage: verify-worktree.sh <checkout-path> <worktree-name> |
| 7 | + |
| 8 | +CHECKOUT_PATH="$1" |
| 9 | +WORKTREE_NAME="$2" |
| 10 | + |
| 11 | +if [ -z "$CHECKOUT_PATH" ] || [ -z "$WORKTREE_NAME" ]; then |
| 12 | + echo "Usage: verify-worktree.sh <checkout-path> <worktree-name>" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +cd "$CHECKOUT_PATH" |
| 17 | + |
| 18 | +# Add safe directory for container environments |
| 19 | +git config --global --add safe.directory "*" 2>/dev/null || true |
| 20 | + |
| 21 | +# Show the includeIf configuration |
| 22 | +echo "Git config includeIf entries:" |
| 23 | +git config --list --show-origin | grep -i include || true |
| 24 | + |
| 25 | +# Create the worktree |
| 26 | +echo "Creating worktree..." |
| 27 | +git worktree add "../$WORKTREE_NAME" HEAD --detach |
| 28 | + |
| 29 | +# Change to worktree directory |
| 30 | +cd "../$WORKTREE_NAME" |
| 31 | + |
| 32 | +# Verify we're in a worktree |
| 33 | +echo "Verifying worktree gitdir:" |
| 34 | +cat .git |
| 35 | + |
| 36 | +# Verify credentials are available in worktree by checking extraheader is configured |
| 37 | +echo "Checking credentials in worktree..." |
| 38 | +if git config --list --show-origin | grep -q "extraheader"; then |
| 39 | + echo "Credentials are configured in worktree" |
| 40 | +else |
| 41 | + echo "ERROR: Credentials are NOT configured in worktree" |
| 42 | + echo "Full git config:" |
| 43 | + git config --list --show-origin |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +# Verify fetch works in the worktree |
| 48 | +echo "Fetching in worktree..." |
| 49 | +git fetch origin |
| 50 | + |
| 51 | +echo "Worktree credentials test passed!" |
0 commit comments