mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 15:28:28 +01:00
Handle errors when switching branches
This commit is contained in:
@@ -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
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user