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
Related
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.
I'm setting up a Gerrit server for the team. I've used Gerrit in the past, but I've never set one up.
One feature I know I've used in the past is, once I get a CL approved, I can rebase the branch without losing the approval. I assume this is a setting somewhere, but I can't find it.
You need to set the "Submit Type" of the repository (in the repository configuration page) to one of these:
Rebase If Necessary
If the change being submitted is a strict superset of the destination branch, then the branch is fast-forwarded to the change. If not, then the change is automatically rebased and then the branch is fast-forwarded to the change.
When Gerrit tries to do a merge, by default the merge will only succeed if there is no path conflict. A path conflict occurs when the same file has also been changed on the other side of the merge.
Rebase Always
Basically, the same as Rebase If Necessary, but it creates a new patchset even if fast forward is possible AND like Cherry Pick it ensures footers such as Change-Id, Reviewed-On, and others are present in resulting commit that is merged.
Thus, Rebase Always can be considered similar to Cherry Pick, but with the important distinction that Rebase Always does not ignore dependencies.
See more details in the Gerrit documentation here.
I think you are looking for the Copy All Score On Trivial Rebase labels.
The example below is from our project.config. For the Verified label the scores will be copied if there is a Trivial Rebase or a No Code Change patchset added, the No Code Change basically means an updated commit message.
[label "Verified"]
function = MaxWithBlock
value = -1 Fails
value = 0 No score
value = +1 Verified
copyAllScoresIfNoCodeChange = true
copyAllScoresOnTrivialRebase = true
defaultValue = 0
I'm using following documentation: https://gerrit.googlesource.com/plugins/hooks/+/HEAD/src/main/resources/Documentation/hooks.md#change_merged which describes parameters passed to given hook.
At the moment I want to get commit message body based on commit that has been merged in Gerrit. Unfortunately there are two parameters which passing commit SHA, those are namely --commit and --newrev. I have also tried to print them out for single merged commit and value points to same commit (in my case both values are: bd2b60cccc9fba84ac66aa161ac07008b4803575)
I'm wondering which one should I use for my use case when I want to refer to commit that generated given instance of event that triggered the hook. Are there any case when those values can differ?
The "newrev" is different from "commit" when a merge commit is generated for that commit when the change is submitted to the destination branch.
See more info here and here.
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.
Use libgit2sharp, how to calculate ahead or behind metrics. like this page https://github.com/libgit2/libgit2sharp/branches
How to calculate ahead or behind metrics
Each Branch bears a TrackingDetails property. This property exposes AheadBy and BehindBy nullable values (null will be returned when the branch has no upstream configuration or if the upstream branch does not exist).
Those values will represent the number of commits the local branch is ahead/behind compared to the upstream branch (ie. the remote branch being tracked).
This outputs similar results than git status -sb
like this page https://github.com/libgit2/libgit2sharp/branches
This page actually compares each branch of the upstream (ie. the one hosted on GitHub) repository against the current tip of the remote HEAD. This feature (comparing two local branches) is not available in LibGit2Sharp.
Provided you're interested with it, please feel free to open a feature request.
Update
A pull request (see #564) introducing a new method repo.ObjectDatabase.CalculateHistoryDivergence(Commit, Commit) is cooking up.
This will allow the user to determine the ahead-by and behind-by counts, along with the merge-base that's been used to calculate those distances.
For those searching (as of pygit2 v 0.27.4), the API is ahead_behind.
Sample code gist:
import pygit2
repo = pygit2.Repository('your-repo-path')
upstream_head = repo.revparse_single('origin/HEAD')
local_head = repo.revparse_single('HEAD')
diff = repo.ahead_behind(local_head.id, upstream_head.id)