如何在ant中运行git checkout?

alestar

我一直在阅读这篇文章,以便在特定日期进行git checkout。我已经能够获得针对检出目标的特定提交的修订提交SHA代码,但是当我尝试实际运行git checkout命令行时,出现错误:

错误:pathspec'de957d59f5ebef20f34155456b8ab46f127dc345'与git已知的任何文件都不匹配。

不确定那是什么意思。我正在Windows 7计算机上从ant 1.94运行此命令

ant命令脚本如下所示:

 <target name="git.revlist" description="Revision list of repo for a particular timeframe" >
    <exec executable="git" dir="${run.repo.dir}" failifexecutionfails="true" output="${output_commit_sha_file}" >
        <arg line="rev-list -n 1 --before=${snapshot_before_date} ${repo_branch}"/>
    </exec>
    <loadfile property="output_commit_sha" srcfile="${output_commit_sha_file}"  />
    <exec executable="git" dir="${run.repo.dir}" failifexecutionfails="true" >
        <arg line="checkout ${output_commit_sha}"/>
    </exec> 
 </target>

第一次执行实际上成功检索到SHA(de957d59f5ebef20f34155456b8ab46f127dc345)代码的位置,但是当尝试将其用于第二个执行任务命令参数时,它会通过上述错误。

关于我在这里缺少什么的任何想法/建议。就像我提到的,我确实有几个看起来像这样的任务命令行,它们用于执行其他任务,例如git clonegit log,但是这个似乎缺少一些关键的东西。

提前致谢

乍得·努伊斯

在错误消息中,我注意到在结束引号之前有一个空格:

pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 '
                                                  ^ a space

我相信在输出文件末尾插入换行符output属性<exec><loadfile>稍后将换行符转换为空格。

为了避免处理空间,请考虑git rev-list使用outputproperty代替将结果保存到Ant属性output

<exec executable="git" dir="${run.repo.dir}" outputproperty="output_commit_sha">
    <arg line="rev-list -n 1 --before=${snapshot_before_date} ${repo_branch}"/>
</exec>
<exec executable="git" dir="${run.repo.dir}">
    <arg line="checkout ${output_commit_sha}"/>
</exec>

上面的版本很不错,因为它避免了创建存储结果的文件的麻烦git rev-list它还会删除对的呼叫<loadfile>

顺便说一句,您可能要使用failonerror="true"代替failifexecutionfails="true"failifexecutionfailstrue默认设置,因此可以省略。failonerror,但是false默认情况下是。添加failonerror="true"<exec>通常是做了一件好事。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章