Exemplo n.º 1
0
def test_get_latest_tag_index():
    with GitRepo() as g:
        g.commit("test: test", allow_empty=True)
        g.commit("test: test2", allow_empty=True)
        assert get_latest_tag_index(g.log()) is None
        g.tag("1.0.0")
        assert get_latest_tag_index(g.log()) == 1
Exemplo n.º 2
0
def test_commiting_files(message):
    with GitRepo() as g:
        with open(g.repo_path + "/test", "w") as f:
            f.write("")
        g.add()
        g.commit(message)
        assert g.log()[0]["message"] == message
Exemplo n.º 3
0
def test_log_with_some_commits():
    messages = ("test: test1", "test: test2", "test: test3")
    with GitRepo() as g:
        for m in messages:
            g.commit(m, allow_empty=True)
        log = g.log()
        for i in range(len(messages)):
            assert messages[i] == log[i]["message"]
Exemplo n.º 4
0
def test_inference_with_suffixes():
    with GitRepo() as g:
        g.commit("feat: initial commit", allow_empty=True)
        g.tag("0.1.0rc1")
        g.commit("fix: test", allow_empty=True)
        assert infer_vnext(g.log(), suffix="rc") == "0.1.0rc2"
        g.tag("0.1.0rc2")
        assert infer_vnext(g.log(), suffix="rc") == "0.1.0rc3"
Exemplo n.º 5
0
def test_main_release_tag_no_commit(capsys):
    with GitRepo() as g:
        g.commit("feat: initial commit", allow_empty=True)
        main(["--repo-path", g.repo_path, "--tag"])
        c = capsys.readouterr()
        assert c.out == "0.1.0\n"
        assert g.log()[0]["message"] == "feat: initial commit"
        assert g.log()[0]["tag"] == "v0.1.0"
Exemplo n.º 6
0
def test_infers_major_bump_correctly():
    with GitRepo() as g:
        g.commit("feat: initial commit", allow_empty=True)
        g.tag("1.1.0")
        g.commit("feat: breaking\nBREAKING CHANGE: breaking", allow_empty=True)
        assert infer_vnext(g.log()) == SemVer(2, 0, 0)
        g.tag("2.0.0")
        g.commit("feat: test\nBREAKING CHANGE: test", allow_empty=True)
        assert infer_vnext(g.log()) == SemVer(3, 0, 0)
Exemplo n.º 7
0
def test_infers_micro_bump_correctly():
    with GitRepo() as g:
        g.commit("feat: initial commit", allow_empty=True)
        g.tag("0.1.0")
        assert infer_vnext(g.log()) == SemVer(0, 1, 1)
        g.commit("chore: test", allow_empty=True)
        g.tag("0.1.1")
        g.commit("fix: test", allow_empty=True)
        assert infer_vnext(g.log()) == SemVer(0, 1, 2)
Exemplo n.º 8
0
def test_tagging():
    with GitRepo() as g:
        g.commit("test: test", allow_empty=True)
        g.commit("test: test2", allow_empty=True)
        g.commit("test: test3", allow_empty=True)
        g.tag("1.0.0")
        log = g.log()[2]
        assert log["message"] == "test: test3" and log["tag"] == "1.0.0"
        g.commit("test: test4", allow_empty=True)
        log = g.log()[3]
        assert log["message"] == "test: test4" and "tag" not in log.keys()
Exemplo n.º 9
0
def test_infers_first_version(suffix, suffix_dot_suffix, suffix_dash_prefix,
                              semver):
    with GitRepo() as g:
        g.commit("test: test", allow_empty=True)
        g.commit("feat: test2", allow_empty=True)
        g.commit("feat: test3\nBREAKING CHANGE: test", allow_empty=True)
        assert (infer_vnext(
            g.log(),
            suffix=suffix,
            suffix_dot_suffix=suffix_dot_suffix,
            suffix_dash_prefix=suffix_dash_prefix,
        ) == semver)
Exemplo n.º 10
0
def main(args=sys.argv[1:]):
    a = parse_args(args)

    if a.version:
        print(__version__)
        sys.exit(0)

    g = GitRepo(a.repo_path)

    if len(g.log()) == 0:
        raise ValueError(f"No commits found in git repo at {a.repo_path}.")

    vnext = infer_vnext(
        g.log(),
        suffix=a.prerelease_suffix,
        suffix_dash_prefix=a.suffix_dash_prefix,
        suffix_dot_suffix=a.suffix_dot_suffix,
    )
    print(vnext)
    if a.commit:
        g.commit(f"release: {vnext}", allow_empty=True)
    if a.tag:
        g.tag(f"v{vnext}")
Exemplo n.º 11
0
def test_gitrepo_as_context_manager_leaves_no_residue():
    with GitRepo() as g:
        r = g.repo_path
        assert os.path.exists(r)
    assert not os.path.exists(r)
Exemplo n.º 12
0
def test_main_with_empty_repo():
    with GitRepo() as g:
        with pytest.raises(ValueError):
            main(["--repo-path", g.repo_path])
Exemplo n.º 13
0
def test_commiting(message):
    with GitRepo() as g:
        g.commit(message, allow_empty=True)
        assert g.log()[0]["message"] == message
Exemplo n.º 14
0
def test_main_first_version(capsys):
    with GitRepo() as g:
        g.commit("feat: initial commit", allow_empty=True)
        main(["--repo-path", g.repo_path])
    c = capsys.readouterr()
    assert c.out == "0.1.0\n"
Exemplo n.º 15
0
def test_log_on_empty_repo():
    with GitRepo() as g:
        g.log() == ()
Exemplo n.º 16
0
def test_gitrepo_custom_path():
    with TemporaryDirectory() as t:
        g = GitRepo(t)
        assert g.git("status").returncode == 0
Exemplo n.º 17
0
def test_gitrepo_is_actually_a_git_repo():
    with GitRepo() as g:
        assert g.git("status").returncode == 0
Exemplo n.º 18
0
def test_main_first_version_with_suffix(capsys):
    with GitRepo() as g:
        g.commit("feat: initial commit", allow_empty=True)
        main(["--repo-path", g.repo_path, "--prerelease-suffix", "rc"])
    c = capsys.readouterr()
    assert c.out == "0.1.0rc1\n"
Exemplo n.º 19
0
def test_version_inference_with_non_cc_commit_msg():
    with GitRepo() as g:
        g.commit("test", allow_empty=True)
        g.tag("v0.1.0")
        g.commit("test2", allow_empty=True)
        assert infer_vnext(g.log()) == "0.1.1"
Exemplo n.º 20
0
def test_version_inference_with_default_v_prefix():
    with GitRepo() as g:
        g.commit("feat: test", allow_empty=True)
        main(["--repo-path", g.repo_path, "--tag"])
        g.commit("fix: test", allow_empty=True)
        assert infer_vnext(g.log()) == "0.1.1"