summaryrefslogtreecommitdiff
path: root/test/test_git.py
blob: 76eccabfc7c2075694dc3f4ce1283771f91d237e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Test git"""

import re
import pytest


@pytest.mark.usefixtures('ds1_copy')
def test_git(runner, yadm_cmd, paths):
    """Test series of passthrough git commands

    Passthru unknown commands to Git
    Git command 'add' - badfile
    Git command 'add'
    Git command 'status'
    Git command 'commit'
    Git command 'log'
    """

    # passthru unknown commands to Git
    run = runner(command=yadm_cmd('bogus'))
    assert run.failure
    assert "git: 'bogus' is not a git command." in run.err
    assert "See 'git --help'" in run.err
    assert run.out == ''

    # git command 'add' - badfile
    run = runner(command=yadm_cmd('add', '-v', 'does_not_exist'))
    assert run.code == 128
    assert "pathspec 'does_not_exist' did not match any files" in run.err
    assert run.out == ''

    # git command 'add'
    newfile = paths.work.join('test_git')
    newfile.write('test_git')
    run = runner(command=yadm_cmd('add', '-v', str(newfile)))
    assert run.success
    assert run.err == ''
    assert "add 'test_git'" in run.out

    # git command 'status'
    run = runner(command=yadm_cmd('status'))
    assert run.success
    assert run.err == ''
    assert re.search(r'new file:\s+test_git', run.out)

    # git command 'commit'
    run = runner(command=yadm_cmd('commit', '-m', 'Add test_git'))
    assert run.success
    assert run.err == ''
    assert '1 file changed' in run.out
    assert '1 insertion' in run.out
    assert re.search(r'create mode .+ test_git', run.out)

    # git command 'log'
    run = runner(command=yadm_cmd('log', '--oneline'))
    assert run.success
    assert run.err == ''
    assert 'Add test_git' in run.out