Title: [281821] trunk/Tools
Revision
281821
Author
jbed...@apple.com
Date
2021-08-31 13:42:13 -0700 (Tue, 31 Aug 2021)

Log Message

[git-webkit] Automatic rebasing or pull-requests
https://bugs.webkit.org/show_bug.cgi?id=229625
<rdar://problem/82451030>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.pull): Add rebase and branch arguments.
* Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
(Git.__init__): Add pull.rebase = true in default config.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py:
(Pull): Add 'up' and 'update' aliases.
(Pull.main): Update the source branch of a pull-request branches.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.parser): Add --rebase/--no-rebase options.
(PullRequest.main): Update and rebase a pull-request on it's source branch.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
(TestPullRequest.test_staged):
(TestPullRequest.test_modified):
(TestPullRequest.test_github):
(TestPullRequest.test_github_update):
(TestPullRequest.test_bitbucket):
(TestPullRequest.test_bitbucket_update):
* Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py:
(TestSetupGitSvn.test_empty):
(TestSetupGitSvn.test_add):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (281820 => 281821)


--- trunk/Tools/ChangeLog	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/ChangeLog	2021-08-31 20:42:13 UTC (rev 281821)
@@ -1,3 +1,34 @@
+2021-08-31  Jonathan Bedard  <jbed...@apple.com>
+
+        [git-webkit] Automatic rebasing or pull-requests
+        https://bugs.webkit.org/show_bug.cgi?id=229625
+        <rdar://problem/82451030>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
+        (Git.pull): Add rebase and branch arguments.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
+        (Git.__init__): Add pull.rebase = true in default config.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py:
+        (Pull): Add 'up' and 'update' aliases.
+        (Pull.main): Update the source branch of a pull-request branches.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
+        (PullRequest.parser): Add --rebase/--no-rebase options.
+        (PullRequest.main): Update and rebase a pull-request on it's source branch.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
+        (TestPullRequest.test_staged):
+        (TestPullRequest.test_modified):
+        (TestPullRequest.test_github):
+        (TestPullRequest.test_github_update):
+        (TestPullRequest.test_bitbucket):
+        (TestPullRequest.test_bitbucket_update):
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py:
+        (TestSetupGitSvn.test_empty):
+        (TestSetupGitSvn.test_add):
+
 2021-08-31  Kate Cheney  <katherine_che...@apple.com>
 
         Loads after session restore marked app initiated in Safari

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='2.0.0',
+    version='2.0.1',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(2, 0, 0)
+version = Version(2, 0, 1)
 
 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 (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -771,9 +771,14 @@
             cwd=self.root_path,
         ).returncode else self.commit()
 
-    def pull(self):
-        commit = self.commit()
-        code = run([self.executable(), 'pull'], cwd=self.root_path).returncode
+    def pull(self, rebase=None, branch=None):
+        code = run(
+            [self.executable(), 'pull'] + (
+                ['origin', branch] if branch else []
+            ) + (
+                [] if rebase is None else ['--rebase={}'.format('True' if rebase else 'False')]
+            ), 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),

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -92,6 +92,8 @@
                     '\tlogallrefupdates = true\n'
                     '\tignorecase = true\n'
                     '\tprecomposeunicode = true\n'
+                    '[pull]\n'
+	                '\trebase = true\n'
                     '[remote "origin"]\n'
                     '\turl = {remote}\n'
                     '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -23,10 +23,13 @@
 import sys
 
 from .command import Command
+from .pull_request import PullRequest
+from webkitscmpy import local
 
 
 class Pull(Command):
     name = 'pull'
+    aliases = ['up', 'update']
     help = 'Update the current checkout, synchronize git-svn if configured'
 
     @classmethod
@@ -34,4 +37,8 @@
         if not repository.path:
             sys.stderr.write('Cannot update remote repository\n')
             return 1
+
+        if isinstance(repository, local.Git):
+            branch_point = PullRequest.branch_point(args, repository, **kwargs)
+            return repository.pull(rebase=True, branch=branch_point.branch)
         return repository.pull()

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -38,11 +38,17 @@
     def parser(cls, parser, loggers=None):
         Branch.parser(parser, loggers=loggers)
         parser.add_argument(
-            '--no-add', '--add',
+            '--add', '--no-add',
             dest='will_add', default=None,
             help='When drafting a change, add (or never add) modified files to set of staged changes to be committed',
             action=""
         )
+        parser.add_argument(
+            '--rebase', '--no-rebase',
+            dest='rebase', default=None,
+            help='Rebase (or do not rebase) the pull-request on the source branch before pushing',
+            action=""
+        )
 
     @classmethod
     def create_commit(cls, args, repository, **kwargs):
@@ -105,6 +111,12 @@
             return result
 
         branch_point = cls.branch_point(args, repository, **kwargs)
+        if args.rebase or (args.rebase is None and repository.config().get('pull.rebase')):
+            log.warning("Rebasing '{}' on '{}'...".format(repository.branch, branch_point.branch))
+            if repository.pull(rebase=True, branch=branch_point.branch):
+                sys.stderr.write("Failed to rebase '{}' on '{},' please resolve conflicts\n".format(repository.branch, branch_point.branch))
+                return 1
+            log.warning("Rebased '{}' on '{}!'".format(repository.branch, branch_point.branch))
 
         rmt = repository.remote()
         if not rmt:

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -194,6 +194,8 @@
         self.assertEqual(captured.root.log.getvalue(), '''Creating the local development branch 'eng/pr-branch'...
 Creating commit...
     Found 1 commit...
+Rebasing 'eng/pr-branch' on 'main'...
+Rebased 'eng/pr-branch' on 'main!'
 ''')
         self.assertEqual(captured.stderr.getvalue(), "'{}' doesn't have a recognized remote\n".format(self.path))
 
@@ -213,6 +215,8 @@
     Adding modified.txt...
 Creating commit...
     Found 1 commit...
+Rebasing 'eng/pr-branch' on 'main'...
+Rebased 'eng/pr-branch' on 'main!'
 ''')
 
     def test_github(self):
@@ -228,10 +232,12 @@
         self.assertEqual(captured.stderr.getvalue(), '')
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
-            log[:4] + log[7 if sys.version_info > (3, 0) else 5:], [
+            log[:6] + log[9 if sys.version_info > (3, 0) else 7:], [
                 "Creating the local development branch 'eng/pr-branch'...",
                 'Creating commit...',
                 '    Found 1 commit...',
+                "Rebasing 'eng/pr-branch' on 'main'...",
+                "Rebased 'eng/pr-branch' on 'main!'",
                 "Pushing 'eng/pr-branch' to 'fork'...",
                 "Creating pull-request for 'eng/pr-branch'...",
                 "Created 'PR 1 | Created commit'!",
@@ -257,9 +263,11 @@
         self.assertEqual(captured.stderr.getvalue(), '')
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
-            log[:3] + log[6 if sys.version_info > (3, 0) else 4:], [
+            log[:5] + log[8 if sys.version_info > (3, 0) else 6:], [
                 "Amending commit...",
                 '    Found 1 commit...',
+                "Rebasing 'eng/pr-branch' on 'main'...",
+                "Rebased 'eng/pr-branch' on 'main!'",
                 "Pushing 'eng/pr-branch' to 'fork'...",
                 "Updating pull-request for 'eng/pr-branch'...",
                 "Updated 'PR 1 | Amended commit'!",
@@ -266,7 +274,7 @@
             ],
         )
 
-    def test_stash(self):
+    def test_bitbucket(self):
         with OutputCapture() as captured, mocks.remote.BitBucket() as remote, mocks.local.Git(self.path, remote='ssh://git@{}/{}/{}.git'.format(
             remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3],
         )) as repo, mocks.local.Svn():
@@ -280,10 +288,12 @@
         self.assertEqual(captured.stderr.getvalue(), '')
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
-            log[:4] + log[7 if sys.version_info > (3, 0) else 5:], [
+            log[:6] + log[9 if sys.version_info > (3, 0) else 7:], [
                 "Creating the local development branch 'eng/pr-branch'...",
                 'Creating commit...',
                 '    Found 1 commit...',
+                "Rebasing 'eng/pr-branch' on 'main'...",
+                "Rebased 'eng/pr-branch' on 'main!'",
                 "Pushing 'eng/pr-branch' to 'origin'...",
                 "Creating pull-request for 'eng/pr-branch'...",
                 "Created 'PR 1 | Created commit'!",
@@ -290,7 +300,7 @@
             ],
         )
 
-    def test_stash_update(self):
+    def test_bitbucket_update(self):
         with mocks.remote.BitBucket() as remote, mocks.local.Git(self.path, remote='ssh://git@{}/{}/{}.git'.format(
             remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3],
         )) as repo, mocks.local.Svn():
@@ -311,9 +321,11 @@
         self.assertEqual(captured.stderr.getvalue(), '')
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
-            log[:3] + log[6 if sys.version_info > (3, 0) else 4:], [
+            log[:5] + log[8 if sys.version_info > (3, 0) else 6:], [
                 "Amending commit...",
                 '    Found 1 commit...',
+                "Rebasing 'eng/pr-branch' on 'main'...",
+                "Rebased 'eng/pr-branch' on 'main!'",
                 "Pushing 'eng/pr-branch' to 'origin'...",
                 "Updating pull-request for 'eng/pr-branch'...",
                 "Updated 'PR 1 | Amended commit'!",

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py (281820 => 281821)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py	2021-08-31 20:40:41 UTC (rev 281820)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py	2021-08-31 20:42:13 UTC (rev 281821)
@@ -69,6 +69,8 @@
                 '\tlogallrefupdates = true\n'
                 '\tignorecase = true\n'
                 '\tprecomposeunicode = true\n'
+                '[pull]\n'
+	            '\trebase = true\n'
                 '[remote "origin"]\n'
                 '\turl = {git_remote}\n'
                 '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
@@ -113,6 +115,8 @@
                 '\tlogallrefupdates = true\n'
                 '\tignorecase = true\n'
                 '\tprecomposeunicode = true\n'
+                '[pull]\n'
+	            '\trebase = true\n'
                 '[remote "origin"]\n'
                 '\turl = {git_remote}\n'
                 '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to