Add revert_recipe function

And adjust the tests to use it so that it covers both revert_recipe and
revert_file.
This commit is contained in:
Brian C. Lane 2017-11-13 15:04:49 -08:00
parent c294b7747d
commit ab6decec0b
2 changed files with 18 additions and 1 deletions

View File

@ -379,6 +379,23 @@ def delete_file(repo, branch, filename):
message = "Recipe %s deleted" % filename message = "Recipe %s deleted" % filename
return repo.create_commit(ref, sig, sig, "UTF-8", message, tree, [parent_commit]) return repo.create_commit(ref, sig, sig, "UTF-8", message, tree, [parent_commit])
def revert_recipe(repo, branch, recipe_name, commit):
"""Revert the contents of a recipe to that of a previous commit
:param repo: Open repository
:type repo: Git.Repository
:param branch: Branch name
:type branch: str
:param recipe_name: Recipe name to revert
:type recipe_name: str
:param commit: Commit hash
:type commit: str
:returns: OId of the new commit
:rtype: Git.OId
:raises: Can raise errors from Ggit
"""
return revert_file(repo, branch, recipe_filename(recipe_name), commit)
def revert_file(repo, branch, filename, commit): def revert_file(repo, branch, filename, commit):
"""Revert the contents of a file to that of a previous commit """Revert the contents of a file to that of a previous commit

View File

@ -184,7 +184,7 @@ class GitRecipesTest(unittest.TestCase):
"""Test reverting a file on a branch""" """Test reverting a file on a branch"""
commits = recipes.list_commits(self.repo, "master", "http-server.toml") commits = recipes.list_commits(self.repo, "master", "http-server.toml")
revert_to = commits[0].commit revert_to = commits[0].commit
oid = recipes.revert_file(self.repo, "master", "http-server.toml", revert_to) oid = recipes.revert_recipe(self.repo, "master", "http-server", revert_to)
self.assertNotEqual(oid, None) self.assertNotEqual(oid, None)
commits = recipes.list_commits(self.repo, "master", "http-server.toml") commits = recipes.list_commits(self.repo, "master", "http-server.toml")