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

Cannot apply HunkHeader on Windows #49

Open
msharathrajms opened this issue May 13, 2020 · 12 comments
Open

Cannot apply HunkHeader on Windows #49

msharathrajms opened this issue May 13, 2020 · 12 comments

Comments

@msharathrajms
Copy link

I am getting the below error.

Failed to execute goal com.cosium.code:git-code-format-maven-plugin:2.4:on-pre-commit (default-cli) on project qe-jira-soap: org.eclipse.jgit.api.errors.PatchApplyException: Cannot ap
ply: HunkHeader[1,9->1,5] -

I have added -X to the pre-commit script and here is the error log.

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.cosium.code:git-code-format-maven-plugin:2.4:on-pre-commit (default-cli) on project qe-jira-soap: org.eclips
e.jgit.api.errors.PatchApplyException: Cannot apply: HunkHeader[1,9->1,5]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: org.eclipse.jgit.api.errors.PatchApplyException: Cannot apply: HunkHeader[1,9->1,5]
at com.cosium.code.format.OnPreCommitMojo.doExecute(OnPreCommitMojo.java:25)
at com.cosium.code.format.AbstractModuleMavenGitCodeFormatMojo.execute(AbstractModuleMavenGitCodeFormatMojo.java:66)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: com.cosium.code.format.MavenGitCodeFormatException: org.eclipse.jgit.api.errors.PatchApplyException: Cannot apply: HunkHeader[1,9->1,5]
at com.cosium.code.format.git.GitStagedFiles.format(GitStagedFiles.java:97)
at com.cosium.code.format.OnPreCommitMojo.onPreCommit(OnPreCommitMojo.java:30)
at com.cosium.code.format.OnPreCommitMojo.doExecute(OnPreCommitMojo.java:22)
... 23 more
Caused by: org.eclipse.jgit.api.errors.PatchApplyException: Cannot apply: HunkHeader[1,9->1,5]
at org.eclipse.jgit.api.ApplyCommand.apply(ApplyCommand.java:224)
at org.eclipse.jgit.api.ApplyCommand.call(ApplyCommand.java:138)
at com.cosium.code.format.git.GitStagedFiles.format(GitStagedFiles.java:92)
... 25 more

I am using CLI, Git version 2.23.0, Windows, Plugin version 2.4. I have a parent pom and added it to that, i am using again in a sub project and this is a multi module project.

@Nayacco
Copy link

Nayacco commented May 20, 2020

Failed to execute goal com.cosium.code:git-code-format-maven-plugin:2.1:on-pre-commit (default-cli) on project scaffold: org.eclipse.jgit.api.errors.PatchApplyException: Cannot apply: HunkHeader[11,7->11,6] -> [Help 1]

plugin version: 2.4
maven: 3.6
OS: "windows 10"
arch: "amd64"

I can run the manual command successful, but when i try to commit and the hook trigger the automatic formatting, it brakes with the above error.

the same look like another issue #42
@reda-alaoui

@reda-alaoui
Copy link
Member

reda-alaoui commented May 20, 2020

This is a long standing and hard to debug Windows specific issue.
I currently don't have the time and the motivation (me and almost all my coworkers are on Linux/Mac OS) to deal with it.

So I hope one of the impacted people will give it a shot. After all, the plugin is written in java and we are all java developers here :)

@reda-alaoui reda-alaoui changed the title Issue with code formatter Failed to execute goal com.cosium.code:git-code-format-maven-plugin:2.4:on-pre-commit (default-cli) on project org.eclipse.jgit.api.errors.PatchApplyException: Cannot ap ply: HunkHeader[1,9->1,5] - Cannot apply: HunkHeader May 20, 2020
@Nayacco
Copy link

Nayacco commented May 20, 2020

I try to fix it, but it doesn't seem easy.

As the author said, this is a problem caused by the combination of lf and CRLF , so change the IDE's line separator to lf. and set the git config below:

git config --global core.autocrlf true
git config --global core.safecrlf true

add * text=auto eol=lf to the repo's .gitattributes file. then run the commond:

git rm --cached -r .
git reset --hard

it will update the repositroy files line separator to lf

@Nayacco

This comment was marked as off-topic.

@reda-alaoui

This comment was marked as off-topic.

@Nayacco

This comment was marked as off-topic.

@reda-alaoui

This comment was marked as off-topic.

@reda-alaoui reda-alaoui changed the title Cannot apply: HunkHeader Cannot apply HunkHeader on Windows May 27, 2020
@Nayacco

This comment was marked as off-topic.

@reda-alaoui

This comment was marked as off-topic.

@yl-coder
Copy link

yl-coder commented Oct 5, 2020

I managed to resolve this in windows using this methods. Not sure why it works though.

git stash push

git stash pop

Somehow the HunkHeader issue is gone for my case.

@cmoine
Copy link

cmoine commented Jun 28, 2022

Personnally I'm still struggle with this issue:

@tomcruise81
Copy link

Using Git Bash / unix2dos, I made sure everything was included CRLF so that my git configuration could handle it correctly. I was only dealing with Java files, so I filtered my matching based on .java file extensions.

shopt -s globstar
unix2dos -v **/*.java

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

6 participants