Skip to content

Instantly share code, notes, and snippets.

@jernejg
Last active December 26, 2015 14:29
Show Gist options
  • Save jernejg/7166587 to your computer and use it in GitHub Desktop.
Save jernejg/7166587 to your computer and use it in GitHub Desktop.
Prevent large file commits with PowerShell and Mercurial hooks
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