Add items to current GIT commit in CheckinHandler
Answered
Hello,
I'm working on a plugin for Intellij which creates baseline projects for GO and takes care of some specific project configurations in our company.
One of the things I'm trying to do is to attach to a GIT commit and add some files to the current commit.
These files are produced by "govendor" which copies all dependencies to the project folder.
Right now I execute git commands from within my CheckinHandler code, but I don't think this is a nice way to go.
Is it somehow possible to add items to the current commit context?
Thanks for you help.
Regards,
Karsten
Please sign in to leave a comment.
So what actions do you actually perform in the CheckinHandler?
Right now I use the ProcessBuilder to execute the following:
And I am wondering if I could do step 2+3 somehow in code without calling the external git command.
You can use the same framework which IDEA uses to call Git commands.
There are different levels of API available:
* GitCheckinEnvironment to add and commit to Git;
* Git interface to call various Git commands;
* GitHandler to call Git commands with more control and tuning.
(check usages of these classes for examples)
Note that all of them still call `git` executable under the hood.
That is good to know.
But that would produce a new commit, right?
So it wouldn't add the vendoring files to the current commit that is executed when I click on the "commit" button in the "Commit changes" dialog?
That's true. It will produce a new commit. Moreover, this commit will be made before the actual user commit (which is probably not what you want especially if user commit fails for some reason).
AFAIK there is no way to add files to the current commit, when commit procedure has already started (i.e. commit dialog was opened).
Since your operation requires only calling a couple of external commands, why don't you use a native Git's post-commit hook, generate the files you need from that hook and amend them to the last commit?
That is a very good point. I will do it with a post-commit hook.
Thank you for your help.