I setup bitbucket client side and server side hooks to do some checks on committed files.
I usually validate the content of the files. If a file deleted and that get committed I no need to do any checks on them, I have identified the deleted files in client side using git diff --cached --name-only --diff-filter=D command.
But In server side do not know how to identify deleted files in a commit and skip them ?
In a pre-receive hook you can do this for each commit you are analysing:
git diff <COMMIT> <COMMIT>~1 --name-only --diff-filter=D
In Java (inside my Bitbucket plugin code) I would do something like this:
GitScmCommandBuilder diffBuilder = gitBuilderFactory.builder(repo).command("diff");
diffBuilder.argument("--name-only");
diffBuilder.argument("--diff-filter=D");
diffBuilder.argument(commit + " " + commit + "~1");
The code will blow up if you happen to hit a root commit (e.g., first commit in a repository), but aside from that it should work. It analyzes the diff along the first-parent path (hence the "~1") which is usually what you want.
(However, sometimes it's useful to detect merge commits and handle them differently.)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.