Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Forked from Deradon/simple_git.rb
Created June 28, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emad-elsaid/33aa446f5ddbcaefc6820d24b7071ab1 to your computer and use it in GitHub Desktop.
Save emad-elsaid/33aa446f5ddbcaefc6820d24b7071ab1 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