Ejemplo n.º 1
0
def get_patch(repo, commit_hash):
  args = ['git', 'diff-tree',
          '-p',
          commit_hash,
          '--'  # Explicitly tell Git that `commit_hash` is a revision, not a path.
          ]

  with scoped_cwd(repo):
    return subprocess.check_output(args)
Ejemplo n.º 2
0
def fetch_origin_check_staged(path):
    """given a path on disk (to a git repo), fetch origin and ensure there aren't unstaged files"""
    with scoped_cwd(path):
        execute(['git', 'fetch', 'origin'])
        status = execute(['git', 'status', '-s']).strip()
        if len(status) > 0:
            print('[ERROR] There appear to be unstaged changes.\n' +
                  'Please resolve these before running (ex: `git status`).')
            return 1
    return 0
def create_dist_zip():
    dist_name = 'thrust-{0}-{1}-{2}.zip'.format(THRUST_SHELL_VERSION,
                                                TARGET_PLATFORM, DIST_ARCH)
    zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)

    with scoped_cwd(DIST_DIR):
        files = TARGET_BINARIES[TARGET_PLATFORM] + ['LICENSE', 'version']
        if TARGET_PLATFORM == 'linux':
            files += SYSTEM_LIBRARIES
        dirs = TARGET_DIRECTORIES[TARGET_PLATFORM]
        make_zip(zip_file, files, dirs)
Ejemplo n.º 4
0
def get_patch(repo, commit_hash):
    args = [
        'git',
        'diff-tree',
        '-p',
        commit_hash,
        '--'  # Explicitly tell Git that `commit_hash` is a revision, not a path.
    ]

    with scoped_cwd(repo):
        return subprocess.check_output(args)
Ejemplo n.º 5
0
def create_dist_zip():
  dist_name = 'thrust-{0}-{1}-{2}.zip'.format(THRUST_SHELL_VERSION,
                                              TARGET_PLATFORM, 
                                              DIST_ARCH)
  zip_file = os.path.join(SOURCE_ROOT, 'dist', dist_name)

  with scoped_cwd(DIST_DIR):
    files = TARGET_BINARIES[TARGET_PLATFORM] +  ['LICENSE', 'version']
    if TARGET_PLATFORM == 'linux':
      files += SYSTEM_LIBRARIES
    dirs = TARGET_DIRECTORIES[TARGET_PLATFORM]
    make_zip(zip_file, files, dirs)
Ejemplo n.º 6
0
def get_title_from_first_commit(path, branch_to_compare):
    """get the first commit subject (useful for the title of a pull request)"""
    with scoped_cwd(path):
        local_branch = execute(['git', 'rev-parse', '--abbrev-ref',
                                'HEAD']).strip()
        title_list = execute([
            'git', 'log', 'origin/' + branch_to_compare + '..HEAD',
            '--pretty=format:%s', '--reverse'
        ])
        title_list = title_list.split('\n')
        if len(title_list) == 0:
            raise Exception('No commits found! Local branch matches "' +
                            branch_to_compare + '"')
        return title_list[0]
Ejemplo n.º 7
0
def commit(repo, author, message):
    """ Commit whatever in the index is now."""

    # Let's setup committer info so git won't complain about it being missing.
    # TODO: Is there a better way to set committer's name and email?
    env = os.environ.copy()
    env['GIT_COMMITTER_NAME'] = 'Anonymous Committer'
    env['GIT_COMMITTER_EMAIL'] = '*****@*****.**'

    args = ['git', 'commit', '--author', author, '--message', message]

    with scoped_cwd(repo):
        return_code = subprocess.call(args, env=env)
        committed_successfully = (return_code == 0)
        return committed_successfully
Ejemplo n.º 8
0
def apply(repo, patch_path, directory=None, index=False, reverse=False):
    args = [
        'git', 'apply', '--ignore-space-change', '--ignore-whitespace',
        '--whitespace', 'fix'
    ]
    if directory:
        args += ['--directory', directory]
    if index:
        args += ['--index']
    if reverse:
        args += ['--reverse']
    args += ['--', patch_path]

    with scoped_cwd(repo):
        return_code = subprocess.call(args)
        applied_successfully = (return_code == 0)
        return applied_successfully
Ejemplo n.º 9
0
def apply(repo, patch_path, directory=None, index=False, reverse=False):
  args = ['git', 'apply',
          '--ignore-space-change',
          '--ignore-whitespace',
          '--whitespace', 'fix'
          ]
  if directory:
    args += ['--directory', directory]
  if index:
    args += ['--index']
  if reverse:
    args += ['--reverse']
  args += ['--', patch_path]

  with scoped_cwd(repo):
    return_code = subprocess.call(args)
    applied_successfully = (return_code == 0)
    return applied_successfully
Ejemplo n.º 10
0
def commit(repo, author, message):
  """ Commit whatever in the index is now."""

  # Let's setup committer info so git won't complain about it being missing.
  # TODO: Is there a better way to set committer's name and email?
  env = os.environ.copy()
  env['GIT_COMMITTER_NAME'] = 'Anonymous Committer'
  env['GIT_COMMITTER_EMAIL'] = '*****@*****.**'

  args = ['git', 'commit',
          '--author', author,
          '--message', message
          ]

  with scoped_cwd(repo):
    return_code = subprocess.call(args, env=env)
    committed_successfully = (return_code == 0)
    return committed_successfully
Ejemplo n.º 11
0
def push_branches_to_remote(path, branches_to_push, dryrun=False, token=None):
    if dryrun:
        print('[INFO] would push the following local branches to remote: ' +
              str(branches_to_push))
    else:
        with scoped_cwd(path):
            for branch_to_push in branches_to_push:
                print('- pushing ' + branch_to_push + '...')
                # TODO: if they already exist, force push?? or error??
                response = execute(
                    ['git', 'remote', 'get-url', '--push', 'origin']).strip()
                if response.startswith('https://'):
                    if len(str(token)) == 0:
                        raise Exception(
                            'GitHub token cannot be null or empty!')
                    remote = response.replace(
                        'https://', 'https://' + token + ':x-oauth-basic@')
                    execute(['git', 'push', '-u', remote, branch_to_push])
                else:
                    execute(['git', 'push', '-u', 'origin', branch_to_push])
Ejemplo n.º 12
0
def finalize_commits():
    global commits
    print('\n\nfinalizing commits')
    # Let's setup committer info so git won't complain about it being missing.
    # TODO: Is there a better way to set committer's name and email?
    env = os.environ.copy()
    env['GIT_COMMITTER_NAME'] = 'Anonymous Committer'
    env['GIT_COMMITTER_EMAIL'] = '*****@*****.**'

    committed_successfully = True

    for repo in commits:
        details = commits[repo]
        # Skip the commit when nothing to commit
        if len(details) == 0:
            continue

        # Reset the list of commits for next time
        commits[repo] = []
        generated_message = 'Applied ' + str(
            len(details)) + ' Electron Patches\n\n'

        for item in details:
            generated_message += 'Author: ' + item[
                0] + '\n' + 'Message: ' + item[1] + '\n\n'

        args = [
            'git', 'commit', '--author',
            'Electron Build Process <*****@*****.**>', '--message',
            generated_message, '-n'
        ]

        with scoped_cwd(repo):
            return_code = subprocess.call(args, env=env)
            if not (return_code == 0):
                print('failed to commit', repo)
            committed_successfully = (return_code
                                      == 0) and committed_successfully

    return committed_successfully
Ejemplo n.º 13
0
def get_head_commit(repo):
  args = ['git', 'rev-parse', 'HEAD']

  with scoped_cwd(repo):
    return subprocess.check_output(args).strip()
Ejemplo n.º 14
0
def get_head_commit(repo):
  args = ['git', 'rev-parse', 'HEAD']

  with scoped_cwd(repo):
    return subprocess.check_output(args).strip()
Ejemplo n.º 15
0
def reset(repo):
    args = ['git', 'reset']

    with scoped_cwd(repo):
        subprocess.check_call(args)
Ejemplo n.º 16
0
def reset(repo):
  args = ['git', 'reset']

  with scoped_cwd(repo):
    subprocess.check_call(args)
Ejemplo n.º 17
0
def get_local_branch_name(path):
    with scoped_cwd(path):
        return execute(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
Ejemplo n.º 18
0
 def run(self, command_name, command_args):
     with scoped_cwd(self.out_dir):
         complete_args = [self._get_executable_name(), command_name, '.'
                          ] + command_args
         return subprocess.check_output(complete_args)