{"thread":{"id":"57960","subject":"How to watch files in a Git repository","startedAt":"2022-06-06T16:04:17Z","lastAt":"2022-06-09T15:07:20Z","messageCount":5,"participants":["R. Diez","Jeff King","rsbecker@nexbridge.com","Son Luong Ngoc"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"456719","messageId":"68627d29-8ffd-2e22-46ca-c28c9e980177@gmail.com","threadId":"57960","inReplyTo":null,"subject":"How to watch files in a Git repository","fromName":"R. Diez","fromEmail":"rdiez1999@gmail.com","sentAt":"2022-06-06T16:04:11Z","receivedAt":"2022-06-06T16:04:17Z","isPatch":false,"sender":{"key":"rdiez1999@gmail.com","avatar":null},"body":"Hi all:\n\nI would like to get a notification e-mail when certain files or directories change in a Git repository.\n\nIn the good old CVS days, you could just 'watch' a file with your favourite CVS GUI.\n\nSome online services like GitHub offer their own notification mechanism, but I would like something generic. I am not looking for a hook solution, because the Git repositories may not be mine, so I may only have read access.\n\nThe idea is that I can set up a cron job to periodically pull a repository, and run a script to generate the e-mails from the commit history. Any new commits which match the desired branch and modify the desired files and/or directories would trigger the notifications.\n\nI've searched the Web, but couldn't find anything straightforward.\n\nIf there is nothing of the sort, I could write my own script in Bash or Perl. I can handle cron and sending e-mails, but I do not know much about Git's internals. Could someone provide a few pointers about how to code this? I would expect there is some command to list commits, and all files touched by a particular commit. And there would be some way to interface with Bash or Perl, which does not need parsing complicated text output from Git.\n\nThanks in advance,\n   rdiez\n"},{"id":"456911","messageId":"YqE27RU45kjNRwxf@coredump.intra.peff.net","threadId":"57960","inReplyTo":"68627d29-8ffd-2e22-46ca-c28c9e980177@gmail.com","subject":"Re: How to watch files in a Git repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-06-08T23:55:25Z","receivedAt":"2022-06-08T23:55:30Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 06, 2022 at 06:04:11PM +0200, R. Diez wrote:\n\n> If there is nothing of the sort, I could write my own script in Bash\n> or Perl. I can handle cron and sending e-mails, but I do not know much\n> about Git's internals. Could someone provide a few pointers about how\n> to code this? I would expect there is some command to list commits,\n> and all files touched by a particular commit. And there would be some\n> way to interface with Bash or Perl, which does not need parsing\n> complicated text output from Git.\n\nThis sounds kind of like git-multimail:\n\n  https://github.com/git-multimail/git-multimail\n\nThat's usually triggered from a hook, I think, but it would not be hard\nto trigger it with arbitrary segments of history.\n\nYou'd probably want to keep a \"seen\" ref of processed commits, and move\nfrom that, like:\n\n  # assuming you just care about one branch on the remote, but this\n  # concept can be extended to several\n  branch=refs/remotes/origin/main\n  seen=refs/heads/seen\n\n  git fetch\n\n  # I don't know what git-multimail expects, but this is similar to what\n  # a server-side receive hook would show\n  echo \"$(git rev-parse $seen) $(git rev-parse $branch) $branch\" |\n  some-git-multimail-command\n\n  # now move your pointer forward for next time\n  git update-ref $seen $branch\n\nIf multimail doesn't do what you want, then you can probably just script\naround:\n\n  git rev-list $seen..$branch -- $paths_you_care_about |\n  git diff-tree --stdin -r --name-only --format=\"Commit %h touched: \" -- $paths_you_care_about\n\ndepending how you want to format things.\n\n-Peff\n"},{"id":"456920","messageId":"007301d87bc8$69608b00$3c21a100$@nexbridge.com","threadId":"57960","inReplyTo":"YqE27RU45kjNRwxf@coredump.intra.peff.net","subject":"RE: How to watch files in a Git repository","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2022-06-09T06:16:03Z","receivedAt":"2022-06-09T06:16:19Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On June 8, 2022 7:55 PM, Jeff King wrote:\n>On Mon, Jun 06, 2022 at 06:04:11PM +0200, R. Diez wrote:\n>\n>> If there is nothing of the sort, I could write my own script in Bash\n>> or Perl. I can handle cron and sending e-mails, but I do not know much\n>> about Git's internals. Could someone provide a few pointers about how\n>> to code this? I would expect there is some command to list commits,\n>> and all files touched by a particular commit. And there would be some\n>> way to interface with Bash or Perl, which does not need parsing\n>> complicated text output from Git.\n>\n>This sounds kind of like git-multimail:\n>\n>  https://github.com/git-multimail/git-multimail\n>\n>That's usually triggered from a hook, I think, but it would not be hard to trigger it\n>with arbitrary segments of history.\n>\n>You'd probably want to keep a \"seen\" ref of processed commits, and move from\n>that, like:\n>\n>  # assuming you just care about one branch on the remote, but this\n>  # concept can be extended to several\n>  branch=refs/remotes/origin/main\n>  seen=refs/heads/seen\n>\n>  git fetch\n>\n>  # I don't know what git-multimail expects, but this is similar to what\n>  # a server-side receive hook would show\n>  echo \"$(git rev-parse $seen) $(git rev-parse $branch) $branch\" |\n>  some-git-multimail-command\n>\n>  # now move your pointer forward for next time\n>  git update-ref $seen $branch\n>\n>If multimail doesn't do what you want, then you can probably just script\n>around:\n>\n>  git rev-list $seen..$branch -- $paths_you_care_about |\n>  git diff-tree --stdin -r --name-only --format=\"Commit %h touched: \" --\n>$paths_you_care_about\n>\n>depending how you want to format things.\n\nI am unsure this solves the question. Is the OP looking for anyone who modifies any set or subset of files in any clone or in the upstream repo? This is generally considered a \"watch\" function and is sometimes available on the upstream repo manager, like GitHub/GitLab/BitBucket rather than in core git, so take into account changes made anywhere. If that is the case and the watch functions are not sufficient, you might have to put the hooks on your upstream rather than in your clone.\n\nJust my thoughts,\nRandall\n\n"},{"id":"456927","messageId":"7E6C6D02-8C56-48B5-B178-2F6B66542DBC@gmail.com","threadId":"57960","inReplyTo":"68627d29-8ffd-2e22-46ca-c28c9e980177@gmail.com","subject":"Re: How to watch files in a Git repository","fromName":"Son Luong Ngoc","fromEmail":"sluongng@gmail.com","sentAt":"2022-06-09T08:33:20Z","receivedAt":"2022-06-09T08:34:10Z","isPatch":false,"sender":{"key":"sluongng@gmail.com","avatar":"https://avatars.githubusercontent.com/u/26684313?v=4"},"body":"Hi Diez,\n\n> On Jun 6, 2022, at 6:04 PM, R. Diez <rdiez1999@gmail.com> wrote:\n> \n> Hi all:\n> \n> I would like to get a notification e-mail when certain files or directories change in a Git repository.\n> \n> In the good old CVS days, you could just 'watch' a file with your favourite CVS GUI.\n> \n> Some online services like GitHub offer their own notification mechanism, but I would like something generic. I am not looking for a hook solution, because the Git repositories may not be mine, so I may only have read access.\n> \n> The idea is that I can set up a cron job to periodically pull a repository, and run a script to generate the e-mails from the commit history. Any new commits which match the desired branch and modify the desired files and/or directories would trigger the notifications.\n> \n> I've searched the Web, but couldn't find anything straightforward.\n\nI would encourage you to try SourceGraph’s CodeMonitoring feature (1).\nYou can configure a search query which target a file path inside\na repository, then it will send email to you when there are new\ncommits/diffs touching those files.\n\nI have no affiliation with them except for being a happy end user.\nIn fact, I used SourceGraph extensively while studying git/git codebase.\n\n> \n> If there is nothing of the sort, I could write my own script in Bash or Perl. I can handle cron and sending e-mails, but I do not know much about Git's internals. Could someone provide a few pointers about how to code this? I would expect there is some command to list commits, and all files touched by a particular commit. And there would be some way to interface with Bash or Perl, which does not need parsing complicated text output from Git.\n> \n> Thanks in advance,\n>  rdiez\n\nCheers,\nSon Luong\n\n(1): https://docs.sourcegraph.com/code_monitoring"},{"id":"456945","messageId":"YqIMno8xpZdOk7SV@coredump.intra.peff.net","threadId":"57960","inReplyTo":"007301d87bc8$69608b00$3c21a100$@nexbridge.com","subject":"Re: How to watch files in a Git repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-06-09T15:07:10Z","receivedAt":"2022-06-09T15:07:20Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jun 09, 2022 at 02:16:03AM -0400, rsbecker@nexbridge.com wrote:\n\n> I am unsure this solves the question. Is the OP looking for anyone who\n> modifies any set or subset of files in any clone or in the upstream\n> repo? This is generally considered a \"watch\" function and is sometimes\n> available on the upstream repo manager, like GitHub/GitLab/BitBucket\n> rather than in core git, so take into account changes made anywhere.\n\nIn the original message the OP said they wanted to watch repos to which\nthey only have read access. So I think any solution has to be \"fetch and\ncheck for changes\".\n\n-Peff\n"}]}