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.

0
7 comments

Does it happen only when you build in IntelliJ IDEA or when you run Maven build in the terminal as well?

0
Avatar
Permanently deleted user

Hi !

Yes, it happens only when I build/push in Intellij IDEA. From the command line, it is correctly executed :

bbo@work ~/B/project>git push origin xxx-branch
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:

[...]

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:05 min
[INFO] Finished at: 2018-10-10T16:29:25+02:00
[INFO] Final Memory: 82M/1278M
[INFO] ------------------------------------------------------------------------
Décompte des objets: 23, fait.
Delta compression using up to 4 threads.
Compression des objets: 100% (20/20), fait.
Écriture des objets: 100% (23/23), 1.73 KiB | 1.73 MiB/s, fait.
Total 23 (delta 14), reused 0 (delta 0)
remote: Resolving deltas: 100% (14/14), completed with 14 local objects.
To github.com:<company>/<project>.git
+ a76b05ac...a59c5f09 <xxx-branch> -> <xxx-branch>
bbo@work ~/B/project> 
0

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.

0

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.

[develop xxx] Commit Message
9 files changed, 38 insertions(+), 39 deletions(-)
14:54:40.080: [backend] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/develop:develop
Running tests pre-push
Test Pre-Push Successful!
Total 30 (delta 23), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for develop, visit:
remote: https:///-/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote:
To https://-
refs/heads/develop:refs/heads/develop abc...xxx
Done
14:58:57.776: [backend] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/develop:develop
Running tests pre-push

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:

IntelliJ IDEA 2024.2.1 RC (Ultimate Edition)
Build #IU-242.21829.40, built on August 18, 2024

Runtime version: 21.0.3+13-b509.11 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 14.6.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 10
Metal Rendering is ON
Registry:
 debugger.new.tool.window.layout=true
 ide.experimental.ui=true
 ide.slow.operations.assertion=false
 i18n.locale=
Non-Bundled Plugins:
 com.jetbrains.space (242.21829.114)
 com.euphoricity.gitignore (0.3)
 org.jetbrains.plugins.spotbugs (1.2.8)
 com.haulmont.jpab (242.21829.3)
 com.intellij.properties.bundle.editor (242.20224.155)
 com.intellij.ml.llm (242.21829.114)
 org.sonarlint.idea (10.8.1.79205)
Kotlin: 242.21829.40-IJ
0

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? 

0

Sure, pre-push hook:

#!/bin/sh
# Ejecuta los tests de Maven
echo "Running tests pre-push"
mvn test -DargLine="-ea -Duser.timezone=UTC"
# Verifica si los tests se ejecutaron correctamente
if [ $? -ne 0 ]; then
  echo "Test failed! Chech errors before trying again."
  exit 1
fi
echo "Test Pre-Push Successful!"
exit 0

Using IDE, after commit I use this UI:

After clicking Push:
14:54:40.080: [backend] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/develop:develop
Running tests pre-push
...
Test Pre-Push Successful!

Total 30 (delta 23), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for develop, visit:
remote: https:///-/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote:
To https://-
refs/heads/develop:refs/heads/develop abc...xxx
Done

14:58:57.776: [backend] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/develop:develop

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.

Test Pre-Push Successful!
Enumerating objects: 46, done.
...
Total 13 (delta 6), reused 0 (delta 0), pack-reused 0
remote: 
remote: To create a merge request for develop, visit:
remote:   https:///-/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote: 
To https://-.git
       refs/heads/develop:refs/heads/develop   abc..xyz
Done
user@MACHINE cwd % 
0

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? 

0

Please sign in to leave a comment.