Title: [289659] trunk/Tools
Revision
289659
Author
[email protected]
Date
2022-02-11 12:25:34 -0800 (Fri, 11 Feb 2022)

Log Message

[git-webkit] Handle local commit on production branch
https://bugs.webkit.org/show_bug.cgi?id=235974
<rdar://problem/88346615>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py: Handle moving
branches to remote reference.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.main): Move local branch ref to remote reference.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:

Canonical link: https://commits.webkit.org/247151@main

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (289658 => 289659)


--- trunk/Tools/ChangeLog	2022-02-11 20:19:40 UTC (rev 289658)
+++ trunk/Tools/ChangeLog	2022-02-11 20:25:34 UTC (rev 289659)
@@ -1,3 +1,19 @@
+2022-02-02  Jonathan Bedard  <[email protected]>
+
+        [git-webkit] Handle local commit on production branch
+        https://bugs.webkit.org/show_bug.cgi?id=235974
+        <rdar://problem/88346615>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py: Handle moving
+        branches to remote reference.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
+        (PullRequest.main): Move local branch ref to remote reference.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
+
 2022-02-11  Jonathan Bedard  <[email protected]>
 
         Git commit message hook should allow source = 'template' case

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (289658 => 289659)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-02-11 20:19:40 UTC (rev 289658)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-02-11 20:25:34 UTC (rev 289659)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.1.1',
+    version='4.1.2',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (289658 => 289659)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-02-11 20:19:40 UTC (rev 289658)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-02-11 20:25:34 UTC (rev 289659)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 1, 1)
+version = Version(4, 1, 2)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2022-02-11 20:19:40 UTC (rev 289658)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2022-02-11 20:25:34 UTC (rev 289659)
@@ -883,6 +883,8 @@
         return mocks.ProcessCompletion(returncode=0)
 
     def move_branch(self, to_be_moved, moved_to):
+        if moved_to.startswith('remotes/'):
+            moved_to = moved_to.split('/', 2)[-1]
         if moved_to == self.default_branch:
             return mocks.ProcessCompletion(returncode=0)
         if to_be_moved != self.default_branch:

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2022-02-11 20:19:40 UTC (rev 289658)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2022-02-11 20:25:34 UTC (rev 289659)
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 Apple Inc. All rights reserved.
+# Copyright (C) 2021-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -138,11 +138,21 @@
             sys.stderr.write("Creating a pull-request for '{}' but we're on '{}'\n".format(args.issue, repository.branch))
             return 1
 
+        # FIXME: Source remote will not always be origin
+        source_remote = 'origin'
+        branch_point = Branch.branch_point(repository)
+        if run([
+            repository.executable(), 'branch', '-f',
+            branch_point.branch,
+            'remotes/{}/{}'.format(source_remote, branch_point.branch),
+        ], cwd=repository.root_path).returncode:
+            sys.stderr.write("Failed to match '{}' to it's remote '{}'\n".format(branch_point.branch, source_remote))
+            return 1
+
         result = cls.create_commit(args, repository, **kwargs)
         if result:
             return result
 
-        branch_point = Branch.branch_point(repository)
         if args.rebase or (args.rebase is None and repository.config().get('pull.rebase')):
             log.info("Rebasing '{}' on '{}'...".format(repository.branch, branch_point.branch))
             if repository.pull(rebase=True, branch=branch_point.branch):
@@ -150,12 +160,14 @@
                 return 1
             log.info("Rebased '{}' on '{}!'".format(repository.branch, branch_point.branch))
             branch_point = Branch.branch_point(repository)
+        else:
+            branch_point = Branch.branch_point(repository)
 
-        rmt = repository.remote()
+        rmt = repository.remote(name=source_remote)
         if not rmt:
             sys.stderr.write("'{}' doesn't have a recognized remote\n".format(repository.root_path))
             return 1
-        target = 'fork' if isinstance(rmt, remote.GitHub) else 'origin'
+        target = 'fork' if isinstance(rmt, remote.GitHub) else source_remote
         log.info("Pushing '{}' to '{}'...".format(repository.branch, target))
         if run([repository.executable(), 'push', '-f', target, repository.branch], cwd=repository.root_path).returncode:
             sys.stderr.write("Failed to push '{}' to '{}' (alias of '{}')\n".format(repository.branch, target, repository.url(name=target)))
@@ -163,7 +175,7 @@
             sys.stderr.write("your checkout may not have permission to push to '{}'\n".format(repository.url(name=target)))
             return 1
 
-        if args.history or (target != 'origin' and args.history is None and args.technique == 'overwrite'):
+        if args.history or (target != source_remote and args.history is None and args.technique == 'overwrite'):
             regex = re.compile(r'^{}-(?P<count>\d+)$'.format(repository.branch))
             count = max([
                 int(regex.match(branch).group('count')) if regex.match(branch) else 0 for branch in

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2022-02-11 20:19:40 UTC (rev 289658)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2022-02-11 20:25:34 UTC (rev 289659)
@@ -271,7 +271,7 @@
                 args=('pull-request', '-i', 'pr-branch', '-v'),
                 path=self.path,
             ))
-        self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/pr-branch'...\n")
+        self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/pr-branch'...\n    Found 1 commit...\n")
         self.assertEqual(captured.stderr.getvalue(), 'No modified files\n')
 
     def test_staged(self):
@@ -287,8 +287,8 @@
         self.assertEqual(
             '\n'.join([line for line in captured.root.log.getvalue().splitlines() if 'Mock process' not in line]),
             """Creating the local development branch 'eng/pr-branch'...
+    Found 1 commit...
 Creating commit...
-    Found 1 commit...
 Rebasing 'eng/pr-branch' on 'main'...
 Rebased 'eng/pr-branch' on 'main!'
     Found 1 commit...""")
@@ -310,9 +310,9 @@
         self.assertEqual(
             '\n'.join([line for line in captured.root.log.getvalue().splitlines() if 'Mock process' not in line]),
             """Creating the local development branch 'eng/pr-branch'...
+    Found 1 commit...
     Adding modified.txt...
 Creating commit...
-    Found 1 commit...
 Rebasing 'eng/pr-branch' on 'main'...
 Rebased 'eng/pr-branch' on 'main!'
     Found 1 commit...""")
@@ -338,8 +338,8 @@
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
                 "Creating the local development branch 'eng/pr-branch'...",
+                '    Found 1 commit...',
                 'Creating commit...',
-                '    Found 1 commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 "    Found 1 commit...",
@@ -373,8 +373,8 @@
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
                 "Amending commit...",
-                '    Found 1 commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 "    Found 1 commit...",
@@ -408,9 +408,8 @@
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
-                "Creating commit...",
                 '    Found 1 commit...',
-                '    Found 2 commits...',
+                'Creating commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 '    Found 1 commit...',
@@ -452,8 +451,8 @@
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
                 "Amending commit...",
-                '    Found 1 commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 "    Found 1 commit...",
@@ -484,8 +483,8 @@
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
                 "Creating the local development branch 'eng/pr-branch'...",
+                '    Found 1 commit...',
                 'Creating commit...',
-                '    Found 1 commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 "    Found 1 commit...",
@@ -521,8 +520,8 @@
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
                 "Amending commit...",
-                '    Found 1 commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 "    Found 1 commit...",
@@ -558,9 +557,8 @@
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
-                "Creating commit...",
                 '    Found 1 commit...',
-                '    Found 2 commits...',
+                'Creating commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 '    Found 1 commit...',
@@ -604,8 +602,8 @@
         log = captured.root.log.getvalue().splitlines()
         self.assertEqual(
             [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
                 "Amending commit...",
-                '    Found 1 commit...',
                 "Rebasing 'eng/pr-branch' on 'main'...",
                 "Rebased 'eng/pr-branch' on 'main!'",
                 "    Found 1 commit...",
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to