How to use the gitlint.git.modified_files function in gitlint

To help you get started, we’ve selected a few gitlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sk- / git-lint / test / unittest / test_git.py View on Github external
def test_modified_files_with_commit(self):
        output = 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
        with mock.patch('subprocess.check_output',
                        return_value=output) as git_call:
            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))
            git_call.assert_called_once_with(
                ['git', 'diff-tree', '-r', '--root', '--no-commit-id',
                 '--name-status', commit])
github sk- / git-lint / test / unittest / test_git.py View on Github external
'M  data/file2.json',
                                  'D  file3.py',
                                  '?? file4.js',
                                  'AM file5.txt',
                                  'MM file6.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/file4.js': '??',
                    '/home/user/repo/file5.txt': 'AM',
                    '/home/user/repo/file6.txt': 'MM',
                },
                git.modified_files('/home/user/repo'))
            git_call.assert_called_once_with([
                'git', 'status', '--porcelain', '--untracked-files=all',
                '--ignore-submodules=all'])
github sk- / git-lint / test / unittest / test_git.py View on Github external
def test_modified_files_non_absolute_root(self):
        with self.assertRaises(AssertionError):
            git.modified_files('foo/bar')
github sk- / git-lint / test / unittest / test_git.py View on Github external
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',
                '--ignore-submodules=all'])
github aosp-mirror / platform_development / tools / checkstyle / checkstyle.py View on Github external
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
github aosp-mirror / platform_development / tools / checkstyle / checkstyle.py View on Github external
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')