验证重写历史记录后,验证C#项目的所有Git提交是否都已编译

时间:2016-09-16 07:49:10

标签: c# git

是否有任何自动方式来验证Git仓库中的所有提交是否处于可编译状态?

我需要这个来验证我在重写历史后没有破坏任何东西。由于我重写了历史记录,因此排除了构建服务器 - 在重写历史记录后,提交时提交的提交可能会被破坏。

例如,我有一个Visual Studio 2015 C#项目,我想象一些脚本如:

git filter-branch --tree-filter msbuild

我希望它在每次提交时运行构建,并在构建过程返回非零时停止并显示错误消息。

3 个答案:

答案 0 :(得分:5)

考虑到树过滤器将从Git bash执行命令,您可能想要使用

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

(确保您的%PATH%确实包含c:\Program Files (x86)\MSBuild\14.0\Bin
(或use forward slash as in here

对于other option提到的in the comments

,这同样有效
git rebase -i --exec MSBuild.exe <first sha you want to test>~

您可以使用CMD session similar to this gist中的Tim Abell

@echo off
REM  batch script for loading git-bash and the vs tools in the same window
REM  inspiration: http://www.drrandom.org/post/2011/11/16/Grappling-with-multiple-remotes-in-git-tfs.aspx
REM  screenshot: https://twitter.com/#!/tim_abell/status/199474387731226624/photo/1
%HOMEDRIVE%
cd %HOMEPATH%
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

答案 1 :(得分:2)

假设您要检查仓库中的所有历史提交,而不是未来的提交:

您可以使用git bisect执行此操作:

git bisect start
git bisect bad # Mark the current HEAD as bad
git bisect good <the first commit>

然后,您需要一个运行msbuild的脚本,为构建错误返回1,为成功构建返回125。这是因为我们不能将任何构建标记为&#34; good&#34;,因为我们不知道在此之前的提交是否也有效,所以我们跳过那些有效的构建。

然后,用run命令开始二等分:

git bisect run myscript

然后,它将开始运行构建(以非连续顺序),直到找到损坏的构建,然后停止。有关详细说明,请参阅https://git-scm.com/docs/git-bisect#_bisect_run

答案 2 :(得分:2)

(在Git BashGit Posh上测试):

  1. 为msbuild命令创建git别名:

    git config --global --add alias.msbuild "!c:\path\to\msbuild.exe"

  2.   

    如果&#34; msbuild.exe&#34;路径出现在PATH env中。 var,你可以写&#34;!msbuild&#34;而不是一条完整的道路。

    1. 然后运行命令:

      git filter-branch --tree-filter "git msbuild"