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 objects
repo.commits
  
# Get list of branches
repo.branches
  
# Get list of modified files (in current working directory)
repo.modified_files
  
# Get diff between latest commits
repo.diff('HEAD', 'HEAD~1')

Commit

1
2
3
4
5
6
7
8
# Stage single file
repo.stage('file.txt')
  
# Stage multiple files
repo.stage(['other1.txt', 'other2.txt'])
  
# Do the commit
repo.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 key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
  
# Do pull
repo.pull()

Push

1
2
3
4
5
6
7
8
repo = Gittle(repo_path, origin_uri=repo_url)
  
# Authentication with RSA private key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
  
# Do push
repo.push()

Authentication for remote operations

1
2
3
4
5
6
# With a key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
  
# With username and password
repo.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 master
repo.create_branch('dev', 'master')
  
# Checkout the branch
repo.switch_branch('dev')
  
# Create an empty branch (like 'git checkout --orphan')
repo.create_orphan_branch('NewBranchName')
  
# Print a list of branches
print(repo.branches)
  
# Remove a branch
repo.remove_branch('dev')
  
# Print a list of branches
print(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 tree
print repo.commit_tree(commit)
  
# List files in a subpath
print repo.commit_ls(commit, "testdir")
  
# Read a file
print repo.commit_file(commit, "testdir/test.txt")

Create a GIT server

1
2
3
4
5
6
7
from gittle import GitServer
  
# Read only
GitServer('/', 'localhost').serve_forever()
  
# Read/Write
GitServer('/', 'localhost', perm='rw').serve_forever()

Python的高级Git库 Gittle的更多相关文章

  1. 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装

    网上的教程,一般Python用RPi.GPIO来控制树莓派的GPIO,而C/C++一般用wringpi库来操作GPIO,RPi.GPIO过于简单,很多高级功能不支持,比如i2c/SPI库等,也缺乏高精 ...

  2. Python测试 ——开发工具库

    Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...

  3. Python常用的标准库以及第三方库有哪些?

    20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们是: Requests.Kenneth Reitz ...

  4. Python常用的标准库以及第三方库

    Python常用的标准库以及第三方库有哪些?   20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们 ...

  5. Python 常用的标准库以及第三方库有哪些?

    作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  6. python测试开发工具库汇总(转载)

    Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...

  7. 进击的Python【第五章】:Python的高级应用(二)常用模块

    Python的高级应用(二)常用模块学习 本章学习要点: Python模块的定义 time &datetime模块 random模块 os模块 sys模块 shutil模块 ConfigPar ...

  8. python的高级应用

    记录一下Python函数式编程,高级的几个BIF,高级官方库方面的用法和心得. 函数式编程 函数式编程是使用一系列函数去解决问题,按照一般编程思维,面对问题时我们的思考方式是"怎么干&quo ...

  9. python下载安装requests库

    一.python下载安装requests库 1.到git下载源码zip源码https://github.com/requests/requests 2.解压到python目录下: 3.“win+R”进 ...

随机推荐

  1. Jenkins+Maven+SVN搭建自动部署、自动测试环境

    .打开http://10.3.15.78:8080/jenkins/,第一次进入里面没有数据,我们需要创建job,我们这有2个项目,需要创建2个job.http://10.3.34.163:9890/ ...

  2. linux shared lib 使用与编译

    一.              动态链接库的原理及使用 Linux提供4个库函数.一个头文件dlfcn.h以及两个共享库(静态库libdl.a和动态库libdl.so)支持动态链接. Ø        ...

  3. [转载] FFmpeg 错误 C4996: ‘avcodec_alloc_frame’: 被声明为已否决 解决方法

    在 Visual Studio 2013 下编写 FFmpeg 程序时出错,错误如下: 出错代码如下: 解决方法为:将 avcodec_alloc_frame() 替换为 av_frame_alloc ...

  4. 【javascript】js 判断微信浏览器

    上周接到个需求,需求是这样的:用户扫一扫二维码会产生一个链接,该链接会向后端发送个请求,返回一个 apk 的下载地址,用户点击下载按钮可以下载此 apk.然后就发生了问题,经过测试,发现用微信扫一扫打 ...

  5. 百度地图API开发指南

    简介什么是百度地图API? 百度地图API是一套由JavaScript语言编写的应用程序接口,它能够帮助您在网站中构建功能丰富.交互性强的地图应用.百度地图API包含了构建地图基本功能的各种接口,提供 ...

  6. Private Bytes,Working Set,Virtual Size的区别

    http://aigo.iteye.com/blog/1930209 http://stackoverflow.com/questions/1984186/what-is-private-bytes- ...

  7. postgresql编译安装与调试(二)

    接前文postgresql编译安装与调试(一),继续说说postgresql的编译安装与调试. 上一篇已经详细说明了如何在Linux系统上编译安装postgresql,这次我们在此基础上简单讲讲如何在 ...

  8. Linux free -m 详细说明

    一.free命令 free命令由procps.*.rpm提供(在Redhat系列的OS上).free命令的所有输出值都是从/proc/meminfo中读出的. 在系统上可能有meminfo(2)这个函 ...

  9. Windows Server 2012 R2 设置 smtp 服务器

    Windows Server 2012/2012 R2:安装和配置 SMTP 服务器 安装 SMTP 服务器 以下是安装 SMTP 服务器功能的步骤: 打开“服务器管理器”:单击键盘上的 Window ...

  10. go 应用程序性能测试

    runtime/pprof 我们要加入对pprof包里的方法调用,程序才能将运行时候程序的堆内存分配状态记录到文件(也可以是写到其他地方,例如网络等)中,以便进一步的分析. 如果你的go程序只是一个应 ...