Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_repository_root_ok(self):
with mock.patch('subprocess.check_output',
return_value=b'/home/user/repo\n') as git_call:
self.assertEqual('/home/user/repo', git.repository_root())
git_call.asser_called_once_with(
['git', 'rev-parse', '--show-toplevel'])
def test_repository_root_error(self):
with mock.patch('subprocess.check_output',
side_effect=subprocess.CalledProcessError(1, '', '')):
self.assertEqual(None, git.repository_root())
def _GetModifiedFiles(commit, out=sys.stdout):
root = git.repository_root()
pending_files = git.modified_files(root, True)
if pending_files:
out.write(ERROR_UNCOMMITTED)
sys.exit(1)
modified_files = git.modified_files(root, True, commit)
modified_files = {f: modified_files[f] for f
in modified_files if f.endswith('.java')}
return modified_files
def _WarnIfUntrackedFiles(out=sys.stdout):
"""Prints a warning and a list of untracked files if needed."""
root = git.repository_root()
untracked_files = git.modified_files(root, False)
untracked_files = {f for f in untracked_files if f.endswith('.java')}
if untracked_files:
out.write(ERROR_UNTRACKED)
for untracked_file in untracked_files:
out.write(untracked_file + '\n')
out.write('\n')