class Git::Status
def [](file)
def [](file) @files[file] end
def added
def added @files.select { |k, f| f.type == 'A' } end
def changed
def changed @files.select { |k, f| f.type == 'M' } end
def construct_status
def construct_status @files = @base.lib.ls_files # find untracked in working dir Dir.chdir(@base.dir.path) do Dir.glob('**/*') do |file| @files[file] = {:path => file, :untracked => true} unless @files[file] || File.directory?(file) end end # find modified in tree @base.lib.diff_files.each do |path, data| @files[path] ? @files[path].merge!(data) : @files[path] = data end # find added but not committed - new files @base.lib.diff_index('HEAD').each do |path, data| @files[path] ? @files[path].merge!(data) : @files[path] = data end @files.each do |k, file_hash| @files[k] = StatusFile.new(@base, file_hash) end end
def deleted
def deleted @files.select { |k, f| f.type == 'D' } end
def each(&block)
def each(&block) @files.values.each(&block) end
def initialize(base)
def initialize(base) @base = base construct_status end
def pretty
def pretty out = '' self.each do |file| out << file.path out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s out << "\n\ttype " + file.type.to_s out << "\n\tstage " + file.stage.to_s out << "\n\tuntrac " + file.untracked.to_s out << "\n" end out << "\n" out end
def untracked
def untracked @files.select { |k, f| f.untracked } end