{"thread":{"id":"45887","subject":"Git smart http: parsing commit messages in git-receive-pack","startedAt":"2017-05-06T12:30:48Z","lastAt":"2017-05-08T02:08:38Z","messageCount":3,"participants":["akos tajti","Bryan Turner","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"318930","messageId":"7DA6022F-02F0-41AC-ABAB-64565E81481F@gmail.com","threadId":"45887","inReplyTo":null,"subject":"Git smart http: parsing commit messages in git-receive-pack","fromName":"akos tajti","fromEmail":"akos.tajti@gmail.com","sentAt":"2017-05-06T12:30:35Z","receivedAt":"2017-05-06T12:30:48Z","isPatch":false,"sender":{"key":"akos.tajti@gmail.com","avatar":null},"body":"Dear All,\n\nwe implemented a java servlet around the git-http-backend. This servlet intercepts the requests sent by the git client when pushing. One thing I want to achieve is parsing the commit messages in the pre push phase (request param service==git-receive-pack) and after checking if the commit messages contain a given string reject/accept the request. The problem is that I couldn't find a way of parsing the commit messages in git-receive-pack (I can do this in the post  push phase but in that case I cannot reject the push because the changes are already on the server). Is there a way of getting the commit messages before they're actually on the server so that I can reject the push?\n\nThanks in advance,\nÁkos Tajti\n\n"},{"id":"318950","messageId":"CAGyf7-EDHPdL_YvNoC9QNy11=YfxSpmZBFZ5UR50ub1o2yqAug@mail.gmail.com","threadId":"45887","inReplyTo":"7DA6022F-02F0-41AC-ABAB-64565E81481F@gmail.com","subject":"Re: Git smart http: parsing commit messages in git-receive-pack","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2017-05-06T19:14:44Z","receivedAt":"2017-05-06T19:14:51Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"On Sat, May 6, 2017 at 5:30 AM, akos tajti <akos.tajti@gmail.com> wrote:\n> Dear All,\n>\n> we implemented a java servlet around the git-http-backend. This servlet intercepts the requests sent by the git client when pushing. One thing I want to achieve is parsing the commit messages in the pre push phase (request param service==git-receive-pack) and after checking if the commit messages contain a given string reject/accept the request. The problem is that I couldn't find a way of parsing the commit messages in git-receive-pack (I can do this in the post  push phase but in that case I cannot reject the push because the changes are already on the server). Is there a way of getting the commit messages before they're actually on the server so that I can reject the push?\n\nThe protocol isn't really intended for use to try and parse pack data\nbefore it's spooled to disk. It might be possible, but it's likely to\nbe brittle (due to things like delta compression, for example).\n\nI believe what you're looking for is a pre-receive hook[1] on your\nserver. This is how Bitbucket Server (which is also written in Java)\nworks. It opens a socket on localhost and installs a pre-receive hook\ninto each repository which uses a Perl script to pipe all of its input\nto the listening socket and then read any response from the server\nback. After the push has written all of its objects to disk, Git\ninvokes any pre-receive hooks and passes in all the ref changes. The\nPerl script pipes those to the server, which applies whatever checks\nare desired and writes any errors or info back to the hook, which then\nprints it for Git to use before exiting with the correct status code\n(0 to accept the push, 1 to reject it).\n\nThis means the objects are on the server, but in Git 2.11 Peff added\n\"quarantine\" functionality which writes those new objects into an\n\"incoming\" directory[2]. That means, while they're on disk, they're\n_not_ in the repository itself. If the pre-receive hook rejects the\npush, those objects are immediately deleted from disk.\n\nThat means if you pair a pre-receive hook with Git 2.11 or newer on\nthe server, you should be able to achieve what you're looking for.\nOnce the objects have been written to the quarantine directory, you\ncan use normal Git commands, like cat-file, rev-list or log, to review\nthem. If they don't meet your requirements, just reject the push and\nGit will delete the objects automatically\n\nHope this helps!\nBryan Turner\n\n>\n> Thanks in advance,\n> Ákos Tajti\n>\n\n[1]: https://git-scm.com/docs/githooks includes documentation for\npre-receive inputs and outputs\n[2]: https://github.com/git/git/blob/master/Documentation/git-receive-pack.txt#L219-L243\nincludes some additional documentation about the quarantine\nenvironment\n"},{"id":"319039","messageId":"xmqq4lwwayn4.fsf@gitster.mtv.corp.google.com","threadId":"45887","inReplyTo":"CAGyf7-EDHPdL_YvNoC9QNy11=YfxSpmZBFZ5UR50ub1o2yqAug@mail.gmail.com","subject":"Re: Git smart http: parsing commit messages in git-receive-pack","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-05-08T02:08:31Z","receivedAt":"2017-05-08T02:08:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bryan Turner <bturner@atlassian.com> writes:\n\n> That means if you pair a pre-receive hook with Git 2.11 or newer on\n> the server, you should be able to achieve what you're looking for.\n\nIt probably is worth mentioning that even without the \"quarantine\"\nchanges of 2.11, the new objects brought in by a rejected push\ncannot be used because they are not reachable from any ref, and will\nbe discarded as garbage when the next GC run.  So pre-receive should\nbe sufficient for the purpose of \"not accepting\" an undesirable\npush, with older versions of Git.  You can view the \"quarantine\"\nfeature mostly as \"quality of implementation\" issue.\n\n\n\n"}]}