0

I'm using the following call to the BitBucket 1.0 API to get all the commits on a branch. This call returns all the commits from the specific branch, but also all the commits from the beginning of time. I'm looking for a way to only get the commits that were committed to the specified branch. Is this even possible?

/rest/api/1.0/projects/{ProjectKey}/repos/{RepoSlug}/commits?until={branchId}

I'm looking for a way to only get the commits since the branch split from the 'tree', to the tip of the branch. It doesn't appear that there's any data in the response that I can use to determine which commit was the first on the branch, or last on the 'tree'

Tim
  • 101
  • 1
  • 7
  • It's not clear what you're asking. A branch is the tip of a tree that extends back to the first commit in the repository. If you ask for "all the commits in a branch", you're going to get exactly what you've described. – larsks Aug 28 '20 at 12:03
  • @larsks Yes, I understand that. What I'm looking for is a way to limit the number of commits to the point where the branch split from the tree. I know there are ways to do this with git log, so I'm just curious if anybody knows how to do it through the BitBucket API. – Tim Aug 28 '20 at 13:03

1 Answers1

2

If you know the branch that the branch in question branched from, you can use the /compare/commits endpoint to get the commits that are on the specified branch but not the 'base' branch.

/rest/api/1.0/projects/{ProjectKey}/repos/{RepoSlug}/compare/commits?from={BranchId}&to={BaseBranchId}

For example:

/rest/api/1.0/projects/{ProjectKey}/repos/{RepoSlug}/compare/commits?from=feature%2FmyCoolFeature&to=master

This will give a list of all the commits that exist on the feature/myCoolFeature branch, but not the master branch.

For my specific scenario, this is enough to get me by. If you're in a situation where you don't know where the branch in question branched from, I haven't yet found a good workaround for that situation.

Tim
  • 101
  • 1
  • 7