mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-27 07:18:28 +01:00
+30
-16
@@ -35,9 +35,11 @@ class GitWrapperI(object):
|
||||
|
||||
@staticmethod
|
||||
def git_file_statuses():
|
||||
Logger.debug('[Git] Getting file statuses. Command: git status --porcelain')
|
||||
code, out, err = Executor.exec_cmd(['git', 'status', '--porcelain'])
|
||||
if code != 0:
|
||||
raise ExecutorError('Git command error - {}'.format(err))
|
||||
raise ExecutorError('[Git] File status command error - {}'.format(err))
|
||||
Logger.debug('[Git] Getting file statuses. Success.')
|
||||
|
||||
return GitWrapper.parse_porcelain_files(out)
|
||||
|
||||
@@ -67,8 +69,8 @@ class GitWrapper(GitWrapperI):
|
||||
def is_ready_to_go(self):
|
||||
statuses = self.git_file_statuses()
|
||||
if len(statuses) > 0:
|
||||
Logger.error('Commit all changed files before running reproducible command.')
|
||||
Logger.error('Changed files:')
|
||||
Logger.error('[Git] Commit all changed files before running reproducible command.')
|
||||
Logger.error('[Git] Changed files:')
|
||||
for status, file in statuses:
|
||||
Logger.error("{} {}".format(status, file))
|
||||
return False
|
||||
@@ -85,10 +87,12 @@ class GitWrapper(GitWrapperI):
|
||||
return self._git_dir
|
||||
|
||||
try:
|
||||
Logger.debug('[Git] Getting git directory. Command: git rev-parse --show-toplevel')
|
||||
code, out, err = Executor.exec_cmd(['git', 'rev-parse', '--show-toplevel'])
|
||||
|
||||
if code != 0:
|
||||
raise ExecutorError('Git command error - {}'.format(err))
|
||||
raise ExecutorError('[Git] Git directory command error - {}'.format(err))
|
||||
Logger.debug('[Git] Getting git directory. Success.')
|
||||
|
||||
self._git_dir = out
|
||||
return self._git_dir
|
||||
@@ -100,25 +104,32 @@ class GitWrapper(GitWrapperI):
|
||||
|
||||
@property
|
||||
def curr_commit(self):
|
||||
if self._commit is None:
|
||||
code, out, err = Executor.exec_cmd(['git', 'rev-parse', '--short', 'HEAD'])
|
||||
if code != 0:
|
||||
raise ExecutorError('Git command error - {}'.format(err))
|
||||
self._commit = out
|
||||
return self._commit
|
||||
Logger.debug('[Git] Getting current git commit. Command: git rev-parse --short HEAD')
|
||||
|
||||
code, out, err = Executor.exec_cmd(['git', 'rev-parse', '--short', 'HEAD'])
|
||||
if code != 0:
|
||||
raise ExecutorError('[Git] Commit command error - {}'.format(err))
|
||||
Logger.debug('[Git] Getting current git commit. Success.')
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def commit_all_changes(message):
|
||||
Logger.debug('[Git] Commit all changes. Commands: {} && {} && {}'.format(
|
||||
'git add --all', 'git status --porcelain', 'git commit -m'))
|
||||
|
||||
Executor.exec_cmd_only_success(['git', 'add', '--all'])
|
||||
out_status = Executor.exec_cmd_only_success(['git', 'status', '--porcelain'])
|
||||
Executor.exec_cmd_only_success(['git', 'commit', '-m', message])
|
||||
Logger.debug('[Git] Commit all changes. Success.')
|
||||
|
||||
return GitWrapper.parse_porcelain_files(out_status)
|
||||
|
||||
def commit_all_changes_and_log_status(self, message):
|
||||
statuses = self.commit_all_changes(message)
|
||||
Logger.printing('A new commit {} was made in the current branch. Added files:'.format(self.curr_commit))
|
||||
Logger.debug('[Git] A new commit {} was made in the current branch. Added files:'.format(
|
||||
self.curr_commit))
|
||||
for status, file in statuses:
|
||||
Logger.printing('\t{} {}'.format(status, file))
|
||||
Logger.debug('[Git]\t{} {}'.format(status, file))
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
@@ -139,18 +150,21 @@ class GitWrapper(GitWrapperI):
|
||||
|
||||
return results
|
||||
|
||||
def were_files_changed(self, file, code_dependencies):
|
||||
def were_files_changed(self, file, code_dependencies, path_factory):
|
||||
Logger.debug('[Git] Identify changes. Commands: {} {} && {}'.format(
|
||||
'git log -1 --pretty=format:"%h"', file, 'git diff --name-only HEAD *'))
|
||||
|
||||
commit = Executor.exec_cmd_only_success(['git', 'log', '-1', '--pretty=format:"%h"', file])
|
||||
commit = commit.strip('"')
|
||||
|
||||
Logger.debug('[Git] Identify changes. Success.')
|
||||
|
||||
changed_files = Executor.exec_cmd_only_success(['git', 'diff', '--name-only', 'HEAD', commit])
|
||||
changed_files = changed_files.strip('"')
|
||||
|
||||
code_files, code_dirs = self.separate_dependency_files_and_dirs(code_dependencies)
|
||||
|
||||
code_files_set = set(code_files)
|
||||
code_files_set = set([path_factory.path(x).dvc for x in code_files])
|
||||
for changed_file in changed_files.split('\n'):
|
||||
changed_file = os.path.realpath(changed_file)
|
||||
if changed_file in code_files_set:
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user