Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 21ade2a28e9987cfdc76425e64f8f0f027b6b1e6..655a2bafcae3e880aa852264799526fdb70d8148 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -163,6 +163,32 @@ def is_dirty_git_tree(cmd): |
| return True |
| return False |
| + |
| +def git_cl_sanity_checks(upstream_git_obj): |
| + # First verify that the commit we're diffing against is in our tree. |
| + upstream_sha = RunGit(['rev-parse', '--verify', upstream_git_obj]).strip() |
| + common_ancestor = RunGit(['merge-base', upstream_sha, 'HEAD']).strip() |
| + 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
|
| + print >> sys.stderr, ( |
| + 'ERROR: %s is not in the current branch. You may need to rebase your ' |
| + 'tracking branch' % upstream_sha) |
| + return False |
| + |
| + commits_in_diff = RunGit( |
| + ['rev-list', '^%s' % upstream_sha, 'HEAD']).splitlines() |
| + commits_in_origin = RunGit( |
| + ['rev-list', '^%s' % upstream_sha, 'remotes/origin/master']).splitlines() |
| + |
| + common_commits = set(commits_in_diff) & set(commits_in_origin) |
| + if common_commits: |
| + print >> sys.stderr, ( |
| + 'ERROR: Your diff contains %d commits already in origin/master.\n' |
| + 'Run "git log --oneline origin/master..HEAD" to get a list of commits ' |
| + 'in the diff' % len(common_commits)) |
| + return False |
| + return True |
| + |
| + |
| def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
| """Return the corresponding git ref if |base_url| together with |glob_spec| |
| matches the full |url|. |
| @@ -607,6 +633,9 @@ or verify this branch is set up to track another (via the --track argument to |
| self.has_issue = False |
| def GetChange(self, upstream_branch, author): |
| + if not git_cl_sanity_checks(upstream_branch): |
| + DieWithError('\nGit sanity check failure') |
| + |
| root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' |
| absroot = os.path.abspath(root) |