Search code examples
gitgerrit

How to abandon a whole topic on Gerrit?


So the long and short of the issue is that, in a fit of fanatical adherence to code review principles and user attribution....

I pushed around 834 commits from an upstream branch to a project's gerrit server.

I was since then informed me that I ought to have (reasonably) first pushed a squashed commit for testing on gerrit and then pointed them to my repo for a merge...

Luckily I had tagged the commits with a topic while uploading them (for ease of testing.... -_-)

How can I now mass abandon the whole damn topic there? (to be replaced with a squashed commit)

There ought to maybe be some sort of terminal command? My gerrit-fu is weak and I haven't any privileged access to the server though..


Solution

  • AFAIK, there is no ready method to achieve this. However, gerrit is awesome tool and you can solve this problem by writing a custom script.

    Sorry, I'm too lazy to make you a ready to use solution, but here's what my script would do:

    1. Prepare environment

      alias gerrit="ssh -p 29418 gerrit.yourdomain.com gerrit"
      
    2. List all the commits with topic:

      gerrit query topic:<topic>
      
    3. Strip Change-Id's

    4. Abandon commits one by one:

      gerrit review <id> --abandon
      

    Update

    Thanks to Marcelo Avila de Oliveira, you have now the script you can use:

    #!/bin/bash
    
    alias gerrit="ssh -p 29418 gerrit.yourdomain.com gerrit"
    
    for c in $(gerrit query topic:trololo | grep "сhange" | cut -d ' ' -f 2);
        do gerrit review $c --abandon;
    done
    

    Replace trololo with whatever you need, or adapt the script to take the argument.