forbid-new-submodules: fix triggering failure when only a submodule is committed (without any other file); support --from-ref and --to-ref; fixes #609

This commit is contained in:
Mikhail Khvoinitsky 2021-06-23 03:10:13 +03:00
parent 8c1183c0c8
commit 10c5e4e166
9 changed files with 65 additions and 25 deletions

View file

@ -6,6 +6,7 @@ import pytest
from pre_commit_hooks.check_merge_conflict import main
from pre_commit_hooks.util import cmd_output
from testing.util import get_resource_path
from testing.util import git_commit
@pytest.fixture
@ -20,19 +21,19 @@ def f1_is_a_conflict_file(tmpdir):
with repo1.as_cwd():
repo1_f1.ensure()
cmd_output('git', 'add', '.')
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
git_commit('-m', 'commit1')
cmd_output('git', 'clone', str(repo1), str(repo2))
# Commit in master
with repo1.as_cwd():
repo1_f1.write('parent\n')
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'master commit2')
git_commit('-am', 'master commit2')
# Commit in clone and pull
with repo2.as_cwd():
repo2_f1.write('child\n')
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'clone commit2')
git_commit('-am', 'clone commit2')
cmd_output('git', 'pull', '--no-rebase', retcode=None)
# We should end up in a merge conflict!
f1 = repo2_f1.read()
@ -75,20 +76,20 @@ def repository_pending_merge(tmpdir):
with repo1.as_cwd():
repo1_f1.ensure()
cmd_output('git', 'add', '.')
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
git_commit('-m', 'commit1')
cmd_output('git', 'clone', str(repo1), str(repo2))
# Commit in master
with repo1.as_cwd():
repo1_f1.write('parent\n')
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'master commit2')
git_commit('-am', 'master commit2')
# Commit in clone and pull without committing
with repo2.as_cwd():
repo2_f2.write('child\n')
cmd_output('git', 'add', '.')
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'clone commit2')
git_commit('-m', 'clone commit2')
cmd_output('git', 'pull', '--no-commit', '--no-rebase')
# We should end up in a pending merge
assert repo2_f1.read() == 'parent\n'