Using API how to find the parent branch in Bitbucket - bitbucket

I want to find the parent branches for a particular branch. Suppose I have created A branch from master and branch B from A. Now I want to find the parents for B like B->A->Master. I checked the Bitbucket API but there is no such a method available. When I pull the data for a branch there is no field which shows the parent branch details.

You can use regular git commands for that:
git branch --merged HEAD --sort=authordate
This lists the ancestor branches of the current working directory in chronological order (you can of course specify any other ref instead of HEAD) and would be great to use in a script or some automated tooling.
A very quick and dirty alternative way would be to just look at the regular output of git log:
git log --graph --decorate | egrep 'commit .* \('
This variation would maybe be interesting for a human to watch but too noisy for a script.

Related

Bitbucket - how to set branch permissions for given source/dest pair?

In Bitbucket cloud it's straightforward to set a branch permission to control who and how changes can be made, for example, consider who can modify the 'main' branch. We need more granularity and would like to be able to set up a rule based on both the source and destination branch.
Imagine we had the following branches:
releaseX
releaseY
featureA
featureB
Is it possible to specify a branching pattern or something that would apply different rules from release* -> main than feature* -> main? Maybe the 'Select branch By pattern' input takes a special pattern like s:release*,d:main etc..? Is this possible?
We also have access to the BB API if that helps somehow.

Bitbucket 2.0 API get all commits merged to master

I am trying to create a utility tool for which I need to get the list of all commits that have been merged to master from the feature branch on Bitbucket. As you can see in the picture, the commit that has "M" label after the commit id is the one that I need. However, when I use the endpoint - https://api.bitbucket.org/2.0/repositories/user-name/repo-name/commits/master - it returns me a list of all the commits including the ones that do not have the label 'M'.
Is there any way I can get a list of only the commits that have been merged to master?
Click here to view the image
to get only the merge commits the parameter "merger is used".
https://api.bitbucket.org/2.0/repositories/user-name/repo-name/commits/master/merge=only

Download file at specific commit with Bitbucket REST API

We are trying to find a way to download a single file from a Bitbucket project using the REST API at a specific commit. Currently, we have the ability to download a file at a specific branch:
https://stash.domain.com:8443/rest/api/1.0/projects/our_project/src/main/java/com/SomeFile.java?at=refs%2Fheads%2Fmaster
Note that the end of the URL, when decoded, contains the query parameter at=refs/heads/master, which refers to the master branch. This also works for specific tags:
https://stash.domain.com:8443/rest/api/1.0/projects/our_project/src/main/java/com/SomeFile.java?at=refs%2Ftags%2Ftesttag1
Here the query parameter at=refs/tags/testtag1 refers to the tag (commit) testtag1.
But because of the nature of our implementation, we would like to refer directly to a commit SHA-1 hash via the Bitbucket REST API. Is this possible?
Obviously, one ugly workaround would be to just add a tag to every commit. But this could bloat the repository and it also feels like an unnecessary hack.
With the help of this SO question, I found one of the answers which tipped me off to the correct syntax. Use this:
<URL>?at=commit_hash
For example:
https://stash.domain.com:8443/rest/api/1.0/projects/our_project/src/main/java/com/SomeFile.java?at=bed2dda5
Here is a table of three main endpoint types with the Bitbucket REST API:
query parameter | role
---------------------------------------------
refs/heads/master | specify master branch
refs/tags/someTag | specify 'someTag' tag
at=bed2dda5 | specify commit #bed2dda5

TFS - is it possible to delete merge flag from files and send commit just like a normal changeset?

Let's say I have two branches: A and child branch B. I wanna merge one changeset from branch A to B, but with one detail: I don't want flag [merge] for files in this changeset, it must look just like I edit files manualy and don't have a link on changeset from branch A. Is it possible?
Yes, the general idea is to generate a diff on the source branch with the following command
tf.exe diff [...] /recursive /format:unified /version:[...] >> diff.patch
Replace the [...] with the actual values (branch folder and versions). The documentation is on MSDN
Then use the patch utility (from sourceforge.net) to apply it the other branch:
patch.exe -p0 < diff.patch
Then check in.

Git merge from a specific folder only

I've created a rails website for client X. I now have a client, Y, who wants a website that does the exact same thing as client X, but with a different skin.
I made a git branch from clientXcode and called it clientYcode. I then did all the changes to the views to make it look different, and lala, the same website with a different skin.
Now here's what I don't understand about git: I've made many changes to clientXcode in the views, models, and controllers; and now I want to merge those changes into clientYcode, excluding any view changes. Since views, models, and controllers each have their own folder in rails I was hoping to be able to do something like:
git merge client_x_code 'app/controllers/*', 'app/models/*'
QUESTION 1: Is something like that possible with git? If so, how would I do it?
QUESTION 2: Was branching the best solution to make a copy of my project?
Well I found the easiest solution to my problem...
git checkout clientYcode
git checkout clientXcode "app/controllers/"
git checkout clientXcode "app/models/"
And that does what I want!
The simplest course of action is to merge everything, except the content of the directory you want to keep.
You can do that by adding a merge driver in that directory, as the How do I tell git to always select my local version for conflicted merges on a specific file? question details.
With that merge driver in place, Branching is a good solution in this case.
Extract:
We have a .gitattributes file defined in the dirWithCopyMerge directory (defined only in the branch where the merge will occurs: myBranch), and we have a .git\config file which now contains a merge driver.
[merge "keepMine"]
name = always keep mine during merge
driver = keepMine.sh %O %A %B

Resources