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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to list/pull all the files under a particular branch inside a repository via Rest Api Edited

I have to check the list of files stored under a particular branch with full path. Currently, I could not find a way of accessing it via a rest endpoint

1 answer

0 votes
Marty Atlassian Team Mar 05, 2019

Hi Tanmoy,

I am not on the Bitbucket team, but I will try to help.

Is there any reason why you need to use a REST API?

If you can use a git client then you could try something like

git ls-tree -r --name-only <branch name>

I hope that helps!

Thanks for your reply Martyn.

My branch has directories inside it. So, I want to list all the files with a relative path from the branch.

$ git ls-tree --name-only feature/API-460
.gitignore
db_connection
sql

I have some jobs that reference the branch files as part of CI.

Accessing via git command would mean that I have to install git client on the machine that wants to access bitbucket.

So, what I am trying to find is a rest-endpoint that would fetch the same result as:

$ git ls-tree -r feature/API-460

100644 blob 73febeeb4545e1 .gitignore
100755 blob 3126b0bfa7ca db_connection/conf.json
100644 blob 27a08b947d5438b0 sql/v1.0.sql
100644 blob e228c3188f92c9d96 sql/v1.1.sql
100644 blob 71ab229376c83 sql/v1.2.sql
100644 blob 39e425ba26ed91e536b sql/v1.3.sql

Like Marty likes this
Marty Atlassian Team Mar 05, 2019

Hi Tanmoy,

I think it will be simpler for you to install a git client on the machine you're using.  Then you can use git commands and shell commands to modify the output to your liking.

The only kind of REST endpoint close to what you're looking for is:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src#get

You would need to then call that multiple times to manually traverse the directory tree.  Ie. it will only list .gitignore, db_connection and sql in the first call.  You would then need to make a second call to list the contents of db_connection/ and a third call to list the content of sql/

I hope that helps!

Like Tanmoy Thakur likes this

Nothing more irritating then answering a question with the wrong solution, I also need to list files under a branch, and we are doing it with node.js so we need to use the bitbucket API... get lost.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,886 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you