-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_star_boost.ps1
99 lines (76 loc) · 4.98 KB
/
git_star_boost.ps1
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Infinite loop to run the script every hour
while ($true) {
# Define the path where all your Git repositories are located
$reposPath = "C:\Github\" # Path to your local repositories
# List of repositories to skip (blacklist)
$blacklist = @("repo1", "repo2", "repo3", "repo4") # Names of repositories to ignore
# Get all the directories (repositories) inside the specified path
$repos = Get-ChildItem -Path $reposPath -Directory # Retrieves all directories in the given path
# Check if GPG (used for signing commits) is available on your system
$gpgAvailable = (Get-Command gpg -ErrorAction SilentlyContinue) -ne $null # Checks if GPG is installed
$gpgConfigured = $false # Default value for GPG configuration
# Set GitHub username and token for authentication
$gitHubUsername = "github_username" # GitHub username
$gitHubToken = "github_personal_token" # GitHub token for authentication
# Iterate over each repository found
foreach ($repo in $repos) {
# Get the full path of the current repository
$repoPath = $repo.FullName
# Skip repositories that are in the blacklist
if ($blacklist -contains $repo.Name) {
continue # Skip to the next repository in the list
}
# Check if the directory is a valid Git repository (it should contain a .git folder)
$gitFolder = Join-Path $repoPath ".git" # Build the path to the .git folder
if (Test-Path $gitFolder) { # If the .git folder exists, it's a Git repository
# Change to the repository directory
Set-Location -Path $repoPath # Navigate to the repository directory
# Update the repository by pulling the latest changes
git remote set-url origin "https://${gitHubUsername}:${gitHubToken}@github.com/${gitHubUsername}/$($repo.Name).git" # Set the remote URL with the GitHub token
git pull # Fetch the latest updates from the remote repository
git status # Show the current status of the repository (modified files, etc.)
git stash -u # Save untracked files to prevent losing them during the reset
# Discard any uncommitted changes by resetting the repository to the last commit
git reset --hard # Reset the repository to the last commit, discarding local changes
git clean -fd # Remove any untracked files and directories
# Search for commits with the message '#UPDATE' and remove them from history
$commitHashes = git log --oneline | Select-String "#UPDATE" | ForEach-Object { $_.Line.Split(' ')[0] } # Get all commit hashes with the message '#UPDATE'
# For each commit with the '#UPDATE' message, remove it from the repository's history
foreach ($commitHash in $commitHashes) {
git rebase --onto $commitHash^ $commitHash # Rebase to remove the commit from the history
}
# Create a temporary file to trigger a commit without changing the content of the repository
$fileName = Join-Path $repoPath "temp_file" # Define the temporary file name
New-Item -Path $fileName -ItemType File -Force # Create the temporary file in the repository
# Stage the temporary file for commit
git add $fileName # Add the temporary file to the staging area
# Create a commit with the temporary file (optional: sign with GPG if configured)
if ($gpgConfigured) {
git commit --gpg-sign --no-edit -m "#TEMP" # Commit with GPG signing
} else {
git commit --no-edit -m "#TEMP" # Commit without GPG signing
}
# Remove the temporary file after committing
Remove-Item $fileName # Delete the temporary file from the local repository
# Remove the file from Git tracking
git rm $fileName # Remove the file from the staging area
# Create another commit with the message '#UPDATE' (again, optional: sign with GPG)
if ($gpgConfigured) {
git commit --gpg-sign --no-edit -m "#UPDATE" # Commit with GPG signing
} else {
git commit --no-edit -m "#UPDATE" # Commit without GPG signing
}
# Force push the changes to the remote repository (overwrites history)
git push --force # Push the changes to the remote repository, overwriting history
# Restore the previously stashed changes (if any)
git stash pop # Apply the saved untracked changes back to the working directory
git status # Show the final status of the repository
} else {
Write-Host ".git not found: $repoPath" # Print a message if the directory isn't a Git repository
}
}
# Wait for 10 hours (36000 seconds) before repeating
Start-Sleep -Seconds 36000
}
# Final message after processing all repositories
Write-Host "Done!" # Indicate that the script has finished running