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

Add support for using git CLI when available #1

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

sciwhiz12
Copy link
Member

@sciwhiz12 sciwhiz12 commented Aug 8, 2023

JGit has some feature holes/defects -- in particular, it lacks support for git work-trees and has so for a long time.

This PR adds support for using the git CLI when it is available, with support for falling back to JGit when not. This means features like work-trees are recognized and work properly.

TODO

  • Move changelog generation to use GitProvider as well
    • This does mean more breaking changes to the API surface, on top of what's already been broken in GradleUtils, due to removing the use of JGit classes.
  • Fix license headers
    • Forge Development LLC has no relation to the new files I've committed
  • Thoroughly test out the changes of this PR
    • Initial tests seem promising in their function
  • Consider switching new classes to Groovy with @CompileStatic
  • Consider adding @CompileStatic to more places in the project

JGit has some feature holes/defects -- in particular, it lacks support
for git work-trees and has so for a long time.

This adds initial support for using the git CLI when it is available,
with support for falling back to JGit when not. This means features
like work-trees are recognized and work properly.

Changelog generation has not yet been moved to using GitProvider, as it
requires more work to detach it from its use of JGit classes.
@sciwhiz12 sciwhiz12 added the enhancement New feature or request label Aug 8, 2023
I can't grok proper array copying, so a collection it is!
git-symbolic-ref modifies the symbolic ref (first argument) to point to
the second argument. A single argument, for a query, is what we want.
@marchermans
Copy link
Contributor

This might need a toggle/override.
If the configuration cache is enabled, then we are not allowed to execute commands like git for versioning.

@zml2008
Copy link

zml2008 commented Sep 23, 2023

you can run external processes by using ExecOperations - and/or a custom ValueSource on a Provider

@marchermans
Copy link
Contributor

You can't at the moment because the projects version property does not support it.....

Even jgit currently throws up the error as it turns out. Because it invokes git as well

@sciwhiz12
Copy link
Member Author

I'm not fully sure what you mean by what isn't supported by the Project.version property?

Although the project version property isn't a full Property<String>, it is somewhat flexible because it's actually stored as an Object which is toStringed on use. I don't remember where I did it, but I recall having using that flexibility to set the project version to a GitVersion object, which lazily calculates the version when it's toStringed.

@lukebemish
Copy link
Contributor

lukebemish commented Mar 19, 2024

This might need a toggle/override. If the configuration cache is enabled, then we are not allowed to execute commands like git for versioning.

If the configuration cache is enabled, using the git cli is isn't that hard - just use a ValueSource or two that takes an ExecOperations and call it a day. I'd recommend switching entirely to the git cli - if you use jgit sometimes and the git cli other times you risk inconsistent behavior causing weirdness

IntelliJ IDEA refuses to work with any lower Gradle version, for some
reason.
Remaining unimplemented change is removing GradleUtils.openGit, as that
is currently used by ChangelogUtils.
The changelog generator value source will be migrated at a later date,
due to its more extensive uses of JGit.
Inline `{@return}` is not in Java 8, which this project uses.
The git CLI provider still needs to implement the required method before
it fully works, but the command needed is supplied in a comment for
future work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants