* hook to get info on commit, and include that in a file that is part of the commit
@ 2019-02-05 1:36 Larry Martell
2019-02-05 1:55 ` brian m. carlson
0 siblings, 1 reply; 7+ messages in thread
From: Larry Martell @ 2019-02-05 1:36 UTC (permalink / raw)
To: git
Is there any way using a git hook to get info on the commit (id,
message), put that in a file, and include that file in the commit?
If I try that in a pre-commit hook I do not get the info on the
current commit. I tried it in pre-receive but it does not seem to get
executed at all.
If I do it in post-receive it's too late to check the file in with the commit.
Os there no way to do this?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: hook to get info on commit, and include that in a file that is part of the commit
2019-02-05 1:36 hook to get info on commit, and include that in a file that is part of the commit Larry Martell
@ 2019-02-05 1:55 ` brian m. carlson
2019-02-05 2:00 ` Larry Martell
0 siblings, 1 reply; 7+ messages in thread
From: brian m. carlson @ 2019-02-05 1:55 UTC (permalink / raw)
To: Larry Martell; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]
On Mon, Feb 04, 2019 at 08:36:10PM -0500, Larry Martell wrote:
> Is there any way using a git hook to get info on the commit (id,
> message), put that in a file, and include that file in the commit?
>
> If I try that in a pre-commit hook I do not get the info on the
> current commit. I tried it in pre-receive but it does not seem to get
> executed at all.
You cannot include a file in the commit with that commit's ID.
The object ID of a commit is based on the data it contains, which is in
turn based on the data in its top-level tree, which is in turn based on
the data in all of its trees and blobs. If you add or change a file in a
commit (or the message of that commit), you necessarily result in that
commit having a different object ID. This is by design and is valuable
for checking the integrity of the history.
Furthermore, the hooks for a commit are designed for checking and
notification, not for editing the commit, with the exception of the
commit message hooks, which are designed only for editing the commit
message, not the contents.
The pre-receive hook runs on the server side, so if you aren't running
it there, then it won't get called at all.
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: hook to get info on commit, and include that in a file that is part of the commit
2019-02-05 1:55 ` brian m. carlson
@ 2019-02-05 2:00 ` Larry Martell
2019-02-05 2:15 ` brian m. carlson
0 siblings, 1 reply; 7+ messages in thread
From: Larry Martell @ 2019-02-05 2:00 UTC (permalink / raw)
To: brian m. carlson, Larry Martell, git
On Mon, Feb 4, 2019 at 8:55 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> On Mon, Feb 04, 2019 at 08:36:10PM -0500, Larry Martell wrote:
> > Is there any way using a git hook to get info on the commit (id,
> > message), put that in a file, and include that file in the commit?
> >
> > If I try that in a pre-commit hook I do not get the info on the
> > current commit. I tried it in pre-receive but it does not seem to get
> > executed at all.
>
> You cannot include a file in the commit with that commit's ID.
>
> The object ID of a commit is based on the data it contains, which is in
> turn based on the data in its top-level tree, which is in turn based on
> the data in all of its trees and blobs. If you add or change a file in a
> commit (or the message of that commit), you necessarily result in that
> commit having a different object ID. This is by design and is valuable
> for checking the integrity of the history.
>
> Furthermore, the hooks for a commit are designed for checking and
> notification, not for editing the commit, with the exception of the
> commit message hooks, which are designed only for editing the commit
> message, not the contents.
>
> The pre-receive hook runs on the server side, so if you aren't running
> it there, then it won't get called at all.
Thanks for the reply. Any suggestions on how to achieve what I want to do?
The use case is that we want to have a file that is part of the
install that has certain info (commit id, date of commit, commit
message, etc.). and we'd like that to be generated automatically.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: hook to get info on commit, and include that in a file that is part of the commit
2019-02-05 2:00 ` Larry Martell
@ 2019-02-05 2:15 ` brian m. carlson
2019-02-05 2:18 ` Larry Martell
0 siblings, 1 reply; 7+ messages in thread
From: brian m. carlson @ 2019-02-05 2:15 UTC (permalink / raw)
To: Larry Martell; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 856 bytes --]
On Mon, Feb 04, 2019 at 09:00:42PM -0500, Larry Martell wrote:
> Thanks for the reply. Any suggestions on how to achieve what I want to do?
>
> The use case is that we want to have a file that is part of the
> install that has certain info (commit id, date of commit, commit
> message, etc.). and we'd like that to be generated automatically.
If you want to generate a file, you can certainly do that in the
post-commit hook or using a Makefile target. You just can't check it
into the repo. Lots of projects do this as part of their build process.
An example of what you could do is "git log --pretty='tformat:%H%n%B' HEAD".
That will print the commit hash and commit message to standard output
for each commit. If you want just one commit, you can use "-1".
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: hook to get info on commit, and include that in a file that is part of the commit
2019-02-05 2:15 ` brian m. carlson
@ 2019-02-05 2:18 ` Larry Martell
2019-02-05 2:40 ` brian m. carlson
0 siblings, 1 reply; 7+ messages in thread
From: Larry Martell @ 2019-02-05 2:18 UTC (permalink / raw)
To: brian m. carlson, Larry Martell, git
On Mon, Feb 4, 2019 at 9:15 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> On Mon, Feb 04, 2019 at 09:00:42PM -0500, Larry Martell wrote:
> > Thanks for the reply. Any suggestions on how to achieve what I want to do?
> >
> > The use case is that we want to have a file that is part of the
> > install that has certain info (commit id, date of commit, commit
> > message, etc.). and we'd like that to be generated automatically.
>
> If you want to generate a file, you can certainly do that in the
> post-commit hook or using a Makefile target. You just can't check it
> into the repo. Lots of projects do this as part of their build process.
>
> An example of what you could do is "git log --pretty='tformat:%H%n%B' HEAD".
> That will print the commit hash and commit message to standard output
> for each commit. If you want just one commit, you can use "-1".
Yeah, but I want it part of the repo so it makes it to the target system.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: hook to get info on commit, and include that in a file that is part of the commit
2019-02-05 2:18 ` Larry Martell
@ 2019-02-05 2:40 ` brian m. carlson
2019-02-05 2:42 ` Larry Martell
0 siblings, 1 reply; 7+ messages in thread
From: brian m. carlson @ 2019-02-05 2:40 UTC (permalink / raw)
To: Larry Martell; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]
On Mon, Feb 04, 2019 at 09:18:14PM -0500, Larry Martell wrote:
> On Mon, Feb 4, 2019 at 9:15 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > If you want to generate a file, you can certainly do that in the
> > post-commit hook or using a Makefile target. You just can't check it
> > into the repo. Lots of projects do this as part of their build process.
> >
> > An example of what you could do is "git log --pretty='tformat:%H%n%B' HEAD".
> > That will print the commit hash and commit message to standard output
> > for each commit. If you want just one commit, you can use "-1".
>
> Yeah, but I want it part of the repo so it makes it to the target system.
You can create an additional commit for each commit that you put in with
the additional file, or you can serialize it as a note for the commit
(using git notes), which can then be pushed to the remote server by
pushing refs/notes/commits.
I'm not aware of any other way to do what you want.
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: hook to get info on commit, and include that in a file that is part of the commit
2019-02-05 2:40 ` brian m. carlson
@ 2019-02-05 2:42 ` Larry Martell
0 siblings, 0 replies; 7+ messages in thread
From: Larry Martell @ 2019-02-05 2:42 UTC (permalink / raw)
To: brian m. carlson, Larry Martell, git
On Mon, Feb 4, 2019 at 9:41 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> On Mon, Feb 04, 2019 at 09:18:14PM -0500, Larry Martell wrote:
> > On Mon, Feb 4, 2019 at 9:15 PM brian m. carlson
> > <sandals@crustytoothpaste.net> wrote:
> > > If you want to generate a file, you can certainly do that in the
> > > post-commit hook or using a Makefile target. You just can't check it
> > > into the repo. Lots of projects do this as part of their build process.
> > >
> > > An example of what you could do is "git log --pretty='tformat:%H%n%B' HEAD".
> > > That will print the commit hash and commit message to standard output
> > > for each commit. If you want just one commit, you can use "-1".
> >
> > Yeah, but I want it part of the repo so it makes it to the target system.
>
> You can create an additional commit for each commit that you put in with
> the additional file, or you can serialize it as a note for the commit
> (using git notes), which can then be pushed to the remote server by
> pushing refs/notes/commits.
>
> I'm not aware of any other way to do what you want.
Thanks. That is what I will end up doing.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-02-05 2:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-05 1:36 hook to get info on commit, and include that in a file that is part of the commit Larry Martell
2019-02-05 1:55 ` brian m. carlson
2019-02-05 2:00 ` Larry Martell
2019-02-05 2:15 ` brian m. carlson
2019-02-05 2:18 ` Larry Martell
2019-02-05 2:40 ` brian m. carlson
2019-02-05 2:42 ` Larry Martell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox