Skip to content

Instantly share code, notes, and snippets.

@benmcredmond
Created June 12, 2011 16:54
Show Gist options
  • Save benmcredmond/1021753 to your computer and use it in GitHub Desktop.
Save benmcredmond/1021753 to your computer and use it in GitHub Desktop.
Example Git Ruby Interface
class Git
@@git_methods = [:add, :bisect, :branch, :checkout, :clone, :commit, :diff, :fetch, :grep, :init, :log, :merge, :mv, :pull, :push, :rebase, :reset, :rm, :show, :status, :tag]
def method_missing(method, *args, &block)
if(@@git_methods.include?(method.to_sym))
key_value_options = args.delete(-1) if args[-1].kind_of?(Hash)
key_value_options ||= nil
command = 'git '
command += (args.join(' ') + ' ')
command += key_value_options.inject("") do |memo,(k,v)|
memo += "--#{k}"
memo += "='#{v}'" unless (v == true)
end
`#{command}`
end
end
end
g = Git.new
g.init('.', :quiet => true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment