Gittle is a high-level, pure Python git repository. Built on top of the Dulwich, providing most of the low-level mechanisms
Gittle is a high-level, pure Python git repository. Built on top of the Dulwich, provides most of the low-level mechanisms.
Install it
pip install gittle
Examples:clone a repository?
| 123456 |
fromgittle 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 sections for more information):
?
| 12 |
auth =GittleAuth(pkey=key)Gittle.clone(repo_url, repo_path, auth=auth) |
Or Clone Bare Repository (no working directory):
Gittle. Clone(repo_urlrepo_pathbare=True
Init Repository from a path
Gittle. Init(path
Get repository information?
| 1234567891011 |
# 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‘) |
A Commit?
| 12345678 |
# Stage single filerepo.stage(‘file.txt‘) # Stage multiple filesrepo.stage([‘other1.txt‘, ‘other2.txt‘]) # Do the commitrepo.commit(name="Samy Pesse", email="[email protected]", message="This is a commit") |
Pull?
| 12345678 |
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?
| 12345678 |
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?
| 123456 |
# 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?
| 1234567891011121314151617 |
# 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?
| 12 |
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.
Count Number of commits
Repo.
Get Information for commits
List commits:
Repo. Commit_info(start=0End=
With a given commit:
Diff with another commit:
?
| 12 |
old_commit =repo.get_previous_commit(commit, n=1)printrepo.diff(commit, old_commit) |
Explore Commit files using:
?
| 12345678910 |
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, |
Create a GIT server?
| 1234567 |
from gittle import gitserver # Read only gitserver ( '/' ). Serve_forever () # read/write gitserver ( '/' ' localhost ' = ' RW ' |
Python's advanced git library gittle