Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Tanmoy Thakur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 5, 2019

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
Atlassian Team members are employees working across the company in a wide variety of roles.
March 5, 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!

Tanmoy Thakur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 5, 2019

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
Atlassian Team members are employees working across the company in a wide variety of roles.
March 5, 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
Richard Lyle July 19, 2020

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.

Like Tiansu Yu likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events