When the Cherry Pick button is clicked I want to show the commit(s) in the branch [which is selected from the dropdown on the left] and all the branches in the repo where the commit can be applied.
One can select the commit and apply it to any other branch(es) on the new page.
It seems that I won’t be able to pass a branch name to the web-item link as the context is not available to the Cherry Pick button location.
So getting the branches list from the REST API and then fetching ALL the commits using another REST API would be way(?)
We implemented a “Cherry Pick” button in our Bit-Booster - Rebase Squash Amend plugin. But we put it on the commit drilldown page instead. In other words, you first click on the commit you want to cherry-pick using Bitbucket’s regular web UI, and once you’ve drilled-down to a single commit, you then click on our little “Cherry-Pick” button (we also provide a “Revert” button).
Clicking on our “Cherry-Pick” button fires up this dialog:
To get current branch we pluck the “?until=” parameter from the current window’s query-string. If that parameter is not present we use current repository’s default branch which we fetch using server-side API
Our overall strategy is mostly based on the servlet approach you mentioned. We have our own REST endpoint we defined with our own servlet, and it runs git commands in the background to figure out appropriate target branches for the cherry-pick (e.g., git branch --contains).
I can’t even remember how the heck our logic works anymore. It must have been complicated because I see I actually left a comment in the code!
// Unfortunately older git versions cannot do "--contains" on "for-each-ref"
// so we need to it awkward like this to retain the sorted order ("-committerdate")
// but using output of "git branch --contains" to partition the sets.
containsCommit.addAll(notContainsCommit);
sr = new StringReader(contains);
br = new BufferedReader(sr);
while ((line = br.readLine()) != null) {
line = line.trim();
String branch = line.charAt(0) == '*' ? line.substring(1).trim() : line;
notContainsCommit.remove(branch);
}
containsCommit.removeAll(notContainsCommit);
I tried similar logic that you suggested, but I am stuck with some very basic problems, when I try to make an AJAX call to my RepoCommitsServlet, I get a page not found error