Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py

Issue 2608923002: [WPT Export] Delete remote branch, add label, additional refactoring (Closed)
Patch Set: Address CL feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 if self.branch_name in self.all_branches():
73 self.run(['git', 'branch', '-D', self.branch_name])
71 74
72 def all_branches(self): 75 def all_branches(self):
73 """Returns a list of local and remote branches.""" 76 """Returns a list of local and remote branches."""
74 return self.run(['git', 'branch', '-a']).splitlines() 77 return self.run(['git', 'branch', '-a']).splitlines()
75 78
76 def create_branch_with_patch(self, message, patch): 79 def create_branch_with_patch(self, message, patch):
77 """Commits the given patch and pushes to the upstream repo. 80 """Commits the given patch and pushes to the upstream repo.
78 81
79 Args: 82 Args:
80 message: Commit message string. 83 message: Commit message string.
81 patch: A patch that can be applied by git apply. 84 patch: A patch that can be applied by git apply.
82 """ 85 """
83 self.clean() 86 self.clean()
84 all_branches = self.all_branches() 87 all_branches = self.all_branches()
85 branch_name = 'chromium-export-try'
86 remote_branch_name = 'remotes/github/%s' % branch_name
87 88
88 if branch_name in all_branches: 89 if self.branch_name in all_branches:
89 _log.info('Local branch %s already exists, deleting', branch_name) 90 _log.info('Local branch %s already exists, deleting', self.branch_na me)
90 self.run(['git', 'branch', '-D', branch_name]) 91 self.run(['git', 'branch', '-D', self.branch_name])
91 92
92 if remote_branch_name in all_branches: 93 _log.info('Creating local branch %s', self.branch_name)
93 _log.info('Remote branch %s already exists, deleting', branch_name) 94 self.run(['git', 'checkout', '-b', self.branch_name])
94 # TODO(jeffcarp): Investigate what happens when remote branch exists .
95 self.run(['git', 'push', 'github', ':{}'.format(branch_name)])
96
97 _log.info('Creating local branch %s', branch_name)
98 self.run(['git', 'checkout', '-b', branch_name])
99 95
100 # Remove Chromium WPT directory prefix. 96 # Remove Chromium WPT directory prefix.
101 patch = patch.replace(CHROMIUM_WPT_DIR, '') 97 patch = patch.replace(CHROMIUM_WPT_DIR, '')
102 98
103 # 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 (/'))
104 # or something not off-by-one. 100 # or something not off-by-one.
105 self.run(['git', 'apply', '-'], input=patch) 101 self.run(['git', 'apply', '-'], input=patch)
106 self.run(['git', 'commit', '-am', message]) 102 self.run(['git', 'commit', '-am', message])
107 self.run(['git', 'push', 'github', branch_name]) 103 self.run(['git', 'push', 'github', self.branch_name])
108 104
109 return branch_name 105 return self.branch_name
110 106
111 def test_patch(self, patch): 107 def test_patch(self, patch):
112 """Returns the expected output of a patch against origin/master. 108 """Returns the expected output of a patch against origin/master.
113 109
114 Args: 110 Args:
115 patch: The patch to test against. 111 patch: The patch to test against.
116 112
117 Returns: 113 Returns:
118 A string containing the diff the patch produced. 114 A string containing the diff the patch produced.
119 """ 115 """
120 self.clean() 116 self.clean()
121 117
122 # Remove Chromium WPT directory prefix. 118 # Remove Chromium WPT directory prefix.
123 patch = patch.replace(CHROMIUM_WPT_DIR, '') 119 patch = patch.replace(CHROMIUM_WPT_DIR, '')
124 120
125 try: 121 try:
126 self.run(['git', 'apply', '-'], input=patch) 122 self.run(['git', 'apply', '-'], input=patch)
127 self.run(['git', 'add', '.']) 123 self.run(['git', 'add', '.'])
128 output = self.run(['git', 'diff', 'origin/master']) 124 output = self.run(['git', 'diff', 'origin/master'])
129 except ScriptError as error: 125 except ScriptError as error:
130 _log.error('Error while applying patch: %s', error) 126 _log.warning('Patch did not apply cleanly, skipping...')
131 output = '' 127 output = ''
132 128
133 self.clean() 129 self.clean()
134 return output 130 return output
135 131
136 def commits_behind_master(self, commit): 132 def commits_behind_master(self, commit):
137 """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 .
138 134
139 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
140 commit is on the the master branch. 136 commit is on the the master branch.
141 """ 137 """
142 return len(self.run([ 138 return len(self.run([
143 'git', 'rev-list', '{}..origin/master'.format(commit) 139 'git', 'rev-list', '{}..origin/master'.format(commit)
144 ]).splitlines()) 140 ]).splitlines())
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698