Base for all objects that can be part of the index file , namely Tree, Blob and SubModule objects
Absolute path to this index object in the file system ( as opposed to the .path field which is a path relative to the git repository ).
The returned path will be native to the system and contains ‘’ on windows.
Implements an Object which may be Blobs, Trees, Commits and Tags
This Object also serves as a constructor for instances of the correct type:
inst = Object.new(repo,id)
inst.sha # objects sha in hex
inst.size # objects uncompressed data size
inst.data # byte string containing the whole data of the object
Writes our data directly to the given output stream
Wraps a git Commit object.
This class will act lazily on some of its attributes and will query the value on demand only if it involves calling the git binary.
Count the number of commits reachable from this commit
Commit the given tree, creating a commit object.
Find all commits matching the given criteria.
Iterate _all_ parents of this commit.
Create a git stat from changes between this commit and its first parent or from all changes done if this is the very first commit.
Module containing all object based types.
Tress represent a ordered list of Blobs and other Trees. Hence it can be accessed like a list.
Tree’s will cache their contents after first retrieval to improve efficiency.
Tree as a list:
Access a specific blob using the
tree['filename'] notation.
You may as well access by index
blob = tree[0]
For documentation, see utils.Traversable.traverse
Trees are set to visist_once = False to gain more performance in the traversal
Module for general utility functions
Class wireing all calls to the contained Process instance.
Use this type to hide the underlying process to provide access only to a specified stream. The process is usually wrapped into an AutoInterrupt class to kill it if the instance goes out of scope.
Simple interface to perforam depth-first or breadth-first traversals into one direction. Subclasses only need to implement one function. Instances of the Subclass must be hashable
Parse out the actor (author or committer) info from a line like:
author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
The Git class manages communication with the Git binary.
It provides a convenient interface to calling the Git binary, such as in:
g = Git( git_dir )
g.init() # calls 'git init' program
rval = g.ls_files() # calls 'git ls-files' program
Kill/Interrupt the stored process instance once this instance goes out of scope. It is used to prevent processes piling up in case iterators stop reading. Besides all attributes are wired through to the contained process object.
The wait method was overridden to perform automatic status code checking and possibly raise.
Wait for the process and return its status code.
Clear all kinds of internal caches to release resources.
Currently persistent commands will be interrupted.
Handles executing the command on the shell and consumes and returns the returned information (stdout)
Returns:
str(output) # extended_output = False (Default)
tuple(int(status), str(stdout), str(stderr)) # extended_output = True
if ouput_stream is True, the stdout value will be your output stream:
output_stream # extended_output = False
tuple(int(status), output_stream, str(stderr))# extended_output = True
As get_object_header, but returns object data as well
Use this method to quickly examine the type and size of the object behind the given ref.
Module containing module parser implementation able to properly read and write configuration files
A Diff contains diff information between two Trees.
It contains two sides a and b of the diff, members are prefixed with “a” and “b” respectively to inidcate that.
Diffs keep information about the changed blob objects, the file mode, renames, deletions and new files.
There are a few cases where None has to be expected as member variable value:
New File:
a_mode is None
a_blob is None
Deleted File:
b_mode is None
b_blob is None
Working Tree Blobs
When comparing to working trees, the working tree blob will have a null hexsha as a corresponding object does not yet exist. The mode will be null as well. But the path will be available though. If it is listed in a diff the working tree version of the file must be different to the version in the index or tree, and hence has been modified.
Implements an Index for diffs, allowing a list of Diffs to be queried by the diff properties.
The class improves the diff handling convenience
Member of DiffIndex.change_type, namely
‘A’ for added paths
‘D’ for deleted paths
‘R’ for renamed paths
‘M’ for paths with modified data
Common interface for all object that can be diffed against another object of compatible type.
Creates diffs between two items being trees, trees and index or an index and the working tree.
Rename detection will only work if create_patch is True.
On a bare repository, ‘other’ needs to be provided as Index or as as Tree/Commit, or a git command error will occour
Module containing all exceptions thrown througout the git package,
Module containing Index implementation, allowing to perform all kinds of index manipulations such as querying and merging.
Small Brother of an index entry which can be created to describe changes done to the index in which case plenty of additional information is not requried.
As the first 4 data members match exactly to the IndexEntry type, methods expecting a BaseIndexEntry can also handle full IndexEntries even if they use numeric indices for performance reasons.
Predicate to be used by iter_blobs allowing to filter only return blobs which match the given list of directories or files.
The given paths are given relative to the repository.
Thrown if a file could not be checked out from the index as it contained changes.
The .failed_files attribute contains a list of relative paths that failed to be checked out as they contained changes that did not exist in the index.
The .failed_reasons attribute contains a string informing about the actual cause of the issue.
The .valid_files attribute contains a list of relative paths to files that were checked out successfully and hence match the version stored in the index
Allows convenient access to IndexEntry data without completely unpacking it.
Attributes usully accessed often are cached in the tuple whereas others are unpacked on demand.
See the properties for a mapping between names and tuple indices.
Uncompressed size of the blob
Implements an Index that can be manipulated using a native implementation in order to save git command function calls wherever possible.
It provides custom merging facilities allowing to merge without actually changing your index or your working tree. This way you can perform own test-merges based on the index only without having to deal with the working copy. This is useful in case of partial working trees.
Entries The index contains an entries dict whose keys are tuples of type IndexEntry to facilitate access.
Otherwise changes to it will be lost when changing the index using its methods.
Merge the given treeish revisions into a new index which is returned. The original index will remain unaltered
One, two or three Tree Objects or Commits. The result changes according to the amount of trees. If 1 Tree is given, it will just be read into a new index If 2 Trees are given, they will be merged into a new index using a
two way merge algorithm. Tree 1 is the ‘current’ tree, tree 2 is the ‘other’ one. It behaves like a fast-forward. If 3 Trees are given, a 3-way merge will be performed with the first tree being the common ancestor of tree 2 and tree 3. Tree 2 is the ‘current’ tree, tree 3 is the ‘other’ one
In the three-way merge case, –aggressive will be specified to automatically resolve more cases in a commonly correct manner. Specify trivial=True as kwarg to override that.
As the underlying git-read-tree command takes into account the current index, it will be temporarily moved out of the way to assure there are no unsuspected interferences.
Resolve the blobs given in blob iterator. This will effectively remove the index entries of the respective path at all non-null stages and add the given blob as new stage null blob.
For each path there may only be one blob, otherwise a ValueError will be raised claiming the path is already at stage 0.
Reread the contents of our index file, discarding all cached information we might have.
Write the current state to our file path or to the given one
Writes the Index in self to a corresponding Tree file into the repository object database and returns it as corresponding Tree object.
Decorator for functions that alter the index using the git command. This would invalidate our possibly existing entries dictionary which is why it must be deleted to allow it to be lazily reread later.
Module containing all ref based objects
Special case of a Symbolic Reference as it represents the repository’s HEAD reference.
Reset our HEAD to the given commit optionally synchronizing the index and working tree. The reference we refer to will be set to commit as well.
A Head is a named reference to a Commit. Every Head instance contains a name and a Commit object.
Examples:
>>> repo = Repo("/path/to/repo")
>>> head = repo.heads[0]
>>> head.name
'master'
>>> head.commit
<git.Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455">
>>> head.commit.sha
'1c09f116cbc2cb4100fb6935bb162daa4723f455'
Checkout this head by setting the HEAD to this reference, by updating the index to reflect the tree we point to and by updating the working tree to reflect the latest index.
The command will fail if changed working tree files would be overwritten.
Create a new head. repo
Repository to create the head in
Delete the given heads
Rename self to a new path
Represents a named reference to any object. Subclasses may apply restrictions though, i.e. Heads can only point to commits.
Create a new reference. repo
Repository to create the reference in
Represents a reference pointing to a remote head.
Delete the given remote references.
NOTE: The returned name is usually not qualified enough to uniquely identify a branch
Represents a special case of a reference such that this reference is symbolic. It does not point to a specific commit, but to another Head, which itself specifies a commit.
A typical example for a symbolic reference is HEAD.
Create a new symbolic reference, hence a reference pointing to another reference. repo
Repository to create the reference in
Delete the reference at the given path
Find all refs in the repository
git.SymbolicReference[], each of them is guaranteed to be a symbolic ref which is not detached.
List is lexigraphically sorted The returned objects represent actual subclasses, such as Head or TagReference
Rename self to a new path
Returns: | string with a full path name which can be used to initialize |
---|
a Reference instance, for instance by using Reference.from_path
Class representing a lightweight tag reference which either points to a commit ,a tag object or any other object. In the latter case additional information, like the signature or the tag-creator, is available.
This tag object will always point to a commit object, but may carray additional information in a tag object:
tagref = TagReference.list_items(repo)[0]
print tagref.commit.message
if tagref.tag is not None:
print tagref.tag.message
Create a new tag reference.
If not None, the message will be used in your tag object. This will also create an additional tag object that allows to obtain that information, i.e.:
tagref.tag.message
Module implementing a remote object allowing easy access to git remotes
Carries information about the results of a fetch operation of a single head:
info = remote.fetch()[0]
info.ref # Symbolic Reference or RemoteReference to the changed
# remote head or FETCH_HEAD
info.flags # additional flags to be & with enumeration members,
# i.e. info.flags & info.REJECTED
# is 0 if ref is SymbolicReference
info.note # additional notes given by git-fetch intended for the user
info.old_commit # if info.flags & info.FORCED_UPDATE|info.FAST_FORWARD,
# field is set to the previous location of ref, otherwise None
Carries information about the result of a push operation of a single head:
info = remote.push()[0]
info.flags # bitflags providing more information about the result
info.local_ref # Reference pointing to the local reference that was pushed
# It is None if the ref was deleted.
info.remote_ref_string # path to the remote reference located on the remote side
info.remote_ref # Remote Reference on the local side corresponding to
# the remote_ref_string. It can be a TagReference as well.
info.old_commit # commit at which the remote_ref was standing before we pushed
# it to local_ref.commit. Will be None if an error was indicated
info.summary # summary line providing human readable english text about the push
Provides easy read and write access to a git remote.
Everything not part of this interface is considered an option for the current remote, allowing constructs like remote.pushurl to query the pushurl.
NOTE: When querying configuration, the configuration accessor will be cached to speed up subsequent accesses.
Create a new remote to the given repository repo
Repository instance that is to receive the new remote
You can only own one writer at a time - delete it to release the configuration file and make it useable by others.
To assure consistent results, you should only query options through the writer. Once you are done writing, you are free to use the config reader once again.
Create a new remote to the given repository repo
Repository instance that is to receive the new remote
Fetch the latest changes for this remote
A “refspec” is used by fetch and push to describe the mapping between remote ref and local ref. They are combined with a colon in the format <src>:<dst>, preceded by an optional plus sign, +. For example: git fetch $URL refs/heads/master:refs/heads/origin means “grab the master branch head from the $URL and store it as my origin branch head”. And git push $URL refs/heads/master:refs/heads/to-upstream means “publish my master branch head as to-upstream branch at $URL”. See also git-push(1).
Taken from the git manual
Pull changes from the given branch, being the same as a fetch followed by a merge of branch with your local branch.
Push changes from source branch in refspec to target branch in refspec.
IterableList of RemoteReference objects. It is prefixed, allowing you to omit the remote path portion, i.e.:
remote.refs.master # yields RemoteReference('/refs/remotes/origin/master')
Rename self to the given new_name
IterableList RemoteReference objects that do not have a corresponding head in the remote reference anymore as they have been deleted on the remote side, but are still available locally.
The IterableList is prefixed, hence the ‘origin’ must be omitted. See ‘refs’ property for an example.
Fetch all changes for this remote, including new branches which will be forced in ( in case your local remote branch is not part the new remote branches ancestry anymore ).
Handler providing an interface to parse progress information emitted by git-push and git-fetch and to dispatch callbacks allowing subclasses to react to the progress.
Called whenever the progress changes
Integer allowing to be compared against Operation IDs and stage IDs.
Stage IDs are BEGIN and END. BEGIN will only be set once for each Operation ID as well as END. It may be that BEGIN and END are set at once in case only one progress message was emitted due to the speed of the operation. Between BEGIN and END, none of these flags will be set
Operation IDs are all held within the OP_MASK. Only one Operation ID will be active per call.
You may read the contents of the current line in self._cur_line
Represents a git repository and allows you to query references, gather commit information, generate diffs, create and clone repositories query the log.
The following attributes are worth using:
‘working_dir’ is the working directory of the git command, wich is the working tree directory if available or the .git directory in case of bare repositories
‘working_tree_dir’ is the working tree directory, but will raise AssertionError if we are a bare repository.
‘git_dir’ is the .git repository directoy, which is always set.
The name of the currently active branch.
Archive the tree at the given revision. ostream
file compatible stream object to which the archive will be written
Examples:
>>> repo.archive(open("archive"))
<String containing tar.gz archive>
The blame information for the given file at the given revision.
A list of Head objects representing the branch heads in this repo
Create a clone from this repository.
The Commit object for the specified revision
GitConfigParser allowing to read the full git configuration, but not to write it
The configuration will include values from the system, user and repository configuration files.
NOTE: On windows, system configuration cannot currently be read as the path is unknown, instead the global path will be used.
Create a new head within the repository.
For more documentation, please see the Head.create method.
Create a new remote.
For more information, please see the documentation of the Remote.create methods
Create a new tag reference.
For more documentation, please see the TagReference.create method.
Delete the given heads
A list of Head objects representing the branch heads in this repo
Initialize a git repository at the given path if specified
Examples:
git.Repo.init('/var/git/myrepo.git',bare=True)
A list of Commit objects representing the history of a given ref/commit
revision specifier, see git-rev-parse for viable options. If None, the active branch will be used.
Note: to receive only commits between two named revisions, use the “revA..revB” revision specifier
Note: Takes all arguments known to iter_commits method
A list of Reference objects representing tags, heads and remote references.
A list of Reference objects representing tags, heads and remote references.
A list of Remote objects allowing to access and manipulate remotes
A list of Tag objects that are available in this repo
The Tree object for the given treeish revision
Examples:
repo.tree(repo.heads[0])
list(str,...)
Files currently untracked as they have not been staged yet. Paths are relative to the current working directory of the git command.
Represents stat information as presented by git at the end of a merge. It is created from the output of a diff operation.
Example:
c = Commit( sha1 )
s = c.stats
s.total # full-stat-dict
s.files # dict( filepath : stat-dict )
stat-dict
A dictionary with the following keys and values:
deletions = number of deleted lines as int
insertions = number of inserted lines as int
lines = total number of lines changed as int, or deletions + insertions
full-stat-dict
In addition to the items in the stat-dict, it features additional information:
files = number of changed files as int
This class facilitates a safe write operation to a file on disk such that we:
- lock the original file
- write to a temporary file
- rename temporary file back to the original one on close
- unlock the original file
This type handles error correctly in that it will assure a consistent state on destruction
Defines an interface for iterable items which is to assure a uniform way to retrieve and iterate items within the git repository
For more information about the arguments, see list_items Return:
iterator yielding Items
Find all items of this type - subclasses can specify args and kwargs differently. If no args are given, subclasses are obliged to return all items if no additional arguments arg given.
Note: Favor the iter_items method as it will
List of iterable objects allowing to query an object by id or by named index:
heads = repo.heads
heads.master
heads['master']
heads[0]
It requires an id_attribute name to be set which will be queried from its contained items to have a means for comparison.
A prefix can be specified which is to be used in case the id returned by the items always contains a prefix that does not matter to the user, so it can be left out.
Provides methods to obtain, check for, and release a file based lock which should be used to handle concurrent access to the same file.
As we are a utility class to be derived from, we only use protected methods.
Locks will automatically be released on destruction
Wrapper around a file-like object that remembers the SHA1 of the data written to it. It will write a sha when the stream is closed or if the asked for explicitly usign write_sha.
A python2.4 workaround for the sha/hashlib module fiasco