I have written test cases, during the test case execution changes will be create, that changes will clean up by merging/abandoning at end. But sometimes some exceptions will raised between the merging/abandoning on clean up process.

Can we think about a way to delete the changes created during the test instead only merging/abandoning them?

class TestChangeMerge(object):
    @pytest.fixture(autouse=True)
    def setup(self, conf, git, gerrit):
        self.git = git(config)
        self.gerrit = gerrit(config)

    def test_change_merge(self):
        log.info("STEP 1 : git-clone")
        self.git.clone()

        log.info("STEP 2 : Create commit and push new change")
        self.git.push_change()

        log.info("STEP 3 : Checking results")
         assert (self.gerrit.change_status(self.git.change_id))

    def teardown(self):
        self.git.cleanup()
        self.gerrit.cleanup() 
     #Here we have stated cleanup, used ssh command 'gerrit review --abandon', in case failed on abandon then what is alternate way to cleanup.

2 Answers

0
Marcus On

You have to know the commit ID of the commit where you want to go back to. Then you can make:

git reset --hard commit-id

Or, optimally, you have placed a tag where you want to go back to.

git reset --hard tagname

If you already pushed your unwanted commit (I assume this as of 'self.git.push_change()' call), you will have to force push afterwards:

git push --force

But make absolutely sure that no one else has pushed to the repo in the meantime - that changes would be lost too. Force pushes have to be synchronized with every each person who uses the repo!!!

0
Marcelo Ávila de Oliveira On

Yes, you can delete changes using REST.

See how to use "Delete Change" endpoint here.

You need to grant Delete Own Changes or Delete Changes permission to the user who will delete the changes.

See more info about the Gerrit REST API here.