OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
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 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 import json | 10 import json |
(...skipping 145 matching lines...) Loading... | |
156 dirty = RunGit(['diff-index', '--name-status', 'HEAD']) | 156 dirty = RunGit(['diff-index', '--name-status', 'HEAD']) |
157 if dirty: | 157 if dirty: |
158 print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd | 158 print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd |
159 print 'Uncommitted files: (git diff-index --name-status HEAD)' | 159 print 'Uncommitted files: (git diff-index --name-status HEAD)' |
160 print dirty[:4096] | 160 print dirty[:4096] |
161 if len(dirty) > 4096: | 161 if len(dirty) > 4096: |
162 print '... (run "git diff-index --name-status HEAD" to see full output).' | 162 print '... (run "git diff-index --name-status HEAD" to see full output).' |
163 return True | 163 return True |
164 return False | 164 return False |
165 | 165 |
166 | |
167 def git_cl_sanity_checks(upstream_git_obj): | |
168 # First verify that the commit we're diffing against is in our tree. | |
169 upstream_sha = RunGit(['rev-parse', '--verify', upstream_git_obj]).strip() | |
170 common_ancestor = RunGit(['merge-base', upstream_sha, 'HEAD']).strip() | |
171 if upstream_sha != common_ancestor: | |
M-A Ruel
2012/10/27 01:29:41
I disagree with this check. It happens I git fetch
Isaac (away)
2012/10/27 01:32:55
This is intended to catch diffing against a rebase
M-A Ruel
2012/10/27 01:37:23
git checkout -b work origin/master
vim foo
git com
| |
172 print >> sys.stderr, ( | |
173 'ERROR: %s is not in the current branch. You may need to rebase your ' | |
174 'tracking branch' % upstream_sha) | |
175 return False | |
176 | |
177 commits_in_diff = RunGit( | |
178 ['rev-list', '^%s' % upstream_sha, 'HEAD']).splitlines() | |
179 commits_in_origin = RunGit( | |
180 ['rev-list', '^%s' % upstream_sha, 'remotes/origin/master']).splitlines() | |
181 | |
182 common_commits = set(commits_in_diff) & set(commits_in_origin) | |
183 if common_commits: | |
184 print >> sys.stderr, ( | |
185 'ERROR: Your diff contains %d commits already in origin/master.\n' | |
186 'Run "git log --oneline origin/master..HEAD" to get a list of commits ' | |
187 'in the diff' % len(common_commits)) | |
188 return False | |
189 return True | |
190 | |
191 | |
166 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): | 192 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
167 """Return the corresponding git ref if |base_url| together with |glob_spec| | 193 """Return the corresponding git ref if |base_url| together with |glob_spec| |
168 matches the full |url|. | 194 matches the full |url|. |
169 | 195 |
170 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). | 196 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). |
171 """ | 197 """ |
172 fetch_suburl, as_ref = glob_spec.split(':') | 198 fetch_suburl, as_ref = glob_spec.split(':') |
173 if allow_wildcards: | 199 if allow_wildcards: |
174 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl) | 200 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl) |
175 if glob_match: | 201 if glob_match: |
(...skipping 424 matching lines...) Loading... | |
600 if issue: | 626 if issue: |
601 RunGit(['config', self._IssueSetting(), str(issue)]) | 627 RunGit(['config', self._IssueSetting(), str(issue)]) |
602 if self.rietveld_server: | 628 if self.rietveld_server: |
603 RunGit(['config', self._RietveldServer(), self.rietveld_server]) | 629 RunGit(['config', self._RietveldServer(), self.rietveld_server]) |
604 else: | 630 else: |
605 RunGit(['config', '--unset', self._IssueSetting()]) | 631 RunGit(['config', '--unset', self._IssueSetting()]) |
606 self.SetPatchset(0) | 632 self.SetPatchset(0) |
607 self.has_issue = False | 633 self.has_issue = False |
608 | 634 |
609 def GetChange(self, upstream_branch, author): | 635 def GetChange(self, upstream_branch, author): |
636 if not git_cl_sanity_checks(upstream_branch): | |
637 DieWithError('\nGit sanity check failure') | |
638 | |
610 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' | 639 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' |
611 absroot = os.path.abspath(root) | 640 absroot = os.path.abspath(root) |
612 | 641 |
613 # We use the sha1 of HEAD as a name of this change. | 642 # We use the sha1 of HEAD as a name of this change. |
614 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() | 643 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() |
615 # Need to pass a relative path for msysgit. | 644 # Need to pass a relative path for msysgit. |
616 try: | 645 try: |
617 files = scm.GIT.CaptureStatus([root], '.', upstream_branch) | 646 files = scm.GIT.CaptureStatus([root], '.', upstream_branch) |
618 except subprocess2.CalledProcessError: | 647 except subprocess2.CalledProcessError: |
619 DieWithError( | 648 DieWithError( |
(...skipping 1189 matching lines...) Loading... | |
1809 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1838 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1810 | 1839 |
1811 # Not a known command. Default to help. | 1840 # Not a known command. Default to help. |
1812 GenUsage(parser, 'help') | 1841 GenUsage(parser, 'help') |
1813 return CMDhelp(parser, argv) | 1842 return CMDhelp(parser, argv) |
1814 | 1843 |
1815 | 1844 |
1816 if __name__ == '__main__': | 1845 if __name__ == '__main__': |
1817 fix_encoding.fix_encoding() | 1846 fix_encoding.fix_encoding() |
1818 sys.exit(main(sys.argv[1:])) | 1847 sys.exit(main(sys.argv[1:])) |
OLD | NEW |