Skip to content

Instantly share code, notes, and snippets.

@Deradon
Created June 28, 2016 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Deradon/29ed7fb6b61b8c3c08786bdde29d9ece to your computer and use it in GitHub Desktop.
Save Deradon/29ed7fb6b61b8c3c08786bdde29d9ece to your computer and use it in GitHub Desktop.
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