Beispiel #1
0
def test_archive(tmpdir, Jagare):
    path = tmpdir.strpath
    temp_repo.create_temp_repo(path, is_bare=True)

    stdout = Jagare.archive(path, prefix='test', ref='master')

    assert stdout
Beispiel #2
0
def test_show_commit(tmpdir, Jagare):
    path = tmpdir.strpath
    temp_repo.create_temp_repo(path, is_bare=True)

    ret = Jagare.show(path, 'master')

    assert ret.commit
    assert ret.commit.sha
Beispiel #3
0
def test_ls_tree(tmpdir, Jagare):
    path = tmpdir.strpath
    temp_repo.create_temp_repo(path, is_bare=True)
    ret = Jagare.ls_tree(path, ref='master', req_path=None,
                         recursive=None, with_size=None, with_commit=None,
                         name_only=None)

    assert ret
Beispiel #4
0
def test_diff(tmpdir, Jagare):
    path = tmpdir.strpath

    temp_repo.create_temp_repo(path, is_bare=True)
    diff = Jagare.diff(path, ref='master', from_ref=None, ignore_space=None,
                       flags=None, context_lines=None, paths=None,
                       rename_detection=None)

    assert diff.patches[0].hunks[0].lines[0].attr == '+'
    assert diff.patch
Beispiel #5
0
def test_ls_tree(tmpdir, Jagare):
    path = tmpdir.strpath
    temp_repo.create_temp_repo(path, is_bare=True)
    ret = Jagare.ls_tree(path,
                         ref='master',
                         req_path=None,
                         recursive=None,
                         with_size=None,
                         with_commit=None,
                         name_only=None)

    assert ret
Beispiel #6
0
def test_diff(tmpdir, Jagare):
    path = tmpdir.strpath

    temp_repo.create_temp_repo(path, is_bare=True)
    diff = Jagare.diff(path,
                       ref='master',
                       from_ref=None,
                       ignore_space=None,
                       flags=None,
                       context_lines=None,
                       paths=None,
                       rename_detection=None)

    assert diff.patches[0].hunks[0].lines[0].attr == '+'
    assert diff.patch
Beispiel #7
0
def test_merge_flow(tmpdir, no_ff, Jagare):
    path = tmpdir.mkdir('to').strpath
    from_repo_path = tmpdir.mkdir('from').strpath

    BR = 'br_test_merge'

    repo = temp_repo.create_temp_repo(path, is_bare=True)
    from_repo = repo.clone(from_repo_path, branch='master',
                           bare=True)

    # commit more things to from_repo:BR
    ret = from_repo.create_branch(BR, 'master')
    assert ret is True
    temp_repo.commit_something(from_repo_path, branch=BR)

    # different repo: from -> to
    sha = Jagare.merge_flow(path, 'lh', '*****@*****.**',
                            'test_header', 'test_body',
                            from_repo_path, BR, 'master',
                            remote_name='hub/xxxproject', no_ff=no_ff)
    assert sha

    # same repo: from -> from
    sha = Jagare.merge_flow(from_repo_path, 'lh', '*****@*****.**',
                            'test_header', 'test_body',
                            from_repo_path, BR, 'master',
                            remote_name=None, no_ff=True)
    assert sha
Beispiel #8
0
def test_format_patch(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)

    t_patch = t_repo.format_patch(ref='master')
    patch = Jagare.format_patch(path, ref='master', from_ref=None)
    assert patch == t_patch
Beispiel #9
0
def test_resolve_commit(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)

    t_sha = t_repo.resolve_commit('master')
    sha = Jagare.resolve_commit(path, 'master')

    assert sha == t_sha
Beispiel #10
0
def test_detect_renamed(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)

    # FIXME: test case too weak

    new_to_old = t_repo.detect_renamed(ref='master')
    ret = Jagare.detect_renamed(path, ref='master')
    assert ret == new_to_old
Beispiel #11
0
    def test_create_temp_repo(self):
        tempdir = self.get_temp_path()
        repo = create_temp_repo(tempdir, is_bare=True)
        assert repo

        repo2 = Jagare(tempdir)
        assert repo == repo2
        assert repo2.bare is True
        assert repo2.empty is False
Beispiel #12
0
def test_merge_base(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)

    to_sha = from_sha = t_repo.sha('master')
    t_oid = t_repo.merge_base(to_sha, from_sha)
    sha = Jagare.merge_base(path, to_sha, from_sha)

    assert sha == t_oid.hex
Beispiel #13
0
def test_merge_base(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)

    to_sha = from_sha = t_repo.sha('master')
    t_oid = t_repo.merge_base(to_sha, from_sha)
    sha = Jagare.merge_base(path, to_sha, from_sha)

    assert sha == t_oid.hex
Beispiel #14
0
    def test_create_temp_repo(self):
        tempdir = self.get_temp_path()
        repo = create_temp_repo(tempdir, is_bare=True)
        assert repo

        repo2 = Jagare(tempdir)
        assert repo == repo2
        assert repo2.bare is True
        assert repo2.empty is False
Beispiel #15
0
def test_get(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)
    repo = Jagare.get(path)

    assert repo.path.rstrip('/') == path
    assert repo.is_bare is True
    assert repo.is_empty is False
    assert repo.workdir is None
    assert repo.head == t_repo.head.name
Beispiel #16
0
def test_create_branch(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)

    TEST_CREATE_BRANCH = 'br_test_create_branch'

    ret = Jagare.create_branch(path, name=TEST_CREATE_BRANCH,
                               ref='master', force=False)

    assert ret is True
    assert TEST_CREATE_BRANCH in t_repo.branches
Beispiel #17
0
def test_blame(tmpdir, Jagare):
    path = tmpdir.strpath
    repo = temp_repo.create_temp_repo(path, is_bare=True)

    blobs = [e['name'] for e in repo.ls_tree('master') if e['type'] == 'blob']
    assert blobs

    for b in blobs:
        blame = Jagare.blame(path, ref='master', req_path=b, lineno=1)
        assert blame.blob
        assert blame.hunks
Beispiel #18
0
def test_add_remote(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)
    ret = Jagare.add_remote(path, 'upstream', 'git@localhost:test.git')

    assert t_repo.remotes() == []  # why?? pygit2 bug??

    repo = JagareRepo(path)

    assert ret is True
    assert 'upstream' in [r.name for r in repo.remotes()]
Beispiel #19
0
def test_list_remotes(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)
    remotes = Jagare.list_remotes(path)

    assert remotes == t_repo.remotes()

    t_repo.add_remote('upstream', 'git@localhost:test.git')
    remotes = Jagare.list_remotes(path)
    assert remotes == [r.name for r in t_repo.remotes()]
    assert 'upstream' in remotes
Beispiel #20
0
def test_fetch_all(tmpdir, Jagare):
    path = tmpdir.mkdir('local').strpath
    path_remote = tmpdir.mkdir('remote').strpath

    repo_remote = temp_repo.create_temp_repo(path_remote, is_bare=True)
    repo = repo_remote.clone(path, bare=False, branch='master')

    assert repo.remotes()

    # oneway method
    Jagare.fetch_all(path)
Beispiel #21
0
def test_fetch(tmpdir, Jagare):
    path = tmpdir.mkdir('local').strpath
    path_remote = tmpdir.mkdir('remote').strpath

    repo_remote = temp_repo.create_temp_repo(path_remote, is_bare=True)
    repo = repo_remote.clone(path, bare=False, branch='master')

    remote_name = [r.name for r in repo.remotes()][0]
    assert remote_name == 'origin'

    # oneway method
    Jagare.fetch(path, remote_name)
Beispiel #22
0
def test_clone(tmpdir, Jagare):
    path = tmpdir.mkdir('source').strpath
    to_path = tmpdir.mkdir('target').strpath

    t_repo = temp_repo.create_temp_repo(path, is_bare=True)
    to_repo = Jagare.clone_to(path, to_path, is_bare=False, branch='master',
                              is_mirror=False, env={})

    assert to_repo.path.rstrip('/') == os.path.join(to_path, '.git')
    assert to_repo.is_bare is False
    assert to_repo.is_empty is False
    assert to_repo.workdir.rstrip('/') == to_path
    assert to_repo.head == t_repo.head.name
Beispiel #23
0
def test_mirror(tmpdir, Jagare):
    path = tmpdir.mkdir('source').strpath
    to_path = tmpdir.mkdir('target').strpath

    t_repo = temp_repo.create_temp_repo(path, is_bare=True)
    to_repo = Jagare.mirror(url=path, to_path=to_path, is_bare=True,
                            branch='master', env={})

    assert to_repo.path.rstrip('/') == to_path
    assert to_repo.is_bare is True
    assert to_repo.is_empty is False
    assert to_repo.workdir is None
    assert to_repo.head == t_repo.head.name
Beispiel #24
0
def test_update_ref(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=False)

    assert t_repo.head.name == 'refs/heads/master'
    head_sha = t_repo.head.target.hex

    temp_repo.commit_something(path)
    assert t_repo.head.target.hex != head_sha
    ret = Jagare.update_ref(path, 'refs/heads/master', head_sha)

    assert ret is True
    assert t_repo.head.target.hex == head_sha
Beispiel #25
0
def test_update_head(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=False)
    t_repo.create_branch('br_test_update_head', 'master')

    head_sha = t_repo.head.target.hex
    temp_repo.commit_something(path)
    assert t_repo.head.target.hex != head_sha

    ret = Jagare.update_head(path, 'br_test_update_head')

    assert ret is True
    assert t_repo.head.target.hex == head_sha
Beispiel #26
0
def test_show_blob(tmpdir, Jagare):
    path = tmpdir.strpath
    repo = temp_repo.create_temp_repo(path, is_bare=True)

    ls = repo.ls_tree('master')
    blobs = [item['sha'] for item in ls if item['type'] == 'blob']
    assert blobs

    for sha in blobs:

        ret = Jagare.show(path, sha)

        assert ret.blob
Beispiel #27
0
def test_fetch_raw(tmpdir, Jagare):
    path = tmpdir.mkdir('local').strpath
    path_remote = tmpdir.mkdir('remote').strpath

    repo_remote = temp_repo.create_temp_repo(path_remote, is_bare=True)
    repo = repo_remote.clone(path, bare=False, branch='master')

    remote_name = [r.name for r in repo.remotes()][0]
    assert remote_name == 'origin'

    if not isinstance(remote_name, str):
        remote_name = remote_name.encode('utf-8')

    # oneway method
    Jagare.fetch_raw(path, name=remote_name, is_q=False, env=None)
Beispiel #28
0
def test_rev_list(tmpdir, Jagare):
    path = tmpdir.strpath

    repo = temp_repo.create_temp_repo(path, is_bare=True)
    from_sha = repo.sha('master')
    temp_repo.commit_something(path)

    ret = Jagare.rev_list(path, to_ref='master', from_ref=from_sha,
                          file_path=None, skip=None, max_count=None,
                          author=None, query=None, first_parent=None,
                          since=None, no_merges=None)

    assert ret[0].committer
    assert ret[0].author
    assert ret[0].sha
    assert ret[0].type == 'commit'
Beispiel #29
0
def test_push(tmpdir, Jagare):
    path = tmpdir.mkdir('source').strpath
    path2 = tmpdir.mkdir('target').strpath
    repo = temp_repo.create_temp_repo(path, is_bare=True)

    repo2 = JagareRepo.init(path2, bare=True)
    assert repo2.empty is True

    repo.add_remote('origin', repo2.path)
    ret = Jagare.push(path, 'origin', 'master', env={})
    assert not repo2.empty

    assert ret.stdout is not None  # why stdout == ''
    assert ret.stderr is not None  # why stderr != ''
    assert ret.fullcmd
    assert ret.returncode == 0
Beispiel #30
0
def test_show_tree(tmpdir, Jagare):
    path = tmpdir.strpath
    repo = temp_repo.create_temp_repo(path, is_bare=True)

    # create a tree
    temp_repo.commit_something(path,
                               file_name=os.path.join('test_tree', 'file'))

    ls = repo.ls_tree('master')
    trees = [item['sha'] for item in ls if item['type'] == 'tree']
    assert trees

    for sha in trees:

        ret = Jagare.show(path, sha)

        assert ret.tree
Beispiel #31
0
def test_show_tag(tmpdir, Jagare):
    path = tmpdir.strpath
    repo = temp_repo.create_temp_repo(path, is_bare=True)

    # create a tag
    ret = repo.create_tag('test_tag', 'master', 'lh', 'lh@localhost', 'msg')
    assert ret

    tag_name = repo.tags[0]
    tag_ref = repo.lookup_reference('refs/tags/%s' % tag_name)
    sha = tag_ref.target.hex

    type_ = repo.resolve_type(sha)
    assert type_ == 'tag'

    ret = Jagare.show(path, sha)
    assert ret.tag.name == tag_name
Beispiel #32
0
def test_can_merge(tmpdir, Jagare):
    path = tmpdir.mkdir('to').strpath
    from_repo_path = tmpdir.mkdir('from').strpath

    BR = 'br_test_merge'

    repo = temp_repo.create_temp_repo(path, is_bare=True)
    from_repo = repo.clone(from_repo_path, branch='master',
                           bare=True)

    # commit more things to from_repo:BR
    ret = from_repo.create_branch(BR, 'master')
    assert ret is True
    temp_repo.commit_something(from_repo_path, branch=BR)

    # can_merge
    ret = Jagare.can_merge(path,
                           from_repo_path, BR, 'master',
                           remote_name='hub/xxxproject')
    assert ret is True
Beispiel #33
0
def test_can_merge(tmpdir, Jagare):
    path = tmpdir.mkdir('to').strpath
    from_repo_path = tmpdir.mkdir('from').strpath

    BR = 'br_test_merge'

    repo = temp_repo.create_temp_repo(path, is_bare=True)
    from_repo = repo.clone(from_repo_path, branch='master', bare=True)

    # commit more things to from_repo:BR
    ret = from_repo.create_branch(BR, 'master')
    assert ret is True
    temp_repo.commit_something(from_repo_path, branch=BR)

    # can_merge
    ret = Jagare.can_merge(path,
                           from_repo_path,
                           BR,
                           'master',
                           remote_name='hub/xxxproject')
    assert ret is True
Beispiel #34
0
def test_merge_flow(tmpdir, no_ff, Jagare):
    path = tmpdir.mkdir('to').strpath
    from_repo_path = tmpdir.mkdir('from').strpath

    BR = 'br_test_merge'

    repo = temp_repo.create_temp_repo(path, is_bare=True)
    from_repo = repo.clone(from_repo_path, branch='master', bare=True)

    # commit more things to from_repo:BR
    ret = from_repo.create_branch(BR, 'master')
    assert ret is True
    temp_repo.commit_something(from_repo_path, branch=BR)

    # different repo: from -> to
    sha = Jagare.merge_flow(path,
                            'lh',
                            '*****@*****.**',
                            'test_header',
                            'test_body',
                            from_repo_path,
                            BR,
                            'master',
                            remote_name='hub/xxxproject',
                            no_ff=no_ff)
    assert sha

    # same repo: from -> from
    sha = Jagare.merge_flow(from_repo_path,
                            'lh',
                            '*****@*****.**',
                            'test_header',
                            'test_body',
                            from_repo_path,
                            BR,
                            'master',
                            remote_name=None,
                            no_ff=True)
    assert sha
Beispiel #35
0
def test_rev_list(tmpdir, Jagare):
    path = tmpdir.strpath

    repo = temp_repo.create_temp_repo(path, is_bare=True)
    from_sha = repo.sha('master')
    temp_repo.commit_something(path)

    ret = Jagare.rev_list(path,
                          to_ref='master',
                          from_ref=from_sha,
                          file_path=None,
                          skip=None,
                          max_count=None,
                          author=None,
                          query=None,
                          first_parent=None,
                          since=None,
                          no_merges=None)

    assert ret[0].committer
    assert ret[0].author
    assert ret[0].sha
    assert ret[0].type == 'commit'
Beispiel #36
0
def test_commit(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=False)

    FILE_NAME = 'test_commit_file_name'
    FILE_CONTENT = """test_content
        test_content
        test_content
        test_content
        """

    data = [(FILE_NAME, FILE_CONTENT, 'insert')]
    ret = Jagare.commit(path,
                        branch='master',
                        parent_ref='master',
                        author_name='testuser',
                        author_email='*****@*****.**',
                        message='commit msg',
                        reflog=' ',
                        data=data)

    assert ret is True
    assert FILE_NAME in [node['name'] for node in t_repo.ls_tree('master')]
Beispiel #37
0
def test_commit(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=False)

    FILE_NAME = 'test_commit_file_name'
    FILE_CONTENT = """test_content
        test_content
        test_content
        test_content
        """

    data = [(FILE_NAME,
             FILE_CONTENT,
             'insert')]
    ret = Jagare.commit(path, branch='master',
                        parent_ref='master',
                        author_name='testuser',
                        author_email='*****@*****.**',
                        message='commit msg',
                        reflog=' ',
                        data=data)

    assert ret is True
    assert FILE_NAME in [node['name'] for node in t_repo.ls_tree('master')]
Beispiel #38
0
def test_list_references(tmpdir, Jagare):
    path = tmpdir.strpath
    t_repo = temp_repo.create_temp_repo(path, is_bare=True)
    refs = Jagare.list_references(path)

    assert refs == t_repo.listall_references()
Beispiel #39
0
def test_resolve_type(tmpdir, Jagare):
    path = tmpdir.strpath
    temp_repo.create_temp_repo(path, is_bare=True)

    type_ = Jagare.resolve_type(path, 'master')
    assert type_ == 'commit'