0

In the company I work for, some users update their Gerrit changes from the web UI features (e.g. edit file content), resulting in new patch sets. It's easy, you don't have to edit, git add, git commit and git push...

However, the Git local copy does not have these new patch sets, and when pushing again from here, the already done edits may be lost or overridden.

Gerrit does not prevent this by default, which is normal, as there is no dependency between patch sets in the same Gerrit change (also seen here).

Is there any way of implementing such a thing, like always ensure the user pushes over the latest patch set? Gerrit custom hook, project accesses...

I.e. having the following behaviour:

  • Change exists: latest patch set is 1/1
  • Edit files from the web UI: latest patch set is 2/2 (Git local copy is not updated)
  • Edit files from the not up-to-date Git local copy, and push: rejected
  • Fetch the patch set 2/2, apply modifications and push again: latest patch set is 3/3.

Thanks guys!

alleen1
  • 418
  • 6
  • 14

1 Answers1

-1

You can implement a git hook doing the following:

  1. Use Gerrit command tools to find out the latest patchset revision.
    Example: ssh gerrit-server -p port gerrit query --format JSON --current-patch-set change:Change-Id
    A response contains the latest patch-set revision.
    Change-Id can be extracted from the user's patch commit message.
  2. Check that the user's commit is a descendant of the latest patch-set commit.
  3. Print error-message and return non-zero status from the hook if the condition from the step 2 is not met.

Hooks suitable for the task:

  • Client side: pre-push
  • Server side: pre-receive or update

For the server side hooks, perhaps, there is a better way to implement the step 1 (since it is executed on the server which it connects to)

kt_
  • 74
  • 5