def PushToGitPending(remote, pending_ref, upstream_ref):
    'Fetches pending_ref, cherry-picks current HEAD on top of it, pushes.\n\n  Returns:\n    (retcode of last operation, output log of last operation).\n  '
    assert pending_ref.startswith('refs/'), pending_ref
    local_pending_ref = ('refs/git-cl/' + pending_ref[len('refs/'):])
    cherry = RunGit(['rev-parse', 'HEAD']).strip()
    code = 0
    out = ''
    max_attempts = 3
    attempts_left = max_attempts
    while attempts_left:
        if (attempts_left != max_attempts):
            print(('Retrying, %d attempts left...' % ((attempts_left - 1),)))
        attempts_left -= 1
        print(('Fetching pending ref %s...' % pending_ref))
        (code, out) = RunGitWithCode(['retry', 'fetch', remote, ('+%s:%s' % (pending_ref, local_pending_ref))])
        if code:
            print(('Fetch failed with exit code %d.' % code))
            if out.strip():
                print(out.strip())
            continue
        print('Cherry-picking commit on top of pending ref...')
        RunGitWithCode(['checkout', local_pending_ref], suppress_stderr=True)
        (code, out) = RunGitWithCode(['cherry-pick', cherry])
        if code:
            print(("Your patch doesn't apply cleanly to ref '%s', the following files have merge conflicts:" % pending_ref))
            print(RunGit(['diff', '--name-status', '--diff-filter=U']).strip())
            print('Please rebase your patch and try again.')
            RunGitWithCode(['cherry-pick', '--abort'])
            return (code, out)
        print(('Pushing commit to %s... It can take a while.' % pending_ref))
        (code, out) = RunGitWithCode(['retry', 'push', '--porcelain', remote, ('HEAD:%s' % pending_ref)])
        if (code == 0):
            print('Commit pushed to pending ref successfully!')
            return (code, out)
        print(('Push failed with exit code %d.' % code))
        if out.strip():
            print(out.strip())
        if IsFatalPushFailure(out):
            print('Fatal push error. Make sure your .netrc credentials and git user.email are correct and you have push access to the repo.')
            return (code, out)
    print('All attempts to push to pending ref failed.')
    return (code, out)
Fetches pending_ref, cherry-picks current HEAD on top of it, pushes.

Returns:
  (retcode of last operation, output log of last operation).
def PushToGitPending(remote, pending_ref, upstream_ref):
    'Fetches pending_ref, cherry-picks current HEAD on top of it, pushes.\n\n  Returns:\n    (retcode of last operation, output log of last operation).\n  '
    assert pending_ref.startswith('refs/'), pending_ref
    local_pending_ref = ('refs/git-cl/' + pending_ref[len('refs/'):])
    cherry = RunGit(['rev-parse', 'HEAD']).strip()
    code = 0
    out = 
    max_attempts = 3
    attempts_left = max_attempts
    while attempts_left:
        if (attempts_left != max_attempts):
            print(('Retrying, %d attempts left...' % ((attempts_left - 1),)))
        attempts_left -= 1
        print(('Fetching pending ref %s...' % pending_ref))
        (code, out) = RunGitWithCode(['retry', 'fetch', remote, ('+%s:%s' % (pending_ref, local_pending_ref))])
        if code:
            print(('Fetch failed with exit code %d.' % code))
            if out.strip():
                print(out.strip())
            continue
        print('Cherry-picking commit on top of pending ref...')
        RunGitWithCode(['checkout', local_pending_ref], suppress_stderr=True)
        (code, out) = RunGitWithCode(['cherry-pick', cherry])
        if code:
            print(("Your patch doesn't apply cleanly to ref '%s', the following files have merge conflicts:" % pending_ref))
            print(RunGit(['diff', '--name-status', '--diff-filter=U']).strip())
            print('Please rebase your patch and try again.')
            RunGitWithCode(['cherry-pick', '--abort'])
            return (code, out)
        print(('Pushing commit to %s... It can take a while.' % pending_ref))
        (code, out) = RunGitWithCode(['retry', 'push', '--porcelain', remote, ('HEAD:%s' % pending_ref)])
        if (code == 0):
            print('Commit pushed to pending ref successfully!')
            return (code, out)
        print(('Push failed with exit code %d.' % code))
        if out.strip():
            print(out.strip())
        if IsFatalPushFailure(out):
            print('Fatal push error. Make sure your .netrc credentials and git user.email are correct and you have push access to the repo.')
            return (code, out)
    print('All attempts to push to pending ref failed.')
    return (code, out)