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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 ['checkout', '--force', '--quiet', self.master_branch]) | 609 ['checkout', '--force', '--quiet', self.master_branch]) |
610 self._sync_remote_branch() | 610 self._sync_remote_branch() |
611 | 611 |
612 if self.working_branch in branches: | 612 if self.working_branch in branches: |
613 self._call_git(['branch', '-D', self.working_branch]) | 613 self._call_git(['branch', '-D', self.working_branch]) |
614 return self._get_head_commit_hash() | 614 return self._get_head_commit_hash() |
615 | 615 |
616 def _sync_remote_branch(self): | 616 def _sync_remote_branch(self): |
617 """Syncs the remote branch.""" | 617 """Syncs the remote branch.""" |
618 # We do a 'git pull origin master:refs/remotes/origin/master' instead of | 618 # We do a 'git pull origin master:refs/remotes/origin/master' instead of |
619 # 'git pull origin master' because from the manpage for git-pull: | 619 # 'git pull origin master' because from the manpage for git-pull: |
620 # A parameter <ref> without a colon is equivalent to <ref>: when | 620 # A parameter <ref> without a colon is equivalent to <ref>: when |
621 # pulling/fetching, so it merges <ref> into the current branch without | 621 # pulling/fetching, so it merges <ref> into the current branch without |
622 # storing the remote branch anywhere locally. | 622 # storing the remote branch anywhere locally. |
623 remote_tracked_path = 'refs/remotes/%s/%s' % ( | 623 remote_tracked_path = 'refs/remotes/%s/%s' % ( |
624 self.remote, self.remote_branch) | 624 self.remote, self.remote_branch) |
625 self._check_call_git( | 625 self._check_call_git( |
626 ['pull', self.remote, | 626 ['pull', self.remote, |
627 '%s:%s' % (self.remote_branch, remote_tracked_path), | 627 '%s:%s' % (self.remote_branch, remote_tracked_path), |
628 '--quiet']) | 628 '--quiet']) |
629 | 629 |
630 def _get_head_commit_hash(self): | 630 def _get_head_commit_hash(self): |
631 """Gets the current revision (in unicode) from the local branch.""" | 631 """Gets the current revision (in unicode) from the local branch.""" |
632 return unicode(self._check_output_git(['rev-parse', 'HEAD']).strip()) | 632 return unicode(self._check_output_git(['rev-parse', 'HEAD']).strip()) |
633 | 633 |
634 def apply_patch(self, patches, post_processors=None, verbose=False, | 634 def apply_patch(self, patches, post_processors=None, verbose=False, |
635 name=None, email=None): | 635 name=None, email=None): |
636 """Applies a patch on 'working_branch' and switches to it. | 636 """Applies a patch on 'working_branch' and switches to it. |
637 | 637 |
638 Also commits the changes on the local branch. | 638 Also commits the changes on the local branch. |
639 | 639 |
640 Ignores svn properties and raise an exception on unexpected ones. | 640 Ignores svn properties and raise an exception on unexpected ones. |
641 """ | 641 """ |
642 post_processors = post_processors or self.post_processors or [] | 642 post_processors = post_processors or self.post_processors or [] |
643 # It this throws, the checkout is corrupted. Maybe worth deleting it and | 643 # It this throws, the checkout is corrupted. Maybe worth deleting it and |
644 # trying again? | 644 # trying again? |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 cmd = ['-c', 'user.email=%s' % email, '-c', 'user.name=%s' % name] + cmd | 716 cmd = ['-c', 'user.email=%s' % email, '-c', 'user.name=%s' % name] + cmd |
717 if verbose: | 717 if verbose: |
718 cmd.append('--verbose') | 718 cmd.append('--verbose') |
719 self._check_call_git(cmd) | 719 self._check_call_git(cmd) |
720 if self.base_ref: | 720 if self.base_ref: |
721 base_ref = self.base_ref | 721 base_ref = self.base_ref |
722 else: | 722 else: |
723 base_ref = '%s/%s' % (self.remote, | 723 base_ref = '%s/%s' % (self.remote, |
724 self.remote_branch or self.master_branch) | 724 self.remote_branch or self.master_branch) |
725 found_files = self._check_output_git( | 725 found_files = self._check_output_git( |
726 ['diff', base_ref, | 726 ['diff', base_ref, '--ignore-submodules', |
727 '--name-only']).splitlines(False) | 727 '--name-only']).splitlines(False) |
728 assert sorted(patches.filenames) == sorted(found_files), ( | 728 assert sorted(patches.filenames) == sorted(found_files), ( |
729 sorted(patches.filenames), sorted(found_files)) | 729 sorted(patches.filenames), sorted(found_files)) |
730 | 730 |
731 def commit(self, commit_message, user): | 731 def commit(self, commit_message, user): |
732 """Commits, updates the commit message and pushes.""" | 732 """Commits, updates the commit message and pushes.""" |
733 assert self.commit_user | 733 assert self.commit_user |
734 assert isinstance(commit_message, unicode) | 734 assert isinstance(commit_message, unicode) |
735 current_branch = self._check_output_git( | 735 current_branch = self._check_output_git( |
736 ['rev-parse', '--abbrev-ref', 'HEAD']).strip() | 736 ['rev-parse', '--abbrev-ref', 'HEAD']).strip() |
737 assert current_branch == self.working_branch | 737 assert current_branch == self.working_branch |
738 | 738 |
739 commit_cmd = ['commit', '--amend', '-m', commit_message] | 739 commit_cmd = ['commit', '--amend', '-m', commit_message] |
740 if user and user != self.commit_user: | 740 if user and user != self.commit_user: |
741 # We do not have the first or last name of the user, grab the username | 741 # We do not have the first or last name of the user, grab the username |
742 # from the email and call it the original author's name. | 742 # from the email and call it the original author's name. |
743 # TODO(rmistry): Do not need the below if user is already in | 743 # TODO(rmistry): Do not need the below if user is already in |
744 # "Name <email>" format. | 744 # "Name <email>" format. |
745 name = user.split('@')[0] | 745 name = user.split('@')[0] |
746 commit_cmd.extend(['--author', '%s <%s>' % (name, user)]) | 746 commit_cmd.extend(['--author', '%s <%s>' % (name, user)]) |
747 self._check_call_git(commit_cmd) | 747 self._check_call_git(commit_cmd) |
748 | 748 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 def revisions(self, rev1, rev2): | 837 def revisions(self, rev1, rev2): |
838 return self.checkout.revisions(rev1, rev2) | 838 return self.checkout.revisions(rev1, rev2) |
839 | 839 |
840 @property | 840 @property |
841 def project_name(self): | 841 def project_name(self): |
842 return self.checkout.project_name | 842 return self.checkout.project_name |
843 | 843 |
844 @property | 844 @property |
845 def project_path(self): | 845 def project_path(self): |
846 return self.checkout.project_path | 846 return self.checkout.project_path |
OLD | NEW |