zzzgoo
zzzgoo

Reputation: 2235

How can I check by hook whether there is a file deletion operation?

How can I check by hook whether there is a file deletion operation?

What I want is that I can get an email alarm if someone deleted a file in a certain commit.

Upvotes: 1

Views: 49

Answers (1)

VonC
VonC

Reputation: 1326376

IF you want to be notified (but still allowing that deletion to be pushed), you can write a post-receive hook on the server side (assuming you have control over that remote Git repositories hosting server).

That hook would loop over the sent commit and check for the file deletion

#!/bin/sh
while read oldvalue newvalue refname
do
   if [ "$(git log -1  --diff-filter=D --summary $newvalue | grep filename)" ne "" ]; then
     # send email
   fi
done

Upvotes: 2

Related Questions