Skip to content

Commit

Permalink
Warn rather than fail when git repository does not exist or has no in…
Browse files Browse the repository at this point in the history
…itial commit
  • Loading branch information
jkschneider committed Oct 26, 2015
1 parent 69d8642 commit 40813ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
@@ -0,0 +1,38 @@
package nebula.plugin.release
import nebula.test.IntegrationSpec
import org.ajoberstar.grgit.Grgit
import org.gradle.api.plugins.JavaPlugin
/**
* Verify the behavior of nebula-release under various states for a new project (e.g. no git repo yet initialized, no
* initial commit)
*/
class ReleasePluginNewProjectIntegrationSpec extends IntegrationSpec {
def 'release tasks unavailable when no git repository has been initialized'() {
when:
buildFile << """
${applyPlugin(ReleasePlugin)}
${applyPlugin(JavaPlugin)}
"""

then:
runTasksSuccessfully('build')
runTasksWithFailure('snapshot')
}

def 'release tasks unavailable when git repository has no commits'() {
setup: // equivalent of having completed `git init` but no initial commit
def origin = new File(projectDir.parent, "${projectDir.name}.git")
origin.mkdirs()
Grgit.init(dir: origin)

when:
buildFile << """
${applyPlugin(ReleasePlugin)}
${applyPlugin(JavaPlugin)}
"""

then:
runTasksSuccessfully('build')
runTasksWithFailure('snapshot')
}
}
9 changes: 9 additions & 0 deletions src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Expand Up @@ -19,6 +19,7 @@ import nebula.core.ProjectType
import org.ajoberstar.gradle.git.release.base.BaseReleasePlugin
import org.ajoberstar.gradle.git.release.base.ReleasePluginExtension
import org.ajoberstar.grgit.Grgit
import org.eclipse.jgit.errors.RepositoryNotFoundException
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down Expand Up @@ -50,6 +51,14 @@ class ReleasePlugin implements Plugin<Project> {

ProjectType type = new ProjectType(project)

try {
Grgit.open(dir: project.rootProject.projectDir)
}
catch(RepositoryNotFoundException e) {
logger.warn("This project does not have a fully initialized git repository yet -- nebula-release tasks will not be available")
return
}

if (type.isRootProject) {
project.plugins.apply(BaseReleasePlugin)
ReleasePluginExtension releaseExtension = project.extensions.findByType(ReleasePluginExtension)
Expand Down

0 comments on commit 40813ac

Please sign in to comment.