Example #1
0
def _GetModifiedFiles(commit, explicit_commit=False, out=sys.stdout):
  root = git.repository_root()
  pending_files = git.modified_files(root, True)
  if pending_files and not explicit_commit:
    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 _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
Example #3
0
 def test_modified_files_nothing_changed(self):
     output = b''
     with mock.patch('subprocess.check_output',
                     return_value=output) as git_call:
         self.assertEqual({}, git.modified_files('/home/user/repo'))
         git_call.assert_called_once_with(
             ['git', 'status', '--porcelain', '--untracked-files=all'])
Example #4
0
 def test_modified_files_nothing_changed(self):
     output = b''
     with mock.patch('subprocess.check_output',
                     return_value=output) as git_call:
         self.assertEqual({}, git.modified_files('/home/user/repo'))
         git_call.assert_called_once_with(
             ['git', 'status', '--porcelain', '--untracked-files=all'])
Example #5
0
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')
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')
Example #7
0
 def test_modified_files_with_spaces(self):
     output = os.linesep.join(['A  "docs/file 1.txt"',
                               'M  "data/file 2.json"']).encode('utf-8')
     with mock.patch('subprocess.check_output',
                     return_value=output) as git_call:
         self.assertEqual(
             {'/home/user/repo/docs/file 1.txt': 'A ',
              '/home/user/repo/data/file 2.json': 'M '},
             git.modified_files('/home/user/repo'))
         git_call.assert_called_once_with(
             ['git', 'status', '--porcelain', '--untracked-files=all'])
Example #8
0
    def test_modified_files_with_spaces(self, check_output):
        check_output.return_value = os.linesep.join(
            ['A  "docs/file 1.txt"', 'M  "data/file 2.json"']).encode('utf-8')

        self.assertEqual({
            '/home/user/repo/docs/file 1.txt': 'A ',
            '/home/user/repo/data/file 2.json': 'M '
        }, git.modified_files('/home/user/repo'))
        check_output.assert_called_once_with([
            'git', 'status', '--porcelain', '--untracked-files=all',
            '--ignore-submodules=all'
        ])
Example #9
0
 def test_modified_files_with_spaces(self):
     output = os.linesep.join(
         ['A  "docs/file 1.txt"', 'M  "data/file 2.json"']).encode('utf-8')
     with mock.patch('subprocess.check_output',
                     return_value=output) as git_call:
         self.assertEqual(
             {
                 '/home/user/repo/docs/file 1.txt': 'A ',
                 '/home/user/repo/data/file 2.json': 'M '
             }, git.modified_files('/home/user/repo'))
         git_call.assert_called_once_with(
             ['git', 'status', '--porcelain', '--untracked-files=all'])
Example #10
0
    def test_modified_files_with_spaces(self, check_output):
        check_output.return_value = os.linesep.join(
            ['A  "docs/file 1.txt"', 'M  "data/file 2.json"']).encode('utf-8')

        self.assertEqual(
            {
                '/home/user/repo/docs/file 1.txt': 'A ',
                '/home/user/repo/data/file 2.json': 'M '
            }, git.modified_files('/home/user/repo'))
        check_output.assert_called_once_with([
            'git', 'status', '--porcelain', '--untracked-files=all',
            '--ignore-submodules=all'
        ])
Example #11
0
 def test_modified_files_tracked_only(self):
     output = os.linesep.join([
         'A  docs/file1.txt', 'M  data/file2.json', 'D  file3.py',
         '?? file4.js', 'AM file5.txt'
     ]).encode('utf-8')
     with mock.patch('subprocess.check_output',
                     return_value=output) as git_call:
         self.assertEqual(
             {
                 '/home/user/repo/docs/file1.txt': 'A ',
                 '/home/user/repo/data/file2.json': 'M ',
                 '/home/user/repo/file5.txt': 'AM'
             }, git.modified_files('/home/user/repo', tracked_only=True))
         git_call.assert_called_once_with(
             ['git', 'status', '--porcelain', '--untracked-files=all'])
Example #12
0
 def test_modified_files_tracked_only(self):
     output = os.linesep.join(['A  docs/file1.txt',
                               'M  data/file2.json',
                               'D  file3.py',
                               '?? file4.js',
                               'AM file5.txt']).encode('utf-8')
     with mock.patch('subprocess.check_output',
                     return_value=output) as git_call:
         self.assertEqual(
             {'/home/user/repo/docs/file1.txt': 'A ',
              '/home/user/repo/data/file2.json': 'M ',
              '/home/user/repo/file5.txt': 'AM'},
             git.modified_files('/home/user/repo', tracked_only=True))
         git_call.assert_called_once_with(
             ['git', 'status', '--porcelain', '--untracked-files=all'])
Example #13
0
    def test_modified_files_tracked_only(self, check_output):
        check_output.return_value = os.linesep.join([
            'A  docs/file1.txt', 'M  data/file2.json', 'D  file3.py',
            '?? file4.js', 'AM file5.txt'
        ]).encode('utf-8')

        self.assertEqual({
            '/home/user/repo/docs/file1.txt': 'A ',
            '/home/user/repo/data/file2.json': 'M ',
            '/home/user/repo/file5.txt': 'AM'
        }, git.modified_files('/home/user/repo', tracked_only=True))
        check_output.assert_called_once_with([
            'git', 'status', '--porcelain', '--untracked-files=all',
            '--ignore-submodules=all'
        ])
Example #14
0
    def test_modified_files_tracked_only(self, check_output):
        check_output.return_value = os.linesep.join([
            'A  docs/file1.txt', 'M  data/file2.json', 'D  file3.py',
            '?? file4.js', 'AM file5.txt'
        ]).encode('utf-8')

        self.assertEqual(
            {
                '/home/user/repo/docs/file1.txt': 'A ',
                '/home/user/repo/data/file2.json': 'M ',
                '/home/user/repo/file5.txt': 'AM'
            }, git.modified_files('/home/user/repo', tracked_only=True))
        check_output.assert_called_once_with([
            'git', 'status', '--porcelain', '--untracked-files=all',
            '--ignore-submodules=all'
        ])
Example #15
0
    def test_modified_files_with_commit(self, check_output):
        check_output.return_value = os.linesep.join([
            'M\ttest/e2etest/data/bash/error.sh',
            'D\ttest/e2etest/data/ruby/error.rb',
            'A\ttest/e2etest/data/rubylint/error.rb',
            '',
        ]).encode('utf-8')
        commit = '0a' * 20

        self.assertEqual(
            {
                '/home/user/repo/test/e2etest/data/bash/error.sh': 'M ',
                '/home/user/repo/test/e2etest/data/rubylint/error.rb': 'A ',
            }, git.modified_files('/home/user/repo', commit=commit))
        check_output.assert_called_once_with([
            'git', 'diff-tree', '-r', '--root', '--no-commit-id',
            '--name-status', commit
        ])
Example #16
0
    def test_modified_files_with_commit(self, check_output):
        check_output.return_value = os.linesep.join([
            'M\ttest/e2etest/data/bash/error.sh',
            'D\ttest/e2etest/data/ruby/error.rb',
            'A\ttest/e2etest/data/rubylint/error.rb',
            '',
        ]).encode('utf-8')
        commit = '0a' * 20

        self.assertEqual(
            {
                '/home/user/repo/test/e2etest/data/bash/error.sh': 'M ',
                '/home/user/repo/test/e2etest/data/rubylint/error.rb': 'A ',
            }, git.modified_files('/home/user/repo', commit=commit))
        check_output.assert_called_once_with([
            'git', 'diff-tree', '-r', '--root', '--no-commit-id',
            '--name-status', commit
        ])
Example #17
0
 def test_modified_files_nothing_changed(self, check_output):
     self.assertEqual({}, git.modified_files('/home/user/repo'))
     check_output.assert_called_once_with([
         'git', 'status', '--porcelain', '--untracked-files=all',
         '--ignore-submodules=all'
     ])
Example #18
0
 def test_modified_files_non_absolute_root(self):
     with self.assertRaises(AssertionError):
         git.modified_files('foo/bar')
Example #19
0
 def test_modified_files_non_absolute_root(self):
     with self.assertRaises(AssertionError):
         git.modified_files('foo/bar')
Example #20
0
 def test_modified_files_nothing_changed(self, check_output):
     self.assertEqual({}, git.modified_files('/home/user/repo'))
     check_output.assert_called_once_with([
         'git', 'status', '--porcelain', '--untracked-files=all',
         '--ignore-submodules=all'
     ])