Rugged 是一个 Git 的 Ruby 开发包,使用 libgit2 API
安装方法:
$ gem install rugged
使用方法:
require 'rugged' repo = Rugged::Repository.new('path/to/my/repository') # => #<Rugged::Repository:2228536260 {path: "path/to/my/repository/.git/"}> Rugged::Repository.init_at('.', :bare) Rugged::Repository.discover("/Users/me/projects/repo/lib/subdir/") # => "/Users/me/projects/repo/.git/" # Does the given SHA1 exist in this repository? repo.exists?('07b44cbda23b726e5d54e2ef383495922c024202') # => true # Boolean repository state values: repo.bare? # => false repo.empty? # => true repo.head_orphan? # => false repo.head_detached? # => false # Path accessors repo.path # => "path/to/my/repository/.git/" repo.workdir # => "path/to/my/repository/" # The HEAD of the repository. ref = repo.head # => #<Rugged::Reference:2228467240 {name: "refs/heads/master", target: "07b44cbda23b726e5d54e2ef383495922c024202"}> # From the returned ref, you can also access the `name` and `target`: ref.name # => "refs/heads/master" ref.target # => "07b44cbda23b726e5d54e2ef383495922c024202" # Reading an object object = repo.read('a0ae5566e3c8a3bddffab21022056f0b5e03ef07') # => #<Rugged::OdbObject:0x109a64780> object.len # => 237 object.data # => "tree 76f23f186076fc291742816721ea8c3e95567241\nparent 8e3c5c52b8f29da0adc7e8be8a037cbeaea6de6b\nauthor Vicent Mart\303\255 <tanoku@gmail.com> 1333859005 +0200\ncommitter Vicent Mart\303\255 <tanoku@gmail.com> 1333859005 +0200\n\nAdd `Repository#blob_at`\n" object.type # => :commit