# Path: pre_commit_hooks/forbid_new_submodules.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument('filenames', nargs='*')
#     args = parser.parse_args(argv)
# 
#     if (
#         'PRE_COMMIT_FROM_REF' in os.environ and
#         'PRE_COMMIT_TO_REF' in os.environ
#     ):
#         diff_arg = '...'.join((
#             os.environ['PRE_COMMIT_FROM_REF'],
#             os.environ['PRE_COMMIT_TO_REF'],
#         ))
#     else:
#         diff_arg = '--staged'
#     added_diff = cmd_output(
#         'git', 'diff', '--diff-filter=A', '--raw', diff_arg, '--',
#         *args.filenames,
#     )
#     retv = 0
#     for line in added_diff.splitlines():
#         metadata, filename = line.split('\t', 1)
#         new_mode = metadata.split(' ')[1]
#         if new_mode == '160000':
#             print(f'{filename}: new submodule introduced')
#             retv = 1
# 
#     if retv:
#         print()
#         print('This commit introduces new submodules.')
#         print('Did you unintentionally `git add .`?')
#         print('To fix: git rm {thesubmodule}  # no trailing slash')
#         print('Also check .gitmodules')
# 
#     return retv
# 
# Path: testing/util.py
# def git_commit(*args, **kwargs):
#     cmd = ('git', 'commit', '--no-gpg-sign', '--no-verify', '--no-edit', *args)
#     subprocess.check_call(cmd, **kwargs)


import os
import subprocess
import pytest
from unittest import mock
from pre_commit_hooks.forbid_new_submodules import main
from testing.util import git_commit
from __future__ import annotations





@pytest.fixture
def git_dir_with_git_dir(tmpdir):
    with tmpdir.as_cwd():
        subprocess.check_call(('git', 'init', '.'))

# Path: pre_commit_hooks/forbid_new_submodules.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument('filenames', nargs='*')
#     args = parser.parse_args(argv)
# 
#     if (
#         'PRE_COMMIT_FROM_REF' in os.environ and
#         'PRE_COMMIT_TO_REF' in os.environ
#     ):
#         diff_arg = '...'.join((
#             os.environ['PRE_COMMIT_FROM_REF'],
#             os.environ['PRE_COMMIT_TO_REF'],
#         ))
#     else:
#         diff_arg = '--staged'
#     added_diff = cmd_output(
#         'git', 'diff', '--diff-filter=A', '--raw', diff_arg, '--',
#         *args.filenames,
#     )
#     retv = 0
#     for line in added_diff.splitlines():
#         metadata, filename = line.split('\t', 1)
#         new_mode = metadata.split(' ')[1]
#         if new_mode == '160000':
#             print(f'{filename}: new submodule introduced')
#             retv = 1
# 
#     if retv:
#         print()
#         print('This commit introduces new submodules.')
#         print('Did you unintentionally `git add .`?')
#         print('To fix: git rm {thesubmodule}  # no trailing slash')
#         print('Also check .gitmodules')
# 
#     return retv
# 
# Path: testing/util.py
# def git_commit(*args, **kwargs):
#     cmd = ('git', 'commit', '--no-gpg-sign', '--no-verify', '--no-edit', *args)
#     subprocess.check_call(cmd, **kwargs)


# Path: tests/forbid_new_submodules_test.py
import os
import subprocess
import pytest
from unittest import mock
from pre_commit_hooks.forbid_new_submodules import main
from testing.util import git_commit

from __future__ import annotations





@pytest.fixture
def git_dir_with_git_dir(tmpdir):
    with tmpdir.as_cwd():
        subprocess.check_call(('git', 'init', '.'))

        git_commit('--allow-empty', '-m', 'init')