verify-worktree.sh 1.3 KB

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