Skip to content

Commit 5031046

Browse files
committed
gitignore
1 parent 8090e66 commit 5031046

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

e.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash
2+
3+
# Script to fix commits made with cursoragent@cursor.com email
4+
# Replaces cursoragent@cursor.com with current git email
5+
# Renames current branch from cursor/name-of-feature to nate/name-of-feature
6+
7+
set -e
8+
9+
# Colors for output
10+
RED='\033[0;31m'
11+
GREEN='\033[0;32m'
12+
YELLOW='\033[1;33m'
13+
BLUE='\033[0;34m'
14+
NC='\033[0m' # No Color
15+
16+
print_info() {
17+
echo -e "${BLUE}[INFO]${NC} $1"
18+
}
19+
20+
print_success() {
21+
echo -e "${GREEN}[SUCCESS]${NC} $1"
22+
}
23+
24+
print_warning() {
25+
echo -e "${YELLOW}[WARNING]${NC} $1"
26+
}
27+
28+
print_error() {
29+
echo -e "${RED}[ERROR]${NC} $1"
30+
}
31+
32+
# Check if we're in a git repository
33+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
34+
print_error "Not in a git repository. Please run this script from a git repository."
35+
exit 1
36+
fi
37+
38+
# Get current git config
39+
CURRENT_NAME=$(git config user.name)
40+
CURRENT_EMAIL=$(git config user.email)
41+
42+
print_info "Current git config:"
43+
print_info " Name: $CURRENT_NAME"
44+
print_info " Email: $CURRENT_EMAIL"
45+
46+
# Get current branch
47+
CURRENT_BRANCH=$(git branch --show-current)
48+
print_info "Current branch: $CURRENT_BRANCH"
49+
50+
# Check if current branch starts with cursor/
51+
if [[ "$CURRENT_BRANCH" == cursor/* ]]; then
52+
NEW_BRANCH=$(echo "$CURRENT_BRANCH" | sed 's/^cursor\//nate\//')
53+
print_info "Will rename branch: $CURRENT_BRANCH -> $NEW_BRANCH"
54+
RENAME_BRANCH=true
55+
else
56+
print_info "Current branch does not start with 'cursor/', no branch renaming needed."
57+
RENAME_BRANCH=false
58+
fi
59+
60+
# Find commits with cursoragent@cursor.com
61+
print_info "Finding commits with cursoragent@cursor.com on current branch..."
62+
63+
CURSOR_COMMITS=$(git log --oneline --author="cursoragent@cursor.com" "$CURRENT_BRANCH")
64+
65+
if [ -z "$CURSOR_COMMITS" ]; then
66+
print_warning "No commits found with cursoragent@cursor.com email on current branch."
67+
COMMIT_COUNT=0
68+
else
69+
print_info "Found the following commits with cursoragent@cursor.com on current branch:"
70+
echo "$CURSOR_COMMITS"
71+
echo ""
72+
73+
# Count commits
74+
COMMIT_COUNT=$(echo "$CURSOR_COMMITS" | wc -l)
75+
print_info "Total commits to fix: $COMMIT_COUNT"
76+
fi
77+
78+
# Confirm before proceeding
79+
if [ $COMMIT_COUNT -gt 0 ] || [ "$RENAME_BRANCH" = true ]; then
80+
print_warning "This will:"
81+
if [ $COMMIT_COUNT -gt 0 ]; then
82+
print_warning " - Change the author email from 'cursoragent@cursor.com' to '$CURRENT_EMAIL' for commits on current branch"
83+
fi
84+
if [ "$RENAME_BRANCH" = true ]; then
85+
print_warning " - Rename current branch from '$CURRENT_BRANCH' to '$NEW_BRANCH'"
86+
fi
87+
88+
read -p "Do you want to continue? (y/N): " -n 1 -r
89+
echo ""
90+
91+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
92+
print_info "Operation cancelled."
93+
exit 0
94+
fi
95+
else
96+
print_warning "No commits or branch renaming needed."
97+
exit 0
98+
fi
99+
100+
# Create backup branch
101+
BACKUP_BRANCH="backup-$(date +%Y%m%d-%H%M%S)"
102+
print_info "Creating backup branch: $BACKUP_BRANCH"
103+
git branch "$BACKUP_BRANCH"
104+
105+
# Use git filter-branch to change commits on current branch only (only if there are commits to fix)
106+
if [ $COMMIT_COUNT -gt 0 ]; then
107+
print_info "Updating commit author emails on current branch..."
108+
109+
git filter-branch --env-filter '
110+
if [ "$GIT_AUTHOR_EMAIL" = "cursoragent@cursor.com" ]; then
111+
export GIT_AUTHOR_EMAIL="'"$CURRENT_EMAIL"'"
112+
export GIT_AUTHOR_NAME="'"$CURRENT_NAME"'"
113+
fi
114+
if [ "$GIT_COMMITTER_EMAIL" = "cursoragent@cursor.com" ]; then
115+
export GIT_COMMITTER_EMAIL="'"$CURRENT_EMAIL"'"
116+
export GIT_COMMITTER_NAME="'"$CURRENT_NAME"'"
117+
fi
118+
' --tag-name-filter cat -- "$CURRENT_BRANCH"
119+
120+
# Clean up the backup refs
121+
print_info "Cleaning up backup refs..."
122+
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
123+
124+
print_success "Successfully updated commits with cursoragent@cursor.com on current branch!"
125+
fi
126+
127+
# Rename current branch from cursor/ to nate/
128+
if [ "$RENAME_BRANCH" = true ]; then
129+
print_info "Renaming current branch from '$CURRENT_BRANCH' to '$NEW_BRANCH'..."
130+
131+
# Rename the current branch locally only
132+
git branch -m "$NEW_BRANCH"
133+
134+
print_success "Successfully renamed branch: $CURRENT_BRANCH -> $NEW_BRANCH"
135+
fi
136+
137+
print_info "Backup branch created: $BACKUP_BRANCH"
138+
print_warning "If you're satisfied with the changes, you may want to delete the backup branch: git branch -d $BACKUP_BRANCH"
139+
print_warning "If you need to push these changes, you may need to force push: git push --force-with-lease"

0 commit comments

Comments
 (0)