-
Notifications
You must be signed in to change notification settings - Fork 1
/
Remove-BFGRepo.ps1
33 lines (31 loc) · 1.1 KB
/
Remove-BFGRepo.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
function Remove-BFGRepo {
<#
.DESCRIPTION
This function requires you installed java and bfg-repo-cleaner to work properly.
BFG will update your commits and all branches and tags so they are clean.
.LINK
https://rtyley.github.io/bfg-repo-cleaner/
.EXAMPLE
git clone --mirror git://example.com/some-repo.git
Remove-BFGRepo -repo some-repo.git -size 50M
#>
[CmdletBinding()]
param(
[Alias('path')][string]$repo,
[string]$size = '100M'
)
$currentDir = "$($PWD)"
if (Test-Path $repo) {
$scoopDir = Split-Path (Get-Command scoop.ps1).Source | Split-Path
$bfgJarFile = (Get-ChildItem -Path "$scoopDir" -Recurse -Filter "bfg.jar" -ErrorAction SilentlyContinue).FullName
java -jar $bfgJarFile --strip-blobs-bigger-than $size $repo
Set-Location $repo
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push
Set-Location $currentDir
}
else {
Write-Error "Repository '$repo' not found."
}
}
Set-Alias -Name 'bfg-clean' -Value 'Remove-BFGRepo'