Skip to content

Commit

Permalink
fix #87: handle failure to find repo with warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
GladeDiviney committed Oct 30, 2020
1 parent 761d77c commit 35adebc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
8 changes: 6 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changes

## 0.4.14

* Print warning message if git repo not found (#87).

## 0.4.13

* Support `%describe%` for git-describe results
* Support `%describe%` for git-describe results.

## 0.4.11

* Support `commitHashLength`
* Support `commitHashLength`.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add `plugins` block to the top of your `app/build.gradle` (or equivalent):

```groovy
plugins {
id 'com.gladed.androidgitversion' version '0.4.13'
id 'com.gladed.androidgitversion' version '0.4.14'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.eclipse.jgit.api.Git
import org.eclipse.jgit.diff.DiffEntry
import org.eclipse.jgit.diff.DiffFormatter
import org.eclipse.jgit.diff.RawTextComparator
import org.eclipse.jgit.errors.RepositoryNotFoundException
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.Repository
Expand All @@ -17,6 +18,7 @@ import org.eclipse.jgit.util.io.DisabledOutputStream
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.slf4j.LoggerFactory

class AndroidGitVersion implements Plugin<Project> {
void apply(Project project) {
Expand Down Expand Up @@ -200,8 +202,9 @@ class AndroidGitVersionExtension {
.readEnvironment()
.findGitDir(project.projectDir)
.build()
} catch (IllegalArgumentException ignore) {
// No repo found
} catch (IllegalArgumentException | RepositoryNotFoundException ignore) {
def logger = LoggerFactory.getLogger("androidGitVersion")
logger.warn("No git repository reachable from ${project.projectDir}")
return results
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class AndroidGitVersionTest extends GroovyTestCase {
}()

Git git = {
return Git.init().setDirectory(projectFolder.root).call();
return Git.init().setDirectory(projectFolder.root).call()
}()

@Lazy
Expand Down
6 changes: 3 additions & 3 deletions src/test/groovy/com/gladed/androidgitversion/MainTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class MainTest extends AndroidGitVersionTest {
assertEquals(1056555, plugin.code())
}


void testSubmodule() {
// Set up a base repo
addCommit()
Expand All @@ -121,17 +120,18 @@ class MainTest extends AndroidGitVersionTest {
libraryGit.tag().setName("2.0").call()

// Add the library repo to the base repo as a submodule
Repository libraryRepo = git.submoduleAdd()
git.submoduleAdd()
.setPath("library")
.setURI(libraryGit.getRepository().getDirectory().getCanonicalPath())
.call()
libraryRepo.close()
.close()

// Add the submodule as a subproject to the base project
Project libraryProject = ProjectBuilder.builder()
.withProjectDir(new File(projectFolder.root, "library"))
.withParent(project)
.build()

libraryProject.pluginManager.apply 'com.gladed.androidgitversion'
AndroidGitVersionExtension libraryPlugin = (AndroidGitVersionExtension) libraryProject.getExtensions().getByName('androidGitVersion')

Expand Down

0 comments on commit 35adebc

Please sign in to comment.