From: Wesley <wesleys@opperschaap.net>
To: git@vger.kernel.org
Subject: git pre-push hook not getting the lines from STDIN
Date: Tue, 8 Aug 2023 18:24:49 -0400 [thread overview]
Message-ID: <676330b6-720a-e262-d583-9012e549bba7@opperschaap.net> (raw)
Hello list,
I'm trying to figure out how I can check which branches are used in a
git push action while using the pre-push hook. In the man page the
following is mentioned:
----<
Information about what is to be pushed is provided on the hook’s
standard input with lines of the form:
<local ref> SP <local object name> SP <remote ref> SP <remote object
name> LF
For instance, if the command `git push origin master:foreign` were run
the hook would receive a line like the following:
refs/heads/master 67890 refs/heads/foreign 12345
----<
I cannot seem to reproduce this behavior with the push action. Only when
pushing to delete a remote branch or pushing to a new branch gets
created yields any success. I went as far back as git 2.9.0 (I can't
build older versions of git), to no avail. The line in the man page
seems to indicate git v1.8.2-rc0 was the first tag to have it (ec55559f).
Could someone verify that what I am seeing is correct behavior or that
this is incorrect?
As stated, I experience issues on git v2.9.0, 2.40.1 (Debian) and also
directly from source 2.42.0.rc0.26.g6ac35453d6.
Thanks,
Wesley
----< a new branch
$ git push origin test:fofofo
+.git/hooks/pre-push:5> remote=origin
+.git/hooks/pre-push:6> url=git@gitlab.com:gitlabmeme/somerepo.git
+.git/hooks/pre-push:8> success=128
+.git/hooks/pre-push:10> z40=0000000000000000000000000000000000000000
+.git/hooks/pre-push:11> IFS=' '
+.git/hooks/pre-push:13> read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA
+.git/hooks/pre-push:15> echo refs/heads/test
refs/heads/test
+.git/hooks/pre-push:16> echo 24a3b84a02937df6040fecce2e0620e16c823b36
24a3b84a02937df6040fecce2e0620e16c823b36
+.git/hooks/pre-push:17> echo refs/heads/fofofo
refs/heads/fofofo
+.git/hooks/pre-push:18> echo 0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
+.git/hooks/pre-push:21> [ refs/heads/test '='
0000000000000000000000000000000000000000 ']'
+.git/hooks/pre-push:23> [ refs/heads/test '=' '(delete)' ']'
+.git/hooks/pre-push:30> exit 128
----< deletion of a branch on the remote
$ git push origin :development
+.git/hooks/pre-push:5> remote=origin
+.git/hooks/pre-push:6> url=git@gitlab.com:gitlabmeme/somerepo.git
+.git/hooks/pre-push:8> success=128
+.git/hooks/pre-push:10> z40=0000000000000000000000000000000000000000
+.git/hooks/pre-push:11> IFS=' '
+.git/hooks/pre-push:13> read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA
+.git/hooks/pre-push:15> echo '(delete)'
(delete)
+.git/hooks/pre-push:16> echo 0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
+.git/hooks/pre-push:17> echo refs/heads/development
refs/heads/development
+.git/hooks/pre-push:18> echo 1762c08fd38c1137bbca27898df7c64ad846f877
1762c08fd38c1137bbca27898df7c64ad846f877
+.git/hooks/pre-push:21> [ '(delete)' '='
0000000000000000000000000000000000000000 ']'
+.git/hooks/pre-push:23> [ '(delete)' '=' '(delete)' ']'
+.git/hooks/pre-push:23> exit 128
----<
If I push to an existing repo on my remote I see this:
$ git push origin HEAD:development
+.git/hooks/pre-push:5> remote=origin
+.git/hooks/pre-push:6> url=git@gitlab.com:gitlabmeme/somerepo.git
+.git/hooks/pre-push:8> success=128
+.git/hooks/pre-push:10> z40=0000000000000000000000000000000000000000
+.git/hooks/pre-push:11> IFS=' '
+.git/hooks/pre-push:13> read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA
+.git/hooks/pre-push:15> echo
+.git/hooks/pre-push:16> echo
+.git/hooks/pre-push:17> echo
+.git/hooks/pre-push:18> echo
+.git/hooks/pre-push:21> [ '' '='
0000000000000000000000000000000000000000 ']'
+.git/hooks/pre-push:23> [ '' '=' '(delete)' ']'
+.git/hooks/pre-push:28> exit 128
----< The pre-push script
#!/usr/bin/env zsh
#
set -x
remote="$1"
url="$2"
success=128
z40=0000000000000000000000000000000000000000
IFS=' '
read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA
echo $LOCAL_REF
echo $LOCAL_SHA
echo $REMOTE_REF
echo $REMOTE_SHA
# deletion of remote branch
[ "$LOCAL_REF" = $z40 ] && exit $success
# git 2.40 at least does not have $z40 as a delete
[ "$LOCAL_REF" = '(delete)' ] && exit $success
exit $success
--
Wesley
Why not both?
next reply other threads:[~2023-08-08 22:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 22:24 Wesley [this message]
2023-08-09 11:00 ` git pre-push hook not getting the lines from STDIN Sean Allred
2023-08-09 12:38 ` Wesley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=676330b6-720a-e262-d583-9012e549bba7@opperschaap.net \
--to=wesleys@opperschaap.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox