@@ -310,19 +310,15 @@ class GitTemporaryHead(object):
310
310
"""
311
311
312
312
def __enter__ (self , git , message ):
313
+ self .git = git
313
314
self .message = message
314
315
self .head_name = git .get_head_refname ()
315
316
return self
316
317
317
318
def __exit__ (self , exc_type , exc_val , exc_tb ):
318
319
if self .head_name :
319
320
try :
320
- check_call ([
321
- 'git' , 'symbolic-ref' ,
322
- '-m' , self .message , 'HEAD' ,
323
- self .head_name ,
324
- ])
325
- check_call (['git' , 'reset' , '--hard' ])
321
+ self .git .restore_head (self .head_name , self .message )
326
322
except CalledProcessError as e :
327
323
raise Failure (
328
324
'Could not restore HEAD to %r!: %s\n '
@@ -989,6 +985,10 @@ class GitRepository(object):
989
985
except CalledProcessError :
990
986
return None
991
987
988
+ def restore_head (self , refname , message ):
989
+ check_call (['git' , 'symbolic-ref' , '-m' , message , 'HEAD' , refname ])
990
+ check_call (['git' , 'reset' , '--hard' ])
991
+
992
992
def checkout (self , refname , quiet = False ):
993
993
cmd = ['git' , 'checkout' ]
994
994
if quiet :
0 commit comments