首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grgit:在build.gradle脚本中添加标签并将文件推送到远程分支

grgit:在build.gradle脚本中添加标签并将文件推送到远程分支
EN

Stack Overflow用户
提问于 2019-03-29 21:38:17
回答 1查看 609关注 0票数 0

我正在尝试使用grgit添加一个git标签,提交并将一个文件推送到远程分支。这是我想要做的:

代码语言:javascript
复制
//Task to push updated build.info to remote branch
task pushToOrigin {
  doLast {
    def grgit = Grgit.open(dir: ".")

    grgit.add(patterns: ['web/build.info'])

    grgit.tag.add(
          name: "Tag3",
          message: "Release of 3-${grgit.head()}",
          force: true
    )

    grgit.commit(message: "Updating build.info")

    //push to remote
    grgit.push(remote:"${branch}", tags: true)
    //grgit.push(remote:"${branch}")

    //cleanup
    grgit.close()
  }

  println "Completed task: pushToOrigin" 
}

我注意到grgit.push(remote:"${branch}", tags: true)添加了标签,并将标签推送到远程,但不推送我暂存的文件更改。

但是,grgit.push(remote:"${branch}")会推送暂存文件更改,但不会推送标签。

我使用的是Gradle 5.3,grgit版本2.3.0

我还需要做些什么才能让两者都能工作吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-03-30 00:19:57

我找到了上述问题的解决方案。下面是我所做的:

代码语言:javascript
复制
task pushToOrigin {
  doLast {
        def grgit = Grgit.open(dir: ".")


        grgit.add(patterns: ['web/build.info'])


        grgit.commit(message: "Updating build.info")

        //Push to remote
        grgit.push(remote:"${branch}")

        //Tag
        tagName = "tag1"

        grgit.tag.add(
              name: tagName,
              message: "Release of ${tagName}"
        )

        //Push
        grgit.push(remote:"${branch}", refsOrSpecs: [tagName])

        //cleanup
        grgit.close()

    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55418712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档