function drush_make_resolve_git_branch

master generate.contents.make.inc drush_make_resolve_git_branch($project)

Resolve branch for a git-based project.

1 call to drush_make_resolve_git_branch()
drush_make_resolve_git_refs in commands/make/generate.contents.make.inc
Resolve branches and revisions for git-based projects.

File

commands/make/generate.contents.make.inc, line 189
Functions for the generate makefile command.

Code

function drush_make_resolve_git_branch($project) {
  drush_log(dt('Resolving default branch for repo at: :repo', array(':repo' => $project['download']['url'])));
  if (drush_shell_exec("git ls-remote %s HEAD", $project['download']['url'])) {
    $head_output = drush_shell_exec_output();
    list($head_commit) = explode("\t", $head_output[0]);

    drush_log(dt('Scanning branches in repo at: :repo', array(':repo' => $project['download']['url'])));
    drush_shell_exec("git ls-remote --heads %s", $project['download']['url']);
    $heads_output = drush_shell_exec_output();
    $branches = array();
    foreach ($heads_output as $key => $head) {
      list($commit, $ref) = explode("\t", $head);
      $branches[$commit] = explode("/", $ref)[2];
    }

    $branch = $branches[$head_commit];
    drush_log(dt('Resolved git branch to: :branch', array(':branch' => $branch)));
    return $branch;
  }
  else {
    drush_log(dt('Could not resolve branch for `:project` using git repo at :repo', array(':project' => $project['name'], ':repo' => $project['download']['url'])), 'warning');
  }
}