def match_commit(self, src_dir):
"""Check that the current commit matches the recorded commit for this experiment.
Raises an error if commits don't match, or if there is dirty state.
Args:
src_dir (str): path to the Git repository
"""
if self.metadata['dirty_repo']:
raise EnvironmentError('Working directory was dirty when commit was recorded.')
repo = Repo(src_dir)
if repo.is_dirty():
raise EnvironmentError('Current working directory is dirty.')
current_commit = repo.head.object.hexsha.encode('utf-8')
exp_commit = self.metadata['commit']
if current_commit != exp_commit:
raise EnvironmentError("Commits don't match.\nCurrent: {}\nRecorded: {}".format(current_commit, exp_commit))
评论列表
文章目录