* build-aux/git-hooks/pre-push
[not found] <875y9cef96.fsf.ref@yahoo.com>
@ 2023-05-01 6:29 ` Po Lu
2023-05-01 6:33 ` build-aux/git-hooks/pre-push Po Lu
2023-05-01 16:55 ` build-aux/git-hooks/pre-push Jim Porter
0 siblings, 2 replies; 10+ messages in thread
From: Po Lu @ 2023-05-01 6:29 UTC (permalink / raw)
To: emacs-devel
This script apparently loses when pushing from a separate worktree,
where .git is a file containing the name of the repository the worktree
was created from.
The following adjustment seems to fix it. However, I don't know much
about git. Objections?
diff --git a/build-aux/git-hooks/pre-push b/build-aux/git-hooks/pre-push
index 8e8277cba4f..8a2866f9d4c 100755
--- a/build-aux/git-hooks/pre-push
+++ b/build-aux/git-hooks/pre-push
@@ -83,4 +83,4 @@ $awk -v origin_name="$1" '
# Print every SHA after oldref, up to (and including) newref.
system("git rev-list --first-parent --reverse " oldref ".." newref)
}
-' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk
+' | $awk -v reason=pre-push -f build-aux/git-hooks/commit-msg-files.awk
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-01 6:29 ` build-aux/git-hooks/pre-push Po Lu
@ 2023-05-01 6:33 ` Po Lu
2023-05-02 5:35 ` build-aux/git-hooks/pre-push Jim Porter
2023-05-01 16:55 ` build-aux/git-hooks/pre-push Jim Porter
1 sibling, 1 reply; 10+ messages in thread
From: Po Lu @ 2023-05-01 6:33 UTC (permalink / raw)
To: emacs-devel
Po Lu <luangruo@yahoo.com> writes:
> This script apparently loses when pushing from a separate worktree,
> where .git is a file containing the name of the repository the worktree
> was created from.
>
> The following adjustment seems to fix it. However, I don't know much
> about git. Objections?
>
> diff --git a/build-aux/git-hooks/pre-push b/build-aux/git-hooks/pre-push
> index 8e8277cba4f..8a2866f9d4c 100755
> --- a/build-aux/git-hooks/pre-push
> +++ b/build-aux/git-hooks/pre-push
> @@ -83,4 +83,4 @@ $awk -v origin_name="$1" '
> # Print every SHA after oldref, up to (and including) newref.
> system("git rev-list --first-parent --reverse " oldref ".." newref)
> }
> -' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk
> +' | $awk -v reason=pre-push -f build-aux/git-hooks/commit-msg-files.awk
Btw, I notice that the script falls back to awk if gawk cannot be found.
Maybe in that case, the awk script should be rewritten to not utilize
getline, sub, function, and other features which do not work with Unix
awk? Or maybe it should try harder to find a POSIX awk?
Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-01 6:29 ` build-aux/git-hooks/pre-push Po Lu
2023-05-01 6:33 ` build-aux/git-hooks/pre-push Po Lu
@ 2023-05-01 16:55 ` Jim Porter
2023-05-02 0:08 ` build-aux/git-hooks/pre-push Po Lu
2023-05-04 10:37 ` build-aux/git-hooks/pre-push Basil Contovounesios
1 sibling, 2 replies; 10+ messages in thread
From: Jim Porter @ 2023-05-01 16:55 UTC (permalink / raw)
To: Po Lu, emacs-devel
On 4/30/2023 11:29 PM, Po Lu wrote:
> This script apparently loses when pushing from a separate worktree,
> where .git is a file containing the name of the repository the worktree
> was created from.
Thanks for catching this bug.
> The following adjustment seems to fix it. However, I don't know much
> about git. Objections?
>
> diff --git a/build-aux/git-hooks/pre-push b/build-aux/git-hooks/pre-push
> index 8e8277cba4f..8a2866f9d4c 100755
> --- a/build-aux/git-hooks/pre-push
> +++ b/build-aux/git-hooks/pre-push
> @@ -83,4 +83,4 @@ $awk -v origin_name="$1" '
> # Print every SHA after oldref, up to (and including) newref.
> system("git rev-list --first-parent --reverse " oldref ".." newref)
> }
> -' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk
> +' | $awk -v reason=pre-push -f build-aux/git-hooks/commit-msg-files.awk
>
>
That won't quite work in general, since it would mean that if you check
out an old branch, "build-aux/git-hooks/commit-msg-files.awk" won't
exist, and then the hook will fail. Instead, I pushed a change to
replace ".git" with "${GIT_DIR:-.git}", which is (as far as I can tell)
the right way to do this.
(The fallback to ".git" in the expansion is purely defensive, just in
case there's some old Git version that doesn't set that variable.)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-01 16:55 ` build-aux/git-hooks/pre-push Jim Porter
@ 2023-05-02 0:08 ` Po Lu
2023-05-04 10:37 ` build-aux/git-hooks/pre-push Basil Contovounesios
1 sibling, 0 replies; 10+ messages in thread
From: Po Lu @ 2023-05-02 0:08 UTC (permalink / raw)
To: Jim Porter; +Cc: emacs-devel
Jim Porter <jporterbugs@gmail.com> writes:
> On 4/30/2023 11:29 PM, Po Lu wrote:
>> This script apparently loses when pushing from a separate worktree,
>> where .git is a file containing the name of the repository the worktree
>> was created from.
>
> Thanks for catching this bug.
>
>> The following adjustment seems to fix it. However, I don't know much
>> about git. Objections?
>> diff --git a/build-aux/git-hooks/pre-push
>> b/build-aux/git-hooks/pre-push
>> index 8e8277cba4f..8a2866f9d4c 100755
>> --- a/build-aux/git-hooks/pre-push
>> +++ b/build-aux/git-hooks/pre-push
>> @@ -83,4 +83,4 @@ $awk -v origin_name="$1" '
>> # Print every SHA after oldref, up to (and including) newref.
>> system("git rev-list --first-parent --reverse " oldref ".." newref)
>> }
>> -' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk
>> +' | $awk -v reason=pre-push -f build-aux/git-hooks/commit-msg-files.awk
>>
>
> That won't quite work in general, since it would mean that if you
> check out an old branch, "build-aux/git-hooks/commit-msg-files.awk"
> won't exist, and then the hook will fail. Instead, I pushed a change
> to replace ".git" with "${GIT_DIR:-.git}", which is (as far as I can
> tell) the right way to do this.
>
> (The fallback to ".git" in the expansion is purely defensive, just in
> case there's some old Git version that doesn't set that variable.)
Oh, OK. Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-01 6:33 ` build-aux/git-hooks/pre-push Po Lu
@ 2023-05-02 5:35 ` Jim Porter
2023-05-02 5:55 ` build-aux/git-hooks/pre-push Po Lu
0 siblings, 1 reply; 10+ messages in thread
From: Jim Porter @ 2023-05-02 5:35 UTC (permalink / raw)
To: Po Lu, emacs-devel
On 4/30/2023 11:33 PM, Po Lu wrote:
> Btw, I notice that the script falls back to awk if gawk cannot be found.
> Maybe in that case, the awk script should be rewritten to not utilize
> getline, sub, function, and other features which do not work with Unix
> awk? Or maybe it should try harder to find a POSIX awk?
I'm not sure the best way to do it, but I think trying to find a POSIX
awk would be the simplest solution. That awk script isn't *terribly*
complex, but it uses enough POSIX awk features that I wouldn't want to
try and make it work with UNIX awk (even if I knew exactly how to do that).
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-02 5:35 ` build-aux/git-hooks/pre-push Jim Porter
@ 2023-05-02 5:55 ` Po Lu
0 siblings, 0 replies; 10+ messages in thread
From: Po Lu @ 2023-05-02 5:55 UTC (permalink / raw)
To: Jim Porter; +Cc: emacs-devel
Jim Porter <jporterbugs@gmail.com> writes:
> On 4/30/2023 11:33 PM, Po Lu wrote:
>> Btw, I notice that the script falls back to awk if gawk cannot be found.
>> Maybe in that case, the awk script should be rewritten to not utilize
>> getline, sub, function, and other features which do not work with Unix
>> awk? Or maybe it should try harder to find a POSIX awk?
>
> I'm not sure the best way to do it, but I think trying to find a POSIX
> awk would be the simplest solution.
Hmm, ok. Unfortunately for some reason the most reliable way to do that
I can think of would be to generate the script with Autoconf... and that
leads to a chicken-egg problem, since the hook is installed from
autogen.sh.
Perhaps we could simply look for:
- /usr/xpg4/bin/awk
- mawk
- nawk
in that order, and not run the script at all if a suitable awk can't be
found.
> That awk script isn't *terribly* complex, but it uses enough POSIX awk
> features that I wouldn't want to try and make it work with UNIX awk
> (even if I knew exactly how to do that).
`(autoconf)Limitations of Usual Tools' describes the limitations of Unix
awk.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-01 16:55 ` build-aux/git-hooks/pre-push Jim Porter
2023-05-02 0:08 ` build-aux/git-hooks/pre-push Po Lu
@ 2023-05-04 10:37 ` Basil Contovounesios
2023-05-04 16:28 ` build-aux/git-hooks/pre-push Jim Porter
1 sibling, 1 reply; 10+ messages in thread
From: Basil Contovounesios @ 2023-05-04 10:37 UTC (permalink / raw)
To: Jim Porter; +Cc: Po Lu, emacs-devel
Jim Porter [2023-05-01 09:55 -0700] wrote:
> On 4/30/2023 11:29 PM, Po Lu wrote:
>> This script apparently loses when pushing from a separate worktree,
>> where .git is a file containing the name of the repository the worktree
>> was created from.
>
> Thanks for catching this bug.
>
>> The following adjustment seems to fix it. However, I don't know much
>> about git. Objections?
>> diff --git a/build-aux/git-hooks/pre-push b/build-aux/git-hooks/pre-push
>> index 8e8277cba4f..8a2866f9d4c 100755
>> --- a/build-aux/git-hooks/pre-push
>> +++ b/build-aux/git-hooks/pre-push
>> @@ -83,4 +83,4 @@ $awk -v origin_name="$1" '
>> # Print every SHA after oldref, up to (and including) newref.
>> system("git rev-list --first-parent --reverse " oldref ".." newref)
>> }
>> -' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk
>> +' | $awk -v reason=pre-push -f build-aux/git-hooks/commit-msg-files.awk
>>
>
> That won't quite work in general, since it would mean that if you check out an
> old branch, "build-aux/git-hooks/commit-msg-files.awk" won't exist, and then the
> hook will fail. Instead, I pushed a change to replace ".git" with
> "${GIT_DIR:-.git}", which is (as far as I can tell) the right way to do this.
>
> (The fallback to ".git" in the expansion is purely defensive, just in case
> there's some old Git version that doesn't set that variable.)
I have a clone of emacs.git under ~/.local/src/emacs, where the master
branch is checked out under the same name.
Then I have a worktree under ~/.local/src/emacs-29, where the emacs-29
branch is checked out in a branch named wt/emacs-29.
I get the following when I try to push from that worktree:
$ git push upstream wt/emacs-29:emacs-29
gawk: fatal: cannot open source file `/home/blc/.local/src/emacs/.git/worktrees/emacs-29/hooks/commit-msg-files.awk' for reading: No such file or directory
error: failed to push some refs to 'git.savannah.gnu.org:/srv/git/emacs.git'
So maybe we should be defensive about the existence of this hook?
Or am I doing something wrong?
Thanks,
--
Basil
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-04 10:37 ` build-aux/git-hooks/pre-push Basil Contovounesios
@ 2023-05-04 16:28 ` Jim Porter
2023-05-04 16:42 ` build-aux/git-hooks/pre-push Basil Contovounesios
0 siblings, 1 reply; 10+ messages in thread
From: Jim Porter @ 2023-05-04 16:28 UTC (permalink / raw)
To: Basil Contovounesios; +Cc: Po Lu, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 267 bytes --]
On 5/4/2023 3:37 AM, Basil Contovounesios wrote:
> So maybe we should be defensive about the existence of this hook?
> Or am I doing something wrong?
I guess that's what I get for just trusting the Git manual instead of
verifying that my fix worked. How about this?
[-- Attachment #2: 0001-Fix-post-commit-and-pre-push-hooks-in-worktrees-agai.patch --]
[-- Type: text/plain, Size: 1755 bytes --]
From d3ec68f5e433e5792c1c63672c7b437bb29c5759 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Thu, 4 May 2023 09:22:40 -0700
Subject: [PATCH] ; Fix post-commit and pre-push hooks in worktrees again
* build-aux/git-hooks/post-commit:
* build-aux/git-hooks/pre-push: Use "$(dirname $0)" to get the hooks
directory.
---
build-aux/git-hooks/post-commit | 4 +++-
build-aux/git-hooks/pre-push | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/build-aux/git-hooks/post-commit b/build-aux/git-hooks/post-commit
index 05f2d778b5c..10f43b539ac 100755
--- a/build-aux/git-hooks/post-commit
+++ b/build-aux/git-hooks/post-commit
@@ -34,6 +34,8 @@
### Code:
+HOOKS_DIR=$(dirname $0)
+
# Prefer gawk if available, as it handles NUL bytes properly.
if type gawk >/dev/null 2>&1; then
awk="gawk"
@@ -42,4 +44,4 @@ else
fi
git rev-parse HEAD | $awk -v reason=post-commit \
- -f ${GIT_DIR:-.git}/hooks/commit-msg-files.awk
+ -f $HOOKS_DIR/commit-msg-files.awk
diff --git a/build-aux/git-hooks/pre-push b/build-aux/git-hooks/pre-push
index 6ff59102fd7..8d5dde2bbaf 100755
--- a/build-aux/git-hooks/pre-push
+++ b/build-aux/git-hooks/pre-push
@@ -31,6 +31,8 @@
### Code:
+HOOKS_DIR=$(dirname $0)
+
# Prefer gawk if available, as it handles NUL bytes properly.
if type gawk >/dev/null 2>&1; then
awk="gawk"
@@ -83,4 +85,4 @@ $awk -v origin_name="$1" '
# Print every SHA after oldref, up to (and including) newref.
system("git rev-list --first-parent --reverse " oldref ".." newref)
}
-' | $awk -v reason=pre-push -f ${GIT_DIR:-.git}/hooks/commit-msg-files.awk
+' | $awk -v reason=pre-push -f $HOOKS_DIR/commit-msg-files.awk
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-04 16:28 ` build-aux/git-hooks/pre-push Jim Porter
@ 2023-05-04 16:42 ` Basil Contovounesios
2023-05-04 16:56 ` build-aux/git-hooks/pre-push Jim Porter
0 siblings, 1 reply; 10+ messages in thread
From: Basil Contovounesios @ 2023-05-04 16:42 UTC (permalink / raw)
To: Jim Porter; +Cc: Po Lu, emacs-devel
Jim Porter [2023-05-04 09:28 -0700] wrote:
> How about this?
It allows git-push to succeed in the emacs-29 worktree.
Thanks,
--
Basil
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: build-aux/git-hooks/pre-push
2023-05-04 16:42 ` build-aux/git-hooks/pre-push Basil Contovounesios
@ 2023-05-04 16:56 ` Jim Porter
0 siblings, 0 replies; 10+ messages in thread
From: Jim Porter @ 2023-05-04 16:56 UTC (permalink / raw)
To: Basil Contovounesios; +Cc: Po Lu, emacs-devel
On 5/4/2023 9:42 AM, Basil Contovounesios wrote:
> It allows git-push to succeed in the emacs-29 worktree.
> Thanks,
Thanks, pushed to master.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-05-04 16:56 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <875y9cef96.fsf.ref@yahoo.com>
2023-05-01 6:29 ` build-aux/git-hooks/pre-push Po Lu
2023-05-01 6:33 ` build-aux/git-hooks/pre-push Po Lu
2023-05-02 5:35 ` build-aux/git-hooks/pre-push Jim Porter
2023-05-02 5:55 ` build-aux/git-hooks/pre-push Po Lu
2023-05-01 16:55 ` build-aux/git-hooks/pre-push Jim Porter
2023-05-02 0:08 ` build-aux/git-hooks/pre-push Po Lu
2023-05-04 10:37 ` build-aux/git-hooks/pre-push Basil Contovounesios
2023-05-04 16:28 ` build-aux/git-hooks/pre-push Jim Porter
2023-05-04 16:42 ` build-aux/git-hooks/pre-push Basil Contovounesios
2023-05-04 16:56 ` build-aux/git-hooks/pre-push Jim Porter
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).