Class: Git::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/toga/extensions.rb

Instance Method Summary collapse

Instance Method Details

#ignoredObject

Retrieves files that are ignored



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/toga/extensions.rb', line 35

def ignored
  ignored = @base.lib.send :command, 'clean', '-ndX'
  ignored = ignored.split("\n").collect {|i| i.gsub('Would remove ', '') }
  files = @files.values.dup
  subdirectory_ignores = {}
  ignored.each do |i|
    if !i[/\/(|\*)$/].nil? # ends in either / or /*
      files.each do |f|
        if f.path.starts_with?(i)
          subdirectory_ignores[f.path] = f
        end
      end
    end
  end
  subdirectory_ignores
end

#modifiedObject



88
89
90
91
# File 'lib/toga/extensions.rb', line 88

def modified
  regex = /^[0]+$/
  added.select {|k,v| v.sha_index[regex] && v.sha_repo[regex] }
end

#subproject_filesObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/toga/extensions.rb', line 65

def subproject_files
  return @base.lib.submodules if @base.lib.respond_to? :submodules
    
  # Ruby-git doesn't support submodules, so do
  # them manually
  submodules = {}
  
  Dir.chdir(@base.dir.to_s) do 
    lines = %x[git submodule status]
  
    lines.split("\n").each do |l|
      exp = /([\-0-9A-f]+) ([^ ]+)/
      m = exp.match(l)
      ref = m[1]
      path = m[2]
    
      submodules[path] = {:ref => ref, :path => path}
    end
  end
  
  submodules
end

#untracked!Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/toga/extensions.rb', line 52

def untracked!
  ignored_files = self.ignored.keys
  subproject_directories = self.subproject_files.keys
  self.untracked.reject do |k,v|
    (lambda do
      return true if ignored_files.include?(k)
      subproject_directories.map {|d| return true if k.starts_with?(d) }
      
      false
    end).call
  end
end