Commit ecbfb0e
committed
Fix pre-commit hook path handling for projects in subdirectories
When the Gradle project root differs from the Git repository root
(e.g., Gradle is in a subdirectory like 'project/submodule/'), the pre-commit hooks
generated by ktlint-gradle fail to properly format files because of
path mismatches.
This change fixes the issue by:
- Using `git diff --relative=$gradleRootDirPrefix` to output paths
relative to the Gradle project root
- Adding proper file path prefix handling in the git add command
when checking if files exist and staging them
This ensures that when git outputs paths like "src/main/Foo.kt"
(relative to project/submodule/), the hook correctly references them as
"project/submodule/src/main/Foo.kt" when checking file existence and staging.
Fixes #3741 parent e79fccb commit ecbfb0e
File tree
1 file changed
+7
-5
lines changed- plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint
1 file changed
+7
-5
lines changedLines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
56 | | - | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
0 commit comments