-
Notifications
You must be signed in to change notification settings - Fork 160
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 git hook version #474
base: main
Are you sure you want to change the base?
Add git hook version #474
Conversation
a459a58
to
80d7d01
Compare
I'm not sure about the best approach for the version of the git hook, I would think matching the version of ktlint would be a bad idea as it would force users to update the hook when there are no changes. Currently this requires manually updating the version when changes are made to GitHook.kt Perhaps the best way to solve this would be to have a build step that checks for changes to GitHook.kt or generates the script and checks diff. If there are changes then increment the |
d0a1490
to
f6f315b
Compare
// if FILTER_INCLUDE_PROPERTY_NAME exists then we are invoked from a git hook, check hook version | ||
if (project.findProperty(hookVersion) != hookVersion) { | ||
throw GradleException("Your ktlint git hook is outdated, please update by running the addKtlint*GitPreCommitHook Gradle task.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be inclined to make this a warning instead of an error. Or, if we do want to make this an error, you should be able to disable it to make it a warning instead.
@Tapchicoma thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this to be a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a warning then the user won't see it because --quiet
.
plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt
Outdated
Show resolved
Hide resolved
f6f315b
to
c2c7feb
Compare
c2c7feb
to
5f93615
Compare
@Test | ||
internal fun `Git hook should send the hook version to gradle`() { | ||
projectRoot.setupGradleProject() | ||
val gitDir = projectRoot.initGit() | ||
|
||
build(":$INSTALL_GIT_HOOK_FORMAT_TASK").run { | ||
assertThat(task(":$INSTALL_GIT_HOOK_FORMAT_TASK")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
assertThat(gitDir.preCommitGitHook().readText()).contains("""-phookVersion=$hookVersion""") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this test to use the @CommonTest
format above?
When git hook is updated users won't know. This change introduces a version number into the hook, and if that version number doesn't match the expected value then the gradle task will fail.
There is also a issue with the formatting of the git hook which I've fixed up.