n0mer / gradle-git-properties

Gradle plugin for `git.properties` file generation
https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties
Apache License 2.0
323 stars 55 forks source link

RepositoryNotFoundException for sub project in git hook #168

Closed jj-sn closed 2 years ago

jj-sn commented 3 years ago

:wave: Hi, I get a RepositoryNotFoundException when I apply the plugin to a gradle sub project and run generateGitProperties from a git hook. The plugin seems to be looking for the git repository in the sub project directory instead of the root project directory. The gradle task runs successfully when executed directly.

Structure:

├── .git
├── build.gradle
├── settings.gradle
├── sub
│   └── build.gradle

settings.gradle:

include ':sub'

sub/build.gradle:

plugins {
    id "com.gorylenko.gradle-git-properties" version "2.2.4"
}

.git/hooks/pre-commit:

#!/bin/sh

./gradlew -i sub:generateGitProperties

Committing triggers the exception:

~/dev/ggp$ git commit
Initialized native services in: /home/jjsn/.gradle/native
The client will now receive all logging from the daemon (pid: 31028). The daemon log file: /home/jjsn/.gradle/daemon/6.1.1/daemon-31028.out.log
Starting 12th build in daemon [uptime: 1 hrs 48 mins 43.413 secs, performance: 100%, non-heap usage: 28% of 268.4 MB]
Using 8 worker leases.
Starting Build
Closing daemon's stdin at end of input.
The daemon will no longer process any standard input.
Settings evaluated using settings file '/home/jjsn/dev/ggp/settings.gradle'.
Projects loaded. Root project using build file '/home/jjsn/dev/ggp/build.gradle'.
Included projects: [root project 'ggp', project ':sub']

> Configure project :
Evaluating root project 'ggp' using build file '/home/jjsn/dev/ggp/build.gradle'.

> Configure project :sub
Evaluating project ':sub' using build file '/home/jjsn/dev/ggp/sub/build.gradle'.
All projects evaluated.
Selected primary task 'sub:generateGitProperties' from project :sub
Tasks to be executed: [task ':sub:generateGitProperties']
:sub:generateGitProperties (Thread[Execution worker for ':',5,main]) started.

> Task :sub:generateGitProperties FAILED
dotGitDirectory = [/home/jjsn/dev/ggp/sub/.git]
:sub:generateGitProperties (Thread[Execution worker for ':',5,main]) completed. Took 0.005 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sub:generateGitProperties'.
> org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /home/jjsn/dev/ggp/sub/.git

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 451ms
1 actionable task: 1 executed
jj-sn commented 3 years ago

I used:

tha2015 commented 2 years ago

Please verify with latest version 2.4.0. Thanks.

jj-sn commented 2 years ago

I cam't even reproduce the problem with the old gradle and gradle-git-properties versions anymore. Current versions work fine, too. :shrug: I guess this can be closed.