Hi everyone,
I'm attempting run some validation of files which have been added/changed in the repository and reject the push if the files are not valid. I have a working plugin, everything is fine however when creating a new branch all my files are attempted to be validated, regardless if they are changed on branch or not.
I am looking for a performance improvement and to only to check the files that have changed on the branch. The problem I'm facing is that when a branch is created and pushed to the repository, all the files seem to be of the ChangeType.ADD. I can't seem to differentiate between files which have been added on the branch and pushed and those which are just a branch create.
I'm using the following classes to determine if the the change types:
and the refChange which is passed to the onReceive method of the PreReceiveRepositoryHook.java:
Has anyone any ideas how to do this?
Community moderators have prevented the ability to post new answers.
First of all, the ChangeType is about the Ref Change (i.e. branch/tag added/moved/deleted), not the commits or files in commits, but I guess you have figured this out already.
For making sure you only process the newly pushed commits, check out this recursive implementation. Lines 97-100 have the check where CommitIndex (newer verson of the now deprecated ChangesetIndex) is used to determine if a commit is newly pushed or not. The recursion goes from refChange.getToHash() backwards until it hits the first commit(s) which are already indexed. This ensures that only the newly pushed commits (and their parents) are visited in the graph.
Hey Balazs, Good answer. I was able to complete what I wanted by following the code that you have posted. Thanks very much for your answer. I'm not sure how to accept your answer, but I think it was the best one. Thanks again, Hugh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Next to my name above on the left you should see a number with two arrows above/below and a grey checkmark below the lower arrow. Click that to accept the answer. (You need to be logged in to do this.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IMHO the answer to this is in @Michael Heemskerk 's comment to my answer here: https://answers.atlassian.com/questions/15696071
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jamie, hmmm, I've found that this might be the better answer: https://answers.atlassian.com/questions/223143/how-to-get-only-new-changesets-in-pre-receive-hook-on-new-branch-push Sorry for not seeing this answer prior to posting this. Should I accept your answer or how should I close this question?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My understanding is that you can't use ChangesetIndex in a pre-receive hook.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, I understand that as the index hasn't yet been updated. However, is it possible to get the list of ref's on a pre-receive hook with the normal Stash API instead of mucking around with org.eclipse.jgit.lib.Repository? You can see an example of this here: https://github.com/sford/yet-another-commit-checker/blob/master/src/main/java/com/isroot/stash/plugin/ChangesetsServiceImpl.java#L84 On the method getBranches() I got all this from one of the comments on that link I posted previously by Bradley Baetz...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What I'm getting at is that you could then exclude all the ref's that as the following: final ChangesetsBetweenRequest request = new ChangesetsBetweenRequest.Builder(repository) .exclude(getBranches(repository)) .include(refChange.getToHash()) .build(); Does that make any sense?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh yes, and I've also tried to use getPercentUnchanged to check if the file has been 100% changed or something but it seems to only work on ChangeType.MOVE, when it's ChangeType.ADD it seems to be -1. Shame, thought I had it with that one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.