ap6491
ap6491

Reputation: 835

grgit: Adding a tag and pushing files to remote branch in build.gradle script

I am trying to add a git tag using grgit, commit and push a file to remote branch. Here's what I am trying to do:

//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" 
}

I noticed that grgit.push(remote:"${branch}", tags: true) adds the tags and pushes the tag to remote but does not push my staged file changes.

However, grgit.push(remote:"${branch}") pushes the staged file changes but does not push the tags.

I am using Gradle 5.3, grgit version 2.3.0

Do I need to do anything else so that both work?

Thanks.

Upvotes: 1

Views: 1252

Answers (1)

ap6491
ap6491

Reputation: 835

I found a solution to the above issue. Here's what I did:

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()

    }
}

Upvotes: 1

Related Questions