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

Support: Recomended way to check if in git directory. #397

Closed
spacey-sooty opened this issue Mar 27, 2024 · 3 comments
Closed

Support: Recomended way to check if in git directory. #397

spacey-sooty opened this issue Mar 27, 2024 · 3 comments

Comments

@spacey-sooty
Copy link

I have a Gradle plugin that will log extra data related to git info if within a git directory. What would be the recomended way to check this?

@ajoberstar
Copy link
Owner

In your plugin, you could do something like:

try {
  var grgitExtension = project.getExtensions().getBytType(GrgitServiceExtension.class);
  var grgit = grgitExtension.getService().getGrgit();
  // if it exists
} catch (IllegalStateException e) {
  // if no git repo
}

@spacey-sooty
Copy link
Author

Would something like

try {
  var grgit = Grgit.open();
} catch (Exception e) {
}

Also work?

spacey-sooty added a commit to spacey-sooty/GradleRIO that referenced this issue Mar 28, 2024
@ajoberstar
Copy link
Owner

Yes, just be mindful of the behavior of Grgit.open with no args. Generally this wouldn't be an issue, but Gradle historically didn't guarantee the working directory matches the project directory, so it could cause it to find the wrong Git repo.

https://ajoberstar.org/grgit/main/grgit-open.html

spacey-sooty added a commit to spacey-sooty/GradleRIO that referenced this issue Mar 28, 2024
requires ajoberstar/grgit#399

Try use grgit to check if in git repo

not sure if this works see ajoberstar/grgit#397

fix grgit
spacey-sooty added a commit to spacey-sooty/GradleRIO that referenced this issue Jun 30, 2024
requires ajoberstar/grgit#399

Try use grgit to check if in git repo

not sure if this works see ajoberstar/grgit#397

fix grgit
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