Created
June 28, 2016 12:06
-
-
Save Deradon/29ed7fb6b61b8c3c08786bdde29d9ece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleGit | |
def self.git(method_name, cmd = nil) | |
define_method(method_name) do |args| | |
if cmd | |
git("#{cmd} #{args}") | |
else | |
git("#{method_name} #{args}") | |
end | |
end | |
end | |
attr_reader :working_directory | |
def initialize(working_directory) | |
@working_directory ||= File.absolute_path(working_directory) | |
end | |
git :checkout | |
git :commit | |
git :fetch | |
git :merge_no_ff, "merge --no-ff" | |
git :rebase | |
git :remote_add, "remote add" | |
git :reset_hard, "reset --hard" | |
private | |
def git(cmd) | |
run "git #{cmd}" | |
end | |
def run(cmd) | |
cmd = <<-CMD | |
cd #{working_directory} && | |
#{cmd} | |
CMD | |
`#{cmd}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment