tools/check_git_config.py
def check_git_config(conf, report_url, verbose):
  """Attempts to push to a git repository, reports results to a server.

  Returns True if the check finished without incidents (push itself may
  have failed) and should NOT be retried on next invocation of the hook.
  """
  # Don't even try to push if netrc is not configured.
  if not conf['chromium_netrc_email']:
    return upload_report(
        conf,
        report_url,
        verbose,
        push_works=False,
        push_log='',
        push_duration_ms=0)

  # Ref to push to, each user has its own ref.
  ref = 'refs/push-test/%s' % conf['chromium_netrc_email']

  push_works = False
  flake = False
  started = time.time()
  try:
    logging.warning('Checking push access to the git repository...')
    with temp_directory() as tmp:
      # Prepare a simple commit on a new timeline.
      runner = Runner(tmp, verbose)
      runner.run([GIT_EXE, 'init', '.'])
      if conf['git_user_name']:
        runner.run([GIT_EXE, 'config', 'user.name', conf['git_user_name']])
      if conf['git_user_email']:
        runner.run([GIT_EXE, 'config', 'user.email', conf['git_user_email']])
      with open(os.path.join(tmp, 'timestamp'), 'w') as f:
        f.write(str(int(time.time() * 1000)))
      runner.run([GIT_EXE, 'add', 'timestamp'])
      runner.run([GIT_EXE, 'commit', '-m', 'Push test.'])
      # Try to push multiple times if it fails due to issues other than ACLs.
      attempt = 0
      while attempt < 5:
        attempt += 1
        logging.info('Pushing to %s %s', TEST_REPO_URL, ref)
        ret = runner.run(
            [GIT_EXE, 'push', TEST_REPO_URL, 'HEAD:%s' % ref, '-f'])
        if not ret:
          push_works = True
          break
        if any(x in runner.log[-1] for x in BAD_ACL_ERRORS):
          push_works = False
          break
  except Exception:
    logging.exception('Unexpected exception when pushing')
    flake = True

  if push_works:
    logging.warning('Git push works!')
  else:
    logging.warning(
        'Git push doesn\'t work, which is fine if you are not a committer.')

  uploaded = upload_report(
      conf,
      report_url,
      verbose,
      push_works=push_works,
      push_log='\n'.join(runner.log),
      push_duration_ms=int((time.time() - started) * 1000))
  return uploaded and not flake
Attempts to push to a git repository, reports results to a server.

  Returns True if the check finished without incidents (push itself may
  have failed) and should NOT be retried on next invocation of the hook.
  
Attempts to push to a git repository, reports results to a server.
Returns True if the check finished without incidents (push itself may
have failed) and should NOT be retried on next invocation of the hook.
Attempts to push to a git repository reports results to a server . Returns True if the check finished without incidents ( push itself may have failed ) and should NOT be retried on next invocation of the hook .
def check_git_config(conf, report_url, verbose):
  if not conf['chromium_netrc_email']:
    return upload_report(
        conf,
        report_url,
        verbose,
        push_works=False,
        push_log='',
        push_duration_ms=0)
  ref = 'refs/push-test/%s' % conf['chromium_netrc_email']
  push_works = False
  flake = False
  started = time.time()
  try:
    logging.warning('Checking push access to the git repository...')
    with temp_directory() as tmp:
      runner = Runner(tmp, verbose)
      runner.run([GIT_EXE, 'init', '.'])
      if conf['git_user_name']:
        runner.run([GIT_EXE, 'config', 'user.name', conf['git_user_name']])
      if conf['git_user_email']:
        runner.run([GIT_EXE, 'config', 'user.email', conf['git_user_email']])
      with open(os.path.join(tmp, 'timestamp'), 'w') as f:
        f.write(str(int(time.time() * 1000)))
      runner.run([GIT_EXE, 'add', 'timestamp'])
      runner.run([GIT_EXE, 'commit', '-m', 'Push test.'])
      attempt = 0
      while attempt < 5:
        attempt += 1
        logging.info('Pushing to %s %s', TEST_REPO_URL, ref)
        ret = runner.run(
            [GIT_EXE, 'push', TEST_REPO_URL, 'HEAD:%s' % ref, '-f'])
        if not ret:
          push_works = True
          break
        if any(x in runner.log[-1] for x in BAD_ACL_ERRORS):
          push_works = False
          break
  except Exception:
    logging.exception('Unexpected exception when pushing')
    flake = True
  if push_works:
    logging.warning('Git push works!')
  else:
    logging.warning(
        'Git push doesn\'t work, which is fine if you are not a committer.')
  uploaded = upload_report(
      conf,
      report_url,
      verbose,
      push_works=push_works,
      push_log='\n'.join(runner.log),
      push_duration_ms=int((time.time() - started) * 1000))
  return uploaded and not flake
def check_git_config ( conf , report_url , verbose ) : if not conf [ 'chromium_netrc_email' ] : return upload_report ( conf , report_url , verbose , push_works = False , push_log = '' , push_duration_ms = 0 ) ref = 'refs/push-test/%s' % conf [ 'chromium_netrc_email' ] push_works = False flake = False started = time . time ( ) try : logging . warning ( 'Checking push access to the git repository...' ) with temp_directory ( ) as tmp : runner = Runner ( tmp , verbose ) runner . run ( [ GIT_EXE , 'init' , '.' ] ) if conf [ 'git_user_name' ] : runner . run ( [ GIT_EXE , 'config' , 'user.name' , conf [ 'git_user_name' ] ] ) if conf [ 'git_user_email' ] : runner . run ( [ GIT_EXE , 'config' , 'user.email' , conf [ 'git_user_email' ] ] ) with open ( os . path . join ( tmp , 'timestamp' ) , 'w' ) as f : f . write ( str ( int ( time . time ( ) * 1000 ) ) ) runner . run ( [ GIT_EXE , 'add' , 'timestamp' ] ) runner . run ( [ GIT_EXE , 'commit' , '-m' , 'Push test.' ] ) attempt = 0 while attempt < 5 : attempt += 1 logging . info ( 'Pushing to %s %s' , TEST_REPO_URL , ref ) ret = runner . run ( [ GIT_EXE , 'push' , TEST_REPO_URL , 'HEAD:%s' % ref , '-f' ] ) if not ret : push_works = True break if any ( x in runner . log [ - 1 ] for x in BAD_ACL_ERRORS ) : push_works = False break except Exception : logging . exception ( 'Unexpected exception when pushing' ) flake = True if push_works : logging . warning ( 'Git push works!' ) else : logging . warning ( 'Git push doesn\'t work, which is fine if you are not a committer.' ) uploaded = upload_report ( conf , report_url , verbose , push_works = push_works , push_log = '\n' . join ( runner . log ) , push_duration_ms = int ( ( time . time ( ) - started ) * 1000 ) ) return uploaded and not flake
Attempts to push to a git repository, reports results to a server.
Attempts to push to a git repository reports results to a server .
"""Attempts to push to a git repository, reports results to a server.

  Returns True if the check finished without incidents (push itself may
  have failed) and should NOT be retried on next invocation of the hook.
  """ # Don't even try to push if netrc is not configured. # Ref to push to, each user has its own ref. # Prepare a simple commit on a new timeline. # Try to push multiple times if it fails due to issues other than ACLs.
conf
report_url
verbose