#!/bin/bash # Script to fix git repository permissions # Fixes "insufficient permission for adding an object" error set -e SERVER_IP="147.45.152.129" SERVER_USER="root" REPO_PATH="/home/vscode/cards" echo "๐Ÿ”ง Fixing git repository permissions on server..." ssh "$SERVER_USER@$SERVER_IP" << 'EOF' set -e REPO_PATH="/home/vscode/cards" VSCODE_USER="vscode" echo "๐Ÿ“ Checking current ownership..." echo "Current ownership of $REPO_PATH:" ls -la "$REPO_PATH" | head -10 echo "" echo "๐Ÿ”„ Fixing ownership and permissions..." # Change ownership of entire repository to vscode user chown -R $VSCODE_USER:$VSCODE_USER "$REPO_PATH" # Fix permissions # Directories: rwxr-xr-x (755) find "$REPO_PATH" -type d -exec chmod 755 {} \; # Files: rw-r--r-- (644) find "$REPO_PATH" -type f -exec chmod 644 {} \; # Make scripts executable find "$REPO_PATH" -type f -name "*.sh" -exec chmod 755 {} \; # Fix .git directory specifically if [ -d "$REPO_PATH/.git" ]; then echo "๐Ÿ” Fixing .git directory permissions..." chown -R $VSCODE_USER:$VSCODE_USER "$REPO_PATH/.git" chmod -R u+rwX "$REPO_PATH/.git" fi # Fix all submodules echo "๐Ÿ“ฆ Fixing submodules if any..." find "$REPO_PATH" -name ".git" -type d | while read gitdir; do echo " Fixing: $gitdir" chown -R $VSCODE_USER:$VSCODE_USER "$gitdir" chmod -R u+rwX "$gitdir" done # Fix common subdirectories for subdir in mnemo_cards_common mnemo_cards_backend mnemo_cards_web_v2 mnemo_cards_frontend_common; do if [ -d "$REPO_PATH/$subdir" ]; then echo " Fixing: $REPO_PATH/$subdir" chown -R $VSCODE_USER:$VSCODE_USER "$REPO_PATH/$subdir" if [ -d "$REPO_PATH/$subdir/.git" ]; then chmod -R u+rwX "$REPO_PATH/$subdir/.git" fi fi done echo "" echo "โœ… Permissions fixed!" echo "" echo "๐Ÿ“Š New ownership:" ls -la "$REPO_PATH" | head -10 echo "" echo "๐Ÿงช Testing git status..." cd "$REPO_PATH/mnemo_cards_common" sudo -u $VSCODE_USER git status || echo "Git status check completed" EOF echo "" echo "โœ… Done! Git operations should now work without permission errors." echo "๐Ÿ’ก Try running your deployment script again."