def set_commit_id(self, commit_id=None):
"""Checks out the commit id for the repo
"""
checkout_id = commit_id if commit_id else self.branch
# Already checked out
if self.prev_commit == checkout_id:
return True
cmd = "git checkout {0}".format(checkout_id)
output, rc = self.run_command(cmd)
if rc > 0:
# Corrupted checkout state, try to recover
logger.warn("Possible corrupted checkout state", desc="Problem with checkout", error=output,
commit_id=checkout_id, path=self.paths['repo_path'],
cmd=cmd, track=self.track)
# Want to guarantee that the branch is completely reset.
git_reset_output, rc = self.run_command("git reset --hard {0}".format(checkout_id)) #pylint: disable=unused-variable
if rc < 1:
# Clean up git so there are no untracked files.
self.run_command("git clean -fd")
if rc > 0:
logger.errorout("set_commit_id", desc="Problem setting commit id", error=output,
commit_id=checkout_id, path=self.paths['repo_path'],
cmd=cmd, track=self.track)
self.prev_commit = checkout_id
return True
评论列表
文章目录