module GitPlumber

Public Instance Methods

git_commit(message) click to toggle source
# File lib/luigi/gitplumber.rb, line 58
def git_commit(message)
  @git.commit(message)
end
git_log(count = 30) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_pull() click to toggle source
# 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_push() click to toggle source
# 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_files() click to toggle source
# 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) click to toggle source
# 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_status() click to toggle source
# 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) click to toggle source
# 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_git() click to toggle source
# 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