Title: [284498] trunk/Tools
Revision
284498
Author
jbed...@apple.com
Date
2021-10-19 14:44:07 -0700 (Tue, 19 Oct 2021)

Log Message

[webkitscmpy] Override http url with ssh url
https://bugs.webkit.org/show_bug.cgi?id=231965
<rdar://problem/84422393>

Reviewed by Ryan Haddad.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git): Exclude / from hostname.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py:
(Setup.git): Prompt user to switch to ssh checkout.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py:
Canonical link: https://commits.webkit.org/243250@main

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (284497 => 284498)


--- trunk/Tools/ChangeLog	2021-10-19 21:41:53 UTC (rev 284497)
+++ trunk/Tools/ChangeLog	2021-10-19 21:44:07 UTC (rev 284498)
@@ -1,3 +1,17 @@
+2021-10-19  Jonathan Bedard  <jbed...@apple.com>
+
+        [webkitscmpy] Override http url with ssh url
+        https://bugs.webkit.org/show_bug.cgi?id=231965
+        <rdar://problem/84422393>
+
+        Reviewed by Ryan Haddad.
+
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
+        (Git): Exclude / from hostname.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py:
+        (Setup.git): Prompt user to switch to ssh checkout.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py:
+
 2021-10-19  Ryan Haddad  <ryanhad...@apple.com>
 
         [EWS] Move EWS bots to iOS 15 / watchOS 8 / tvOS 15

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (284497 => 284498)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-10-19 21:41:53 UTC (rev 284497)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-10-19 21:44:07 UTC (rev 284498)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='2.2.14',
+    version='2.2.15',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (284497 => 284498)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-10-19 21:41:53 UTC (rev 284497)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-10-19 21:44:07 UTC (rev 284498)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(2, 2, 14)
+version = Version(2, 2, 15)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-10-19 21:41:53 UTC (rev 284497)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-10-19 21:44:07 UTC (rev 284498)
@@ -275,7 +275,7 @@
 
     GIT_COMMIT = re.compile(r'commit (?P<hash>[0-9a-f]+)')
     SSH_REMOTE = re.compile('(ssh://)?git@(?P<host>[^:/]+)[:/](?P<path>.+).git')
-    HTTP_REMOTE = re.compile('(?P<protocol>https?)://(?P<host>.+)/(?P<path>.+).git')
+    HTTP_REMOTE = re.compile(r'(?P<protocol>https?)://(?P<host>[^\/]+)/(?P<path>.+).git')
     REMOTE_BRANCH = re.compile(r'remotes\/(?P<remote>[^\/]+)\/(?P<branch>.+)')
 
     @classmethod

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py (284497 => 284498)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py	2021-10-19 21:41:53 UTC (rev 284497)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py	2021-10-19 21:44:07 UTC (rev 284498)
@@ -131,7 +131,7 @@
         log.warning('Set better Objective-C diffing behavior!')
 
         if args.defaults or Terminal.choose(
-            'Auto-color status, diff, and branch?'.format(email),
+            'Auto-color status, diff, and branch?',
             default='Yes',
         ) == 'Yes':
             for command in ('status', 'diff', 'branch'):
@@ -187,6 +187,24 @@
         else:
             log.warning("Set git editor to '{}'".format(editor_name))
 
+        # Pushing to http repositories is difficult, offer to change http checkouts to ssh
+        http_remote = local.Git.HTTP_REMOTE.match(repository.url())
+        if http_remote and not args.defaults and Terminal.choose(
+            "http based remotes will prompt for your password when pushing,\nwould you like to convert to a ssh remote?",
+            default='Yes',
+        ) == 'Yes':
+            if run([
+                local.Git.executable(), 'config', 'remote.origin.url',
+                'git@{}:{}.git'.format(http_remote.group('host'), http_remote.group('path')),
+            ], capture_output=True, cwd=repository.root_path).returncode:
+                sys.stderr.write("Failed to change remote to ssh remote '{}'\n".format(
+                    'git@{}:{}.git'.format(http_remote.group('host'), http_remote.group('path'))
+                ))
+                result += 1
+            else:
+                # Force reset cache
+                repository.url(cached=False)
+
         # Any additional setup passed to main
         if additional_setup:
             result += additional_setup(args, repository)

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py (284497 => 284498)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py	2021-10-19 21:41:53 UTC (rev 284497)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py	2021-10-19 21:44:07 UTC (rev 284498)
@@ -25,7 +25,7 @@
 
 from webkitcorepy import Editor, OutputCapture, testing
 from webkitcorepy.mocks import Terminal as MockTerminal
-from webkitscmpy import program, mocks
+from webkitscmpy import local, program, mocks
 
 
 class TestSetup(testing.PathTestCase):
@@ -95,9 +95,11 @@
 
     def test_github_checkout(self):
         with OutputCapture() as captured, mocks.remote.GitHub() as remote, \
-            MockTerminal.input('n', 'commit...@webkit.org', 'n', 'Committer', 'n', '1', 'y'), \
-            mocks.local.Git(self.path, remote='https://{}'.format(remote.remote)) as repo:
+            MockTerminal.input('n', 'commit...@webkit.org', 'n', 'Committer', 'n', '1', 'y', 'y'), \
+            mocks.local.Git(self.path, remote='https://{}.git'.format(remote.remote)) as repo:
 
+            self.assertEqual('https://github.example.com/WebKit/WebKit.git', local.Git(self.path).url())
+
             self.assertEqual(0, program.main(
                 args=('setup',),
                 path=self.path,
@@ -107,6 +109,7 @@
             self.assertNotIn('color.status', config)
             self.assertEqual('Committer', config.get('user.name', ''))
             self.assertEqual('commit...@webkit.org', config.get('user.email', ''))
+            self.assertEqual('g...@github.example.com:WebKit/WebKit.git', local.Git(self.path).url())
 
         programs = ['default'] + [p.name for p in Editor.programs()]
         self.assertEqual(
@@ -119,10 +122,12 @@
 Pick a commit message editor:
     {}
 : 
+http based remotes will prompt for your password when pushing,
+would you like to convert to a ssh remote? (Yes/No): 
 Create a private fork of 'WebKit' belonging to 'username' (Yes/No): 
 '''.format('\n    '.join(['{}) {}'.format(count + 1, programs[count]) for count in range(len(programs))])))
         self.assertEqual(captured.stderr.getvalue(), '')
-        self.maxDiff = None
+
         self.assertEqual(
             captured.root.log.getvalue(),
             '''Setting git user email for {repository}...
@@ -141,7 +146,7 @@
 Adding forked remote as 'username' and 'fork'...
 Added remote 'username'
 Added remote 'fork'
-Fetching 'https://github.example.com/username/WebKit.git'
+Fetching 'g...@github.example.com:username/WebKit.git'
 '''.format(repository=self.path),
         )
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to