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')))
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, )
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))
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())
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)
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))
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')))))
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)
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')))))
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
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
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]
def test_scm_type(self): self.assertTrue(remote.Svn(self.remote).is_svn) self.assertFalse(remote.Svn(self.remote).is_git)
def test_tags(self): with mocks.remote.Svn(): self.assertEqual( remote.Svn(self.remote).tags, ['tag-1', 'tag-2'], )
def test_branches(self): with mocks.remote.Svn(): self.assertEqual( remote.Svn(self.remote).branches, ['trunk', 'branch-a', 'branch-b'], )
def test_tag_previous(self): with mocks.remote.Svn(): self.assertEqual(7, remote.Svn(self.remote).commit(identifier='2.2@tags/tag-1').revision)
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')))
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, )
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')
def test_no_identifier(self): with mocks.remote.Svn(): self.assertIsNone(remote.Svn(self.remote).find('trunk', include_identifier=False).identifier)
def test_tag(self): with mocks.remote.Svn(): self.assertEqual(9, remote.Svn(self.remote).commit(tag='tag-1').revision)
def test_id(self): self.assertEqual(remote.Svn(self.remote).id, 'webkit')
def test_no_log(self): with mocks.remote.Svn(): self.assertIsNone(remote.Svn(self.remote).commit(identifier='4@trunk', include_log=False).message)
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))