示例#1
0
def test_run_ns_post_checkout():
    ns = hook_impl._run_ns('post-checkout', True, ('a', 'b', 'c'), b'')
    assert ns is not None
    assert ns.hook_stage == 'post-checkout'
    assert ns.color is True
    assert ns.from_ref == 'a'
    assert ns.to_ref == 'b'
    assert ns.checkout_type == 'c'
示例#2
0
def test_run_ns_pre_push_deleting_branch(push_example):
    src, src_head, clone, _ = push_example

    with cwd(clone):
        args = ('origin', src)
        stdin = f'(delete) {hook_impl.Z40} refs/heads/b {src_head}'.encode()
        ns = hook_impl._run_ns('pre-push', False, args, stdin)

    assert ns is None
示例#3
0
def test_run_ns_pre_push_new_branch_existing_rev(push_example):
    src, src_head, clone, _ = push_example

    with cwd(clone):
        args = ('origin', src)
        stdin = f'HEAD {src_head} refs/heads/b2 {hook_impl.Z40}\n'.encode()
        ns = hook_impl._run_ns('pre-push', False, args, stdin)

    assert ns is None
def test_run_ns_prepare_commit_msg_one_arg():
    ns = hook_impl._run_ns(
        'prepare-commit-msg', False,
        ('.git/COMMIT_MSG',), b'',
    )
    assert ns is not None
    assert ns.hook_stage == 'prepare-commit-msg'
    assert ns.color is False
    assert ns.commit_msg_filename == '.git/COMMIT_MSG'
def test_run_ns_pre_push_ref_with_whitespace(push_example):
    src, src_head, clone, _ = push_example

    with cwd(clone):
        args = ('origin', src)
        line = f'HEAD^{{/ }} {src_head} refs/heads/b2 {hook_impl.Z40}\n'
        stdin = line.encode()
        ns = hook_impl._run_ns('pre-push', False, args, stdin)

    assert ns is None
示例#6
0
def test_run_ns_pre_push_new_branch(push_example):
    src, src_head, clone, clone_head = push_example

    with cwd(clone):
        args = ('origin', src)
        stdin = f'HEAD {clone_head} refs/heads/b {hook_impl.Z40}\n'.encode()
        ns = hook_impl._run_ns('pre-push', False, args, stdin)

    assert ns is not None
    assert ns.from_ref == src_head
    assert ns.to_ref == clone_head
def test_run_ns_prepare_commit_msg_three_arg():
    ns = hook_impl._run_ns(
        'prepare-commit-msg', False,
        ('.git/COMMIT_MSG', 'message', 'HEAD'), b'',
    )
    assert ns is not None
    assert ns.hook_stage == 'prepare-commit-msg'
    assert ns.color is False
    assert ns.commit_msg_filename == '.git/COMMIT_MSG'
    assert ns.prepare_commit_message_source == 'message'
    assert ns.commit_object_name == 'HEAD'
示例#8
0
def test_pushing_orphan_branch(push_example):
    src, src_head, clone, _ = push_example

    cmd_output('git', 'checkout', '--orphan', 'b2', cwd=clone)
    git_commit(cwd=clone, msg='something else to get unique hash')
    clone_rev = git.head_rev(clone)

    with cwd(clone):
        args = ('origin', src)
        stdin = f'HEAD {clone_rev} refs/heads/b2 {hook_impl.Z40}\n'.encode()
        ns = hook_impl._run_ns('pre-push', False, args, stdin)

    assert ns is not None
    assert ns.all_files is True
示例#9
0
def test_run_ns_pre_push_updating_branch(push_example):
    src, src_head, clone, clone_head = push_example

    with cwd(clone):
        args = ('origin', src)
        stdin = f'HEAD {clone_head} refs/heads/b {src_head}\n'.encode()
        ns = hook_impl._run_ns('pre-push', False, args, stdin)

    assert ns is not None
    assert ns.hook_stage == 'push'
    assert ns.color is False
    assert ns.remote_name == 'origin'
    assert ns.remote_url == src
    assert ns.from_ref == src_head
    assert ns.to_ref == clone_head
    assert ns.all_files is False
示例#10
0
def test_run_ns_pre_commit():
    ns = hook_impl._run_ns('pre-commit', True, (), b'')
    assert ns is not None
    assert ns.hook_stage == 'commit'
    assert ns.color is True
示例#11
0
def test_run_ns_post_rewrite():
    ns = hook_impl._run_ns('post-rewrite', True, ('amend', ), b'')
    assert ns is not None
    assert ns.hook_stage == 'post-rewrite'
    assert ns.color is True
    assert ns.rewrite_command == 'amend'
示例#12
0
def test_run_ns_post_merge():
    ns = hook_impl._run_ns('post-merge', True, ('1', ), b'')
    assert ns is not None
    assert ns.hook_stage == 'post-merge'
    assert ns.color is True
    assert ns.is_squash_merge == '1'