Missed Team ’24? Catch up on announcements here.

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

How do I check if a file exists in bitbucket remote b

Kailash Subramanian August 6, 2018

Actually when the user commits a file into their local repository I need to update come information into those files automatically like for example: version string, for this I use pre-commit hooks.

To update the version string first I need to take the current version of the file from already existing file in bitbucket remote branch. Of Couse I should not take the current version for the file in my local repository since other users could have done some changes and  pushed the same file.

To get the file in bitbucket remote branch I wrote a small python script using 'requests' module. So when the file exists in remote branch it returns me the raw content of the file.  When the file does not exists it returns status code 404(page not found) . So I assumed that file does not exists! I think this is not the reliable way to say file does not exists in the branch. Is there a reliable way to check if the file exists in the remote branch or not ?

1 answer

0 votes
Vivian C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 17, 2018

Hi Kailash,

In this case, the git command you want is:

git ls-tree -r <remote_branch>

The git command above should list all files which exists in the specified remote branch -- from there, you should be able to check if a particular file exists in the remote branch or not.

- Vivian

Sangeetha Viswanathan
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!
October 21, 2021

Hi Vivian, 

Is it possible to check the existence of a file giving the input as a URL and a branch?

Thanks

Sangeetha

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events