sashoalm sashoalm - 3 months ago 14
Git Question

Verify that all Git commits of a C# project compile after rewriting history

Is there any automated way to verify that all commits in a Git repo are in a compilable state?

I need this to verify I haven't broken anything after rewriting history. Since I'm rewriting history, this excludes a build server - a commit that worked at the time it was committed might be broken after rewriting history.

For example I have a Visual Studio 2015 C# project, and I imagine some script like:

git filter-branch --tree-filter msbuild

I want it to run a build on each commit, and stop with an error message if the build process returns nonzero.


Considering the tree-filter will execute the command from a Git bash, you might want to use

git filter-branch --tree-filter "MSBuild.exe" 

(making sure your %PATH% does include c:\Program Files (x86)\MSBuild\14.0\Bin)
(or use forward slash as in here)

That would be equally valid for the other option mentioned in the comments

git rebase -i --exec MSBuild.exe <first sha you want to test>~

You can use a CMD session similar to this gist, from Tim Abell:

@echo off
REM  batch script for loading git-bash and the vs tools in the same window
REM  inspiration:
REM  screenshot:!/tim_abell/status/199474387731226624/photo/1
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
echo Use full exe names when running under bash, e.g. "msbuild.exe"
echo Loading bash, you may now use git and msbuild in the same console \o/.
"C:\Program Files (x86)\Git\bin\sh.exe" --login -i