Running custom CLI command before Commit
已回答
I am developing a new IntelliJ IDEA plugin which should replace git action.
For example, I want to replace “git commit” command used with “my-cli git commit” command for each commit.
Where should I start on this? Any pointers or examples would be great and helpful.
请先登录再写评论。
Hi,
I'm afraid it is not possible. See
git4idea.config.GitExecutable
. It is a sealed class, so it is impossible to contribute custom subclasses.Karol Lewandowski Thanks for the response. Is there a way to enforce pre-commit hooks via plugin which needs to be run a cli tool at the backend?
>I want to replace “git commit” command
The only way is to replace the “Path to Git executable” with some wrapper script, that delegates non-commit commands to real git and handles commit itself.
You can override the ENV passed to git executable too - see ‘com.intellij.openapi.vcs.VcsEnvCustomizer’.
>Is there a way to enforce pre-commit hooks via plugin which needs to be run a cli tool at the backend?
Are you talking about overriding the "git commit --no-verify" command, to make sure git hooks are run (if user chose to ignore hooks in commit option)? Why?
If you need some IDE-side pre-commit taks to run, there's `com.intellij.openapi.vcs.checkin.CommitCheck` api (and an older ‘com.intellij.openapi.vcs.checkin.CheckinHandler#beforeCheckin’ api, that is not preferred for long tasks).