* Running git(1) from within hooks/post-update
@ 2023-11-24 14:00 Alejandro Colomar
2023-11-24 15:42 ` Alejandro Colomar
0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2023-11-24 14:00 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]
Hi,
I'm trying to set up a post-update hook to produce a build of the Linux
man-pages PDF book after every push to my personal server to the 'main'
branch, so that I can serve man-pages-HEAD.pdf at some URL, for users to
be able to easily check the manual at git HEAD without having to clone
the repo.
I thought of having a git non-bare repo where I build it, so the script
would be the following (the paths are tmp, because I'm still testing).
$ cat post-update
#!/bin/sh
test "$1" = "refs/heads/main" || exit 0;
cd ~/tmp/man-pages/;
whoami; pwd; ls -ld .git/; # This is for debugging.
git fetch srv #>/dev/null 2>&1;
git reset srv/main --hard #>/dev/null 2>&1;
git clean -dffx #>/dev/null 2>&1;
scripts/LinuxManBook/build.sh >~/tmp/LMB-HEAD.pdf &
But it's not working. The git(1) calls are failing, saying it's not a
git repo, but it clearly is, and I have permissions, so I don't
understand what's going wrong. Here's the 'remote:' output of a push to
that testing server:
remote: alx
remote: /home/alx/tmp/man-pages
remote: drwxr-xr-x 8 alx alx 4096 Nov 24 14:41 .git/
remote: fatal: not a git repository: '.'
remote: fatal: not a git repository: '.'
remote: fatal: not a git repository: '.'
remote: hooks/post-update: 12: ./scripts/LinuxManBook/build.sh: not found
Can you please help? :)
Thanks,
Alex
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Running git(1) from within hooks/post-update
2023-11-24 14:00 Running git(1) from within hooks/post-update Alejandro Colomar
@ 2023-11-24 15:42 ` Alejandro Colomar
2023-11-24 15:49 ` Alejandro Colomar
0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2023-11-24 15:42 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1873 bytes --]
On Fri, Nov 24, 2023 at 03:00:22PM +0100, Alejandro Colomar wrote:
> Hi,
>
> I'm trying to set up a post-update hook to produce a build of the Linux
> man-pages PDF book after every push to my personal server to the 'main'
> branch, so that I can serve man-pages-HEAD.pdf at some URL, for users to
> be able to easily check the manual at git HEAD without having to clone
> the repo.
>
> I thought of having a git non-bare repo where I build it, so the script
> would be the following (the paths are tmp, because I'm still testing).
>
> $ cat post-update
> #!/bin/sh
>
> test "$1" = "refs/heads/main" || exit 0;
>
> cd ~/tmp/man-pages/;
>
> whoami; pwd; ls -ld .git/; # This is for debugging.
>
> git fetch srv #>/dev/null 2>&1;
> git reset srv/main --hard #>/dev/null 2>&1;
> git clean -dffx #>/dev/null 2>&1;
> scripts/LinuxManBook/build.sh >~/tmp/LMB-HEAD.pdf &
The script works fine when called manually. It seems it's calling it
as a hook that fails. It seems it's running git(1) from within a
post-update hook that is problematic. Is that expected, or is it a bug,
and can it be fixed?
>
> But it's not working. The git(1) calls are failing, saying it's not a
> git repo, but it clearly is, and I have permissions, so I don't
> understand what's going wrong. Here's the 'remote:' output of a push to
> that testing server:
>
> remote: alx
> remote: /home/alx/tmp/man-pages
> remote: drwxr-xr-x 8 alx alx 4096 Nov 24 14:41 .git/
> remote: fatal: not a git repository: '.'
> remote: fatal: not a git repository: '.'
> remote: fatal: not a git repository: '.'
> remote: hooks/post-update: 12: ./scripts/LinuxManBook/build.sh: not found
>
> Can you please help? :)
>
> Thanks,
> Alex
>
> --
> <https://www.alejandro-colomar.es/>
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Running git(1) from within hooks/post-update
2023-11-24 15:42 ` Alejandro Colomar
@ 2023-11-24 15:49 ` Alejandro Colomar
0 siblings, 0 replies; 3+ messages in thread
From: Alejandro Colomar @ 2023-11-24 15:49 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 2780 bytes --]
On Fri, Nov 24, 2023 at 04:42:16PM +0100, Alejandro Colomar wrote:
> On Fri, Nov 24, 2023 at 03:00:22PM +0100, Alejandro Colomar wrote:
> > Hi,
> >
> > I'm trying to set up a post-update hook to produce a build of the Linux
> > man-pages PDF book after every push to my personal server to the 'main'
> > branch, so that I can serve man-pages-HEAD.pdf at some URL, for users to
> > be able to easily check the manual at git HEAD without having to clone
> > the repo.
> >
> > I thought of having a git non-bare repo where I build it, so the script
> > would be the following (the paths are tmp, because I'm still testing).
> >
> > $ cat post-update
> > #!/bin/sh
> >
> > test "$1" = "refs/heads/main" || exit 0;
> >
> > cd ~/tmp/man-pages/;
> >
> > whoami; pwd; ls -ld .git/; # This is for debugging.
> >
> > git fetch srv #>/dev/null 2>&1;
> > git reset srv/main --hard #>/dev/null 2>&1;
> > git clean -dffx #>/dev/null 2>&1;
> > scripts/LinuxManBook/build.sh >~/tmp/LMB-HEAD.pdf &
>
> The script works fine when called manually. It seems it's calling it
> as a hook that fails. It seems it's running git(1) from within a
> post-update hook that is problematic. Is that expected, or is it a bug,
> and can it be fixed?
Ahh, after this I've found it documented in githooks(5):
Environment variables, such as GIT_DIR, GIT_WORK_TREE, etc., are
exported so that Git commands run by the hook can correctly
locate the repository. If your hook needs to invoke Git commands
in a foreign repository or in a different working tree of the
same repository, then it should clear these environment variables
so they do not interfere with Git operations at the foreign
location. For example:
local_desc=$(git describe)
foreign_desc=$(unset $(git rev-parse --local-env-vars); git -C ../foreign-repo describe)
Never mind.
Thanks,
Alex
>
> >
> > But it's not working. The git(1) calls are failing, saying it's not a
> > git repo, but it clearly is, and I have permissions, so I don't
> > understand what's going wrong. Here's the 'remote:' output of a push to
> > that testing server:
> >
> > remote: alx
> > remote: /home/alx/tmp/man-pages
> > remote: drwxr-xr-x 8 alx alx 4096 Nov 24 14:41 .git/
> > remote: fatal: not a git repository: '.'
> > remote: fatal: not a git repository: '.'
> > remote: fatal: not a git repository: '.'
> > remote: hooks/post-update: 12: ./scripts/LinuxManBook/build.sh: not found
> >
> > Can you please help? :)
> >
> > Thanks,
> > Alex
> >
> > --
> > <https://www.alejandro-colomar.es/>
>
>
>
> --
> <https://www.alejandro-colomar.es/>
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-24 15:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-24 14:00 Running git(1) from within hooks/post-update Alejandro Colomar
2023-11-24 15:42 ` Alejandro Colomar
2023-11-24 15:49 ` Alejandro Colomar
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 NNTP newsgroup(s).