Save before creating restore point: Before implementing auto-commit system
Auto-saved at 2025-07-29 14:24:49 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
106
auto-commit.sh
Executable file
106
auto-commit.sh
Executable file
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Auto-commit script for timeshift project
|
||||
# Usage: ./auto-commit.sh [message]
|
||||
|
||||
set -e
|
||||
|
||||
# Function to auto-commit changes
|
||||
auto_commit() {
|
||||
local message="$1"
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# Check if there are any changes
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "🔄 Auto-committing changes at $timestamp"
|
||||
|
||||
# Add all changes
|
||||
git add .
|
||||
|
||||
# Create commit message
|
||||
if [[ -z "$message" ]]; then
|
||||
message="Auto-commit: Save work in progress"
|
||||
fi
|
||||
|
||||
# Commit with timestamp
|
||||
git commit -m "$(cat <<EOF
|
||||
$message
|
||||
|
||||
Auto-saved at $timestamp
|
||||
|
||||
🤖 Generated with [Claude Code](https://claude.ai/code)
|
||||
|
||||
Co-Authored-By: Claude <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
|
||||
echo "✅ Changes committed successfully"
|
||||
|
||||
# Show short log
|
||||
git log --oneline -3
|
||||
else
|
||||
echo "📝 No changes to commit at $timestamp"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create a safe restore point
|
||||
create_restore_point() {
|
||||
local description="$1"
|
||||
local branch_name="restore-point-$(date '+%Y%m%d-%H%M%S')"
|
||||
|
||||
echo "🔖 Creating restore point: $branch_name"
|
||||
|
||||
# Commit current changes first
|
||||
auto_commit "Save before creating restore point: $description"
|
||||
|
||||
# Create a new branch as restore point
|
||||
git branch "$branch_name"
|
||||
|
||||
echo "✅ Restore point created: $branch_name"
|
||||
echo "📋 To restore later, run: git checkout $branch_name"
|
||||
}
|
||||
|
||||
# Function to show available restore points
|
||||
list_restore_points() {
|
||||
echo "📋 Available restore points:"
|
||||
git branch | grep "restore-point-" | sed 's/^..//' | sort -r
|
||||
}
|
||||
|
||||
# Function to clean old restore points (keep last 10)
|
||||
cleanup_restore_points() {
|
||||
echo "🧹 Cleaning old restore points (keeping last 10)..."
|
||||
git branch | grep "restore-point-" | sed 's/^..//' | sort -r | tail -n +11 | while read branch; do
|
||||
git branch -D "$branch" 2>/dev/null && echo "🗑️ Deleted old restore point: $branch"
|
||||
done
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
case "$1" in
|
||||
"commit")
|
||||
auto_commit "$2"
|
||||
;;
|
||||
"restore-point")
|
||||
create_restore_point "$2"
|
||||
;;
|
||||
"list")
|
||||
list_restore_points
|
||||
;;
|
||||
"cleanup")
|
||||
cleanup_restore_points
|
||||
;;
|
||||
*)
|
||||
echo "📚 Auto-commit utility for timeshift project"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " $0 commit [message] - Auto-commit current changes"
|
||||
echo " $0 restore-point [desc] - Create a restore point branch"
|
||||
echo " $0 list - List available restore points"
|
||||
echo " $0 cleanup - Clean old restore points"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 commit 'Fixed spreadsheet layout'"
|
||||
echo " $0 restore-point 'Before major refactor'"
|
||||
echo ""
|
||||
auto_commit "$1"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user