2010-06-27 44 views
7

我正在尋找可用於更新和提交本地存儲庫中更改的Git客戶端的Ruby或Python實現。用於Ruby或Python的Git庫?

我更喜歡圖書館根本不使用shell命令,而是將所有內容都保存在「純代碼」中。

有沒有?

預先感謝您。

回答

6

Grit爲您提供面向對象的通過Ruby讀取/寫入Git存儲庫的權限。

require 'grit' 
include Grit 
repo = Repo.new("/Users/tom/dev/grit") 

repo.commits 
# => [#<Grit::Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">, 
     #<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">, 
     #<Grit::Commit "038af8c329ef7c1bae4568b98bd5c58510465493">, 
     #<Grit::Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">, 
     #<Grit::Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">] 

... 
3

您可以檢查出ruby-git gem

+0

這是目前(2015年10月)在Ruby中最常用的包裝器的Git。 – mliebelt 2015-10-07 06:14:27

3

對於Python,有@RyanWilcox已經提到的Dulwich庫。

對於Ruby,不幸的是沒有Git庫。有Grit,它實現了Ruby中的一個Git子集,並封裝了一些額外功能的命令行工具,但只支持GitHub需要的Git子集。您可以通過JRuby或IronRuby使用JGitGit#

0

GitPython具有類似砂礫一個面向對象的API:

>>> #$ pip install GitPython 
>>> import git 
>>> repo = git.Repo('.') 
>>> repo.git_dir 
'/home/hobs/src/twip/.git' 
>>> repo.bare 
False 
>>> repo.untracked_files 
[u'twip/scripts.bak/__init__.py', 
u'twip/scripts.bak/cat_tweets.py', 
u'twip/scripts.bak/clean.py', 
u'twip/scripts.bak/explore.py', 
u'twip/scripts.bak/generate.py', 
u'twip/scripts.bak/plot_globe.py', 
u'twip/scripts.bak/skeleton.py'] 
>>> repo.head.ref 
<git.Head "refs/heads/master"> 
>>> repo.tags 
[<git.TagReference "refs/tags/0.0.1">, 
<git.TagReference "refs/tags/0.0.2">, 
<git.TagReference "refs/tags/0.0.3">]