如何通过build.xml执行git pull(ant任务)

时间:2014-12-12 10:57:20

标签: git ant build.xml

在这里,我试图从git中提取文件,如果它不在本地文件夹中,这是我的代码。

<?xml version="1.0" encoding="utf-8"?>
<project name="MyProject" default="deploy">

    <target name="deploy" depends="file-checks, local-file, git-file"/>

    <target name="file-checks">
       <available file="C:\Users\Hareesh\Desktop\H2H\conf\rdbms1.properties"  property="file.found"/>
    </target>

    <target name="local-file" if="file.found">
        <echo message="File is available in Local" />
    </target>
    <target name="git-file" unless="file.found">
        <echo message="No" />
        <git command = "clone">
            <args>
                <arg value = "git://github.com/280north/ojunit.git" />
                <arg value = "ojunit" />
            </args>
        </git> 
    </target>
</project>

显示如下错误:

Buildfile: C:\Users\Hareesh\Desktop\H2H\conf\build.xml
file-checks:
local-file:
git-file:
     [echo] No

BUILD FAILED
C:\Users\Hareesh\Desktop\H2H\conf\build.xml:15: Problem: failed to create task or type git
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


Total time: 203 milliseconds

我已按照以下网址: http://tlrobinson.net/blog/2008/11/ant-tasks-for-git/

arg值是否有任何错误?我无法找到,因为我没有git命令的知识...请帮帮我..谢谢。

1 个答案:

答案 0 :(得分:4)

通过检查提供的链接,作者将git定义为macrodef。因此,您需要在构建文件中包含这些定义,否则Ant将无法识别git是什么:

<macrodef name = "git">
    <attribute name = "command" />
    <attribute name = "dir" default = "" />
    <element name = "args" optional = "true" />
    <sequential>
        <echo message = "git @{command}" />
        <exec executable = "git" dir = "@{dir}">
            <arg value = "@{command}" />
            <args/>
        </exec>
    </sequential>
</macrodef>

<macrodef name = "git-clone-pull">
    <attribute name = "repository" />
    <attribute name = "dest" />
    <sequential>
        <git command = "clone">
            <args>
                <arg value = "@{repository}" />
                <arg value = "@{dest}" />
            </args>
        </git>
        <git command = "pull" dir = "@{dest}" />
    </sequential>
</macrodef>