git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How to watch files in a Git repository
@ 2022-06-06 16:04 R. Diez
  2022-06-08 23:55 ` Jeff King
  2022-06-09  8:33 ` Son Luong Ngoc
  0 siblings, 2 replies; 5+ messages in thread
From: R. Diez @ 2022-06-06 16:04 UTC (permalink / raw)
  To: git

Hi all:

I would like to get a notification e-mail when certain files or directories change in a Git repository.

In the good old CVS days, you could just 'watch' a file with your favourite CVS GUI.

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.

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.

I've searched the Web, but couldn't find anything straightforward.

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.

Thanks in advance,
   rdiez

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to watch files in a Git repository
  2022-06-06 16:04 How to watch files in a Git repository R. Diez
@ 2022-06-08 23:55 ` Jeff King
  2022-06-09  6:16   ` rsbecker
  2022-06-09  8:33 ` Son Luong Ngoc
  1 sibling, 1 reply; 5+ messages in thread
From: Jeff King @ 2022-06-08 23:55 UTC (permalink / raw)
  To: R. Diez; +Cc: git

On Mon, Jun 06, 2022 at 06:04:11PM +0200, R. Diez wrote:

> 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.

This sounds kind of like git-multimail:

  https://github.com/git-multimail/git-multimail

That's usually triggered from a hook, I think, but it would not be hard
to trigger it with arbitrary segments of history.

You'd probably want to keep a "seen" ref of processed commits, and move
from that, like:

  # assuming you just care about one branch on the remote, but this
  # concept can be extended to several
  branch=refs/remotes/origin/main
  seen=refs/heads/seen

  git fetch

  # I don't know what git-multimail expects, but this is similar to what
  # a server-side receive hook would show
  echo "$(git rev-parse $seen) $(git rev-parse $branch) $branch" |
  some-git-multimail-command

  # now move your pointer forward for next time
  git update-ref $seen $branch

If multimail doesn't do what you want, then you can probably just script
around:

  git rev-list $seen..$branch -- $paths_you_care_about |
  git diff-tree --stdin -r --name-only --format="Commit %h touched: " -- $paths_you_care_about

depending how you want to format things.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: How to watch files in a Git repository
  2022-06-08 23:55 ` Jeff King
@ 2022-06-09  6:16   ` rsbecker
  2022-06-09 15:07     ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: rsbecker @ 2022-06-09  6:16 UTC (permalink / raw)
  To: 'Jeff King', 'R. Diez'; +Cc: git

On June 8, 2022 7:55 PM, Jeff King wrote:
>On Mon, Jun 06, 2022 at 06:04:11PM +0200, R. Diez wrote:
>
>> 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.
>
>This sounds kind of like git-multimail:
>
>  https://github.com/git-multimail/git-multimail
>
>That's usually triggered from a hook, I think, but it would not be hard to trigger it
>with arbitrary segments of history.
>
>You'd probably want to keep a "seen" ref of processed commits, and move from
>that, like:
>
>  # assuming you just care about one branch on the remote, but this
>  # concept can be extended to several
>  branch=refs/remotes/origin/main
>  seen=refs/heads/seen
>
>  git fetch
>
>  # I don't know what git-multimail expects, but this is similar to what
>  # a server-side receive hook would show
>  echo "$(git rev-parse $seen) $(git rev-parse $branch) $branch" |
>  some-git-multimail-command
>
>  # now move your pointer forward for next time
>  git update-ref $seen $branch
>
>If multimail doesn't do what you want, then you can probably just script
>around:
>
>  git rev-list $seen..$branch -- $paths_you_care_about |
>  git diff-tree --stdin -r --name-only --format="Commit %h touched: " --
>$paths_you_care_about
>
>depending how you want to format things.

I 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.

Just my thoughts,
Randall


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to watch files in a Git repository
  2022-06-06 16:04 How to watch files in a Git repository R. Diez
  2022-06-08 23:55 ` Jeff King
@ 2022-06-09  8:33 ` Son Luong Ngoc
  1 sibling, 0 replies; 5+ messages in thread
From: Son Luong Ngoc @ 2022-06-09  8:33 UTC (permalink / raw)
  To: R. Diez; +Cc: git

Hi Diez,

> On Jun 6, 2022, at 6:04 PM, R. Diez <rdiez1999@gmail.com> wrote:
> 
> Hi all:
> 
> I would like to get a notification e-mail when certain files or directories change in a Git repository.
> 
> In the good old CVS days, you could just 'watch' a file with your favourite CVS GUI.
> 
> 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.
> 
> 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.
> 
> I've searched the Web, but couldn't find anything straightforward.

I would encourage you to try SourceGraph’s CodeMonitoring feature (1).
You can configure a search query which target a file path inside
a repository, then it will send email to you when there are new
commits/diffs touching those files.

I have no affiliation with them except for being a happy end user.
In fact, I used SourceGraph extensively while studying git/git codebase.

> 
> 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.
> 
> Thanks in advance,
>  rdiez

Cheers,
Son Luong

(1): https://docs.sourcegraph.com/code_monitoring

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to watch files in a Git repository
  2022-06-09  6:16   ` rsbecker
@ 2022-06-09 15:07     ` Jeff King
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2022-06-09 15:07 UTC (permalink / raw)
  To: rsbecker; +Cc: 'R. Diez', git

On Thu, Jun 09, 2022 at 02:16:03AM -0400, rsbecker@nexbridge.com wrote:

> I 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.

In the original message the OP said they wanted to watch repos to which
they only have read access. So I think any solution has to be "fetch and
check for changes".

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-09 15:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 16:04 How to watch files in a Git repository R. Diez
2022-06-08 23:55 ` Jeff King
2022-06-09  6:16   ` rsbecker
2022-06-09 15:07     ` Jeff King
2022-06-09  8:33 ` Son Luong Ngoc

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).