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

Fetch list of files with details present under branch or tag

prajakta101 August 7, 2019

Here I want detail of files which are present under particular tag or branch.

I tried below GET API but it is returning only commit message of that particular file. But I want file name and other details as well.

https://api.bitbucket.org/2.0/repositories/project_name/repo_name/refs/branches/branch_name

Can someone help me here to fetch details of files present under specific branch or tag.

2 answers

0 votes
Julius Davies _bit-booster_com_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 9, 2019

If you have access to a "git clone" checkout for your repository then the "git ls-tree" command is a great way to get this info, assuming it's up to date (e.g., "git fetch" was recently run).

 

Example:

git ls-tree -r origin/master
0 votes
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 7, 2019

Hello @prajakta101,

I believe /src/{node}/{path} endpoint is what you're looking for. The documentation page looks a bit broken, but node is a branch, a tag, or a commit, while path is path from the root of the repository. This endpoint returns some metadata for each file and directory.

Hope this helps.

Cheers,
Daniil

prajakta101 August 13, 2019

Hi Daniil,

When I enter file name as PATH then I am getting all details of file. But I want to find file name for particular branch or tag.

Can you please tell me where I can get PATH.

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 13, 2019

Sorry I don't quite understand what you're trying to get. You can list your repository, starting from root, at any branch or tag, or commit. For example, this is the URL to fetch everything (all files and directories) at the root level of atlassain/atlaskit-mk-2 repository at master branch:

https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit-mk-2/src/master/

 Or just their name and type (and pagination attributes):

https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit-mk-2/src/master/?fields=pagelen,page,next,values.path,values.type

The latter would result in something like this: 

{
pagelen: 10,
values: [
{
path: ".changeset",
type: "commit_directory"
},
{
path: "__mocks__",
type: "commit_directory"
},
{
path: "build",
type: "commit_directory"
},
{
path: "docs",
type: "commit_directory"
},
{
path: "flow-typed",
type: "commit_directory"
},
{
path: "packages",
type: "commit_directory"
},
{
path: "releases",
type: "commit_directory"
},
{
path: "typings",
type: "commit_directory"
},
{
path: "website",
type: "commit_directory"
},
{
path: ".editorconfig",
type: "commit_file"
}
],
page: 1,
next: "https://bitbucket.org/!api/2.0/repositories/atlassian/atlaskit-mk-2/src/master/?fields=pagelen%2Cpage%2Cnext%2Cvalues.path%2Cvalues.type&page=8xhd"
}

Now this would list files and directories under /docs/guides at branch AK-3659 in the same repository:

https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit-mk-2/src/AK-3659/docs/guides/

 

If you are rather looking for a name of a particular file on some another branch, i.e. track renames, you need to use the diff API instead. If the file is not listed in the diff, it means that file is same between branches (both content and location).

Let me know if this helps.

Cheers,
Daniil

Like Paz likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events