Get the current branch but raise an error if it looks like we're on a detched head.

 @api private
 @return [String]
163207
def current_branch
      repo.current_branch.tap {|b| raise Thor::Error.new("No explicit branch passed and current head looks detached: #{b}") if b[0] == '(' }
    end
786473
def get_nowait(self):
        
        new_get = Future()

        with self._lock:
            if not self._get.done():
                raise QueueEmpty
            get, self._get = self._get, new_get

        hole = get.result()
        if not hole.done():
            # Restore the unfinished hole.
            new_get.set_result(hole)
            raise QueueEmpty

        node = hole.result()
        value = node.value
        new_hole, node.next = node.next, None
        new_get.set_result(new_hole)
        return value
414757
def get!
      index = proxies.find_index(&:connectable?)
      return if index.nil?

      proxy = proxies.delete_at(index)
      tail = proxies[index..-1]

      @proxies = tail << proxy

      proxy
    end
943655
public function getMainBranch()
    {
        $filtered = array_filter(
            $this->getBranches(),
            function (Branch $branch) {
                return $branch->getCurrent();
            }
        );
        sort($filtered);

        return $filtered[0];
    }
583666
def extract_branches blocks

      branches = []
      blocks.each do |block|
        block.each do |stmt|
          case stmt
          when GotoStatement
            next if stmt.identifiers.length < 2
            unless stmt.identifiers.length == 2
              fail "Unexpected goto statement: #{stmt}"
            end

            if annotation = stmt.previous_sibling
              fail "Expected :branchcond annotation" unless
                annotation.has_attribute?(:branchcond)
            end

            branches.push(stmt)
          end
        end
      end
      return branches
    end
597007
def is_branch?(branch)
      branch_names = self.branches.map {|b| b.name}
      branch_names.include?(branch)
    end
1006213
def root_snapshot
      return nil if current_snapshot.nil?

      current = current_snapshot
      current = current.parent while current.parent != nil
      current
    end
1069977
def branches(self):
		
		# get all remote branches
		refs = filter(lambda l: isinstance(l, git.RemoteReference), self.repo.references)
		# filter out HEAD branch
		refs = filter(lambda l: l.name != "origin/HEAD", refs)
		# filter out all branches not starting with 'origin/'
		refs = filter(lambda l: l.name.startswith("origin/"), refs)
		for ref in refs:
			self.refs[ref.name[7:]] = ref

		# remove 'origin/' prefix
		return map(lambda l: l.name[7:], refs)
489278
def current_branch(self):
        """"""
        output = self.context.capture('git', 'rev-parse', '--abbrev-ref', 'HEAD', check=False, silent=True)
        return output if output != 'HEAD' else None
1162980
def branch(options=False, *args, **kwargs):
    
    return (options
            and run('branch %s' % options, *args, **kwargs)
            or rev_parse('--abbrev-ref HEAD', *args, **kwargs))
1019324
def rails_root
      if defined?(::Rails.root)
        return ::Rails.root.to_s if ::Rails.root
        raise "ERROR: Rails.root is nil!"
      end
      return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
      nil
    end
1121471
def _get_upstream(self):
    """"""
    if not self._remote or not self._branch:
      branch = self.branch_name
      if not branch:
        raise Scm.LocalException('Failed to determine local branch')

      def get_local_config(key):
        value = self._check_output(['config', '--local', '--get', key],
                                   raise_type=Scm.LocalException)
        return value.strip()

      self._remote = self._remote or get_local_config('branch.{}.remote'.format(branch))
      self._branch = self._branch or get_local_config('branch.{}.merge'.format(branch))
    return self._remote, self._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
27786
public function getCurrentBranch()
    {
        $output = $this->git('branch');

        foreach(explode("\n", $this->git('branch')) as $branchLine) {
            if('*' === $branchLine{0}) {
                return substr($branchLine, 2);
            }
        }
    }
833202
protected function getLastTagOnBranch($current_branch) {
    // List all tags, sort numerically, and filter out any that aren't numeric.
    $output = $this->taskExecStack()
      ->exec("git -c 'versionsort.suffix=-' tag --sort=-v:refname --merged $current_branch | sed '/^[[:alpha:]]/d'")
      ->interactive(FALSE)
      ->silent(TRUE)
      ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
      ->run()
      ->getMessage();
    $tags_on_branch = explode("\n", $output);
    $prev_tag = reset($tags_on_branch);

    return $prev_tag;
  }
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
339168
def call_git_branch():
    """"""
    try:
        with open(devnull, "w") as fnull:
            arguments = [GIT_COMMAND, 'rev-parse', '--abbrev-ref', 'HEAD']
            return check_output(arguments, cwd=CURRENT_DIRECTORY,
                                stderr=fnull).decode("ascii").strip()
    except (OSError, CalledProcessError):
        return None