diff --git a/.gitignore b/.gitignore index 06fad92..62d678e 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,8 @@ Thumbs.db # IRC bot specific *.pid -*.lockbackup_bots/ +*.lock + +# Project specific +backup_bots/ +git_push.log diff --git a/README_git_script.md b/README_git_script.md index 454f3f8..d0193cd 100644 --- a/README_git_script.md +++ b/README_git_script.md @@ -35,11 +35,39 @@ Examples of what the script generates: - **After**: ~20-50 tokens per git operation - **Savings**: ~75% reduction in git-related token usage -## Claude Usage +## Claude Usage - TOKEN EFFICIENT WORKFLOW -When Claude needs to push changes: +**✅ CORRECT (Low Token Usage):** ``` Please run: ./git_push.sh ``` +*Claude ignores output completely* -Instead of multiple git commands + output analysis. \ No newline at end of file +**❌ AVOID (High Token Usage):** +``` +git status +git add . +git commit -m "..." +git push origin main +``` +*Reading outputs wastes tokens* + +## Logging System + +- All operations logged to `git_push.log` +- Only check log if there's an issue +- **Claude should NOT read logs unless asked** +- Log file ignored by git + +## Error Handling + +If push fails: +1. User will see error on console +2. User can ask: "Check the git log for errors" +3. Only then should Claude read `git_push.log` + +## Token Savings Protocol + +- **Normal operation**: Use script, ignore output +- **Only on errors**: Read logs when requested +- **Maximum efficiency**: No unnecessary output reading \ No newline at end of file diff --git a/git_push.sh b/git_push.sh index 6a338dc..310f8e3 100755 --- a/git_push.sh +++ b/git_push.sh @@ -4,6 +4,10 @@ set -e # Exit on any error +# Create log file with timestamp +LOG_FILE="git_push.log" +echo "=== Git Push Log - $(date) ===" >> "$LOG_FILE" + # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' @@ -15,12 +19,14 @@ echo -e "${BLUE}🚀 Smart Git Push${NC}" # Check if we're in a git repo if ! git rev-parse --git-dir > /dev/null 2>&1; then echo -e "${RED}❌ Not in a git repository${NC}" + echo "ERROR: Not in a git repository" >> "$LOG_FILE" exit 1 fi # Check if there are any changes (including untracked files) if git diff --quiet && git diff --staged --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then echo -e "${GREEN}✅ No changes to commit${NC}" + echo "INFO: No changes to commit" >> "$LOG_FILE" exit 0 fi @@ -78,20 +84,28 @@ COMMIT_MSG="$COMMIT_MSG Co-Authored-By: Claude " +# Log the operation details +echo "Files changed: $MODIFIED_FILES" >> "$LOG_FILE" +echo "Commit message: $COMMIT_MSG" >> "$LOG_FILE" + # Stage all changes echo -e "${BLUE}📦 Staging changes...${NC}" -git add . +git add . 2>> "$LOG_FILE" # Commit -echo -e "${BLUE}💾 Committing: $COMMIT_MSG${NC}" -git commit -m "$COMMIT_MSG" > /dev/null +echo -e "${BLUE}💾 Committing...${NC}" +git commit -m "$COMMIT_MSG" >> "$LOG_FILE" 2>&1 # Push echo -e "${BLUE}⬆️ Pushing to origin...${NC}" -git push origin main > /dev/null 2>&1 +git push origin main >> "$LOG_FILE" 2>&1 echo -e "${GREEN}✅ Successfully pushed to git!${NC}" # Show summary (minimal) CHANGED_COUNT=$(echo "$MODIFIED_FILES" | wc -l) -echo -e "${GREEN}📊 Pushed $CHANGED_COUNT file(s)${NC}" \ No newline at end of file +echo -e "${GREEN}📊 Pushed $CHANGED_COUNT file(s)${NC}" + +# Log success +echo "SUCCESS: Push completed at $(date)" >> "$LOG_FILE" +echo "" >> "$LOG_FILE" \ No newline at end of file