Last active
December 26, 2015 14:29
-
-
Save jernejg/7166587 to your computer and use it in GitHub Desktop.
Prevent large file commits with PowerShell and Mercurial hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-HgAddedLargeFile | |
{ | |
process | |
{ | |
return ForEach-Object {$_.Insert(1,",").Remove(2,1)} ` | |
| ConvertFrom-Csv -Header Status,Path ` | |
| Where-Object {$_.Status -ieq "A"} ` | |
| Get-Item ` | |
| Where-Object {$_.Length -gt 1MB} | |
} | |
} | |
Set-Location (Get-Childitem Env:HG_PENDING).Value | |
$largeFilesCount = (hg status ` | |
| Get-HgAddedLargeFile ` | |
| measure).Count | |
if ($largeFilesCount -gt 0) | |
{ | |
Write-Host Some files are to large to commit! -ForegroundColor "red" | |
hg status | Get-HgAddedLargeFile | |
} | |
exit $largeFilesCount |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment