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

Improve git hook execution in other then main worktree #605

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed

- git `pre-commit` hook should now work in all worktrees [#605](https://github.com/JLLeitschuh/ktlint-gradle/pull/605)

## [11.0.0] - 2022-08-24

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ internal fun generateGitHook(
echo "Running ktlint over these files:"
echo "${'$'}CHANGED_FILES"

diff=.git/unstaged-ktlint-git-hook.diff
GITDIR=${'$'}(git rev-parse --git-dir)
diff=${'$'}GITDIR/unstaged-ktlint-git-hook.diff

git diff --color=never > ${'$'}diff
if [ -s ${'$'}diff ]; then
git apply -R ${'$'}diff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class GitHookTasksTest : AbstractPluginTest() {
assertThat(hookText).contains("git apply -R \$diff")
assertThat(hookText).contains("git apply --ignore-whitespace \$diff")
assertThat(hookText).contains("rm \$diff")
assertThat(hookText).contains("GITDIR=\$(git rev-parse --git-dir)")
assertThat(hookText).contains("diff=\$GITDIR/unstaged-ktlint-git-hook.diff")
}
}
}
Expand Down