def repository_is_pending_merge(in_tmpdir):
    # Make a (non-conflicting) merge
    cmd_output('git', 'init', 'repo1')
    with cwd('repo1'):
        io.open('f1', 'w').close()
        cmd_output('git', 'add', 'f1')
        cmd_output('git', 'commit', '-m' 'commit1')

    cmd_output('git', 'clone', 'repo1', 'repo2')

    # Commit in master
    with cwd('repo1'):
        write_file('f1', 'parent\n')
        cmd_output('git', 'commit', '-am', 'master commit2')

    # Commit in clone and pull without committing
    with cwd('repo2'):
        write_file('f2', 'child\n')
        cmd_output('git', 'add', 'f2')
        cmd_output('git', 'commit', '-m', 'clone commit2')
        cmd_output('git', 'pull', '--no-commit')
        # We should end up in a pending merge
        assert io.open('f1').read().startswith('parent\n')
        assert io.open('f2').read().startswith('child\n')
        assert os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
        yield
def test_added_file_not_in_pre_commits_list(temp_git_dir):
    with local.cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        local['git']('add', 'f.py')

        # Should pass even with a size of 0
        assert find_large_added_files(['g.py'], 0) == 0
def repository_is_pending_merge(in_tmpdir):
    # Make a (non-conflicting) merge
    cmd_output('git', 'init', 'repo1')
    with cwd('repo1'):
        io.open('f1', 'w').close()
        cmd_output('git', 'add', 'f1')
        cmd_output('git', 'commit', '-m' 'commit1')

    cmd_output('git', 'clone', 'repo1', 'repo2')

    # Commit in master
    with cwd('repo1'):
        write_file('f1', 'parent\n')
        cmd_output('git', 'commit', '-am', 'master commit2')

    # Commit in clone and pull without committing
    with cwd('repo2'):
        write_file('f2', 'child\n')
        cmd_output('git', 'add', 'f2')
        cmd_output('git', 'commit', '-m', 'clone commit2')
        cmd_output('git', 'pull', '--no-commit')
        # We should end up in a pending merge
        assert io.open('f1').read().startswith('parent\n')
        assert io.open('f2').read().startswith('child\n')
        assert os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
        yield
def test_adding_something(temp_git_dir):
    with local.cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        local['git']('add', 'f.py')

        # Should fail with max size of 0
        assert find_large_added_files(['f.py'], 0) == 1
def test_adding_something(temp_git_dir):
    with cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        cmd_output('git', 'add', 'f.py')

        # Should fail with max size of 0
        assert find_large_added_files(['f.py'], 0) == 1
def f1_is_a_conflict_file(in_tmpdir):
    # Make a merge conflict
    cmd_output('git', 'init', 'repo1')
    with cwd('repo1'):
        io.open('f1', 'w').close()
        cmd_output('git', 'add', 'f1')
        cmd_output('git', 'commit', '-m' 'commit1')

    cmd_output('git', 'clone', 'repo1', 'repo2')

    # Commit in master
    with cwd('repo1'):
        write_file('f1', 'parent\n')
        cmd_output('git', 'commit', '-am', 'master commit2')

    # Commit in clone and pull
    with cwd('repo2'):
        write_file('f1', 'child\n')
        cmd_output('git', 'commit', '-am', 'clone commit2')
        cmd_output('git', 'pull', retcode=None)
        # We should end up in a merge conflict!
        assert io.open('f1').read().startswith(
            '<<<<<<< HEAD\n'
            'child\n'
            '=======\n'
            'parent\n'
            '>>>>>>>'
        )
        assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
        yield
def test_added_file_not_in_pre_commits_list(temp_git_dir):
    with cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        cmd_output('git', 'add', 'f.py')

        # Should pass even with a size of 0
        assert find_large_added_files(['g.py'], 0) == 0
def f1_is_a_conflict_file(in_tmpdir):
    # Make a merge conflict
    cmd_output('git', 'init', 'repo1')
    with cwd('repo1'):
        io.open('f1', 'w').close()
        cmd_output('git', 'add', 'f1')
        cmd_output('git', 'commit', '-m' 'commit1')

    cmd_output('git', 'clone', 'repo1', 'repo2')

    # Commit in master
    with cwd('repo1'):
        write_file('f1', 'parent\n')
        cmd_output('git', 'commit', '-am', 'master commit2')

    # Commit in clone and pull
    with cwd('repo2'):
        write_file('f1', 'child\n')
        cmd_output('git', 'commit', '-am', 'clone commit2')
        cmd_output('git', 'pull', retcode=None)
        # We should end up in a merge conflict!
        assert io.open('f1').read().startswith('<<<<<<< HEAD\n'
                                               'child\n'
                                               '=======\n'
                                               'parent\n'
                                               '>>>>>>>')
        assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
        yield
def test_adding_something_with_conflict(temp_git_dir):
    with local.cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        local['git']('add', 'f.py')
        write_file('F.py', "print('hello world')")
        local['git']('add', 'F.py')

        assert find_conflicting_filenames(['f.py', 'F.py']) == 1
def test_file_conflicts_with_committed_file(temp_git_dir):
    with local.cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        local['git']('add', 'f.py')
        local['git']('commit', '--no-verify', '-m', 'Add f.py')

        write_file('F.py', "print('hello world')")
        local['git']('add', 'F.py')

        assert find_conflicting_filenames(['F.py']) == 1
def test_allows_gitlfs(temp_git_dir):  # pragma: no cover
    with cwd(temp_git_dir):
        # Work around https://github.com/github/git-lfs/issues/913
        cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
        cmd_output('git', 'lfs', 'install')
        write_file('f.py', 'a' * 10000)
        cmd_output('git', 'lfs', 'track', 'f.py')
        cmd_output('git', 'add', '.')
        # Should succeed
        assert main(('--maxkb', '9', 'f.py')) == 0
def test_allows_gitlfs(temp_git_dir):  # pragma: no cover
    with cwd(temp_git_dir):
        # Work around https://github.com/github/git-lfs/issues/913
        cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
        cmd_output('git', 'lfs', 'install')
        write_file('f.py', 'a' * 10000)
        cmd_output('git', 'lfs', 'track', 'f.py')
        cmd_output('git', 'add', '.')
        # Should succeed
        assert main(('--maxkb', '9', 'f.py')) == 0
def test_moves_with_gitlfs(temp_git_dir):  # pragma: no cover
    with cwd(temp_git_dir):
        cmd_output('git', 'lfs', 'install')
        cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
        # First add the file we're going to move
        write_file('a.bin', 'a' * 10000)
        cmd_output('git', 'add', '.')
        cmd_output('git', 'commit', '-am', 'foo')
        # Now move it and make sure the hook still succeeds
        cmd_output('git', 'mv', 'a.bin', 'b.bin')
        assert main(('--maxkb', '9', 'b.bin')) == 0
def test_moves_with_gitlfs(temp_git_dir):  # pragma: no cover
    with cwd(temp_git_dir):
        cmd_output('git', 'lfs', 'install')
        cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
        # First add the file we're going to move
        write_file('a.bin', 'a' * 10000)
        cmd_output('git', 'add', '.')
        cmd_output('git', 'commit', '-am', 'foo')
        # Now move it and make sure the hook still succeeds
        cmd_output('git', 'mv', 'a.bin', 'b.bin')
        assert main(('--maxkb', '9', 'b.bin')) == 0
def test_integration(temp_git_dir):
    with local.cwd(temp_git_dir):
        assert main(argv=[]) == 0

        write_file('f.py', 'a' * 10000)
        local['git']('add', 'f.py')

        # Should not fail with default
        assert main(argv=['f.py']) == 0

        # Should fail with --maxkb
        assert main(argv=['--maxkb', '9', 'f.py']) == 1
def test_integration(temp_git_dir):
    with cwd(temp_git_dir):
        assert main(argv=[]) == 0

        write_file('f.py', 'a' * 10000)
        cmd_output('git', 'add', 'f.py')

        # Should not fail with default
        assert main(argv=['f.py']) == 0

        # Should fail with --maxkb
        assert main(argv=['--maxkb', '9', 'f.py']) == 1
def test_integration(temp_git_dir):
    with cwd(temp_git_dir):
        assert main(argv=[]) == 0

        write_file('f.py', "print('hello world')")
        cmd_output('git', 'add', 'f.py')

        assert main(argv=['f.py']) == 0

        write_file('F.py', "print('hello world')")
        cmd_output('git', 'add', 'F.py')

        assert main(argv=['F.py']) == 1
def test_integration(temp_git_dir):
    with local.cwd(temp_git_dir):
        assert main(argv=[]) == 0

        write_file('f.py', "print('hello world')")
        local['git']('add', 'f.py')

        assert main(argv=['f.py']) == 0

        write_file('F.py', "print('hello world')")
        local['git']('add', 'F.py')

        assert main(argv=['F.py']) == 1
def test_add_something_giant(temp_git_dir):
    with cwd(temp_git_dir):
        write_file('f.py', 'a' * 10000)

        # Should not fail when not added
        assert find_large_added_files(['f.py'], 0) == 0

        cmd_output('git', 'add', 'f.py')

        # Should fail with strict bound
        assert find_large_added_files(['f.py'], 0) == 1

        # Should also fail with actual bound
        assert find_large_added_files(['f.py'], 9) == 1

        # Should pass with higher bound
        assert find_large_added_files(['f.py'], 10) == 0
def test_add_something_giant(temp_git_dir):
    with local.cwd(temp_git_dir):
        write_file('f.py', 'a' * 10000)

        # Should not fail when not added
        assert find_large_added_files(['f.py'], 0) == 0

        local['git']('add', 'f.py')

        # Should fail with strict bound
        assert find_large_added_files(['f.py'], 0) == 1

        # Should also fail with actual bound
        assert find_large_added_files(['f.py'], 9) == 1

        # Should pass with higher bound
        assert find_large_added_files(['f.py'], 10) == 0
Example #21
0
def test_merge_conflicts_ok(ok_contents):
    write_file('f1', ok_contents)
    assert detect_merge_conflict(['f1']) == 0
Example #22
0
def test_merge_conflicts_failing(failing_contents):
    write_file('f2', failing_contents)
    assert detect_merge_conflict(['f2']) == 1
def test_adding_something(temp_git_dir):
    with cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        cmd_output('git', 'add', 'f.py')

        assert find_conflicting_filenames(['f.py']) == 0
def test_added_file_not_in_pre_commits_list(temp_git_dir):
    with local.cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        local['git']('add', 'f.py')

        assert find_conflicting_filenames(['g.py']) == 0
def test_merge_conflicts_failing(failing_contents):
    write_file('f2', failing_contents)
    assert detect_merge_conflict(['f2']) == 1
def test_merge_conflicts_ok(ok_contents):
    write_file('f1', ok_contents)
    assert detect_merge_conflict(['f1']) == 0