[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: build-aux/git-hooks/pre-push
From: |
Basil Contovounesios |
Subject: |
Re: build-aux/git-hooks/pre-push |
Date: |
Thu, 04 May 2023 12:37:35 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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