Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Grabbing files being pushed to stash w/ Pre-recieve hooks

Jordan Salina June 5, 2014

I'm writing a plugin which needs each file in its entirety being pushed to Stash. How can I get those files?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Michael Heemskerk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 5, 2014

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

Jordan Salina June 5, 2014

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?

Michael Heemskerk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 9, 2014

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

  • add a single commit to a branch
  • add multiple commits to a branch
  • add 2 commits to branch A and 3 commits to branch B
  • add thousands of commits and 10s of branches/tags (initial push)
  • rewind a branch - thus removing a number of commits
  • rebase a branch - removing and adding commits

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:

  • CommitService.streamFile to get the contents of a single file
  • CommitService.streamDiff to get the diff between two commits
  • CommitService.streamChanges to a the changes (paths + type of change) between two commits

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

Like Lukasz Ladynski likes this
Jordan Salina June 10, 2014

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!

TAGS
AUG Leaders

Atlassian Community Events