157 lines
4.5 KiB
Bash
157 lines
4.5 KiB
Bash
#!/bin/bash
|
||
# Git Credentials Test Script for Linux Mint
|
||
|
||
set -e
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
PURPLE='\033[0;35m'
|
||
CYAN='\033[0;36m'
|
||
NC='\033[0m' # No Color
|
||
|
||
print_header() {
|
||
echo -e "${CYAN}🧪 Git Credentials Test${NC}"
|
||
echo -e "${CYAN}======================${NC}"
|
||
echo ""
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
print_info() {
|
||
echo -e "${PURPLE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
# Main script
|
||
print_header
|
||
|
||
# Check if we're in a Git repository
|
||
if [ ! -d ".git" ]; then
|
||
print_error "Not in a Git repository. Please run from the repository root."
|
||
exit 1
|
||
fi
|
||
|
||
# Get repository info
|
||
print_info "Repository Information:"
|
||
echo "Remote URL: $(git remote get-url origin 2>/dev/null || echo 'No remote')"
|
||
echo "Current Branch: $(git branch --show-current 2>/dev/null || echo 'No branch')"
|
||
echo ""
|
||
|
||
# Check Git configuration
|
||
print_info "Git Configuration:"
|
||
echo "User Name: $(git config --global user.name 2>/dev/null || echo 'Not set')"
|
||
echo "User Email: $(git config --global user.email 2>/dev/null || echo 'Not set')"
|
||
echo "Credential Helper: $(git config --global credential.helper 2>/dev/null || echo 'Not set')"
|
||
echo ""
|
||
|
||
# Test credential helper
|
||
credential_helper=$(git config --global credential.helper 2>/dev/null || echo "")
|
||
|
||
print_info "Testing Credential Setup:"
|
||
case $credential_helper in
|
||
"cache")
|
||
print_success "Using Git credential cache"
|
||
echo " Credentials cached temporarily (default: 15 minutes)"
|
||
;;
|
||
"store")
|
||
print_warning "Using Git credential store (plain text)"
|
||
echo " Credentials stored in: ~/.git-credentials"
|
||
;;
|
||
"libsecret")
|
||
print_success "Using GNOME Keyring (encrypted)"
|
||
echo " Credentials stored securely in keyring"
|
||
;;
|
||
"vscode")
|
||
print_success "Using VS Code credential helper"
|
||
echo " VS Code manages credentials securely"
|
||
;;
|
||
"")
|
||
print_error "No credential helper configured"
|
||
echo " Run ./setup-git-credentials-linux.sh to configure"
|
||
;;
|
||
*)
|
||
print_info "Using custom credential helper: $credential_helper"
|
||
;;
|
||
esac
|
||
|
||
# Check SSH keys if using SSH remote
|
||
remote_url=$(git remote get-url origin 2>/dev/null || echo "")
|
||
if [[ $remote_url == git@* ]]; then
|
||
echo ""
|
||
print_info "SSH Key Check:"
|
||
|
||
ssh_key_path="$HOME/.ssh/id_ed25519"
|
||
if [ -f "$ssh_key_path" ]; then
|
||
print_success "SSH key found at: $ssh_key_path"
|
||
|
||
# Test SSH connection
|
||
echo "Testing SSH connection to git.d-popov.com..."
|
||
if ssh -T git@git.d-popov.com "echo 'SSH connection successful'" 2>/dev/null; then
|
||
print_success "SSH connection to git.d-popov.com works"
|
||
else
|
||
print_error "SSH connection failed"
|
||
echo " Make sure your public key is added to git.d-popov.com"
|
||
echo " Test manually: ssh -T git@git.d-popov.com"
|
||
fi
|
||
else
|
||
print_error "SSH key not found at: $ssh_key_path"
|
||
echo " Run ./setup-git-credentials-linux.sh and choose SSH option"
|
||
fi
|
||
fi
|
||
|
||
# Test Git operations
|
||
echo ""
|
||
print_info "Testing Git Operations:"
|
||
|
||
echo -n "git fetch: "
|
||
if git fetch --quiet 2>/dev/null; then
|
||
print_success "Success"
|
||
else
|
||
print_error "Failed"
|
||
fi
|
||
|
||
echo -n "git status: "
|
||
if git status --porcelain >/dev/null 2>&1; then
|
||
print_success "Success"
|
||
else
|
||
print_error "Failed"
|
||
fi
|
||
|
||
# Summary and recommendations
|
||
echo ""
|
||
print_info "Summary & Recommendations:"
|
||
|
||
if [ -z "$credential_helper" ]; then
|
||
print_error "No credential helper configured"
|
||
echo " → Run ./setup-git-credentials-linux.sh"
|
||
elif [ "$credential_helper" = "store" ]; then
|
||
print_warning "Using plain text credential storage"
|
||
echo " → Consider switching to SSH keys or GNOME Keyring"
|
||
elif [[ $remote_url == git@* ]] && [ ! -f "$HOME/.ssh/id_ed25519" ]; then
|
||
print_warning "Using SSH but no SSH key found"
|
||
echo " → Set up SSH keys for passwordless authentication"
|
||
else
|
||
print_success "Credential setup looks good!"
|
||
echo " → You should be able to push/pull without prompts"
|
||
fi
|
||
|
||
echo ""
|
||
print_info "Troubleshooting Commands:"
|
||
echo "• Clear stored credentials: git config --global --unset credential.helper"
|
||
echo "• Reset credential helper: ./setup-git-credentials-linux.sh"
|
||
echo "• Test SSH: ssh -T git@git.d-popov.com"
|
||
echo "• Check Git config: git config --list --show-origin"
|
||
echo "• Clear credential cache: git config --global --unset-all credential.helper"
|