-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-author.ps1
More file actions
79 lines (68 loc) · 2.66 KB
/
Copy pathgit-author.ps1
File metadata and controls
79 lines (68 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
param(
[string]$OldEmail = "old@email.com",
[string]$NewEmail = "user@tooark.com",
[string]$NewName = "Tooark User"
)
Write-Host "=== Git Author Tool ===" -ForegroundColor Cyan
Write-Host "Old Email : $OldEmail"
Write-Host "New Email : $NewEmail"
Write-Host "New Name : $NewName"
Write-Host ""
# Check if git-filter-repo is installed
$gitFilterRepo = Get-Command git-filter-repo -ErrorAction SilentlyContinue
if (-not $gitFilterRepo) {
Write-Host "ERROR: git-filter-repo not found in PATH." -ForegroundColor Red
Write-Host "Install with: pip install git-filter-repo"
Write-Host "Alternative: pipx install git-filter-repo"
exit 1
}
# Confirmation before execution
Write-Host "Do you really want to rewrite the ENTIRE repository history?" -ForegroundColor Yellow
Write-Host "This is irreversible and affects all commits." -ForegroundColor Yellow
$confirm = Read-Host "Type 'YES' to continue"
if ($confirm -ne "YES") {
Write-Host "Operation cancelled." -ForegroundColor Red
exit 0
}
# Create Python callback
$commitCallback = @"
if commit.author_email == b"$OldEmail":
commit.author_email = b"$NewEmail"
commit.author_name = b"$NewName"
commit.committer_email = b"$NewEmail"
commit.committer_name = b"$NewName"
"@
Write-Host "Preparing repository..." -ForegroundColor Yellow
# Check if 'git' is available and we're inside a git repository
$gitAvailable = Get-Command git -ErrorAction SilentlyContinue
if (-not $gitAvailable) {
Write-Host "Warning: 'git' not available in PATH. Proceeding without stash." -ForegroundColor Yellow
} else {
git rev-parse --is-inside-work-tree 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Host "Warning: Does not appear to be a git repository. Proceeding without stash." -ForegroundColor Yellow
} else {
# Check if there are local changes (including untracked files)
$changes = git status --porcelain
if ($changes) {
Write-Host "Local changes detected. Creating stash 'Git-Author-Commit'..." -ForegroundColor Yellow
git stash push -u -m "Git-Author-Commit"
if ($LASTEXITCODE -eq 0) {
Write-Host "Stash created successfully: 'Git-Author-Commit'." -ForegroundColor Green
} else {
Write-Host "Failed to create stash. Aborting." -ForegroundColor Red
exit 1
}
} else {
Write-Host "No local changes, proceeding." -ForegroundColor Yellow
}
}
}
Write-Host "Running git-filter-repo..." -ForegroundColor Yellow
git-filter-repo --force `
--commit-callback "$commitCallback"
if ($LASTEXITCODE -eq 0) {
Write-Host "`nProcess completed successfully!" -ForegroundColor Green
} else {
Write-Host "`nAn error occurred during the process." -ForegroundColor Red
}