Created
July 19, 2022 03:33
-
-
Save burkenyo/b8a78569b55d4d955f9aefe24f4b15c2 to your computer and use it in GitHub Desktop.
(PowerShell Core) find long lines within a git commit range
This file contains 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
#!/usr/bin/env pwsh | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true, Position=0)] | |
$StartRef, | |
[Parameter(Mandatory=$true, Position=1)] | |
$EndRef, | |
[ValidateRange(72, 132)] | |
[int]$Cutoff = 88 | |
) | |
cd $PSScriptRoot/.. | |
$files = git --no-pager diff $StartRef $EndRef --name-only | | |
% { $PWD.Path + '/' + $_ } | |
$commits = @{} | |
foreach($commitInfo in (git --no-pager log --pretty=format:'%h %s' "$StartRef...$EndRef")){ | |
$commits += (ConvertFrom-StringData $commitInfo -Delimiter ' ') | |
} | |
foreach ($file in $files) { | |
$lineNum = 1 | |
$path = Resolve-Path $file -Relative | |
$first = $true | |
foreach ($line in (Get-Content $file)) { | |
if ($line.Length -gt $Cutoff) { | |
$commit = git --no-pager log --pretty=format:"%h %s" -n 1 -L $lineNum,+1:$file --no-patch | |
$commit = $commit.Split(' ', 2)[0] | |
if ($commit -notin $commits.Keys) { | |
continue | |
} | |
if ($first) { | |
$path | |
$first = $false | |
} | |
" line $lineNum is $($line.Length) chars:" | |
" $($line.Trim())" | |
" modified in:" | |
" $commit – $($commits[$commit])" | |
"" | |
} | |
$lineNum++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment