Class: GitExplorer::Explorer

Inherits:
Thor
  • Object
show all
Includes:
GitExplorer, Thor::Actions
Defined in:
lib/git_explorer.rb

Defined Under Namespace

Classes: Line

Constant Summary collapse

LOGGER =
Logger.new(STDOUT)

Constants included from GitExplorer

VERSION

Instance Method Summary collapse

Methods included from GitExplorer

#extract_dir_name, #extract_light_status, #extract_path, #extract_status, #git_repository?, #git_status

Instance Method Details

#explore(root_dir = './') ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/git_explorer.rb', line 60

def explore(root_dir='./')
  if options.light?
    run("ls #{root_dir} -l | awk '{if(NR>1)print}'", config={:capture=>true, :verbose=>false})
        .split("\n")
        .map{|line| Line.new(line)}
        .map{|line| Line.new(line.full_line, '', git_repository?(extract_path(line.full_line, root_dir)))}
        .map{|line| Line.new(line.full_line, (extract_light_status(git_status(extract_path(line.full_line, root_dir))) if line.git_repository == true), line.git_repository)}
        .map{|line|
      say(message="#{line.full_line} ")
      say(message="#{'[' + line.state.branch + ']'}", color=(:red)) if line.git_repository == true and line.state.status != :up_to_date
      say(message="#{'[' + line.state.branch + ']'}", color=(:green)) if line.git_repository == true and line.state.status == :up_to_date
      say(message="\n")
    }
  else
    run("find #{root_dir} -type d -name .git", config={:capture=>true, :verbose=>false})
        .split("\n")
        .map{|file| file >> extract_dir_name}
        .map{|dir| run("basename `git -C #{dir} rev-parse --show-toplevel`; git -C #{dir} status", config={:capture=>true, :verbose=>false})}
        .map{|status| status >> extract_status}
        .map{|status| say(message="#{status.project_name} is #{status.status} on branch #{status.branch}\n#{status.files.map{|f| "\t#{f}\n"}.join}", color=(:red if status.status.equal?(:not_staged)))}
  end
end