【问题标题】:How to do git pull through build.xml (ant task)如何通过 build.xml 进行 git pull(ant 任务)
【发布时间】:2015-02-11 01:48:21
【问题描述】:

在这里,如果本地文件夹中不存在文件,我正在尝试从 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 命令...请帮助我..提前致谢。

【问题讨论】:

    标签: git ant build.xml


    【解决方案1】:

    通过查看提供的链接,作者已将git 定义为宏定义。所以你需要在你的构建文件中包含这些定义,否则 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>
    

    【讨论】:

    • 好的,我可以直接在“git-file”目标下包含这个宏定义
    • @HarithaR 是的,您可以在目标中包含宏定义,但是将其作为顶级元素添加到外部会使所有目标都可以看到它,以防其他目标也想使用它。
    • 现在我已经更正了我的方法并发送了正确的值,但它引发了如下异常:C:\Users\Haritha\Desktop\H2H\conf\build.xml:23: The directory C:\Users\Haritha\Desktop\H2H\conf\https:\github.com\libgit2\libgit2.git does not exist,正在发送输入 https:\github.com\libgit2\libgit2.git 但 windows 路径正在添加中,如何解决此问题
    • @HarithaR 请在另一个问题中提出这个问题,指定更新的构建文件和确切的错误。
    猜你喜欢
    • 2015-07-08
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多