I'm writing a plugin which needs each file in its entirety being pushed to Stash. How can I get those files?
Community moderators have prevented the ability to post new answers.
Hi Jordan,
Have a look at https://answers.atlassian.com/questions/171295/stash-pre-receive-hook-plugin-accessing-committed-contents
Note that HistoryService has since been replaced by CommitService.
Cheers,
Michael
Hey Michael,
Thanks for the reply. I was looking over there and noticed that in streamFile() it basically streams it line by line. Is there no way to get the file in its entirety? It also asks for the filepath. How do I get that? Also, can I not simply access the file using the file path once I have it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which file do you want to get? Note that when you push to Stash, you're pushing one or more branches/tags - not individual commits. So a push could
Lots of different scenarios to consider! Also, when a file is changed in a commit, are you interested in the whole file or just the change? Depending on what you need to do there are different options:
I'm guessing that you're writing some kind of hook that performs a code style or static analysis check on the code that's being pushed. In that case you'll want to do something like this:
for each RefChange, use CommitService.streamChanges to determine the modified and added paths between RefChange.fromHash and RefChange.toHash (ignore the removed paths).
For each of these paths stream the file (using CommitService.streamFile) and perform the static analysis (or create a temporary directory and stream the file to a file on disk - then perform the static analysis).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's actually exactly what I ended up doing. I'm not 100% sure how it works, but it's good to know that I went about things correctly. And all that extra information definitely helps me to understand more. Thanks a lot for your response!
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.