Title: [271340] trunk/Tools
Revision
271340
Author
[email protected]
Date
2021-01-08 17:58:21 -0800 (Fri, 08 Jan 2021)

Log Message

[webkitscmpy] Provide command to automatically configure git-svn
https://bugs.webkit.org/show_bug.cgi?id=220442
<rdar://problem/72908233>

Reviewed by Yusuke Suzuki.

Add commands to update repository and connect a git repository to a subversion repository.

* Scripts/git-webkit: Define subversion URL.
* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.pull): Add function to update repository with the remote.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py:
(Scm.pull): Add function to update repository with the remote.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
(Svn.__init__): Suppress exception when metadata cache is invalid.
(Svn.pull): Add function to update repository with the remote.
* Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
(Git): Use tabs in git config, add 'git svn fetch' and 'git pull' commands.
* Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py:
(Svn.__init__): Add 'svn up' command.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py:
(main): Add Pull and SetupGitSvn commands.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py:
(Command.parser): Support use of the default parser.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py: Added.
(Pull): Update the current repository from its remote.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/setup_git_svn.py: Added.
(SetupGitSvn): Add command which populates the .git config file with information
linking to a subversion repository.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py: Added.
(TestSetupGitSvn):
(TestSetupGitSvn.test_svn):
(TestSetupGitSvn.test_empty):
(TestSetupGitSvn.test_add):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (271339 => 271340)


--- trunk/Tools/ChangeLog	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/ChangeLog	2021-01-09 01:58:21 UTC (rev 271340)
@@ -1,3 +1,42 @@
+2021-01-08  Jonathan Bedard  <[email protected]>
+
+        [webkitscmpy] Provide command to automatically configure git-svn
+        https://bugs.webkit.org/show_bug.cgi?id=220442
+        <rdar://problem/72908233>
+
+        Reviewed by Yusuke Suzuki.
+
+        Add commands to update repository and connect a git repository to a subversion repository.
+
+        * Scripts/git-webkit: Define subversion URL.
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
+        (Git.pull): Add function to update repository with the remote.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py:
+        (Scm.pull): Add function to update repository with the remote.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
+        (Svn.__init__): Suppress exception when metadata cache is invalid.
+        (Svn.pull): Add function to update repository with the remote.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
+        (Git): Use tabs in git config, add 'git svn fetch' and 'git pull' commands.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py:
+        (Svn.__init__): Add 'svn up' command.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py:
+        (main): Add Pull and SetupGitSvn commands.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py:
+        (Command.parser): Support use of the default parser.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py: Added.
+        (Pull): Update the current repository from its remote.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/setup_git_svn.py: Added.
+        (SetupGitSvn): Add command which populates the .git config file with information
+        linking to a subversion repository.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py: Added.
+        (TestSetupGitSvn):
+        (TestSetupGitSvn.test_svn):
+        (TestSetupGitSvn.test_empty):
+        (TestSetupGitSvn.test_add):
+
 2021-01-08  Jer Noble  <[email protected]>
 
         Unreviewed test gardening. Attempting to diagnose failing PiP API tests by enabling more logging 

Modified: trunk/Tools/Scripts/git-webkit (271339 => 271340)


--- trunk/Tools/Scripts/git-webkit	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/git-webkit	2021-01-09 01:58:21 UTC (rev 271340)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -46,5 +46,6 @@
         path=os.path.dirname(__file__),
         contributors=contributors,
         identifier_template='Canonical link: https://commits.webkit.org/{}',
+        subversion='https://svn.webkit.org/repository/webkit',
     ))
 

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitscmpy',
-    version='0.7.4',
+    version='0.8.0',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 7, 4)
+version = Version(0, 8, 0)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('monotonic', Version(1, 5)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -318,3 +318,12 @@
             [self.executable(), 'checkout'] + [argument] + log_arg,
             cwd=self.root_path,
         ).returncode else self.commit()
+
+    def pull(self):
+        commit = self.commit()
+        code = run([self.executable(), 'pull'], cwd=self.root_path).returncode
+        if not code and self.is_svn:
+            return run([
+                self.executable(), 'svn', 'fetch', '--log-window-size=5000', '-r', '{}:HEAD'.format(commit.revision),
+            ], cwd=self.root_path).returncode
+        return code

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -77,3 +77,6 @@
 
     def checkout(self, argument):
         raise NotImplementedError()
+
+    def pull(self):
+        raise NotImplementedError()

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -64,7 +64,6 @@
                     self._metadata_cache = json.load(file)
             except BaseException:
                 self._metadata_cache = dict(version=str(self.CACHE_VERSION))
-                raise
         else:
             self._metadata_cache = dict(version=str(self.CACHE_VERSION))
 
@@ -392,3 +391,6 @@
             command.append('-q')
 
         return None if run(command, cwd=self.root_path).returncode else commit
+
+    def pull(self):
+        return run([self.executable(), 'up'], cwd=self.root_path).returncode

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -70,18 +70,18 @@
             with open(os.path.join(self.path, '.git', 'config'), 'w') as config:
                 config.write(
                     '[core]\n'
-                    '    repositoryformatversion = 0\n'
-                    '	filemode = true\n'
-                    '	bare = false\n'
-                    '	logallrefupdates = true\n'
-                    '	ignorecase = true\n'
-                    '	precomposeunicode = true\n'
+                    '\trepositoryformatversion = 0\n'
+                    '\tfilemode = true\n'
+                    '\tbare = false\n'
+                    '\tlogallrefupdates = true\n'
+                    '\tignorecase = true\n'
+                    '\tprecomposeunicode = true\n'
                     '[remote "origin"]\n'
-                    '    url = ""
-                    '    fetch = +refs/heads/*:refs/remotes/origin/*\n'
+                    '\turl = {remote}\n'
+                    '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
                     '[branch "{branch}"]\n'
-                    '    remote = origin\n'
-                    '    merge = refs/heads/{branch}\n'.format(
+                    '\tremote = origin\n'
+                    '\tmerge = refs/heads/{branch}\n'.format(
                         remote=self.remote,
                         branch=self.default_branch,
                     ))
@@ -282,6 +282,15 @@
                     environment_shell=args[4] if args[3] == '--env-filter' and args[4] else None,
                 )
             ), mocks.Subprocess.Route(
+                self.executable, 'svn', 'fetch', '--log-window-size=5000', '-r', re.compile(r'\d+:HEAD'),
+                cwd=self.path,
+                generator=lambda *args, **kwargs:
+                    mocks.ProcessCompletion(returncode=0) if git_svn or local.Git(self.path).is_svn else mocks.ProcessCompletion(returncode=-1),
+            ), mocks.Subprocess.Route(
+                self.executable, 'pull',
+                cwd=self.path,
+                completion=mocks.ProcessCompletion(returncode=0),
+            ), mocks.Subprocess.Route(
                 self.executable,
                 cwd=self.path,
                 completion=mocks.ProcessCompletion(

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -130,6 +130,10 @@
                 generator=lambda *args, **kwargs:
                     mocks.ProcessCompletion(returncode=0) if self.up(args[3]) else mocks.ProcessCompletion(returncode=1)
             ), mocks.Subprocess.Route(
+                self.executable, 'up',
+                cwd=self.path,
+                completion=mocks.ProcessCompletion(returncode=0),
+            ), mocks.Subprocess.Route(
                 self.executable,
                 cwd=self.path,
                 completion=mocks.ProcessCompletion(

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -23,7 +23,6 @@
 import argparse
 import logging
 import os
-import sys
 
 from webkitcorepy import arguments, log as webkitcorepy_log
 from webkitscmpy import local, log, remote
@@ -32,9 +31,11 @@
 from .command import Command
 from .checkout import Checkout
 from .find import Find
+from .pull import Pull
+from .setup_git_svn import SetupGitSvn
 
 
-def main(args=None, path=None, loggers=None, contributors=None, identifier_template=None):
+def main(args=None, path=None, loggers=None, contributors=None, identifier_template=None, subversion=None):
     logging.basicConfig(level=logging.WARNING)
 
     loggers = [logging.getLogger(), webkitcorepy_log,  log] + (loggers or [])
@@ -55,7 +56,11 @@
 
     subparsers = parser.add_subparsers(help='sub-command help')
 
-    for program in [Find, Checkout, Canonicalize]:
+    programs = [Find, Checkout, Canonicalize, Pull]
+    if subversion:
+        programs.append(SetupGitSvn)
+
+    for program in programs:
         subparser = subparsers.add_parser(program.name, help=program.help)
         subparser.set_defaults(main=program.main)
         program.parser(subparser, loggers=loggers)
@@ -67,4 +72,9 @@
     else:
         repository = local.Scm.from_path(path=parsed.repository, contributors=contributors)
 
-    return parsed.main(args=parsed, repository=repository, identifier_template=identifier_template)
+    return parsed.main(
+        args=parsed,
+        repository=repository,
+        identifier_template=identifier_template,
+        subversion=subversion,
+    )

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py (271339 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py	2021-01-09 01:54:31 UTC (rev 271339)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -28,7 +28,7 @@
     help = None
 
     @classmethod
-    def parser(cls, parser):
+    def parser(cls, parser, loggers=None):
         if cls.name is None:
             raise NotImplementedError('Command does not have a name')
         if cls.help is None:

Copied: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py (from rev 271337, trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py) (0 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py	                        (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -0,0 +1,37 @@
+# Copyright (C) 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import sys
+
+from .command import Command
+
+
+class Pull(Command):
+    name = 'pull'
+    help = 'Update the current checkout, synchronize git-svn if configured'
+
+    @classmethod
+    def main(cls, args, repository, **kwargs):
+        if not repository.path:
+            sys.stderr.write('Cannot update remote repository\n')
+            return 1
+        return repository.pull()

Added: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup_git_svn.py (0 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup_git_svn.py	                        (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup_git_svn.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -0,0 +1,92 @@
+# Copyright (C) 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import sys
+
+from .command import Command
+from webkitcorepy import run
+from webkitscmpy import remote
+
+
+class SetupGitSvn(Command):
+    name = 'setup-git-svn'
+    help = 'Connect a git checkout to the Subversion repository it is (or was) based on'
+
+    @classmethod
+    def parser(cls, parser, loggers=None):
+        parser.add_argument(
+            '--all-branches', '-a',
+            help='Match all git branches to their subversion counterparts',
+            action='',
+            dest='all_branches',
+            default=False,
+        )
+
+    @classmethod
+    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=""
+                    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

Added: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py (0 => 271340)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py	                        (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py	2021-01-09 01:58:21 UTC (rev 271340)
@@ -0,0 +1,143 @@
+# Copyright (C) 2021, 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from datetime import datetime
+from webkitcorepy import LoggerCapture, OutputCapture
+from webkitcorepy.mocks import Time as MockTime
+from webkitscmpy import program, mocks
+
+
+class TestSetupGitSvn(unittest.TestCase):
+    git_remote = '[email protected]:Example'
+    svn_remote = 'https://svn.example.org/repository/example'
+
+    def test_svn(self):
+        try:
+            dirname = tempfile.mkdtemp()
+            with OutputCapture() as captured, mocks.local.Git(), mocks.local.Svn(dirname, remote=self.svn_remote), MockTime:
+                self.assertEqual(1, program.main(
+                    args=('setup-git-svn',),
+                    path=dirname,
+                    subversion=self.svn_remote,
+                ))
+            self.assertEqual(captured.stderr.getvalue(), 'Cannot setup git-svn on Subversion repository\n')
+
+        finally:
+            shutil.rmtree(dirname)
+
+    def test_empty(self):
+        try:
+            dirname = tempfile.mkdtemp()
+            with OutputCapture() as captured, mocks.local.Git(dirname, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
+                self.assertEqual(0, program.main(
+                    args=('setup-git-svn',),
+                    path=dirname,
+                    subversion=self.svn_remote,
+                ))
+            self.assertEqual(
+                captured.stdout.getvalue(),
+                'Adding svn-remote to git config\n' +
+                'Populating svn commit mapping (will take a few minutes)...\n',
+            )
+
+            with open(os.path.join(dirname, '.git/config')) as config:
+                self.assertEqual(
+                    config.read(),
+                    '[core]\n'
+                    '\trepositoryformatversion = 0\n'
+                    '\tfilemode = true\n'
+                    '\tbare = false\n'
+                    '\tlogallrefupdates = true\n'
+                    '\tignorecase = true\n'
+                    '\tprecomposeunicode = true\n'
+                    '[remote "origin"]\n'
+                    '\turl = {git_remote}\n'
+                    '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
+                    '[branch "main"]\n'
+                    '\tremote = origin\n'
+                    '\tmerge = refs/heads/main\n'
+                    '[svn-remote "svn"]\n'
+                    '\turl = {svn_remote}\n'
+                    '\tfetch = trunk:refs/remotes/origin/main\n'.format(
+                        git_remote=self.git_remote,
+                        svn_remote=self.svn_remote,
+                    ),
+                )
+
+        finally:
+            shutil.rmtree(dirname)
+
+    def test_add(self):
+        try:
+            dirname = tempfile.mkdtemp()
+            with OutputCapture(), mocks.local.Git(dirname, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
+                self.assertEqual(0, program.main(
+                    args=('setup-git-svn',),
+                    path=dirname,
+                    subversion=self.svn_remote,
+                ))
+
+            with OutputCapture() as captured, mocks.local.Git(dirname, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
+                self.assertEqual(0, program.main(
+                    args=('setup-git-svn', '--all-branches'),
+                    path=dirname,
+                    subversion=self.svn_remote,
+                ))
+            self.assertEqual(
+                captured.stdout.getvalue(),
+                'Adding svn-remote to git config\n' +
+                'Populating svn commit mapping (will take a few minutes)...\n',
+            )
+
+            with open(os.path.join(dirname, '.git/config')) as config:
+                self.assertEqual(
+                    config.read(),
+                    '[core]\n'
+                    '\trepositoryformatversion = 0\n'
+                    '\tfilemode = true\n'
+                    '\tbare = false\n'
+                    '\tlogallrefupdates = true\n'
+                    '\tignorecase = true\n'
+                    '\tprecomposeunicode = true\n'
+                    '[remote "origin"]\n'
+                    '\turl = {git_remote}\n'
+                    '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
+                    '[branch "main"]\n'
+                    '\tremote = origin\n'
+                    '\tmerge = refs/heads/main\n'
+                    '[svn-remote "svn"]\n'
+                    '\turl = {svn_remote}\n'
+                    '\tfetch = trunk:refs/remotes/origin/main\n'
+                    '\tfetch = branches/branch-a:refs/remotes/origin/branch-a\n'
+                    '\tfetch = branches/branch-b:refs/remotes/origin/branch-b\n'.format(
+                        git_remote=self.git_remote,
+                        svn_remote=self.svn_remote,
+                    ),
+                )
+
+        finally:
+            shutil.rmtree(dirname)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to