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

Compare branch via rest api

Vishal Gaurav
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!
May 8, 2023

There is a feature as "Compare branches or tags" which I am using to compare the branches for any merge conflict(screenshot attached). Now I want to do this via the bitbucket REST api. I tried searching to docs but was unable to find the endpoint. Can somebody please help with this?

 

IMAGE 2023-05-09 11_35_06.jpgIMAGE 2023-05-09 11_35_31.jpg

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 10, 2023

Hi @Vishal Gaurav and welcome to the community!

You can use the following API endpoint to compare two branches as well:

An example with curl:

curl -u username:app_password --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/diffstat/main..feature' \
--header 'Accept: application/json'

For the conflicted files, you will see in the output the field "status": "merge conflict".

Please feel free to let me know if this works for you and if you have any questions.

Kind regards,
Theodora

Vishal Gaurav
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!
May 10, 2023

Thanks @Theodora Boudale  for the answer, it works. Now I can see the "status": "merge conflict" in the response. However, I have a doubt.

I just went through the diffstat API documentation and found out about the "topic" parameter. By default, when I don't include this parameter (as shown in the example above), I only get diffstats of type "merge conflict" (which is exactly what I'm looking for). However, if I set it to false or true, I get a lot more diffstats, and they don't seem to include diffstats of type "merge conflict".

Omitting the topic parameter altogether works for me, but I wanted to be aware of what is actually happening. Can you please help me with this confusion?

Regards,
Vishal Gaurav

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 12, 2023

Hi Vishal,

Please allow me to give some context about diffs first. Git has two types of diff:

(A) The two-dot diff

git diff --stat main..feature

This will show the diffstat for file changes in both branches, main and feature, since their common ancestor.

(B) The three-dot diff

git diff --stat main...feature

This will show the diffstat for files changed in feature branch only, since the common ancestor of main and feature branches. Therefore, this may include less diffstats than (A), since it won't include changes in main branch.


The example I shared in my previous example is using the three-dot diff (B) and it will show changes in the main branch only. If you want to see changes in the feature branch instead, you will need to reverse the order of the branches

https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/diffstat/feature..main

When the topic parameter is absent, and also when it is true, the three-dot diff (B) is used.

When the topic parameter is false, the two dot diff is used (A) and this may show more diffstats since it will include changes in both branches.


Regarding your questions:

1. Getting more diffstats with topic=false is expected. However, I cannot reproduce a case where topic=true shows more diffstats than if omitted. Are you able to reproduce this in a public test repo, with some dummy content, so I can take a look?

2. When topic=true is used, merge conflicts are indeed not indicated. I will reach out to the development team for more info on why this occurs, and I will get back to you when I have an update.


Kind regards,
Theodora

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 15, 2023

Hi Vishal,

I reached out to the development team regarding question 2:

2. When topic=true is used, merge conflicts are indeed not indicated. I will reach out to the development team for more info on why this occurs, and I will get back to you when I have an update.

The topic query parameter was introduced last year when we made changes in the diff algorithm we use:

The status "merge conflict" was not added as a status when the topic query is used, because we will eventually remove it. When we do, we will provide a public conflict API endpoint for customers who use this status for that purpose, to ensure continuity.

Any changes in the API are announced here:

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events