Skip to content

Instantly share code, notes, and snippets.

@RReverser
Created December 1, 2023 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RReverser/60032effbd90d11183da9b679d808e41 to your computer and use it in GitHub Desktop.
Save RReverser/60032effbd90d11183da9b679d808e41 to your computer and use it in GitHub Desktop.
Bisect list of files within a large commit
$files = git diff --name-only main
# Binary search for a file that causes `./test/runner other.test_closure_type_annotations` to fail.
# At each step, try to revert half of the files to `main` branch.
# In the end $files will contain only the files that cause the test to fail.
while ($files.Length -gt 1) {
Write-Output "Testing $($files.Length) files:"
$files | ForEach-Object { Write-Output " $_" }
$mid = [math]::floor($files.Length / 2)
$lower = $files[0..($mid - 1)]
$upper = $files[$mid..$files.Length]
git checkout main -- $lower
git checkout -- $upper
./test/runner other.test_closure_type_annotations
if ($?) {
git checkout -- $lower
git checkout main -- $upper
./test/runner other.test_closure_type_annotations
if ($?) {
# If both variants succeeded, we're splitting incorrectly - there's a dependency between files.
# Shuffle them and try again.
$files = $files | Sort-Object {Get-Random}
} else {
$files = $lower
}
} else {
$files = $upper
}
git reset --hard
}
# Print the file that causes the test to fail.
$files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment