def GitSanityChecks(self, upstream_git_obj):
    'Checks git repo status and ensures diff is from local commits.'
    if (upstream_git_obj is None):
        if (self.GetBranch() is None):
            print('ERROR: unable to determine current branch (detached HEAD?)', file=sys.stderr)
        else:
            print('ERROR: no upstream branch', file=sys.stderr)
        return False
    upstream_sha = RunGit(['rev-parse', '--verify', upstream_git_obj]).strip()
    common_ancestor = RunGit(['merge-base', upstream_sha, 'HEAD']).strip()
    if (upstream_sha != common_ancestor):
        print(('ERROR: %s is not in the current branch.  You may need to rebase your tracking branch' % upstream_sha), file=sys.stderr)
        return False
    commits_in_diff = RunGit(['rev-list', ('^%s' % upstream_sha), 'HEAD']).splitlines()
    (code, remote_branch) = RunGitWithCode(['config', 'gitcl.remotebranch'])
    remote_branch = remote_branch.strip()
    if (code != 0):
        (_, remote_branch) = self.GetRemoteBranch()
    commits_in_remote = RunGit(['rev-list', ('^%s' % upstream_sha), remote_branch]).splitlines()
    common_commits = (set(commits_in_diff) & set(commits_in_remote))
    if common_commits:
        print(('ERROR: Your diff contains %d commits already in %s.\nRun "git log --oneline %s..HEAD" to get a list of commits in the diff.  If you are using a custom git flow, you can override the reference used for this check with "git config gitcl.remotebranch <git-ref>".' % (len(common_commits), remote_branch, upstream_git_obj)), file=sys.stderr)
        return False
    return True
Checks git repo status and ensures diff is from local commits.
def GitSanityChecks(self, upstream_git_obj):
    
    if (upstream_git_obj is None):
        if (self.GetBranch() is None):
            print('ERROR: unable to determine current branch (detached HEAD?)', file=sys.stderr)
        else:
            print('ERROR: no upstream branch', file=sys.stderr)
        return False
    upstream_sha = RunGit(['rev-parse', '--verify', upstream_git_obj]).strip()
    common_ancestor = RunGit(['merge-base', upstream_sha, 'HEAD']).strip()
    if (upstream_sha != common_ancestor):
        print(('ERROR: %s is not in the current branch.  You may need to rebase your tracking branch' % upstream_sha), file=sys.stderr)
        return False
    commits_in_diff = RunGit(['rev-list', ('^%s' % upstream_sha), 'HEAD']).splitlines()
    (code, remote_branch) = RunGitWithCode(['config', 'gitcl.remotebranch'])
    remote_branch = remote_branch.strip()
    if (code != 0):
        (_, remote_branch) = self.GetRemoteBranch()
    commits_in_remote = RunGit(['rev-list', ('^%s' % upstream_sha), remote_branch]).splitlines()
    common_commits = (set(commits_in_diff) & set(commits_in_remote))
    if common_commits:
        print(('ERROR: Your diff contains %d commits already in %s.\nRun "git log --oneline %s..HEAD" to get a list of commits in the diff.  If you are using a custom git flow, you can override the reference used for this check with "git config gitcl.remotebranch <git-ref>".' % (len(common_commits), remote_branch, upstream_git_obj)), file=sys.stderr)
        return False
    return True