GET THE CURRENT GIT BRANCH
351750
def get_branch():
    
    proc = Process("git status", ["git", "status"])

    try:
        while True:
            raw_line = proc.stdout.pop()
            line = raw_line.decode('utf8').strip()
            if line.startswith("On branch "):
                return line[10:]
    finally:
        try:
            proc.join()
        except Exception:
            pass
683234
def branch(self):
        """"""
        result = get_branch(repo=self.repo)
        if result is None:
            result = get_travis_branch()
        return result
899924
def current_id(self):
        
        try:
            cmd = ['git', 'rev-parse', '--short', 'HEAD']
            return self.sh(cmd,
                        shell=False,
                        ignore_error=True).rstrip()
        except subprocess.CalledProcessError as e:
            log.exception(e)
            #if e.returncode == 128  # bare repo
            return None
65504
function lastRelease() {
  const {stdout: branches} = exec(`git branch -a | grep 'origin/release'`)
  const releases = branches.
    split("\n")
    .map(b => b.replace(/remotes\/origin\//, '').trim())
    .filter(b => b.match(/^release-(\d+)$/))

  const ordered = sortBy(releases, r => parseInt(/\d+/.exec(r)[0], 10)  )
  return ordered[ordered.length -1];
}
1082970
function getCurrentBranch(verbose) {
  return Promise.resolve()
    .then(execCmd.bind(null,
      'git',
      ['symbolic-ref', 'HEAD', '-q'],
      'problem getting current branch',
      verbose
    ))
    .catch(function() {
      return '';
    })
    .then(function(result) {
      return result.replace(new RegExp('^refs\/heads\/'), '');
    });
}
300013
def get_branches(self):
        
        return github.PaginatedList.PaginatedList(
            github.Branch.Branch,
            self._requester,
            self.url + "/branches",
            None
        )
987683
def _get_branch(repo, name):
    '''
    
    '''
    try:
        return [x for x in _all_branches(repo) if x[0] == name][0]
    except IndexError:
        return False
1023707
def get_branch():
        
        if os.getenv('GIT_BRANCH'):
            # Travis
            branch = os.getenv('GIT_BRANCH')
        elif os.getenv('BRANCH_NAME'):
            # Jenkins 2
            branch = os.getenv('BRANCH_NAME')
        else:
            branch = check_output(
                "git rev-parse --abbrev-ref HEAD".split(" ")
                ).decode('utf-8').strip()

        return branch.replace("/", "_")
76257
def get_default_branch(repo):
    """"""
    url = "{}/repos/{}".format(GITHUB_API_BASE, repo)
    response = requests.get(url)
    if response.status_code == 200:
        api_response = json.loads(response.text)
        return api_response['default_branch']
    else:
        return 'master'
164399
def get_version():
    """"""
    try:
        tag = check_output(
            ["git", "describe", "--abbrev=0"], universal_newlines=True
        ).strip()
        assert not tag.startswith("v")
        version = tag

        # add .devNN if needed
        log = check_output(
            ["git", "log", "%s..HEAD" % tag, "--oneline"],
            universal_newlines=True,
        )
        commits_since_tag = log.count("\n")
        if commits_since_tag:
            version += ".dev%i" % commits_since_tag

        # update tcod/version.py
        open("tcod/version.py", "w").write('__version__ = "%s"\n' % version)
        return version
    except:
        exec(open("tcod/version.py").read(), globals())
        return __version__
434571
def get_current_branch(self, location):
        
        # git-symbolic-ref exits with empty stdout if "HEAD" is a detached
        # HEAD rather than a symbolic ref.  In addition, the -q causes the
        # command to exit with status code 1 instead of 128 in this case
        # and to suppress the message to stderr.
        args = ['symbolic-ref', '-q', 'HEAD']
        output = self.run_command(
            args, extra_ok_returncodes=(1, ), show_stdout=False, cwd=location,
        )
        ref = output.strip()

        if ref.startswith('refs/heads/'):
            return ref[len('refs/heads/'):]

        return None
318396
function checkBranch (branches, cb) {
  if (branches === "ALL") {
    return cb(null, true);
  }

  if (!_.isArray(branches)) {
    branches = _.invoke(branches.split(","), "trim");
  }

  return git.currentBranch().then(function (branch) {
    return [_.any(branches, _.partial(minimatch, branch)), branch];
  });
}
186529
public function getCurrentBranch()
    {
        /** @var $result CallResult */
        $result = $this->getGit()->{'rev-parse'}($this->getRepositoryPath(), array(
            '--symbolic-full-name',
            '--abbrev-ref',
            'HEAD'
        ));
        $result->assertSuccess(
            sprintf('Cannot retrieve current branch from "%s"', $this->getRepositoryPath())
        );

        return $result->getStdOut();
    }
433005
def status(self) -> str:
        
        status: str = self.repo.git.status()
        LOGGER.debug('git status: %s', status)
        return status
120620
def get_git_status(git_path='git'):
    
    status_output = subprocess.call((git_path, 'diff-files', '--quiet'))
    if status_output != 0:
        return 'UNCLEAN: Modified working tree'
    else:
        # check index for changes
        status_output = subprocess.call((git_path, 'diff-index', '--cached',
                                         '--quiet', 'HEAD'))
        if status_output != 0:
            return 'UNCLEAN: Modified index'
        else:
            return 'CLEAN: All modifications committed'
873667
def branches(config, searchstring=""):
    """"""
    repo = config.repo

    branches_ = list(find(repo, searchstring))
    if branches_:
        merged = get_merged_branches(repo)
        info_out("Found existing branches...")
        print_list(branches_, merged)
        if len(branches_) == 1 and searchstring:
            # If the found branch is the current one, error
            active_branch = repo.active_branch
            if active_branch == branches_[0]:
                error_out("You're already on '{}'".format(branches_[0].name))
            branch_name = branches_[0].name
            if len(branch_name) > 50:
                branch_name = branch_name[:47] + "…"
            check_it_out = (
                input("Check out '{}'? [Y/n] ".format(branch_name)).lower().strip()
                != "n"
            )
            if check_it_out:
                branches_[0].checkout()
    elif searchstring:
        error_out("Found no branches matching '{}'.".format(searchstring))
    else:
        error_out("Found no branches.")
1182981
def git_list_branches(repo_dir):
    
    command = ['git', 'branch', '--remotes', '--all',
               '--verbose', '--no-abbrev']
    output = execute_git_command(command, repo_dir=repo_dir).splitlines()
    # remove nullish lines
    lines = [l.strip() for l in output if l.strip()]
    # find the * current branch
    try:
        current_branch = [l for l in lines if l.startswith('* ')][0]
    except IndexError:
        current_branch = None
    item = None
    if current_branch:
        lines.remove(current_branch)
        current_branch = current_branch.replace('* ', '', 1)
        if re.match('\(.*detached.+\)', current_branch):
            branch, rest = current_branch.split(')', 1)
            branch = "%s)" % branch
            sha, msg = rest.split(None, 1)
            item = {'branch': branch, 'commit': sha, 'message': msg}
        else:
            lines.insert(0, current_branch)
    # <branch> <hash> <commit_message>
    # make a list of lists with clean elements of equal length
    breakout = [k.split(None, 2) for k in lines]
    # remove any strange hashless outliers
    breakout = [k for k in breakout if len(k[1]) == 40]
    headers = ['branch', 'commit', 'message']
    # use izip_longest so we fill in None if message was empty
    result = [dict(zip_longest(headers, vals))
              for vals in breakout]
    if item:
        result.append(item)
    return result