OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """A utility class for interacting with a local checkout of the Web Platform Tes
ts.""" | 5 """A utility class for interacting with a local checkout of the Web Platform Tes
ts.""" |
6 | 6 |
7 import logging | 7 import logging |
8 | 8 |
9 from webkitpy.common.system.executive import ScriptError | 9 from webkitpy.common.system.executive import ScriptError |
10 from webkitpy.w3c.chromium_commit import ChromiumCommit | 10 from webkitpy.w3c.chromium_commit import ChromiumCommit |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 self.run(['git', 'reset', '--hard', 'HEAD']) | 69 self.run(['git', 'reset', '--hard', 'HEAD']) |
70 self.run(['git', 'clean', '-fdx']) | 70 self.run(['git', 'clean', '-fdx']) |
71 self.run(['git', 'checkout', 'origin/master']) | 71 self.run(['git', 'checkout', 'origin/master']) |
72 if self.branch_name in self.all_branches(): | 72 if self.branch_name in self.all_branches(): |
73 self.run(['git', 'branch', '-D', self.branch_name]) | 73 self.run(['git', 'branch', '-D', self.branch_name]) |
74 | 74 |
75 def all_branches(self): | 75 def all_branches(self): |
76 """Returns a list of local and remote branches.""" | 76 """Returns a list of local and remote branches.""" |
77 return self.run(['git', 'branch', '-a']).splitlines() | 77 return self.run(['git', 'branch', '-a']).splitlines() |
78 | 78 |
79 def create_branch_with_patch(self, message, patch): | 79 def create_branch_with_patch(self, message, patch, author): |
80 """Commits the given patch and pushes to the upstream repo. | 80 """Commits the given patch and pushes to the upstream repo. |
81 | 81 |
82 Args: | 82 Args: |
83 message: Commit message string. | 83 message: Commit message string. |
84 patch: A patch that can be applied by git apply. | 84 patch: A patch that can be applied by git apply. |
85 """ | 85 """ |
86 self.clean() | 86 self.clean() |
87 all_branches = self.all_branches() | 87 all_branches = self.all_branches() |
88 | 88 |
89 if self.branch_name in all_branches: | 89 if self.branch_name in all_branches: |
90 _log.info('Local branch %s already exists, deleting', self.branch_na
me) | 90 _log.info('Local branch %s already exists, deleting', self.branch_na
me) |
91 self.run(['git', 'branch', '-D', self.branch_name]) | 91 self.run(['git', 'branch', '-D', self.branch_name]) |
92 | 92 |
93 _log.info('Creating local branch %s', self.branch_name) | 93 _log.info('Creating local branch %s', self.branch_name) |
94 self.run(['git', 'checkout', '-b', self.branch_name]) | 94 self.run(['git', 'checkout', '-b', self.branch_name]) |
95 | 95 |
96 # Remove Chromium WPT directory prefix. | 96 # Remove Chromium WPT directory prefix. |
97 patch = patch.replace(CHROMIUM_WPT_DIR, '') | 97 patch = patch.replace(CHROMIUM_WPT_DIR, '') |
98 | 98 |
99 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
(/')) | 99 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
(/')) |
100 # or something not off-by-one. | 100 # or something not off-by-one. |
101 self.run(['git', 'apply', '-'], input=patch) | 101 self.run(['git', 'apply', '-'], input=patch) |
102 self.run(['git', 'commit', '-am', message]) | 102 self.run(['git', 'commit', '--author', author, '-am', message]) |
103 self.run(['git', 'push', 'github', self.branch_name]) | 103 self.run(['git', 'push', 'github', self.branch_name]) |
104 | 104 |
105 return self.branch_name | 105 return self.branch_name |
106 | 106 |
107 def test_patch(self, patch): | 107 def test_patch(self, patch): |
108 """Returns the expected output of a patch against origin/master. | 108 """Returns the expected output of a patch against origin/master. |
109 | 109 |
110 Args: | 110 Args: |
111 patch: The patch to test against. | 111 patch: The patch to test against. |
112 | 112 |
(...skipping 18 matching lines...) Expand all Loading... |
131 | 131 |
132 def commits_behind_master(self, commit): | 132 def commits_behind_master(self, commit): |
133 """Returns the number of commits after the given commit on origin/master
. | 133 """Returns the number of commits after the given commit on origin/master
. |
134 | 134 |
135 This doesn't include the given commit, and this assumes that the given | 135 This doesn't include the given commit, and this assumes that the given |
136 commit is on the the master branch. | 136 commit is on the the master branch. |
137 """ | 137 """ |
138 return len(self.run([ | 138 return len(self.run([ |
139 'git', 'rev-list', '{}..origin/master'.format(commit) | 139 'git', 'rev-list', '{}..origin/master'.format(commit) |
140 ]).splitlines()) | 140 ]).splitlines()) |
OLD | NEW |