@@ -21,7 +21,12 @@ class PatchTestRepo(object):
self.repodir = repodir
self.repo = git.Repo.init(repodir)
self.patch = mbox.PatchSeries(patch)
- self.current_branch = self.repo.active_branch.name
+
+ if self.repo.head.is_detached:
+ self.current_commit = self.repo.head.commit.hexsha
+ self.current_branch = None
+ else:
+ self.current_branch = self.repo.active_branch.name
# targeted branch defined on the patch may be invalid, so make sure there
# is a corresponding remote branch
@@ -80,6 +85,6 @@ class PatchTestRepo(object):
self._patchmerged = True
def clean(self):
- self.repo.git.execute(['git', 'checkout', self.current_branch])
+ self.repo.git.execute(['git', 'checkout', self.current_branch if self.current_branch else self.current_commit])
self.repo.git.execute(['git', 'branch', '-D', self._workingbranch])
self._patchmerged = False