示例#1
0
 def update_head(self, path, branch_name):
     try:
         repo = Jagare(path)
         repo.update_head(branch_name)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#2
0
 def add_remote(self, path, name, url):
     try:
         repo = Jagare(path)
         repo.add_remote(name, url)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#3
0
 def update_ref(self, path, ref, newvalue):
     try:
         repo = Jagare(path)
         repo.update_ref(ref, newvalue)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#4
0
文件: test_show.py 项目: CMGS/ellen
 def test_show_blob(self):
     repo = Jagare(self.path)
     ls = repo.ls_tree('master')
     blobs = [item['sha'] for item in ls if item['type'] == 'blob']
     for sha in blobs:
         ret = repo.show(sha)
         assert ret['type'] == 'blob'
示例#5
0
 def delete_branch(self, path, name):
     try:
         repo = Jagare(path)
         repo.delete_branch(name)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#6
0
 def resolve_type(self, path, version):
     """version means git object sha, return str of blob/tree/commit/tag"""
     try:
         repo = Jagare(path)
         return repo.resolve_type(version)
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#7
0
 def merge_base(self, path, to_sha, from_sha):
     try:
         repo = Jagare(path)
         oid = repo.merge_base(to_sha, from_sha)
         return oid.hex if oid else None
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#8
0
 def update_head(self, path, branch_name):
     try:
         repo = Jagare(path)
         repo.update_head(branch_name)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#9
0
 def blame(self, path, ref, req_path, lineno):
     try:
         repo = Jagare(path)
         ret = repo.blame(ref, path=req_path, lineno=lineno)
         return BlameConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#10
0
 def push(self, path, remote, ref, env):
     try:
         repo = Jagare(path)
         ret = repo.push(remote, ref, _env=env)
         return ProcessResultConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#11
0
def get_temp_project(origin=None, repo_path=BARE_REPO_PATH):
    if origin:
        prefix_path = get_repo_root()
        temp_repo_path = tempfile.mkdtemp(suffix=".git",
                                          prefix="test_",
                                          dir=prefix_path)
        project_name = temp_repo_path[len(prefix_path) + 1:][:-4]
        project = CodeDoubanProject.add(project_name,
                                        TEMP_PROJECT_OWNER,
                                        TEMP_PROJECT_DESCRIPTION,
                                        fork_from=origin.id,
                                        create_trac=False)
        return project

    prefix_path = get_repo_root()
    temp_repo_path = tempfile.mkdtemp(suffix=".git",
                                      prefix="test_",
                                      dir=prefix_path)
    project_name = temp_repo_path[len(prefix_path) + 1:][:-4]
    project = CodeDoubanProject.add(project_name, TEMP_PROJECT_OWNER,
                                    TEMP_PROJECT_DESCRIPTION)

    shutil.rmtree(temp_repo_path)
    repo = Jagare(repo_path)
    repo.clone(temp_repo_path, bare=True)

    return project
示例#12
0
 def archive(self, path, prefix, ref):
     try:
         repo = Jagare(path)
         stdout = repo.archive(prefix=prefix, ref=ref)
         return stdout
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#13
0
 def merge_commits(self, path, ours, theirs):
     try:
         repo = Jagare(path)
         ret = repo.merge_tree(ours, theirs)
         return MergeIndexConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#14
0
 def merge_head(self, path, ref):
     try:
         repo = Jagare(path)
         ret = repo.merge_head(ref)
         return MergeResultConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#15
0
 def merge_base(self, path, to_sha, from_sha):
     try:
         repo = Jagare(path)
         oid = repo.merge_base(to_sha, from_sha)
         return oid.hex if oid else None
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#16
0
 def push(self, path, remote, ref, env):
     try:
         repo = Jagare(path)
         ret = repo.push(remote, ref, _env=env)
         return ProcessResultConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#17
0
文件: utils.py 项目: 000fan000/code
def get_temp_project(origin=None, repo_path=BARE_REPO_PATH):
    if origin:
        prefix_path = get_repo_root()
        temp_repo_path = tempfile.mkdtemp(suffix=".git",
                                          prefix="test_",
                                          dir=prefix_path)
        project_name = temp_repo_path[len(prefix_path) + 1:][:-4]
        project = CodeDoubanProject.add(project_name,
                                        TEMP_PROJECT_OWNER,
                                        TEMP_PROJECT_DESCRIPTION,
                                        fork_from=origin.id,
                                        create_trac=False)
        return project

    prefix_path = get_repo_root()
    temp_repo_path = tempfile.mkdtemp(suffix=".git",
                                      prefix="test_",
                                      dir=prefix_path)
    project_name = temp_repo_path[len(prefix_path) + 1:][:-4]
    project = CodeDoubanProject.add(project_name, TEMP_PROJECT_OWNER,
                                    TEMP_PROJECT_DESCRIPTION)

    shutil.rmtree(temp_repo_path)
    repo = Jagare(repo_path)
    repo.clone(temp_repo_path, bare=True)

    return project
示例#18
0
 def archive(self, path, prefix, ref):
     try:
         repo = Jagare(path)
         stdout = repo.archive(prefix=prefix, ref=ref)
         return stdout
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#19
0
 def delete_branch(self, path, name):
     try:
         repo = Jagare(path)
         repo.delete_branch(name)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#20
0
 def resolve_type(self, path, version):
     """version means git object sha, return str of blob/tree/commit/tag"""
     try:
         repo = Jagare(path)
         return repo.resolve_type(version)
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#21
0
 def merge_head(self, path, ref):
     try:
         repo = Jagare(path)
         ret = repo.merge_head(ref)
         return MergeResultConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#22
0
    def merge_flow(self, path, merger_name, merger_email, message_header,
                   message_body, from_repo_path, from_ref, to_ref, remote_name,
                   no_ff):
        """merge with worktree(tmpdir)"""
        try:
            repo = Jagare(path)
            with get_tmpdir() as tmpdir:

                assert tmpdir

                ret = repo.merge_flow(merger_name,
                                      merger_email,
                                      message_header,
                                      message_body,
                                      tmpdir,
                                      from_repo_path,
                                      from_ref,
                                      to_ref,
                                      remote_name=remote_name,
                                      no_ff=no_ff)

                assert ret

            return ret
        except Exception as e:
            raise ServiceUnavailable(repr(e))
示例#23
0
 def add_remote(self, path, name, url):
     try:
         repo = Jagare(path)
         repo.add_remote(name, url)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#24
0
 def test_show_blob(self):
     repo = Jagare(self.path)
     ls = repo.ls_tree('master')
     blobs = [item['sha'] for item in ls if item['type'] == 'blob']
     for sha in blobs:
         ret = repo.show(sha)
         assert ret['type'] == 'blob'
示例#25
0
 def update_ref(self, path, ref, newvalue):
     try:
         repo = Jagare(path)
         repo.update_ref(ref, newvalue)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#26
0
 def blame(self, path, ref, req_path, lineno):
     try:
         repo = Jagare(path)
         ret = repo.blame(ref, path=req_path, lineno=lineno)
         return BlameConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#27
0
    def test_blame(self):
        repo = Jagare(self.path)

        tree = repo.ls_tree('master')
        blobs = [item['path'] for item in tree if item['type'] == 'blob']
        for node in blobs:
            blame_ret = repo.blame('master', path=node)
            if node == 'new.txt':
                for hunk in blame_ret['hunks']:
                    self.assertEquals(
                        '4bc90207e76d68d5cda435e67c5f85a0ce710f44',
                        hunk['final_commit_id'])
                    self.assertEquals(hunk['final_committer']['email'],
                                      '*****@*****.**')
                    self.assertEquals(hunk['orig_committer']['email'],
                                      '*****@*****.**')

            if node == 'README.md':
                for hunk in blame_ret['hunks']:
                    self.assertEquals(
                        'e9f35005ca7d004d87732598f761b1be3b9d1c61',
                        hunk['final_commit_id'])
                    self.assertEquals(hunk['final_committer']['email'],
                                      '*****@*****.**')
                    self.assertEquals(hunk['orig_committer']['email'],
                                      '*****@*****.**')
示例#28
0
 def merge_commits(self, path, ours, theirs):
     try:
         repo = Jagare(path)
         ret = repo.merge_tree(ours, theirs)
         return MergeIndexConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#29
0
def test_check_none_result(tmpdir, Jagare):
    path = tmpdir.strpath
    JagareRepo.init(path, bare=True)

    try:
        sha = Jagare.resolve_commit(path, 'master')
    except Exception as e:
        assert type(e) in (NoneResult, NoneResultMock)
示例#30
0
    def test_format_patch(self):
        repo = Jagare(self.path)

        ret = repo.format_patch('master')
        assert ret

        ret = repo.format_patch(BARE_REPO_OTHER_BRANCH, from_ref='master')
        assert ret
示例#31
0
 def merge(self, path, ref, msg, commit_msg, no_ff, env):
     try:
         repo = Jagare(path)
         ret = repo.merge(ref=ref, msg=msg, commit_msg=commit_msg,
                          no_ff=no_ff, _env=env)
         return ProcessResultConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#32
0
 def show(self, path, ref):
     try:
         repo = Jagare(path)
         obj_dict = repo.show(ref)
         ret = get_gitobject_from_show(obj_dict)
         return ret
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#33
0
 def show(self, path, ref):
     try:
         repo = Jagare(path)
         obj_dict = repo.show(ref)
         ret = get_gitobject_from_show(obj_dict)
         return ret
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#34
0
文件: repo.py 项目: banjin/code
 def __init__(self, project, pull=None):
     self.type = "project"
     self.pull = pull
     self.project = project
     self.project_name = project.name
     self.name = project.name
     self.path = project.repo_path
     self.repo = Jagare(self.path)
示例#35
0
文件: test_tag.py 项目: CMGS/ellen
    def test_create(self):
        repo = Jagare(self.path)
        tags = repo.tags

        ret = repo.create_tag('test_create_tag', 'master', 'lh',
                              'lh@localhost', 'message')

        assert ret
        assert len(repo.tags) == len(tags) + 1
示例#36
0
 def test_delete(self):
     repo = Jagare(self.path)
     path = self.get_temp_path()
     clone_repo = repo.clone(path, bare=True)
     clone_repo.delete_branch('chinese')
     branches = clone_repo.branches
     assert 'chinese' in repo.branches
     assert 'chinese' not in branches
     assert 'master' in branches
示例#37
0
    def test_create(self):
        repo = Jagare(self.path)
        tags = repo.tags

        ret = repo.create_tag('test_create_tag', 'master', 'lh',
                              'lh@localhost', 'message')

        assert ret
        assert len(repo.tags) == len(tags) + 1
示例#38
0
文件: test_branch.py 项目: CMGS/ellen
 def test_delete(self):
     repo = Jagare(self.path)
     path = self.get_temp_path()
     clone_repo = repo.clone(path, bare=True)
     clone_repo.delete_branch('chinese')
     branches = clone_repo.branches
     assert 'chinese' in repo.branches
     assert 'chinese' not in branches
     assert 'master' in branches
示例#39
0
 def commit(self, path, branch, parent_ref, author_name, author_email,
            message, reflog, data):
     try:
         repo = Jagare(path)
         repo.commit_file(branch, parent_ref, author_name, author_email,
                          message, reflog, data)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#40
0
 def ls_tree(self, path, ref, req_path, recursive, with_size,
             with_commit, name_only):
     try:
         repo = Jagare(path)
         ret = repo.ls_tree(ref, path=req_path, recursive=recursive,
                            size=with_size, with_commit=with_commit,
                            name_only=name_only)
         return json.dumps(ret)
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#41
0
文件: test_clone.py 项目: CMGS/ellen
 def test_mirror(self):
     repo = Jagare(self.path)
     path = self.get_temp_path()
     clone_repo = repo.clone(path, mirror=True)
     pygit2_repo = Repository(path)
     assert is_repository(path) is True
     assert pygit2_repo.is_empty is False
     assert pygit2_repo.is_bare is True
     assert clone_repo.empty is False
     assert clone_repo.bare is True
示例#42
0
 def commit(self, path, branch, parent_ref,
            author_name, author_email, message, reflog, data):
     try:
         repo = Jagare(path)
         repo.commit_file(branch, parent_ref,
                          author_name, author_email,
                          message, reflog, data)
         return True
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#43
0
 def test_simple(self):
     repo = Jagare(self.path)
     path = self.get_temp_path()
     clone_repo = repo.clone(path)
     pygit2_repo = Repository(path)
     assert is_repository(path) is True
     assert pygit2_repo.is_empty is False
     assert pygit2_repo.is_bare is False
     assert clone_repo.empty is False
     assert clone_repo.bare is False
示例#44
0
文件: test_show.py 项目: CMGS/ellen
    def test_show_tag(self):
        repo = Jagare(self.path)
        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 = repo.show(sha)
        assert ret['name'] == BARE_REPO_TAGS[0]
示例#45
0
 def can_merge(self, path, from_repo_path, from_ref, to_ref,
               remote_name=None):
     """test auto merge"""
     try:
         repo = Jagare(path)
         with get_tmpdir() as tmpdir:
             ret = repo.can_merge(tmpdir, from_repo_path, from_ref, to_ref,
                                  remote_name=remote_name)
         return ret
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#46
0
 def test_resolve_commit(self):
     repo = Jagare(self.path)
     test_commit_hex1 = 'e9f35005ca7d004d87732598f761b1be3b9d1c61'
     test_commit_tree_hex1 = 'be483ca0381e9a61b76fac84863acdd970b9150f'
     test_commit_blob_hex1 = '7a8a76c619b95af88fb71e5514509e9ac8da6779'
     test_master_commit_hex = '9119237c2d5aa2c4a110296e255c7ec194711066'
     # FIXME tag test
     assert repo.resolve_commit(test_commit_hex1) == test_commit_hex1
     assert repo.resolve_commit(test_commit_tree_hex1) is None
     assert repo.resolve_commit(test_commit_blob_hex1) is None
     assert repo.resolve_commit('master') == test_master_commit_hex
示例#47
0
    def test_show_tag(self):
        repo = Jagare(self.path)
        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 = repo.show(sha)
        assert ret['name'] == BARE_REPO_TAGS[0]
示例#48
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()]
示例#49
0
 def diff(self, path, ref, from_ref, ignore_space, flags,
          context_lines, paths, rename_detection):
     try:
         repo = Jagare(path)
         diff_dict = repo.diff(ref, from_ref=from_ref,
                               ignore_space=ignore_space, flags=flags,
                               context_lines=context_lines, paths=paths,
                               rename_detection=rename_detection)
         return DiffConverter(**diff_dict).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#50
0
 def merge(self, path, ref, msg, commit_msg, no_ff, env):
     try:
         repo = Jagare(path)
         ret = repo.merge(ref=ref,
                          msg=msg,
                          commit_msg=commit_msg,
                          no_ff=no_ff,
                          _env=env)
         return ProcessResultConverter(**ret).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#51
0
文件: mixes.py 项目: CMGS/jagare
def mirror(name, url):
    target_path = os.path.join(config.REPOS_PATH, name)
    target_path = endwith_git(target_path)

    repository_exist = is_repository(target_path)

    if repository_exist:
        raise JagareError("repository already exists", 409)

    Jagare.mirror(url, target_path)

    return make_message_response("Mirror success.")
示例#52
0
 def clone_to(self, path, to_path, is_bare, branch, is_mirror, env):
     try:
         repo = Jagare(path)
         to_repo = repo.clone(path=to_path, bare=is_bare, branch=branch,
                              mirror=is_mirror, env=env)
         return Repository(path=to_repo.path,
                           is_empty=to_repo.empty,
                           is_bare=to_repo.bare,
                           workdir=to_repo.repository.workdir,
                           head=to_repo.head and to_repo.head.name)
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#53
0
文件: mixes.py 项目: CMGS/jagare
def init(name):
    repository_path = os.path.join(config.REPOS_PATH, name)
    repository_path = endwith_git(repository_path)

    repository_exist = is_repository(repository_path)

    if repository_exist:
        raise JagareError("repository already exists.", 409)

    Jagare.init(repository_path)

    return make_message_response("initialize success")
示例#54
0
 def ls_tree(self, path, ref, req_path, recursive, with_size, with_commit,
             name_only):
     try:
         repo = Jagare(path)
         ret = repo.ls_tree(ref,
                            path=req_path,
                            recursive=recursive,
                            size=with_size,
                            with_commit=with_commit,
                            name_only=name_only)
         return json.dumps(ret)
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#55
0
 def diff(self, path, ref, from_ref, ignore_space, flags, context_lines,
          paths, rename_detection):
     try:
         repo = Jagare(path)
         diff_dict = repo.diff(ref,
                               from_ref=from_ref,
                               ignore_space=ignore_space,
                               flags=flags,
                               context_lines=context_lines,
                               paths=paths,
                               rename_detection=rename_detection)
         return DiffConverter(**diff_dict).convert()
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#56
0
 def clone_to(self, path, to_path, is_bare, branch, is_mirror, env):
     try:
         repo = Jagare(path)
         to_repo = repo.clone(path=to_path,
                              bare=is_bare,
                              branch=branch,
                              mirror=is_mirror,
                              env=env)
         return Repository(path=to_repo.path,
                           is_empty=to_repo.empty,
                           is_bare=to_repo.bare,
                           workdir=to_repo.repository.workdir,
                           head=to_repo.head and to_repo.head.name)
     except Exception as e:
         raise ServiceUnavailable(repr(e))