用于GItHub交互的Gem

时间:2012-09-04 11:48:14

标签: ruby-on-rails-3 gem

我正在寻找一个gem,它可以让我在Git Repository上发出一些pull请求,并下载一个分支的文件。我正在使用这个https://github.com/peter-murach/github#readme,但我似乎找不到'获取/拉取'请求。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您正在寻找git宝石

sudo gem install git

以下是您使用它的方式(摘自自述文件):

   g = Git.init
     Git.init('project')
     Git.init('/home/schacon/proj', 
          { :git_dir => '/opt/git/proj.git', 
             :index_file => '/tmp/index'} )

   g = Git.clone(URI, :name => 'name', :path => '/tmp/checkout')   
   g.config('user.name', 'Scott Chacon')
   g.config('user.email', 'email@email.com')      

   g.add('.')
   g.add([file1, file2])

   g.remove('file.txt')
   g.remove(['file.txt', 'file2.txt'])

   g.commit('message')
   g.commit_all('message')

   g = Git.clone(repo, 'myrepo')
   g.chdir do
    new_file('test-file', 'blahblahblah')
    g.status.changed.each do |file|
     puts file.blob(:index).contents
    end
   end

   g.reset # defaults to HEAD
   g.reset_hard(Git::Commit)

   g.branch('new_branch') # creates new or fetches existing
   g.branch('new_branch').checkout
   g.branch('new_branch').delete
   g.branch('existing_branch').checkout

   g.checkout('new_branch')
   g.checkout(g.branch('new_branch'))

   g.branch(name).merge(branch2)
   g.branch(branch2).merge  # merges HEAD with branch2

   g.branch(name).in_branch(message) { # add files }  # auto-commits
   g.merge('new_branch')
   g.merge('origin/remote_branch')
   g.merge(g.branch('master'))
   g.merge([branch1, branch2])

   r = g.add_remote(name, uri)  # Git::Remote
   r = g.add_remote(name, Git::Base)  # Git::Remote

   g.remotes  # array of Git::Remotes
   g.remote(name).fetch
   g.remote(name).remove
   g.remote(name).merge
   g.remote(name).merge(branch)

   g.fetch
   g.fetch(g.remotes.first)

   g.pull
   g.pull(Git::Repo, Git::Branch) # fetch and a merge

   g.add_tag('tag_name') # returns Git::Tag

   g.repack

   g.push
   g.push(g.remote('name'))