Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has git check to check project directory and custom location #37

Closed
domcc opened this issue Jan 20, 2017 · 6 comments
Closed

has git check to check project directory and custom location #37

domcc opened this issue Jan 20, 2017 · 6 comments

Comments

@domcc
Copy link

domcc commented Jan 20, 2017

We have a slightly unconventional layout for some of our projects that means the .git folder may not be in the project.rootProject.file('.git') location. Also the code in GitInfoService uses the project path and not the root .git location
def grgit = Grgit.open(currentDir: project.projectDir)

Also in one case we have a git repo where the java project is not at the root directory so we need a way to specify the location of the .git location.

@dcoraboeuf
Copy link
Contributor

Hi Dominic,

So you'd wish to be able to specific the location of your .git directory using a configuration parameters, like:

versioning {
   gitDirectory = "..."
}

Would that be OK?

@domcc
Copy link
Author

domcc commented Jan 20, 2017

Wow quick reply! Something like that i was actually trying to work out how to create a PR. i changed to this:

$ git diff
diff --git a/build.gradle b/build.gradle
index 3d9079c..3ffb5ad 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,6 +34,12 @@ dependencies {
     compile "org.eclipse.jgit:org.eclipse.jgit.ui:${jgitVersion}"
     compile "org.eclipse.jgit:org.eclipse.jgit:${jgitVersion}"
     compile 'org.tmatesoft.svnkit:svnkit:1.8.12'
+    testCompile "junit:junit:4.12"
+    testCompile "commons-lang:commons-lang:2.6"
+    testCompile "commons-io:commons-io:2.5"
+
+
+
 }

 /**
diff --git a/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy b/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy
index c623f98..c8af50f 100644
--- a/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy
+++ b/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy
@@ -49,6 +49,14 @@ class VersioningExtension {
     String scm = 'git'

     /**
+     * Allow setting location of .git file for non conventional git/gradle setups.
+     * This is the path to the .git folder used to validate if git is present for the current
+     * project.
+     *
+     */
+    String dotgitPath = null
+
+    /**
      * Fetch the branch from environment variable if available.
      *
      * By default, the environment is not taken into account, in order to be backward compatible
diff --git a/src/main/groovy/net/nemerosa/versioning/git/GitInfoService.groovy b/src/main/groovy/net/nemerosa/versioning/git/GitInfoService.groovy
index 56881b4..90654b4 100644
--- a/src/main/groovy/net/nemerosa/versioning/git/GitInfoService.groovy
+++ b/src/main/groovy/net/nemerosa/versioning/git/GitInfoService.groovy
@@ -19,7 +19,9 @@ class GitInfoService implements SCMInfoService {
     @Override
     SCMInfo getInfo(Project project, VersioningExtension extension) {
         // Is Git enabled?
-        boolean hasGit = project.rootProject.file('.git').exists()
+        boolean hasGit = project.rootProject.file('.git').exists() ||
+                         project.file('.git').exists() ||
+                         (extension.dotgitPath != null && new File(extension.dotgitPath).exists())
         // No Git information
         if (!hasGit) {
             SCMInfo.NONE

`

@dcoraboeuf
Copy link
Contributor

Looks like a good patch. I'll need to create some integration test first. I'll do that later today or this week-end. You can also jump in and try to create a PR.

@domcc
Copy link
Author

domcc commented Jan 20, 2017

Great thanks Damien. First time creating a PR on github so i will work it out when i get home.

domcc pushed a commit to domcc/versioning that referenced this issue Jan 20, 2017
…bility to specify location of .git location
domcc pushed a commit to domcc/versioning that referenced this issue Jan 20, 2017
@domcc
Copy link
Author

domcc commented Jan 20, 2017

Hi Damien, managed to create a pull request #38

Thank you,
Dominic

@dcoraboeuf
Copy link
Contributor

Closing this ticket in favour of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants