module GitExplorer

Constants

GitStatus
VERSION

Public Instance Methods

extract_dir_name() click to toggle source
# File lib/git_explorer.rb, line 34
def extract_dir_name
  -> (dot_git_file_path) { dot_git_file_path.gsub(/\.git$/,'') }
end
extract_light_status(status_output) click to toggle source
# File lib/git_explorer.rb, line 23
def extract_light_status(status_output)
  project_name = status_output[/^(?<project_name>.*)$/, "project_name"]
  branch = status_output[/On branch\s(?<branch>.*)/, "branch"]
  status = []
  status << :up_to_date if status_output[/up-to-date/]
  status << :not_staged if status_output[/not staged/]
  status << :to_be_committed if status_output[/to be committed/]
  files = status_output.scan(/modified: \s*(.*)$/).flatten
  GitStatus.new(status, project_name, branch, files)
end
extract_path(line, root_dir) click to toggle source
# File lib/git_explorer.rb, line 38
def extract_path(line, root_dir)
  parsed_path = line[/.*\s(?<path>.*)$/, 'path']
  root_dir + parsed_path
end
extract_status() click to toggle source
# File lib/git_explorer.rb, line 10
def extract_status
  -> (status_output) {
    project_name = status_output[/^(?<project_name>.*)$/, "project_name"]
    branch = status_output[/On branch\s(?<branch>.*)/, "branch"]
    status = []
    status << :up_to_date if status_output[/up-to-date/]
    status << :not_staged if status_output[/not staged/]
    status << :to_be_committed if status_output[/to be committed/]
    files = status_output.scan(/modified: \s*(.*)$/).flatten
    GitStatus.new(status, project_name, branch, files)
  }
end
git_repository?(path) click to toggle source
# File lib/git_explorer.rb, line 43
def git_repository?(path)
  return nil if path.nil?
  is_directory = File.directory?(path)
  is_repository = run("find #{path} -maxdepth 1 -type d -name .git", config={:capture=>true, :verbose=>false}) if is_directory
  is_directory and !is_repository.empty?
end
git_status(path) click to toggle source
# File lib/git_explorer.rb, line 50
def git_status(path)
  run("basename `git -C #{path} rev-parse --show-toplevel`; git -C #{path} status", config={:capture=>true, :verbose=>false})
end
translate_color(statuses) click to toggle source
# File lib/git_explorer.rb, line 65
def translate_color(statuses)
  return :green if statuses == [:up_to_date]
  return :red if statuses == [:conflict]

  :cyan
end
translate_status(statuses) click to toggle source
# File lib/git_explorer.rb, line 54
def translate_status(statuses)
  possible_status = {
      to_be_committed: '✚',
      up_to_date: '✔',
      not_staged: '●',
      conflict: '✖'
  }

  statuses.inject('') {|string, status| string = string + possible_status[status].to_s}
end