{"thread":{"id":"50399","subject":"hook to get info on commit, and include that in a file that is part of the commit","startedAt":"2019-02-05T01:36:49Z","lastAt":"2019-02-05T02:42:48Z","messageCount":7,"participants":["Larry Martell","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"368501","messageId":"CACwCsY5xU0pUaPZDJMqWNB0dz7DjTx3_b2Lvrft0NjA6cnPvcg@mail.gmail.com","threadId":"50399","inReplyTo":null,"subject":"hook to get info on commit, and include that in a file that is part of the commit","fromName":"Larry Martell","fromEmail":"larry.martell@gmail.com","sentAt":"2019-02-05T01:36:10Z","receivedAt":"2019-02-05T01:36:49Z","isPatch":false,"sender":{"key":"larry.martell@gmail.com","avatar":"https://gravatar.com/avatar/313d9bd902360d7f418940cc0b9ae47593b1b2ac2f606bb1621102c15705eca1?d=mp&s=160"},"body":"Is there any way using a git hook to get info on the commit (id,\nmessage), put that in a file, and include that file in the commit?\n\nIf I try that in a pre-commit hook I do not get the info on the\ncurrent commit. I tried it in pre-receive but it does not seem to get\nexecuted at all.\n\nIf I do it in post-receive it's too late to check the file in with the commit.\n\nOs there no way to do this?\n"},{"id":"368503","messageId":"20190205015506.GB527887@genre.crustytoothpaste.net","threadId":"50399","inReplyTo":"CACwCsY5xU0pUaPZDJMqWNB0dz7DjTx3_b2Lvrft0NjA6cnPvcg@mail.gmail.com","subject":"Re: hook to get info on commit, and include that in a file that is part of the commit","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-02-05T01:55:06Z","receivedAt":"2019-02-05T01:55:14Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 04, 2019 at 08:36:10PM -0500, Larry Martell wrote:\n> Is there any way using a git hook to get info on the commit (id,\n> message), put that in a file, and include that file in the commit?\n> \n> If I try that in a pre-commit hook I do not get the info on the\n> current commit. I tried it in pre-receive but it does not seem to get\n> executed at all.\n\nYou cannot include a file in the commit with that commit's ID.\n\nThe object ID of a commit is based on the data it contains, which is in\nturn based on the data in its top-level tree, which is in turn based on\nthe data in all of its trees and blobs. If you add or change a file in a\ncommit (or the message of that commit), you necessarily result in that\ncommit having a different object ID. This is by design and is valuable\nfor checking the integrity of the history.\n\nFurthermore, the hooks for a commit are designed for checking and\nnotification, not for editing the commit, with the exception of the\ncommit message hooks, which are designed only for editing the commit\nmessage, not the contents.\n\nThe pre-receive hook runs on the server side, so if you aren't running\nit there, then it won't get called at all.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"368504","messageId":"CACwCsY4fwr6=2S5CHe5bH7=7Hukq9np+eT1VO+kUDyBtMLKPcA@mail.gmail.com","threadId":"50399","inReplyTo":"20190205015506.GB527887@genre.crustytoothpaste.net","subject":"Re: hook to get info on commit, and include that in a file that is part of the commit","fromName":"Larry Martell","fromEmail":"larry.martell@gmail.com","sentAt":"2019-02-05T02:00:42Z","receivedAt":"2019-02-05T02:01:22Z","isPatch":false,"sender":{"key":"larry.martell@gmail.com","avatar":"https://gravatar.com/avatar/313d9bd902360d7f418940cc0b9ae47593b1b2ac2f606bb1621102c15705eca1?d=mp&s=160"},"body":"On Mon, Feb 4, 2019 at 8:55 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> On Mon, Feb 04, 2019 at 08:36:10PM -0500, Larry Martell wrote:\n> > Is there any way using a git hook to get info on the commit (id,\n> > message), put that in a file, and include that file in the commit?\n> >\n> > If I try that in a pre-commit hook I do not get the info on the\n> > current commit. I tried it in pre-receive but it does not seem to get\n> > executed at all.\n>\n> You cannot include a file in the commit with that commit's ID.\n>\n> The object ID of a commit is based on the data it contains, which is in\n> turn based on the data in its top-level tree, which is in turn based on\n> the data in all of its trees and blobs. If you add or change a file in a\n> commit (or the message of that commit), you necessarily result in that\n> commit having a different object ID. This is by design and is valuable\n> for checking the integrity of the history.\n>\n> Furthermore, the hooks for a commit are designed for checking and\n> notification, not for editing the commit, with the exception of the\n> commit message hooks, which are designed only for editing the commit\n> message, not the contents.\n>\n> The pre-receive hook runs on the server side, so if you aren't running\n> it there, then it won't get called at all.\n\nThanks for the reply. Any suggestions on how to achieve what I want to do?\n\nThe use case is that we want to have a file that is part of the\ninstall that has certain info (commit id, date of commit, commit\nmessage, etc.). and we'd like that to be generated automatically.\n"},{"id":"368505","messageId":"20190205021513.GC527887@genre.crustytoothpaste.net","threadId":"50399","inReplyTo":"CACwCsY4fwr6=2S5CHe5bH7=7Hukq9np+eT1VO+kUDyBtMLKPcA@mail.gmail.com","subject":"Re: hook to get info on commit, and include that in a file that is part of the commit","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-02-05T02:15:13Z","receivedAt":"2019-02-05T02:15:22Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 04, 2019 at 09:00:42PM -0500, Larry Martell wrote:\n> Thanks for the reply. Any suggestions on how to achieve what I want to do?\n> \n> The use case is that we want to have a file that is part of the\n> install that has certain info (commit id, date of commit, commit\n> message, etc.). and we'd like that to be generated automatically.\n\nIf you want to generate a file, you can certainly do that in the\npost-commit hook or using a Makefile target. You just can't check it\ninto the repo. Lots of projects do this as part of their build process.\n\nAn example of what you could do is \"git log --pretty='tformat:%H%n%B' HEAD\".\nThat will print the commit hash and commit message to standard output\nfor each commit. If you want just one commit, you can use \"-1\".\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"368506","messageId":"CACwCsY7o=ArM4T4n7umun-R9Dip5NmmOEL7Ygd9zEQdCyQa4Og@mail.gmail.com","threadId":"50399","inReplyTo":"20190205021513.GC527887@genre.crustytoothpaste.net","subject":"Re: hook to get info on commit, and include that in a file that is part of the commit","fromName":"Larry Martell","fromEmail":"larry.martell@gmail.com","sentAt":"2019-02-05T02:18:14Z","receivedAt":"2019-02-05T02:18:53Z","isPatch":false,"sender":{"key":"larry.martell@gmail.com","avatar":"https://gravatar.com/avatar/313d9bd902360d7f418940cc0b9ae47593b1b2ac2f606bb1621102c15705eca1?d=mp&s=160"},"body":"On Mon, Feb 4, 2019 at 9:15 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> On Mon, Feb 04, 2019 at 09:00:42PM -0500, Larry Martell wrote:\n> > Thanks for the reply. Any suggestions on how to achieve what I want to do?\n> >\n> > The use case is that we want to have a file that is part of the\n> > install that has certain info (commit id, date of commit, commit\n> > message, etc.). and we'd like that to be generated automatically.\n>\n> If you want to generate a file, you can certainly do that in the\n> post-commit hook or using a Makefile target. You just can't check it\n> into the repo. Lots of projects do this as part of their build process.\n>\n> An example of what you could do is \"git log --pretty='tformat:%H%n%B' HEAD\".\n> That will print the commit hash and commit message to standard output\n> for each commit. If you want just one commit, you can use \"-1\".\n\nYeah, but I want it part of the repo so it makes it to the target system.\n"},{"id":"368510","messageId":"20190205024055.GD527887@genre.crustytoothpaste.net","threadId":"50399","inReplyTo":"CACwCsY7o=ArM4T4n7umun-R9Dip5NmmOEL7Ygd9zEQdCyQa4Og@mail.gmail.com","subject":"Re: hook to get info on commit, and include that in a file that is part of the commit","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-02-05T02:40:56Z","receivedAt":"2019-02-05T02:41:05Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Feb 04, 2019 at 09:18:14PM -0500, Larry Martell wrote:\n> On Mon, Feb 4, 2019 at 9:15 PM brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > If you want to generate a file, you can certainly do that in the\n> > post-commit hook or using a Makefile target. You just can't check it\n> > into the repo. Lots of projects do this as part of their build process.\n> >\n> > An example of what you could do is \"git log --pretty='tformat:%H%n%B' HEAD\".\n> > That will print the commit hash and commit message to standard output\n> > for each commit. If you want just one commit, you can use \"-1\".\n> \n> Yeah, but I want it part of the repo so it makes it to the target system.\n\nYou can create an additional commit for each commit that you put in with\nthe additional file, or you can serialize it as a note for the commit\n(using git notes), which can then be pushed to the remote server by\npushing refs/notes/commits.\n\nI'm not aware of any other way to do what you want.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"368511","messageId":"CACwCsY4tAZm4+R+jxkuSyJUEz8ZTt4_CMW-OU0TRBPpFXp=vJw@mail.gmail.com","threadId":"50399","inReplyTo":"20190205024055.GD527887@genre.crustytoothpaste.net","subject":"Re: hook to get info on commit, and include that in a file that is part of the commit","fromName":"Larry Martell","fromEmail":"larry.martell@gmail.com","sentAt":"2019-02-05T02:42:09Z","receivedAt":"2019-02-05T02:42:48Z","isPatch":false,"sender":{"key":"larry.martell@gmail.com","avatar":"https://gravatar.com/avatar/313d9bd902360d7f418940cc0b9ae47593b1b2ac2f606bb1621102c15705eca1?d=mp&s=160"},"body":"On Mon, Feb 4, 2019 at 9:41 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> On Mon, Feb 04, 2019 at 09:18:14PM -0500, Larry Martell wrote:\n> > On Mon, Feb 4, 2019 at 9:15 PM brian m. carlson\n> > <sandals@crustytoothpaste.net> wrote:\n> > > If you want to generate a file, you can certainly do that in the\n> > > post-commit hook or using a Makefile target. You just can't check it\n> > > into the repo. Lots of projects do this as part of their build process.\n> > >\n> > > An example of what you could do is \"git log --pretty='tformat:%H%n%B' HEAD\".\n> > > That will print the commit hash and commit message to standard output\n> > > for each commit. If you want just one commit, you can use \"-1\".\n> >\n> > Yeah, but I want it part of the repo so it makes it to the target system.\n>\n> You can create an additional commit for each commit that you put in with\n> the additional file, or you can serialize it as a note for the commit\n> (using git notes), which can then be pushed to the remote server by\n> pushing refs/notes/commits.\n>\n> I'm not aware of any other way to do what you want.\n\nThanks. That is what I will end up doing.\n"}]}