Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Authoring a commit that depends on multiple other Gerrit changes?

Tags:

git

gerrit

At my place of work, we use a Gerrit server for code review. Often times different people will author commits that are unrelated. I've run into an issue where I must author a commit which depends on two other, unrelated commits.

Let's say there are two commits on a gerrit server:

  • Commit A: "Added function flipImage"
  • Commit B: "Added function rotateImage"

These two are independent of each other. My job is to implement Commit C: "Added function flipRotateImage". This requires both commits A and B to be present.

I have two questions:

  1. How to I 'pull in' both A and B, and then author C, in such a way that I'm not actually changing A or B? In other words I can't cherry-pick A or B because it would change them. My goal is to be able to upload C for review without needing to update A & B.
  2. Let's say the author of A uploads a new patch set. I want to update my working branch such that the "A" in my chain is the latest "A", not an older patchset. Can this be done?
like image 960
Adam S Avatar asked Jan 23 '14 19:01

Adam S


People also ask

How do you add depends on Gerrit?

A Gerrit URL refers to a single change on a single branch, so if your change depends on multiple changes, or the same change on multiple branches of a project, you will need to explicitly list each URL. Simply add another “Depends-On:” line to the footer for each additional change.

What is relation chain in Gerrit?

You can, however, also add another commit on top of your existing commit in Gerrit, which will create a second change (and thus another review) that is based on your first change. Gerrit will show the relationship between these two changes as a so-called relation chain.

How do you rebase changes in Gerrit?

In some cases, it is possible to resolve merge conflicts issues in Gerrit using simple rebase triggered directly from the Gerrit UI. Just click on "Rebase" button to rebase the change. The behaviour is described in Gerrit Review UI: If the rebase is successful, a new patch set with the rebased commit is created.

How do I merge Gerrit changes?

While you resolve conflicts that arise from a git merge for GitHub, you will need to use git rebase with your change on Gerrit. After resolving locally, with GitHub, you end up with another commit on your pull request branch and push it to the server, which should then allow you to finish merging the change.


2 Answers

  1. Unless A or B is rebased to depend on the other you can't have C depend on both A and B. One possibility would be to check out A and merge from B to create a merge commit D onto which you could put C, but then you'd have to upload this otherwise useless merge commit for review, but graph-wise it's the only way of making both A and B reachable from C without making A reachable from B or vice versa.
  2. Yes, fetch the new A into your workspace with the URL provided in the Gerrit UI and put C on top of it using e.g. git rebase --onto. The exact procedure would depend slightly on how you choose to deal with the problem in the first question, but ignoring that and assuming you have checked out the topic branch for C then git rebase --onto newA oldA will do.
like image 124
Magnus Bäck Avatar answered Oct 17 '22 23:10

Magnus Bäck


A change has been proposed in Gerrit to support this kind of dependency specification outside of the git DAG. The change is intended for cross-project dependencies, but it should also support this kind of intra-project commit dependency as well. Sorry it doesn't help you now, though.

https://gerrit-review.googlesource.com/#/c/55243

like image 2
Phil Hord Avatar answered Oct 17 '22 22:10

Phil Hord