class Git::Dust

Constants

COMMIT_MESSAGE

Public Class Methods

commit(args) click to toggle source
# File lib/git/dust.rb, line 45
def self.commit(args)
  run_command(*%w(git commit -m), COMMIT_MESSAGE, *args)
end
edit_rebase_commit_list(args) click to toggle source
# File lib/git/dust.rb, line 62
def self.edit_rebase_commit_list(args)
  output = []
  rebase_todo_path = Pathname(args.first)
  rebase_todo_path.open do |f|
    lines = f.each_line
    lines.each do |l| # write first commit
      if !/\A\s*#/.match(l)
        output << l
        break
      end
    end
    lines.each do |l| # change "pick" to "fixup"
      output << l.sub(/\Apick/, "fixup")
    end
  end
  rebase_todo_path.write(output.join)
end
fix(args) click to toggle source
# File lib/git/dust.rb, line 49
def self.fix(args)
  base_sha1 = find_non_dust_commit
  saved_editor_environment = ENV["GIT_SEQUENCE_EDITOR"]
  begin
    ENV["GIT_SEQUENCE_EDITOR"] = "git dust edit-rebase-commit-list"
    run_command(*%w(git rebase -i), base_sha1)
  ensure
    ENV["GIT_SEQUENCE_EDITOR"] = saved_editor_environment
  end
  run_command(*%w(git reset --soft HEAD^))
  run_command("git commit --edit")
end
help(args = []) click to toggle source
# File lib/git/dust.rb, line 21
  def self.help(args = [])
    STDERR.puts(<<EOS)
#{File.basename($0)} <command> [<args>]

git dust commands are:
* commit
EOS
  end
run(command_and_args) click to toggle source
# File lib/git/dust.rb, line 30
def self.run(command_and_args)
  command = command_and_args.first || "help"
  command_symbol = command.gsub("-", "_").to_sym
  args = command_and_args[1 .. -1]
  defined_commands = public_methods(false) - %i(allocate new superclass run)
  if defined_commands.include?(command_symbol)
    send(command_symbol, args)
  else
    STDERR.puts("sub command not found: sub_command=<#{command}>")
    STDERR.puts
    help
    exit(1)
  end
end

Private Class Methods

find_non_dust_commit() click to toggle source
# File lib/git/dust.rb, line 90
def self.find_non_dust_commit
  Open3.popen2("git log --format=oneline") do |stdin, stdout, wait_thread|
    stdout.each_line.each do |line|
      sha1, subject = line.chomp.split(" ", 2)
      return sha1 if COMMIT_MESSAGE != subject
    end
  end
  raise "non dust commit is not exist."
end
run_command(*args) click to toggle source
# File lib/git/dust.rb, line 84
def self.run_command(*args)
  if !system(*args)
    raise "failed: args=<#{args.inspect}>"
  end
end