Python的高级Git库 Gittle
Gittle是一个高级纯python git 库。构建在dulwich之上,提供了大部分的低层机制
Gittle是一个高级纯python git 库。构建在dulwich之上,提供了大部分的低层机制。
Install it
pip install gittle
Examples :
Clone a repository
|
1
2
3
4
5
6
|
from gittle import Gittle repo_path = '/tmp/gittle_bare'repo_url = 'git://github.com/FriendCode/gittle.git' repo = Gittle.clone(repo_url, repo_path) |
With authentication (see Authentication section for more information) :
|
1
2
|
auth = GittleAuth(pkey=key)Gittle.clone(repo_url, repo_path, auth=auth) |
Or clone bare repository (no working directory) :
repo = Gittle.clone(repo_url, repo_path, bare=True)
Init repository from a path
repo = Gittle.init(path)
Get repository information
|
1
2
3
4
5
6
7
8
9
10
11
|
# Get list of objectsrepo.commits # Get list of branchesrepo.branches # Get list of modified files (in current working directory)repo.modified_files # Get diff between latest commitsrepo.diff('HEAD', 'HEAD~1') |
Commit
|
1
2
3
4
5
6
7
8
|
# Stage single filerepo.stage('file.txt') # Stage multiple filesrepo.stage(['other1.txt', 'other2.txt']) # Do the commitrepo.commit(name="Samy Pesse", email="samy@friendco.de", message="This is a commit") |
Pull
|
1
2
3
4
5
6
7
8
|
repo = Gittle(repo_path, origin_uri=repo_url) # Authentication with RSA private keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # Do pullrepo.pull() |
Push
|
1
2
3
4
5
6
7
8
|
repo = Gittle(repo_path, origin_uri=repo_url) # Authentication with RSA private keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # Do pushrepo.push() |
Authentication for remote operations
|
1
2
3
4
5
6
|
# With a keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # With username and passwordrepo.auth(username="your_name", password="your_password") |
Branch
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# Create branch off masterrepo.create_branch('dev', 'master') # Checkout the branchrepo.switch_branch('dev') # Create an empty branch (like 'git checkout --orphan')repo.create_orphan_branch('NewBranchName') # Print a list of branchesprint(repo.branches) # Remove a branchrepo.remove_branch('dev') # Print a list of branchesprint(repo.branches) |
Get file version
|
1
2
|
versions = repo.get_file_versions('gittle/gittle.py')print("Found %d versions out of a total of %d commits" % (len(versions), repo.commit_count())) |
Get list of modified files (in current working directory)
repo.modified_files
Count number of commits
repo.commit_count
Get information for commits
List commits :
# Get 20 first commits repo.commit_info(start=0, end=20)
With a given commit :
commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc"
Diff with another commit :
|
1
2
|
old_commit = repo.get_previous_commit(commit, n=1)print repo.diff(commit, old_commit) |
Explore commit files using :
|
1
2
3
4
5
6
7
8
9
10
|
commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc" # Files treeprint repo.commit_tree(commit) # List files in a subpathprint repo.commit_ls(commit, "testdir") # Read a fileprint repo.commit_file(commit, "testdir/test.txt") |
Create a GIT server
|
1
2
3
4
5
6
7
|
from gittle import GitServer # Read onlyGitServer('/', 'localhost').serve_forever() # Read/WriteGitServer('/', 'localhost', perm='rw').serve_forever() |
Python的高级Git库 Gittle的更多相关文章
- 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装
网上的教程,一般Python用RPi.GPIO来控制树莓派的GPIO,而C/C++一般用wringpi库来操作GPIO,RPi.GPIO过于简单,很多高级功能不支持,比如i2c/SPI库等,也缺乏高精 ...
- Python测试 ——开发工具库
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
- Python常用的标准库以及第三方库有哪些?
20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们是: Requests.Kenneth Reitz ...
- Python常用的标准库以及第三方库
Python常用的标准库以及第三方库有哪些? 20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们 ...
- Python 常用的标准库以及第三方库有哪些?
作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- python测试开发工具库汇总(转载)
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
- 进击的Python【第五章】:Python的高级应用(二)常用模块
Python的高级应用(二)常用模块学习 本章学习要点: Python模块的定义 time &datetime模块 random模块 os模块 sys模块 shutil模块 ConfigPar ...
- python的高级应用
记录一下Python函数式编程,高级的几个BIF,高级官方库方面的用法和心得. 函数式编程 函数式编程是使用一系列函数去解决问题,按照一般编程思维,面对问题时我们的思考方式是"怎么干&quo ...
- python下载安装requests库
一.python下载安装requests库 1.到git下载源码zip源码https://github.com/requests/requests 2.解压到python目录下: 3.“win+R”进 ...
随机推荐
- 在Eclipse中运行cmd
第一步:设置一个新的外部配置工具 在 Eclipse 中,选择 “Run -> External Tools -> External Tools Configurations” 第二步: ...
- Java RGB数组图像合成 ImageCombining (整理)
/** * Java RGB数组图像合成 ImageCombinning (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * * 注意事项: * 1.本程序为java程序,同时感谢您花费 ...
- LeetCode Reverse Linked List II 反置链表2
题意:将指定的一段位置[m,n]的链表反置,返回链表头. 思路:主要麻烦在链表头,如果要从链表头就开始,比较特殊. 目前用DFS实现,先找到m-1的位置,再找到n+1的位置,中间这段就是否要反置的,交 ...
- php里的declare用法
function tick_handler () { echo "tick_handler() called<br>" ; } function tick_handle ...
- In App Purchase翻译
一.In App Purchase概览 Store Kit代表App和App Store之间进行通信.程序将从App Store接收那些你想要提供的产品的信息,并将它们显示出来供用户购买.当用户需要购 ...
- Java核心技术II读书笔记(三)
ch2 XML SAX解析器 SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory ...
- PHPMailer邮件类使用错误分析
PHPMailer配置清单如下: require_once ‘class.phpmailer.php‘; $receiver = ”; $mail = new PHPMailer ( ); $mai ...
- hdu 2732 Leapin' Lizards(最大流)Mid-Central USA 2005
废话: 这道题不难,稍微构造一下图就可以套最大流的模板了.但是我还是花了好久才解决.一方面是最近确实非常没状态(托词,其实就是最近特别颓废,整天玩游戏看小说,没法静下心来学习),另一方面是不够细心,输 ...
- spring mvc 异常统一处理方式
springMVC提供的异常处理主要有两种方式: 一种是直接实现自己的HandlerExceptionResolver: 另一种是使用注解的方式实现一个专门用于处理异常的Controller——Exc ...
- duilib让不同的容器使用不同的滚动条样式
装载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/42240569 以前在给一个容器设置横纵向的滚动条时,一直是通过设置xml ...