Skip to content
Permalink
Browse files
[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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@289659 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Feb 11, 2022
1 parent 8f020e6 commit e90dfd8d81e91ca0df39ed9f2fa26fa4148e614d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
@@ -1,3 +1,19 @@
2022-02-02 Jonathan Bedard <jbedard@apple.com>

[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 <jbedard@apple.com>

Git commit message hook should allow source = 'template' case
@@ -29,7 +29,7 @@ def readme():

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=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"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)))
@@ -883,6 +883,8 @@ def pull(self, autostash=False):
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:
@@ -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,32 +138,44 @@ def main(cls, args, repository, **kwargs):
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):
sys.stderr.write("Failed to rebase '{}' on '{},' please resolve conflicts\n".format(repository.branch, branch_point.branch))
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)))
sys.stderr.write("Your checkout may be mis-configured, try re-running 'git-webkit setup' or\n")
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
@@ -271,7 +271,7 @@ def test_no_modified(self):
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 @@ def test_staged(self):
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'...
Creating commit...
Found 1 commit...
Creating commit...
Rebasing 'eng/pr-branch' on 'main'...
Rebased 'eng/pr-branch' on 'main!'
Found 1 commit...""")
@@ -310,9 +310,9 @@ def test_modified(self):
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 @@ def test_github(self):
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Creating the local development branch 'eng/pr-branch'...",
'Creating commit...',
' Found 1 commit...',
'Creating commit...',
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
@@ -373,8 +373,8 @@ def test_github_update(self):
log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Amending commit...",
' Found 1 commit...',
"Amending commit...",
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
@@ -408,9 +408,8 @@ def test_github_append(self):
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 @@ def test_github_reopen(self):
log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Amending commit...",
' Found 1 commit...',
"Amending commit...",
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
@@ -484,8 +483,8 @@ def test_bitbucket(self):
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Creating the local development branch 'eng/pr-branch'...",
'Creating commit...',
' Found 1 commit...',
'Creating commit...',
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
@@ -521,8 +520,8 @@ def test_bitbucket_update(self):
log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Amending commit...",
' Found 1 commit...',
"Amending commit...",
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
@@ -558,9 +557,8 @@ def test_bitbucket_append(self):
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 @@ def test_bitbucket_reopen(self):
log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
"Amending commit...",
' Found 1 commit...',
"Amending commit...",
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",

0 comments on commit e90dfd8

Please sign in to comment.