示例#1
0
    def test_merge_commits(self):
        repo = Jagare(self.path)
        BR = 'br_test_merge'
        path = self.get_temp_path()

        # repo has work-tree
        repo.clone(path, branch=BARE_REPO_OTHER_BRANCH)
        repo = Jagare(os.path.join(path, '.git'))

        ret = repo.create_branch(BR, BARE_REPO_OTHER_BRANCH)
        assert ret

        commit_something(path, branch=BR)
        repo.update_head(BARE_REPO_OTHER_BRANCH)
        merge_index = repo.merge_commits(repo.head.target.hex, BR)
        assert merge_index['has_conflicts'] is False
示例#2
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
示例#3
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))
示例#4
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))
示例#5
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))
示例#6
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))
示例#7
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))
示例#8
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))
示例#9
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))
示例#10
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))
示例#11
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))
示例#12
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))
示例#13
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))
示例#14
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'
示例#15
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))
示例#16
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'],
                                      '*****@*****.**')
示例#17
0
    def test_merge_head(self):
        repo = Jagare(self.path)
        BR = 'br_test_merge'
        path = self.get_temp_path()

        # repo has work-tree
        repo.clone(path, branch=BARE_REPO_OTHER_BRANCH)
        repo = Jagare(os.path.join(path, '.git'))

        ret = repo.create_branch(BR, BARE_REPO_OTHER_BRANCH)
        assert ret

        commit_something(path, branch=BR)
        repo.update_head(BARE_REPO_OTHER_BRANCH)
        merge_result = repo.merge_head(BR)
        assert merge_result['is_fastforward']
示例#18
0
 def test_update(self):
     repo = Jagare(self.path)
     path = os.path.join(self.path, 'hooks')
     assert os.path.islink(path) is False
     target = '/'
     update_hooks(repo.repository, target)
     assert os.path.islink(path) is True
     assert os.path.realpath(path) == target
示例#19
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)
示例#20
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))
示例#21
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
示例#22
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
示例#23
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
示例#24
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))
示例#25
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
示例#26
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
示例#27
0
    def test_push(self):
        repo = Jagare(self.path)

        path2 = self.get_temp_path()
        repo2 = Jagare.init(path2, bare=True)
        assert repo2.empty

        repo.add_remote('origin', repo2.path)
        repo.push('origin', 'master')
        assert not repo2.empty
示例#28
0
 def get(self, path):
     try:
         repo = Jagare(path)
         return Repository(path=repo.path,
                           is_empty=repo.empty,
                           is_bare=repo.bare,
                           workdir=repo.repository.workdir,
                           head=repo.head and repo.head.name)
     except Exception as e:
         raise ServiceUnavailable(repr(e))
示例#29
0
    def _merge(self, no_ff):
        repo = Jagare(self.path)
        BR = 'br_test_merge'
        path = self.get_temp_path()

        # repo has work-tree
        repo.clone(path, branch=BARE_REPO_OTHER_BRANCH)
        repo = Jagare(os.path.join(path, '.git'))

        ret = repo.create_branch(BR, BARE_REPO_OTHER_BRANCH)
        assert ret
        sha1 = repo.sha(BARE_REPO_OTHER_BRANCH)

        commit_something(path, branch=BR)
        repo.update_head(BARE_REPO_OTHER_BRANCH)
        ret = repo.merge(BR, no_ff=no_ff)
        sha2 = repo.sha(BARE_REPO_OTHER_BRANCH)

        assert sha1 != sha2
        assert repo.sha(sha1) == sha1
示例#30
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]