Urbanleg
Urbanleg

Reputation: 6532

gradle - getWorkingBranch error on gradle-git

I'm trying to get branches from my git server.

my gradle file looks like this:

apply plugin: 'java'
apply plugin: 'eclipse'


buildscript {
  repositories { mavenCentral() }
  dependencies { classpath 'org.ajoberstar:gradle-git:0.6.3' }
}

import org.ajoberstar.gradle.git.tasks.*

task getBranchName(type: GitBranchList) << {
    print getWorkingBranch().name
}

But i get an error:

Caused by: org.gradle.api.UncheckedIOException: org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: C:\workspace\GradleTC

Upvotes: 3

Views: 1528

Answers (1)

Benjamin Muschko
Benjamin Muschko

Reputation: 33436

My assumption is that you are not executing the task within a checked out local repository path. If you want to be explicit, you'll have to tell the task which repository your are referring to. This is done by setting the property repoPath. If you only want to query for the remote branches, you'll also have to set the branchType to REMOTE.

task getBranchName(type: GitBranchList) {
    repoPath = 'path-to-repo'
    branchType = GitBranchList.BranchType.REMOTE

    doLast {
        print getWorkingBranch().name
    }
}

Upvotes: 3

Related Questions