Module: GitPlumber

Defined in:
lib/luigi/gitplumber.rb

Instance Method Summary collapse

Instance Method Details

#git_commit(message) ⇒ Object



58
59
60
# File 'lib/luigi/gitplumber.rb', line 58

def git_commit(message)
  @git.commit(message)
end

#git_log(count = 30) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/luigi/gitplumber.rb', line 33

def git_log(count = 30)
  table = Textboxes.new
  table.style[:border] = false
  @git.log(count = count).to_a.reverse.each do |commit|
    table.add_row [
      commit.author.name,
      commit.message,
      commit.date.strftime("%d.%m.%Y-%H:%M"),
    ]
  end
  puts table
end

#git_print_renamed(files) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/luigi/gitplumber.rb', line 134

def git_print_renamed files
  puts "#{files.length} Renamed:" if files.length > 0
  width = 0
  files.map {|a,b| width = a.length if a.length > width}
  out = ""
  files.each {|a,b|
    a = a.ljust(width)
    out << Paint[ "\e[32m✓\e[0m" , :green] + " "
    out << Paint[a, :red]
    out << " -> "
    out << Paint[b, :green]
    out << "\n"
  }
  puts out if out.length > 0
end

#git_print_status(name, exclude) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/luigi/gitplumber.rb', line 92

def git_print_status name, exclude
  case name
    when :added     then status = @git.status.added
    when :changed   then status = @git.status.changed
    when :deleted   then status = @git.status.deleted
    when :untracked then status = @git.status.untracked
  end
  status.reject! {|k,v| exclude.include? k }

  puts "#{status.length} #{name.to_s.capitalize}:" if status.length > 0
  status.each do |path, info|
    case info.type
    when "M" then color = :yellow
    when "A" then color = :green
    when "D" then color = :red
    else color = :default
    end
    line = Paint[path, color]
    state = " "
    state = Paint[ "\e[32m✓\e[0m" , :green] if !info.sha_index.nil? and info.sha_index.to_i(16) > 0
    puts "#{state} #{line}"
  end
  puts if status.length > 0
end

#git_pullObject



52
53
54
55
56
# File 'lib/luigi/gitplumber.rb', line 52

def git_pull()
  @git = Git.open @dirs[:storage], :log => Logger.new(STDOUT)
  out = @git.pull()
  puts out if out
end

#git_pushObject



46
47
48
49
50
# File 'lib/luigi/gitplumber.rb', line 46

def git_push()
  @git = Git.open @dirs[:storage], :log => Logger.new(STDOUT)
  out = @git.push()
  puts out if out
end

#git_renamed_filesObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/luigi/gitplumber.rb', line 117

def git_renamed_files
  repo_shas = {}
  index_shas = {}
  out = ""
  files = []
  @git.lib.diff_index('HEAD').each { |file, data|
    sr = data[:sha_repo]
    si = data[:sha_index]
    repo_shas[sr] = file if sr.to_i(16) > 0
    index_shas[si] = file if si.to_i(16) > 0
    if index_shas.include? sr
      files.push [ repo_shas[sr], index_shas[sr] ]
    end
  }
  return files
end

#git_save(message) ⇒ Object



72
73
74
75
76
# File 'lib/luigi/gitplumber.rb', line 72

def git_save message
  puts "GITSAVE\n"
  git_add()
  @git.commit_all "ruby git #commit_all \"#{message}\""
end

#git_statusObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/luigi/gitplumber.rb', line 78

def git_status
  renamed = git_renamed_files
  exclude = renamed.flatten
  if @git.status.added.length + @git.status.deleted.length + @git.status.untracked.length + @git.status.changed.length == 0
    puts "Nothing Changed"
  end

  git_print_status :added,      exclude
  git_print_status :changed,    exclude
  git_print_status :deleted,    exclude
  git_print_status :untracked,  exclude
  git_print_renamed renamed
end

#git_update_path(path = @git.dir) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/luigi/gitplumber.rb', line 62

def git_update_path path = @git.dir
  return unless @settings['use_git']
  if File.exists? path
    @git.add path
  else
    @git.remove path, {:recursive => true}
  end

end

#open_gitObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/luigi/gitplumber.rb', line 21

def open_git
  return false unless @using_git
  logger = Logger.new STDOUT
  begin
    @git = Git.open @dirs[:storage]
    return true
  rescue => error
    logger.error "#{@dirs[:storage]} does not seem to be a git repository"
    return false
  end
end