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 12 matching lines...) Expand all Loading... | |
23 Args: | 23 Args: |
24 host: A Host object. | 24 host: A Host object. |
25 path: Optional, the directory where LocalWPT will check out web-plat form-tests. | 25 path: Optional, the directory where LocalWPT will check out web-plat form-tests. |
26 no_fetch: Optional, passing true will skip updating the local WPT. | 26 no_fetch: Optional, passing true will skip updating the local WPT. |
27 Intended for use only in development after fetching once. | 27 Intended for use only in development after fetching once. |
28 use_github: Optional, passing true will check if the GitHub remote i s enabled | 28 use_github: Optional, passing true will check if the GitHub remote i s enabled |
29 (necessary for later pull request steps). | 29 (necessary for later pull request steps). |
30 """ | 30 """ |
31 self.host = host | 31 self.host = host |
32 self.path = path | 32 self.path = path |
33 self.branch_name = 'chromium-export-try' | |
33 | 34 |
34 if no_fetch: | 35 if no_fetch: |
35 _log.info('Skipping remote WPT fetch') | 36 _log.info('Skipping remote WPT fetch') |
36 return | 37 return |
37 | 38 |
38 if self.host.filesystem.exists(self.path): | 39 if self.host.filesystem.exists(self.path): |
39 _log.info('WPT checkout exists at %s, fetching latest', self.path) | 40 _log.info('WPT checkout exists at %s, fetching latest', self.path) |
40 self.run(['git', 'fetch', '--all']) | 41 self.run(['git', 'fetch', '--all']) |
41 self.run(['git', 'checkout', 'origin/master']) | 42 self.run(['git', 'checkout', 'origin/master']) |
42 else: | 43 else: |
(...skipping 18 matching lines...) Expand all Loading... | |
61 position = position.strip() | 62 position = position.strip() |
62 assert position | 63 assert position |
63 | 64 |
64 chromium_commit = ChromiumCommit(self.host, position=position) | 65 chromium_commit = ChromiumCommit(self.host, position=position) |
65 return sha, chromium_commit | 66 return sha, chromium_commit |
66 | 67 |
67 def clean(self): | 68 def clean(self): |
68 self.run(['git', 'reset', '--hard', 'HEAD']) | 69 self.run(['git', 'reset', '--hard', 'HEAD']) |
69 self.run(['git', 'clean', '-fdx']) | 70 self.run(['git', 'clean', '-fdx']) |
70 self.run(['git', 'checkout', 'origin/master']) | 71 self.run(['git', 'checkout', 'origin/master']) |
72 try: | |
73 self.run(['git', 'branch', '-D', self.branch_name]) | |
74 except ScriptError: | |
75 pass | |
qyearsley
2017/01/06 19:20:24
What kind of circumstance would result in a Script
jeffcarp
2017/01/06 23:51:59
If the branch doesn't exist, it throws a ScriptErr
| |
71 | 76 |
72 def all_branches(self): | 77 def all_branches(self): |
73 """Returns a list of local and remote branches.""" | 78 """Returns a list of local and remote branches.""" |
74 return self.run(['git', 'branch', '-a']).splitlines() | 79 return self.run(['git', 'branch', '-a']).splitlines() |
75 | 80 |
76 def create_branch_with_patch(self, message, patch): | 81 def create_branch_with_patch(self, message, patch): |
77 """Commits the given patch and pushes to the upstream repo. | 82 """Commits the given patch and pushes to the upstream repo. |
78 | 83 |
79 Args: | 84 Args: |
80 message: Commit message string. | 85 message: Commit message string. |
81 patch: A patch that can be applied by git apply. | 86 patch: A patch that can be applied by git apply. |
82 """ | 87 """ |
83 self.clean() | 88 self.clean() |
84 all_branches = self.all_branches() | 89 all_branches = self.all_branches() |
85 branch_name = 'chromium-export-try' | 90 remote_branch_name = 'remotes/github/%s' % self.branch_name |
qyearsley
2017/01/06 19:20:24
Where is the remote name "github" determined?
jeffcarp
2017/01/06 23:51:59
Right now it's set manually when I add it to the l
| |
86 remote_branch_name = 'remotes/github/%s' % branch_name | |
87 | 91 |
88 if branch_name in all_branches: | 92 if self.branch_name in all_branches: |
89 _log.info('Local branch %s already exists, deleting', branch_name) | 93 _log.info('Local branch %s already exists, deleting', self.branch_na me) |
90 self.run(['git', 'branch', '-D', branch_name]) | 94 self.run(['git', 'branch', '-D', self.branch_name]) |
91 | 95 |
96 # TODO(jeffcarp): this is broken | |
qyearsley
2017/01/06 19:20:24
Should be more specific: What's broken, how, and w
jeffcarp
2017/01/07 00:08:48
Removing this functionality. Since we're deleting
| |
92 if remote_branch_name in all_branches: | 97 if remote_branch_name in all_branches: |
93 _log.info('Remote branch %s already exists, deleting', branch_name) | 98 _log.info('Remote branch %s already exists, deleting', self.branch_n ame) |
94 # TODO(jeffcarp): Investigate what happens when remote branch exists . | 99 # TODO(jeffcarp): Investigate what happens when remote branch exists . |
95 self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) | 100 self.run(['git', 'push', 'github', ':{}'.format(self.branch_name)]) |
96 | 101 |
97 _log.info('Creating local branch %s', branch_name) | 102 _log.info('Creating local branch %s', self.branch_name) |
98 self.run(['git', 'checkout', '-b', branch_name]) | 103 self.run(['git', 'checkout', '-b', self.branch_name]) |
99 | 104 |
100 # Remove Chromium WPT directory prefix. | 105 # Remove Chromium WPT directory prefix. |
101 patch = patch.replace(CHROMIUM_WPT_DIR, '') | 106 patch = patch.replace(CHROMIUM_WPT_DIR, '') |
102 | 107 |
103 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/')) | 108 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/')) |
104 # or something not off-by-one. | 109 # or something not off-by-one. |
105 self.run(['git', 'apply', '-'], input=patch) | 110 self.run(['git', 'apply', '-'], input=patch) |
106 self.run(['git', 'commit', '-am', message]) | 111 self.run(['git', 'commit', '-am', message]) |
107 self.run(['git', 'push', 'github', branch_name]) | 112 self.run(['git', 'push', 'github', self.branch_name]) |
108 | 113 |
109 return branch_name | 114 return self.branch_name |
110 | 115 |
111 def test_patch(self, patch): | 116 def test_patch(self, patch): |
112 """Returns the expected output of a patch against origin/master. | 117 """Returns the expected output of a patch against origin/master. |
113 | 118 |
114 Args: | 119 Args: |
115 patch: The patch to test against. | 120 patch: The patch to test against. |
116 | 121 |
117 Returns: | 122 Returns: |
118 A string containing the diff the patch produced. | 123 A string containing the diff the patch produced. |
119 """ | 124 """ |
120 self.clean() | 125 self.clean() |
121 | 126 |
122 # Remove Chromium WPT directory prefix. | 127 # Remove Chromium WPT directory prefix. |
123 patch = patch.replace(CHROMIUM_WPT_DIR, '') | 128 patch = patch.replace(CHROMIUM_WPT_DIR, '') |
124 | 129 |
125 try: | 130 try: |
126 self.run(['git', 'apply', '-'], input=patch) | 131 self.run(['git', 'apply', '-'], input=patch) |
127 self.run(['git', 'add', '.']) | 132 self.run(['git', 'add', '.']) |
128 output = self.run(['git', 'diff', 'origin/master']) | 133 output = self.run(['git', 'diff', 'origin/master']) |
129 except ScriptError as error: | 134 except ScriptError as error: |
130 _log.error('Error while applying patch: %s', error) | 135 _log.info('Patch did not apply cleanly, skipping...') |
qyearsley
2017/01/06 19:20:24
This could also be "warning" rather than "info".
| |
131 output = '' | 136 output = '' |
132 | 137 |
133 self.clean() | 138 self.clean() |
134 return output | 139 return output |
135 | 140 |
136 def commits_behind_master(self, commit): | 141 def commits_behind_master(self, commit): |
137 """Returns the number of commits after the given commit on origin/master . | 142 """Returns the number of commits after the given commit on origin/master . |
138 | 143 |
139 This doesn't include the given commit, and this assumes that the given | 144 This doesn't include the given commit, and this assumes that the given |
140 commit is on the the master branch. | 145 commit is on the the master branch. |
141 """ | 146 """ |
142 return len(self.run([ | 147 return len(self.run([ |
143 'git', 'rev-list', '{}..origin/master'.format(commit) | 148 'git', 'rev-list', '{}..origin/master'.format(commit) |
144 ]).splitlines()) | 149 ]).splitlines()) |
OLD | NEW |