<commit_before>class SCM::Git::Branch < SCM::Git::CommandProxyBase
  module BranchHelperMethods
    def shorten(name)
      name && name.gsub(/refs\/(heads|remotes)\//, "")
    end
    
    def format_name(name, format = :short)
      (format == :short) ? shorten(name) : name
    end
  end
  
  include BranchHelperMethods
  
  def [](name)
    SCM::Git::Branch::Proxy.new(@base, self, name)
  end
  
  def create_and_switch(name)
    base.command("checkout", "-b", name)
  end
  
  def create(name, options = {})
    args = ["branch"]
    args << "--track" if options[:autotrack]
    args << name
    case
    when ! options[:source].blank?
      args << options[:source]
    when ! options[:tag].blank?
      args << options[:tag]
    when ! options[:revision].blank?
      args << options[:revision]
    end
    base.command(*args)
  end
  
  def switch(name)
    result = base.command("checkout", name)
    rescan_project
    result
  end
  
  def all_for_local_or_remote(which, options = {})
    list(which, options).map do |branch_params| 
      BranchProxy.new(@base, self, branch_params)
    end
  end
  
  def all(which = :both, options = {})
    branches = []
    which = [:local, :remote] if which == :both
    [which].flatten.each do |side|
      branches.concat all_for_local_or_remote(side, options)
    end
    
    branches.compact
  end
  
  def list(which = :local, options= {})
    params = []
    case which
    when :local then params << "refs/heads"
    when :remote then params << "refs/remotes"
    end
    result = base.command("for-each-ref", *params).split("\n").map do |e|
      next unless /^([a-f0-9]{40})\s*commit\s*(.+)$/.match(e)
      {:ref => $1, :name => $2}
    end.compact
    
    if options[:remote]
      r_prefix = @base.remote[options[:remote]].remote_branch_prefix
      result.delete_if { |r| r[:name][0..(r_prefix.length-1)] != r_prefix }
    end
    result
  end
  
  def list_names(which = :local, options = {})
    list(*args).map do |b|
      format_name(b[:name], :options[:format])
    end
  end
  
  alias names list_names
  
  def current
    _current_name = current_name(:long)
    list(:local).each do |branch_params|
      return BranchProxy.new(@base, self, branch_params) if branch_params[:name] == _current_name
    end
    
    nil
  end
  
  def current_name(format = :short)
    return unless /^ref: (.+)$/.match(File.read(@base.path_for(".git/HEAD")))
    name = $1
    format_name(name, format)
  end
  
  alias current_branch current

  def delete(name, options = {})
    branch_type = options[:branch_type] || (name.include?("/") ? :remote : :local)<commit_msg>format_name defaults to :short.  fixed a few blunders<commit_after>class SCM::Git::Branch < SCM::Git::CommandProxyBase
  module BranchHelperMethods
    def shorten(name)
      name && name.gsub(/refs\/(heads|remotes)\//, "")
    end
    
    def format_name(name, format = :short)
      (format == :short || format == nil) ? shorten(name) : name
    end
  end
  
  include BranchHelperMethods
  
  def [](name)
    SCM::Git::Branch::Proxy.new(@base, self, name)
  end
  
  def create_and_switch(name)
    base.command("checkout", "-b", name)
  end
  
  def create(name, options = {})
    args = ["branch"]
    args << "--track" if options[:autotrack]
    args << name
    case
    when ! options[:source].blank?
      args << options[:source]
    when ! options[:tag].blank?
      args << options[:tag]
    when ! options[:revision].blank?
      args << options[:revision]
    end
    base.command(*args)
  end
  
  def switch(name)
    result = base.command("checkout", name)
    rescan_project
    result
  end
  
  def all_for_local_or_remote(which, options = {})
    list(which, options).map do |branch_params| 
      BranchProxy.new(@base, self, branch_params)
    end
  end
  
  def all(which = :both, options = {})
    branches = []
    which = [:local, :remote] if which == :both
    [which].flatten.each do |side|
      branches.concat all_for_local_or_remote(side, options)
    end
    
    branches.compact
  end
  
  def list(which = :local, options= {})
    params = []
    case which
    when :local then params << "refs/heads"
    when :remote then params << "refs/remotes"
    end
    result = base.command("for-each-ref", *params).split("\n").map do |e|
      next unless /^([a-f0-9]{40})\s*commit\s*(.+)$/.match(e)
      {:ref => $1, :name => $2}
    end.compact
    
    if options[:remote]
      r_prefix = @base.remote[options[:remote]].remote_branch_prefix
      result.delete_if { |r| r[:name][0..(r_prefix.length-1)] != r_prefix }
    end
    result
  end
  
  def list_names(which = :local, options = {})
    list(which, options).map do |b|
      format_name(b[:name], options[:format])
    end
  end
  
  alias names list_names
  
  def current
    _current_name = current_name(:long)
    list(:local).each do |branch_params|
      return BranchProxy.new(@base, self, branch_params) if branch_params[:name] == _current_name
    end
    
    nil
  end
  
  def current_name(format = :short)
    return unless /^ref: (.+)$/.match(File.read(@base.path_for(".git/HEAD")))
    name = $1
    format_name(name, format)
  end
  
  alias current_branch current

  def delete(name, options = {})
    branch_type = options[:branch_type] || (name.include?("/") ? :remote : :local)
{'fraction_non_alphanumeric': 0.15085478113845577, 'fraction_numerical': 0.0033815517565282736, 'mean_word_length': 2.8663761801016703, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337779', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1809, 'n_words': 403}