| 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.w3c.chromium_commit import ChromiumCommit |    9 from webkitpy.w3c.chromium_commit import ChromiumCommit | 
|   10  |   10  | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   65  |   65  | 
|   66     def clean(self): |   66     def clean(self): | 
|   67         self.run(['git', 'reset', '--hard', 'HEAD']) |   67         self.run(['git', 'reset', '--hard', 'HEAD']) | 
|   68         self.run(['git', 'clean', '-fdx']) |   68         self.run(['git', 'clean', '-fdx']) | 
|   69         self.run(['git', 'checkout', 'origin/master']) |   69         self.run(['git', 'checkout', 'origin/master']) | 
|   70  |   70  | 
|   71     def all_branches(self): |   71     def all_branches(self): | 
|   72         """Returns a list of local and remote branches.""" |   72         """Returns a list of local and remote branches.""" | 
|   73         return self.run(['git', 'branch', '-a']).splitlines() |   73         return self.run(['git', 'branch', '-a']).splitlines() | 
|   74  |   74  | 
|   75     def create_branch_with_patch(self, branch_name, message, patch): |   75     def create_branch_with_patch(self, message, patch): | 
|   76         """Commits the given patch and pushes to the upstream repo. |   76         """Commits the given patch and pushes to the upstream repo. | 
|   77  |   77  | 
|   78         Args: |   78         Args: | 
|   79             branch_name: A name that is used for both the local branch |  | 
|   80                 and the remote branch on github. |  | 
|   81             message: Commit message string. |   79             message: Commit message string. | 
|   82             patch: A patch that can be applied by git apply. |   80             patch: A patch that can be applied by git apply. | 
|   83         """ |   81         """ | 
|   84         self.clean() |   82         self.clean() | 
|   85         all_branches = self.all_branches() |   83         all_branches = self.all_branches() | 
 |   84         branch_name = 'chromium-export-try' | 
|   86         remote_branch_name = 'remotes/github/%s' % branch_name |   85         remote_branch_name = 'remotes/github/%s' % branch_name | 
|   87  |   86  | 
|   88         if branch_name in all_branches: |   87         if branch_name in all_branches: | 
|   89             _log.info('Local branch %s already exists, deleting', branch_name) |   88             _log.info('Local branch %s already exists, deleting', branch_name) | 
|   90             self.run(['git', 'branch', '-D', branch_name]) |   89             self.run(['git', 'branch', '-D', branch_name]) | 
|   91  |   90  | 
|   92         if remote_branch_name in all_branches: |   91         if remote_branch_name in all_branches: | 
|   93             _log.info('Remote branch %s already exists, deleting', branch_name) |   92             _log.info('Remote branch %s already exists, deleting', branch_name) | 
|   94             # TODO(jeffcarp): Investigate what happens when remote branch exists
     . |   93             # TODO(jeffcarp): Investigate what happens when remote branch exists
     . | 
|   95             self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) |   94             self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) | 
|   96  |   95  | 
|   97         _log.info('Creating local branch %s', branch_name) |   96         _log.info('Creating local branch %s', branch_name) | 
|   98         self.run(['git', 'checkout', '-b', branch_name]) |   97         self.run(['git', 'checkout', '-b', branch_name]) | 
|   99  |   98  | 
|  100         # Remove Chromium WPT directory prefix. |   99         # Remove Chromium WPT directory prefix. | 
|  101         patch = patch.replace(CHROMIUM_WPT_DIR, '') |  100         patch = patch.replace(CHROMIUM_WPT_DIR, '') | 
|  102  |  101  | 
|  103         # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
     (/')) |  102         # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
     (/')) | 
|  104         # or something not off-by-one. |  103         # or something not off-by-one. | 
|  105         self.run(['git', 'apply', '-'], input=patch) |  104         self.run(['git', 'apply', '-'], input=patch) | 
|  106         self.run(['git', 'commit', '-am', message]) |  105         self.run(['git', 'commit', '-am', message]) | 
|  107         self.run(['git', 'push', 'github', branch_name]) |  106         self.run(['git', 'push', 'github', branch_name]) | 
|  108  |  107  | 
 |  108         return branch_name | 
 |  109  | 
|  109     def commits_behind_master(self, commit): |  110     def commits_behind_master(self, commit): | 
|  110         """Returns the number of commits after the given commit on origin/master
     . |  111         """Returns the number of commits after the given commit on origin/master
     . | 
|  111  |  112  | 
|  112         This doesn't include the given commit, and this assumes that the given |  113         This doesn't include the given commit, and this assumes that the given | 
|  113         commit is on the the master branch. |  114         commit is on the the master branch. | 
|  114         """ |  115         """ | 
|  115         return len(self.run([ |  116         return len(self.run([ | 
|  116             'git', 'rev-list', '{}..origin/master'.format(commit) |  117             'git', 'rev-list', '{}..origin/master'.format(commit) | 
|  117         ]).splitlines()) |  118         ]).splitlines()) | 
| OLD | NEW |