OLD | NEW |
1 # coding=utf8 | 1 # coding=utf8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Manages a project checkout. | 5 """Manages a project checkout. |
6 | 6 |
7 Includes support for svn, git-svn and git. | 7 Includes support for svn, git-svn and git. |
8 """ | 8 """ |
9 | 9 |
10 import ConfigParser | 10 import ConfigParser |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 ['log', '-q', self.svn_url, '-r', '%s:%s' % (rev1, rev2)]) | 546 ['log', '-q', self.svn_url, '-r', '%s:%s' % (rev1, rev2)]) |
547 except subprocess.CalledProcessError: | 547 except subprocess.CalledProcessError: |
548 return None | 548 return None |
549 # Ignore the '----' lines. | 549 # Ignore the '----' lines. |
550 return len([l for l in out.splitlines() if l.startswith('r')]) - 1 | 550 return len([l for l in out.splitlines() if l.startswith('r')]) - 1 |
551 | 551 |
552 | 552 |
553 class GitCheckout(CheckoutBase): | 553 class GitCheckout(CheckoutBase): |
554 """Manages a git checkout.""" | 554 """Manages a git checkout.""" |
555 def __init__(self, root_dir, project_name, remote_branch, git_url, | 555 def __init__(self, root_dir, project_name, remote_branch, git_url, |
556 commit_user, post_processors=None): | 556 commit_user, post_processors=None, base_ref=None): |
557 super(GitCheckout, self).__init__(root_dir, project_name, post_processors) | 557 super(GitCheckout, self).__init__(root_dir, project_name, post_processors) |
| 558 self.base_ref = base_ref |
558 self.git_url = git_url | 559 self.git_url = git_url |
559 self.commit_user = commit_user | 560 self.commit_user = commit_user |
560 self.remote_branch = remote_branch | 561 self.remote_branch = remote_branch |
561 # The working branch where patches will be applied. It will track the | 562 # The working branch where patches will be applied. It will track the |
562 # remote branch. | 563 # remote branch. |
563 self.working_branch = 'working_branch' | 564 self.working_branch = 'working_branch' |
564 # There is no reason to not hardcode origin. | 565 # There is no reason to not hardcode origin. |
565 self.remote = 'origin' | 566 self.remote = 'origin' |
566 # There is no reason to not hardcode master. | 567 # There is no reason to not hardcode master. |
567 self.master_branch = 'master' | 568 self.master_branch = 'master' |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 'While running %s;\n%s%s' % ( | 704 'While running %s;\n%s%s' % ( |
704 ' '.join(e.cmd), | 705 ' '.join(e.cmd), |
705 align_stdout(stdout), | 706 align_stdout(stdout), |
706 align_stdout([getattr(e, 'stdout', '')]))) | 707 align_stdout([getattr(e, 'stdout', '')]))) |
707 # Once all the patches are processed and added to the index, commit the | 708 # Once all the patches are processed and added to the index, commit the |
708 # index. | 709 # index. |
709 cmd = ['commit', '-m', 'Committed patch'] | 710 cmd = ['commit', '-m', 'Committed patch'] |
710 if verbose: | 711 if verbose: |
711 cmd.append('--verbose') | 712 cmd.append('--verbose') |
712 self._check_call_git(cmd) | 713 self._check_call_git(cmd) |
| 714 if self.base_ref: |
| 715 base_ref = self.base_ref |
| 716 else: |
| 717 base_ref = '%s/%s' % (self.remote, |
| 718 self.remote_branch or self.master_branch) |
713 found_files = self._check_output_git( | 719 found_files = self._check_output_git( |
714 ['diff', '%s/%s' % (self.remote, | 720 ['diff', base_ref, |
715 self.remote_branch or self.master_branch), | |
716 '--name-only']).splitlines(False) | 721 '--name-only']).splitlines(False) |
717 assert sorted(patches.filenames) == sorted(found_files), ( | 722 assert sorted(patches.filenames) == sorted(found_files), ( |
718 sorted(patches.filenames), sorted(found_files)) | 723 sorted(patches.filenames), sorted(found_files)) |
719 | 724 |
720 def commit(self, commit_message, user): | 725 def commit(self, commit_message, user): |
721 """Commits, updates the commit message and pushes.""" | 726 """Commits, updates the commit message and pushes.""" |
722 assert self.commit_user | 727 assert self.commit_user |
723 assert isinstance(commit_message, unicode) | 728 assert isinstance(commit_message, unicode) |
724 current_branch = self._check_output_git( | 729 current_branch = self._check_output_git( |
725 ['rev-parse', '--abbrev-ref', 'HEAD']).strip() | 730 ['rev-parse', '--abbrev-ref', 'HEAD']).strip() |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 def revisions(self, rev1, rev2): | 830 def revisions(self, rev1, rev2): |
826 return self.checkout.revisions(rev1, rev2) | 831 return self.checkout.revisions(rev1, rev2) |
827 | 832 |
828 @property | 833 @property |
829 def project_name(self): | 834 def project_name(self): |
830 return self.checkout.project_name | 835 return self.checkout.project_name |
831 | 836 |
832 @property | 837 @property |
833 def project_path(self): | 838 def project_path(self): |
834 return self.checkout.project_path | 839 return self.checkout.project_path |
OLD | NEW |