Handle errors when switching branches

This commit is contained in:
Dmitry
2017-11-19 04:53:14 -08:00
parent 5bd7819a53
commit d64390e9d0
2 changed files with 10 additions and 6 deletions
+8 -4
View File
@@ -2,8 +2,8 @@ from dvc.command.common.common_error import CmdCommonError
class BranchChangerError(CmdCommonError):
def __init__(self, msg):
super(CmdCommonError, self).__init__('DVC locker error: {}'.format(msg))
def __init__(self, branch, msg):
super(CmdCommonError, self).__init__('Error in changing branch \'{}\': {}'.format(branch, msg))
class BranchChanger(object):
@@ -19,9 +19,13 @@ class BranchChanger(object):
def __enter__(self):
if self.perform_action:
self.git.checkout(self.branch, self.create_new)
code, _, err = self.git.checkout(self.branch, self.create_new)
if code != 0:
raise BranchChangerError(self.branch, err)
return self
def __exit__(self, type, value, traceback):
if self.perform_action:
self.git.checkout_previous()
code, _, err = self.git.checkout_previous()
if code != 0:
raise BranchChangerError(self.branch, err)
+2 -2
View File
@@ -321,13 +321,13 @@ class GitWrapper(GitWrapperI):
prefix = '-b ' if create_new else ''
Logger.debug('[dvc-git] Checkout {}{}'.format(prefix, commit_or_branch))
cmd = 'git checkout {}{}'.format(prefix, commit_or_branch)
Executor.exec_cmd(cmd.split())
return Executor.exec_cmd(cmd.split())
@staticmethod
def checkout_previous():
Logger.debug('[dvc-git] Checkout previous')
cmd = 'git checkout -'
Executor.exec_cmd(cmd.split())
return Executor.exec_cmd(cmd.split())
def separate_dependency_files_and_dirs(self, code_dependencies):
code_files = []