mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 21:04:17 +00:00
Increase robustness of tests involving git
1. Disable automatic `git commit` GPG-signing, since that requires interaction. This issue was encountered in practice by me, causing spurious test failures 2. In case path operands could turn out to start with dashes, escape the operand list with '--'.
This commit is contained in:
parent
6b1aa19425
commit
9e89b7616a
4 changed files with 23 additions and 16 deletions
|
|
@ -80,11 +80,18 @@ xfailif_no_gitlfs = pytest.mark.xfail(
|
||||||
def test_allows_gitlfs(temp_git_dir): # pragma: no cover
|
def test_allows_gitlfs(temp_git_dir): # pragma: no cover
|
||||||
with temp_git_dir.as_cwd():
|
with temp_git_dir.as_cwd():
|
||||||
# Work around https://github.com/github/git-lfs/issues/913
|
# Work around https://github.com/github/git-lfs/issues/913
|
||||||
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
|
cmd_output(
|
||||||
|
'git',
|
||||||
|
'commit',
|
||||||
|
'--no-gpg-sign',
|
||||||
|
'--allow-empty',
|
||||||
|
'-m',
|
||||||
|
'foo',
|
||||||
|
)
|
||||||
cmd_output('git', 'lfs', 'install')
|
cmd_output('git', 'lfs', 'install')
|
||||||
temp_git_dir.join('f.py').write('a' * 10000)
|
temp_git_dir.join('f.py').write('a' * 10000)
|
||||||
cmd_output('git', 'lfs', 'track', 'f.py')
|
cmd_output('git', 'lfs', 'track', 'f.py')
|
||||||
cmd_output('git', 'add', '.')
|
cmd_output('git', 'add', '--', '.')
|
||||||
# Should succeed
|
# Should succeed
|
||||||
assert main(('--maxkb', '9', 'f.py')) == 0
|
assert main(('--maxkb', '9', 'f.py')) == 0
|
||||||
|
|
||||||
|
|
@ -96,8 +103,8 @@ def test_moves_with_gitlfs(temp_git_dir): # pragma: no cover
|
||||||
cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
|
cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
|
||||||
# First add the file we're going to move
|
# First add the file we're going to move
|
||||||
temp_git_dir.join('a.bin').write('a' * 10000)
|
temp_git_dir.join('a.bin').write('a' * 10000)
|
||||||
cmd_output('git', 'add', '.')
|
cmd_output('git', 'add', '--', '.')
|
||||||
cmd_output('git', 'commit', '-am', 'foo')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'foo')
|
||||||
# Now move it and make sure the hook still succeeds
|
# Now move it and make sure the hook still succeeds
|
||||||
cmd_output('git', 'mv', 'a.bin', 'b.bin')
|
cmd_output('git', 'mv', 'a.bin', 'b.bin')
|
||||||
assert main(('--maxkb', '9', 'b.bin')) == 0
|
assert main(('--maxkb', '9', 'b.bin')) == 0
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ def test_file_conflicts_with_committed_file(temp_git_dir):
|
||||||
with temp_git_dir.as_cwd():
|
with temp_git_dir.as_cwd():
|
||||||
temp_git_dir.join('f.py').write("print('hello world')")
|
temp_git_dir.join('f.py').write("print('hello world')")
|
||||||
cmd_output('git', 'add', 'f.py')
|
cmd_output('git', 'add', 'f.py')
|
||||||
cmd_output('git', 'commit', '--no-verify', '-m', 'Add f.py')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-n', '-m', 'Add f.py')
|
||||||
|
|
||||||
temp_git_dir.join('F.py').write("print('hello world')")
|
temp_git_dir.join('F.py').write("print('hello world')")
|
||||||
cmd_output('git', 'add', 'F.py')
|
cmd_output('git', 'add', 'F.py')
|
||||||
|
|
|
||||||
|
|
@ -23,23 +23,23 @@ def f1_is_a_conflict_file(tmpdir):
|
||||||
repo2 = tmpdir.join('repo2')
|
repo2 = tmpdir.join('repo2')
|
||||||
repo2_f1 = repo2.join('f1')
|
repo2_f1 = repo2.join('f1')
|
||||||
|
|
||||||
cmd_output('git', 'init', repo1.strpath)
|
cmd_output('git', 'init', '--', repo1.strpath)
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
repo1_f1.ensure()
|
repo1_f1.ensure()
|
||||||
cmd_output('git', 'add', repo1_f1.strpath)
|
cmd_output('git', 'add', '--', repo1_f1.strpath)
|
||||||
cmd_output('git', 'commit', '-m', 'commit1')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
|
||||||
|
|
||||||
cmd_output('git', 'clone', repo1.strpath, repo2.strpath)
|
cmd_output('git', 'clone', repo1.strpath, repo2.strpath)
|
||||||
|
|
||||||
# Commit in master
|
# Commit in master
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
repo1_f1.write('parent\n')
|
repo1_f1.write('parent\n')
|
||||||
cmd_output('git', 'commit', '-am', 'master commit2')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'master commit2')
|
||||||
|
|
||||||
# Commit in clone and pull
|
# Commit in clone and pull
|
||||||
with repo2.as_cwd():
|
with repo2.as_cwd():
|
||||||
repo2_f1.write('child\n')
|
repo2_f1.write('child\n')
|
||||||
cmd_output('git', 'commit', '-am', 'clone commit2')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'clone commit2')
|
||||||
cmd_output('git', 'pull', retcode=None)
|
cmd_output('git', 'pull', retcode=None)
|
||||||
# We should end up in a merge conflict!
|
# We should end up in a merge conflict!
|
||||||
f1 = repo2_f1.read()
|
f1 = repo2_f1.read()
|
||||||
|
|
@ -73,21 +73,21 @@ def repository_is_pending_merge(tmpdir):
|
||||||
cmd_output('git', 'init', repo1.strpath)
|
cmd_output('git', 'init', repo1.strpath)
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
repo1_f1.ensure()
|
repo1_f1.ensure()
|
||||||
cmd_output('git', 'add', repo1_f1.strpath)
|
cmd_output('git', 'add', '--', repo1_f1.strpath)
|
||||||
cmd_output('git', 'commit', '-m' 'commit1')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
|
||||||
|
|
||||||
cmd_output('git', 'clone', repo1.strpath, repo2.strpath)
|
cmd_output('git', 'clone', repo1.strpath, repo2.strpath)
|
||||||
|
|
||||||
# Commit in master
|
# Commit in master
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
repo1_f1.write('parent\n')
|
repo1_f1.write('parent\n')
|
||||||
cmd_output('git', 'commit', '-am', 'master commit2')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'master commit2')
|
||||||
|
|
||||||
# Commit in clone and pull without committing
|
# Commit in clone and pull without committing
|
||||||
with repo2.as_cwd():
|
with repo2.as_cwd():
|
||||||
repo2_f2.write('child\n')
|
repo2_f2.write('child\n')
|
||||||
cmd_output('git', 'add', repo2_f2.strpath)
|
cmd_output('git', 'add', '--', repo2_f2.strpath)
|
||||||
cmd_output('git', 'commit', '-m', 'clone commit2')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'clone commit2')
|
||||||
cmd_output('git', 'pull', '--no-commit')
|
cmd_output('git', 'pull', '--no-commit')
|
||||||
# We should end up in a pending merge
|
# We should end up in a pending merge
|
||||||
assert repo2_f1.read() == 'parent\n'
|
assert repo2_f1.read() == 'parent\n'
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,5 @@ from pre_commit_hooks.util import cmd_output
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def temp_git_dir(tmpdir):
|
def temp_git_dir(tmpdir):
|
||||||
git_dir = tmpdir.join('gits')
|
git_dir = tmpdir.join('gits')
|
||||||
cmd_output('git', 'init', git_dir.strpath)
|
cmd_output('git', 'init', '--', git_dir.strpath)
|
||||||
yield git_dir
|
yield git_dir
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue