Example #1
0
    def test_non_cannonical_identifiers(self):
        with mocks.remote.Svn():
            self.assertEqual('2@trunk', str(remote.Svn(self.remote).commit(identifier='0@branch-a')))
            self.assertEqual('1@trunk', str(remote.Svn(self.remote).commit(identifier='-1@branch-a')))

            self.assertEqual('2@trunk', str(remote.Svn(self.remote).commit(identifier='0@branch-b')))
            self.assertEqual('1@trunk', str(remote.Svn(self.remote).commit(identifier='-1@branch-b')))
Example #2
0
 def __init__(self):
     self.svn = remote.Svn('https://svn.webkit.org/repository/webkit')
     self.github = remote.GitHub('https://github.com/WebKit/WebKit')
     super(WebKitRepository, self).__init__(
         key='webkit',
         default_branch=self.github.default_branch,
     )
Example #3
0
    def from_url(cls, url, contributors=None):
        from webkitscmpy import remote

        if remote.Svn.is_webserver(url):
            return remote.Svn(url, contributors=contributors)
        if remote.GitHub.is_webserver(url):
            return remote.GitHub(url, contributors=contributors)
        raise OSError("'{}' is not a known SCM server".format(url))
Example #4
0
 def test_info(self):
     with mocks.remote.Svn():
         self.assertDictEqual({
             'Last Changed Author': '*****@*****.**',
             'Last Changed Date': datetime.fromtimestamp(1601665100).strftime('%Y-%m-%d %H:%M:%S'),
             'Last Changed Rev': '6',
             'Revision': 10,
         }, remote.Svn(self.remote).info())
Example #5
0
 def test_identifier(self):
     with mocks.remote.Svn():
         self.assertEqual(1, remote.Svn(self.remote).commit(identifier='1@trunk').revision)
         self.assertEqual(2, remote.Svn(self.remote).commit(identifier='2@trunk').revision)
         self.assertEqual(3, remote.Svn(self.remote).commit(identifier='2.1@branch-a').revision)
         self.assertEqual(4, remote.Svn(self.remote).commit(identifier='3@trunk').revision)
         self.assertEqual(5, remote.Svn(self.remote).commit(identifier='2.2@branch-b').revision)
         self.assertEqual(6, remote.Svn(self.remote).commit(identifier='4@trunk').revision)
         self.assertEqual(7, remote.Svn(self.remote).commit(identifier='2.2@branch-a').revision)
         self.assertEqual(8, remote.Svn(self.remote).commit(identifier='2.3@branch-b').revision)
Example #6
0
    def test_commit_revision(self):
        with mocks.remote.Svn():
            self.assertEqual('1@trunk', str(remote.Svn(self.remote).commit(revision=1)))
            self.assertEqual('2@trunk', str(remote.Svn(self.remote).commit(revision=2)))
            self.assertEqual('2.1@branch-a', str(remote.Svn(self.remote).commit(revision=3)))
            self.assertEqual('3@trunk', str(remote.Svn(self.remote).commit(revision=4)))
            self.assertEqual('2.2@branch-b', str(remote.Svn(self.remote).commit(revision=5)))
            self.assertEqual('4@trunk', str(remote.Svn(self.remote).commit(revision=6)))
            self.assertEqual('2.2@branch-a', str(remote.Svn(self.remote).commit(revision=7)))
            self.assertEqual('2.3@branch-b', str(remote.Svn(self.remote).commit(revision=8)))

            # Out-of-bounds commit
            with self.assertRaises(remote.Svn.Exception):
                self.assertEqual(None, remote.Svn(self.remote).commit(revision=11))
Example #7
0
 def test_commits_branch(self):
     with mocks.remote.Svn(), OutputCapture():
         svn = remote.Svn(self.remote)
         self.assertEqual(Commit.Encoder().default([
             svn.commit(revision='r7'),
             svn.commit(revision='r3'),
             svn.commit(revision='r2'),
             svn.commit(revision='r1'),
         ]), Commit.Encoder().default(list(svn.commits(begin=dict(argument='r1'), end=dict(argument='r7')))))
Example #8
0
    def __exit__(self, *args, **kwargs):
        cache_path = scmremote.Svn('http://{}'.format(self.remote))._cache_path
        if os.path.isfile(cache_path):
            os.remove(cache_path)
        if self._cache_contents:
            with open(cache_path, 'w') as cache:
                cache.write(self._cache_contents)

        super(Svn, self).__exit__(*args, **kwargs)
Example #9
0
 def test_commits(self):
     self.maxDiff = None
     with mocks.remote.Svn():
         svn = remote.Svn(self.remote)
         self.assertEqual(Commit.Encoder().default([
             svn.commit(revision='r6'),
             svn.commit(revision='r4'),
             svn.commit(revision='r2'),
             svn.commit(revision='r1'),
         ]), Commit.Encoder().default(list(svn.commits(begin=dict(revision='r1'), end=dict(revision='r6')))))
Example #10
0
    def __enter__(self):
        super(Svn, self).__enter__()

        cache_path = scmremote.Svn('http://{}'.format(self.remote))._cache_path
        if os.path.isfile(cache_path):
            with open(cache_path, 'r') as cache:
                self._cache_contents = cache.read()
            os.remove(cache_path)

        return self
Example #11
0
    def main(cls, args, repository, subversion=None, **kwargs):
        if not repository.path:
            sys.stderr.write('Cannot setup git-svn on remote repository\n')
            return 1
        if not repository.is_git:
            sys.stderr.write('Cannot setup git-svn on Subversion repository\n')
            return 1
        if not subversion:
            sys.stderr.write(
                'Failed to find Subversion remote: {}\n'.format(subversion))
            return 1

        print('Adding svn-remote to git config')
        config_path = os.path.join(repository.root_path, '.git', 'config')
        config_data = []
        with open(config_path, 'r') as config:
            is_in_svn_remote = False
            for line in config.readlines():
                if is_in_svn_remote and not line[:1].isspace():
                    is_in_svn_remote = False
                if line.startswith('[svn-remote "svn"]'):
                    is_in_svn_remote = True
                if not is_in_svn_remote:
                    config_data.append(line)

        with open(config_path, 'w') as config:
            for line in config_data:
                config.write(line)
            config.write('[svn-remote "svn"]\n')
            config.write('\turl = {}\n'.format(subversion))
            config.write('\tfetch = trunk:refs/remotes/origin/{}\n'.format(
                repository.default_branch))

            if args.all_branches:
                svn_remote = remote.Svn(
                    url=subversion,
                    dev_branches=repository.dev_branches,
                    prod_branches=repository.prod_branches,
                    contributors=repository.contributors,
                )

                git_branches = repository.branches
                for branch in sorted(svn_remote.branches):
                    if branch not in git_branches:
                        continue
                    config.write(
                        '\tfetch = branches/{branch}:refs/remotes/origin/{branch}\n'
                        .format(branch=branch))

        print('Populating svn commit mapping (will take a few minutes)...')
        return run([
            repository.executable(), 'svn', 'fetch', '--log-window-size=5000',
            '-r', '1:HEAD'
        ],
                   cwd=repository.root_path).returncode
Example #12
0
    def __init__(self, remote='svn.example.org/repository/webkit', datafile=None):
        if not scmremote.Svn.is_webserver('https://{}'.format(remote)):
            raise ValueError('"{}" is not a valid Svn remote'.format(remote))

        super(Svn, self).__init__(remote.split('/')[0])
        if remote[-1] != '/':
            remote += '/'
        self.remote = remote
        self._cache_contents = None
        self.patches.append(scmremote.Svn('http://{}'.format(self.remote))._cache_lock())

        with open(datafile or os.path.join(os.path.dirname(os.path.dirname(__file__)), 'svn-repo.json')) as file:
            self.commits = json.load(file)
        for key, commits in self.commits.items():
            self.commits[key] = [Commit(**kwargs) for kwargs in commits]
Example #13
0
 def test_scm_type(self):
     self.assertTrue(remote.Svn(self.remote).is_svn)
     self.assertFalse(remote.Svn(self.remote).is_git)
Example #14
0
 def test_tags(self):
     with mocks.remote.Svn():
         self.assertEqual(
             remote.Svn(self.remote).tags,
             ['tag-1', 'tag-2'],
         )
Example #15
0
 def test_branches(self):
     with mocks.remote.Svn():
         self.assertEqual(
             remote.Svn(self.remote).branches,
             ['trunk', 'branch-a', 'branch-b'],
         )
Example #16
0
 def test_tag_previous(self):
     with mocks.remote.Svn():
         self.assertEqual(7, remote.Svn(self.remote).commit(identifier='2.2@tags/tag-1').revision)
Example #17
0
 def test_commit_from_branch(self):
     with mocks.remote.Svn():
         self.assertEqual('4@trunk', str(remote.Svn(self.remote).commit(branch='trunk')))
         self.assertEqual('2.2@branch-a', str(remote.Svn(self.remote).commit(branch='branch-a')))
         self.assertEqual('2.3@branch-b', str(remote.Svn(self.remote).commit(branch='branch-b')))
Example #18
0
 def __init__(self):
     self.remote = remote.Svn('https://svn.webkit.org/repository/webkit')
     super(WebKitRepository, self).__init__(
         key='webkit',
         default_branch=self.remote.default_branch,
     )
Example #19
0
 def test_alternative_default_branch(self):
     with mocks.remote.Svn():
         self.assertEqual(str(remote.Svn(self.remote).find('4@main')), '4@trunk')
         self.assertEqual(str(remote.Svn(self.remote).find('4@master')), '4@trunk')
Example #20
0
 def test_no_identifier(self):
     with mocks.remote.Svn():
         self.assertIsNone(remote.Svn(self.remote).find('trunk', include_identifier=False).identifier)
Example #21
0
 def test_tag(self):
     with mocks.remote.Svn():
         self.assertEqual(9, remote.Svn(self.remote).commit(tag='tag-1').revision)
Example #22
0
 def test_id(self):
     self.assertEqual(remote.Svn(self.remote).id, 'webkit')
Example #23
0
 def test_no_log(self):
     with mocks.remote.Svn():
         self.assertIsNone(remote.Svn(self.remote).commit(identifier='4@trunk', include_log=False).message)
Example #24
0
def bug_comment_from_svn_revision(svn_revision):
    repo = remote.Svn('https://svn.webkit.org/repository/webkit')
    identifier = str(repo.commit(revision=svn_revision)).replace('trunk', 'main')
    return 'Committed r{} ({}): <{}>'.format(svn_revision, identifier, urls.view_identifier_url(identifier))