module Kmc::GitAdapter

Public Class Methods

commit_everything(repo_path, commit_message) click to toggle source
# File lib/kmc/git_adapter.rb, line 17
def commit_everything(repo_path, commit_message)
  Dir.chdir(repo_path) do
    `git add -A -f`
    `git commit --allow-empty -m "#{commit_message}"`
  end
end
init_repo(path) click to toggle source
# File lib/kmc/git_adapter.rb, line 4
def init_repo(path)
  Dir.chdir(path) do
    `git init`
    `git config user.name KMC`
    `git config user.email kmc@kmc.kmc`
    `git config core.autocrlf false`

    File.open('.gitignore', 'w') do |file|
      file.write "!*\n"
    end
  end
end
list_commits(repo_path) click to toggle source
# File lib/kmc/git_adapter.rb, line 37
def list_commits(repo_path)
  Dir.chdir(repo_path) do
    `git log --oneline`.lines.map do |line|
      sha, message = line.split(' ', 2)
      Commit.new(message, sha)
    end
  end
end
revert_commit(repo_path, commit) click to toggle source
# File lib/kmc/git_adapter.rb, line 24
def revert_commit(repo_path, commit)
  Dir.chdir(repo_path) do
    # Favor "ours" (which is always HEAD for our purposes) when git-revert
    # can handle that on its own.
    `git revert --no-commit --strategy=merge --strategy-option=ours #{commit.sha}`

    # When files are being created or deleted, git will not do anything.
    # In this case, keep all files alive; better to accidentally pollute
    # than accidentally delete something important.
    `git add *`
  end
end