Git pre-push hook executed twice
Answered
Hi,
I'm using IDEA Commuity on a Maven multi-project and Git. I have configured a hook to "mvn clean install" before pushing a branch. The script is at <project_dir>/.git/hooks/pre-push
bbo@work ~/B/projects> cd .git/hooks/
bbo@work ~/B/p/.g/hooks> ls -l pre-push
-rwxrwxr-x. 1 bbo bbo 79 16 mars 2018 pre-push*
But the hook is executed twice : before and after pushing.
[...]
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] [1;32mBUILD SUCCESS[m
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] Total time: 02:01 min
[[1;34mINFO[m] Finished at: 2018-10-09T11:54:57+02:00
[[1;34mINFO[m] Final Memory: 82M/1567M
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
Delta compression using up to 4 threads.
Total 167 (delta 64), reused 0 (delta 0)
remote:
remote: Create a pull request for '<xxx-Branch>' on GitHub by visiting:
remote: https://github.com/<company>/<project>/pull/new/<xxx-Branch>
remote:
To github.com:<company>/<project>.git
* refs/heads/<xxx-Branch>:refs/heads/<xxx-Branch> [new branch]
Branch '<xxx-Branch>' set up to track remote branch '<xxx-Branch>' from 'origin'.
Done
11:55:02.107: [<project>] git -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/<xxx-Branch>:<xxx-Branch> --set-upstream
[[1;34mINFO[m] Scanning for projects...
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] [1mReactor Build Order:[m
[[1;34mINFO[m]
[...]
Would you have some clue to avoid it ?
Thank you.
Please sign in to leave a comment.
Does it happen only when you build in IntelliJ IDEA or when you run Maven build in the terminal as well?
Hi !
Yes, it happens only when I build/push in Intellij IDEA. From the command line, it is correctly executed :
Are you sure it is the hook which is executed twice? Can it be possible that one of these `mvn clean install` commands are issued from IDEA Maven Integration? If you're not sure, to diagnose this you can add some output line to the hook that would clearly indicate that it it a hook which is being executed.
At any case, please reproduce the issue and attach idea.log file.
The same is happening to me, if a use the UI the pre-push hook is executed twice. The second time, a modal window appears asking for credentials.
I reproduce it each time while using the UI. Running git push in the terminal executes pre-push only once.
I can provide more info if needed.
Right now I have this version:
What exactly does the hook do? Can you share it?
Also, what is the difference between output when you push via terminal vs inside IDE? Can you share both examples?
Sure, pre-push hook:
Using IDE, after commit I use this UI:
It presents this modal window, because it is trying to push again
If I introduce the token, it continues and runs again pre-push hook: Running tests pre-push
When running on terminal, just running the same command
git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/develop:develop
runs pre-push hook only once.
Can you please reproduce it and share the whole log file? https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files
Are you using git lfs?