Module: Kosmos::GitAdapter
- Defined in:
- lib/kosmos/git_adapter.rb
Defined Under Namespace
Classes: Commit
Class Method Summary collapse
- .commit_everything(repo_path, commit_message) ⇒ Object
- .init_repo(path) ⇒ Object
- .list_commits(repo_path) ⇒ Object
- .revert_commit(repo_path, commit) ⇒ Object
Class Method Details
.commit_everything(repo_path, commit_message) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/kosmos/git_adapter.rb', line 17 def commit_everything(repo_path, ) Dir.chdir(repo_path) do `git add -A -f` `git commit --allow-empty -m "#{}"` end end |
.init_repo(path) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/kosmos/git_adapter.rb', line 4 def init_repo(path) Dir.chdir(path) do `git init` `git config user.name Kosmos` `git config user.email [email protected]` `git config core.autocrlf false` File.open('.gitignore', 'w') do |file| file.write "!*\n" end end end |
.list_commits(repo_path) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/kosmos/git_adapter.rb', line 37 def list_commits(repo_path) Dir.chdir(repo_path) do `git log --oneline`.lines.map do |line| sha, = line.split(' ', 2) Commit.new(, sha) end end end |
.revert_commit(repo_path, commit) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kosmos/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 |