Exemplo n.º 1
0
def _check_uncommitted_change():
    uncommitted_files = git.get_uncommitted_files()
    if uncommitted_files:
        print ''
        print 'Please commit or stash the following uncommitted files.'
        print '\n'.join(uncommitted_files)
        print ''
        return -1
    return 0
Exemplo n.º 2
0
def _check_uncommitted_change():
    uncommitted_files = git.get_uncommitted_files()
    if uncommitted_files:
        print ""
        print "Please commit or stash the following uncommitted files."
        print "\n".join(uncommitted_files)
        print ""
        return -1
    return 0
Exemplo n.º 3
0
def run(dest, force):
    if (not force and git.has_initial_commit(cwd=dest)
            and git.get_uncommitted_files(cwd=dest)):
        logging.error('Uncommitted files in %s, reset or pass --force' % dest)
        sys.exit(1)
    logging.info('Synchronizing open source tree at: ' + dest)
    submodule_paths = _add_and_sync_submodules(dest, force)
    sync_set = _find_sync_set('.', submodule_paths)
    _sync_files(dest, '.', sync_set)
    _purge_non_synced_ignored_files(dest, '.', sync_set, submodule_paths)
Exemplo n.º 4
0
def run(dest, force):
  if (not force and git.has_initial_commit(cwd=dest) and
      git.get_uncommitted_files(cwd=dest)):
    logging.error('Uncommitted files in %s, reset or pass --force' % dest)
    sys.exit(1)
  logging.info('Synchronizing open source tree at: ' + dest)
  submodule_paths = _add_and_sync_submodules(dest, force)
  sync_set = _find_sync_set('.', submodule_paths)
  _sync_files(dest, '.', sync_set)
  _purge_non_synced_ignored_files(dest, '.', sync_set, submodule_paths)
Exemplo n.º 5
0
def _add_and_sync_submodule(dest, force, src_submodule, dest_submodule):
    # If dest_submodule is none, it means the open source repo does not contain
    # the submodule, and we've never before tried to check it out on this machine.
    # Conversely if dest_submodule.path does not exist, the open source repo does
    # not have it, and we have checked it out on this machine before (there is
    # data in .git/modules/... for it, but nothing actually checked out to the
    # working tree.
    if (dest_submodule is None
            or not os.path.exists(os.path.join(dest, dest_submodule.path))):
        logging.info('Adding submodule for %s' % src_submodule.path)
        # We need to use --force for the second case of it already being a
        # submodule. This ensures we get a checkout in the working tree.
        subprocess.check_call([
            'git', 'submodule', 'add', '--force', src_submodule.url,
            src_submodule.path
        ],
                              cwd=dest)
    if dest_submodule is None or dest_submodule.head != src_submodule.head:
        logging.warning('Updating repository %s' % src_submodule.path)
        if dest_submodule is not None:
            logging.info('Repository was at %s' % dest_submodule.head)
        logging.info('Checking out to %s' % src_submodule.head)
        submodule_path = os.path.join(dest, src_submodule.path)
        if dest_submodule is not None and src_submodule.url != dest_submodule.url:
            logging.info('Updating repository url to %s', src_submodule.url)
            # Replace the url in the .gitmodules file with the updated url.
            subprocess.check_call([
                'git', 'config', '-f', '.gitmodules', '--replace-all',
                'submodule.%s.url' % src_submodule.path, src_submodule.url
            ],
                                  cwd=dest)
            # Syncronize the new url in .gitmodules with the actual submodule
            # configuration.
            subprocess.check_call(
                ['git', 'submodule', 'sync', src_submodule.path], cwd=dest)
        subprocess.check_call(
            ['git', 'submodule', 'update', '--init', src_submodule.path],
            cwd=dest)
        subprocess.check_call(['git', 'remote', 'update'], cwd=submodule_path)
        # Remove any changes to the submodule.  Aborting a checkout or update
        # can result in it appearing that there are local modifications, so
        # this cleans it up.
        if not force and git.get_uncommitted_files(cwd=submodule_path):
            logging.error(
                'Uncommitted files in submodule %s, reset or pass --force' %
                submodule_path)
            sys.exit(1)
        subprocess.check_call(['git', 'reset', '--hard', 'HEAD'],
                              cwd=submodule_path)
        subprocess.check_call(['git', 'checkout', src_submodule.head],
                              cwd=submodule_path)
Exemplo n.º 6
0
def _add_and_sync_submodule(dest, force, src_submodule, dest_submodule):
  # If dest_submodule is none, it means the open source repo does not contain
  # the submodule, and we've never before tried to check it out on this machine.
  # Conversely if dest_submodule.path does not exist, the open source repo does
  # not have it, and we have checked it out on this machine before (there is
  # data in .git/modules/... for it, but nothing actually checked out to the
  # working tree.
  if (dest_submodule is None or
      not os.path.exists(os.path.join(dest, dest_submodule.path))):
    logging.info('Adding submodule for %s' % src_submodule.path)
    # We need to use --force for the second case of it already being a
    # submodule. This ensures we get a checkout in the working tree.
    subprocess.check_call(['git', 'submodule', 'add', '--force',
                           src_submodule.url, src_submodule.path],
                          cwd=dest)
  if dest_submodule is None or dest_submodule.head != src_submodule.head:
    logging.warning('Updating repository %s' % src_submodule.path)
    if dest_submodule is not None:
      logging.info('Repository was at %s' % dest_submodule.head)
    logging.info('Checking out to %s' % src_submodule.head)
    submodule_path = os.path.join(dest, src_submodule.path)
    if dest_submodule is not None and src_submodule.url != dest_submodule.url:
      logging.info('Updating repository url to %s', src_submodule.url)
      # Replace the url in the .gitmodules file with the updated url.
      subprocess.check_call(['git', 'config', '-f', '.gitmodules',
                             '--replace-all',
                             'submodule.%s.url' % src_submodule.path,
                             src_submodule.url], cwd=dest)
      # Syncronize the new url in .gitmodules with the actual submodule
      # configuration.
      subprocess.check_call(['git', 'submodule', 'sync', src_submodule.path],
                            cwd=dest)
    subprocess.check_call(['git', 'submodule', 'update', '--init',
                           src_submodule.path],
                          cwd=dest)
    subprocess.check_call(['git', 'remote', 'update'], cwd=submodule_path)
    # Remove any changes to the submodule.  Aborting a checkout or update
    # can result in it appearing that there are local modifications, so
    # this cleans it up.
    if not force and git.get_uncommitted_files(cwd=submodule_path):
      logging.error('Uncommitted files in submodule %s, reset or pass --force' %
                    submodule_path)
      sys.exit(1)
    subprocess.check_call(['git', 'reset', '--hard', 'HEAD'],
                          cwd=submodule_path)
    subprocess.check_call(['git', 'checkout', src_submodule.head],
                          cwd=submodule_path)
Exemplo n.º 7
0
def main():
  assert not open_source.is_open_source_repo(), ('Cannot be run from open '
                                                 'source repo.')
  parser = argparse.ArgumentParser()
  parser.add_argument('--branch', default=None,
                      help='Which branch in the open source repo to push')
  parser.add_argument('--force', action='store_true',
                      help='Overwrite any changes in the destination')
  parser.add_argument('--push-changes', action='store_true',
                      help=('Push changes to the destination repository\'s '
                            'remote'))
  parser.add_argument('--verbose', '-v', action='store_true',
                      help='Get verbose output')
  parser.add_argument('dest')
  args = parser.parse_args(sys.argv[1:])
  if args.verbose:
    logging.getLogger().setLevel(logging.INFO)
  _validate_args(args)

  _clone_repo_if_needed(args.dest)
  _validate_local_repository(args.dest)
  if (git.get_uncommitted_files(cwd=args.dest) and not args.force):
    logging.error('%s has uncommitted files, use --force to override')
    return 1
  _reset_and_clean_repo(args.dest)
  _check_out_matching_branch(args.dest, args.branch)
  # Submodules abandoned between branches will still leave their directories
  # around which can confuse prepare_open_source_commit, so we clean them out.
  _reset_and_clean_repo(args.dest)

  prepare_open_source_commit.run(args.dest, args.force)

  _test_changes(args.dest)
  if args.push_changes:
    commit_label = subprocess.check_output(['git', 'describe']).strip()
    _set_git_user('arc-push', '*****@*****.**', args.dest)
    _commit_changes(args.dest, commit_label)
    _sync_head_tags(args.dest, '.')
    _push_changes(args.dest)
  else:
    _reset_and_clean_repo(args.dest)
  return 0
Exemplo n.º 8
0
def _git_has_local_modification():
    if git.get_current_branch_name(cwd=_ARC_INTERNAL_DIR) != 'master':
        return True  # not on master
    if git.get_uncommitted_files(cwd=_ARC_INTERNAL_DIR):
        return True  # found modified or staged file(s)
    return False
Exemplo n.º 9
0
def _git_has_local_modification():
  if git.get_current_branch_name(cwd=_ARC_INTERNAL_DIR) != 'master':
    return True  # not on master
  if git.get_uncommitted_files(cwd=_ARC_INTERNAL_DIR):
    return True  # found modified or staged file(s)
  return False