Implements an Object which may be Blobs, Trees, Commits and Tags
Returns: | True if the objects have the same SHA1 |
---|
Returns: | Hash of our id allowing objects to be used in dicts and sets |
---|
Initialize an object by identifying it by its binary sha. All keyword arguments will be set on demand if None.
Parameters: |
|
---|
Returns: | True if the objects do not have the same SHA1 |
---|
Returns: | string with pythonic representation of our object |
---|
Returns: | string of our SHA1 as understood by all git commands |
---|
Returns: | File Object compatible stream to the uncompressed raw data of the object |
---|---|
Note: | returned streams must be read in order |
Returns: | 40 byte hex version of our 20 byte binary sha |
---|
Returns: | New Object instance of a type appropriate to the object type behind id. The id of the newly created object will be a binsha even though the input id may have been a Reference or Rev-Spec |
---|---|
Parameters: | id – reference, rev-spec, or hexsha |
Note: | This cannot be a __new__ method as it would always call __init__ with the input id which is not necessarily a binsha. |
Returns: | new object instance of a type appropriate to represent the given binary sha1 |
---|---|
Parameters: | sha1 – 20 byte binary sha1 |
Writes our data directly to the given output stream :param ostream: File object compatible stream object. :return: self
Base for all objects that can be part of the index file , namely Tree, Blob and SubModule objects
Returns: | Hash of our path as index items are uniquely identifyable by path, not by their data ! |
---|
Initialize a newly instanced IndexObject
Parameters: |
|
---|---|
Note: | Path may not be set of the index object has been created directly as it cannot be retrieved without knowing the parent tree. |
Returns: | 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. |
---|
Returns: | Name portion of the path, effectively being the basename |
---|
A Blob encapsulates a git blob object
Returns: | String describing the mime type of this file (based on the filename) |
---|---|
Note: | Defaults to ‘text/plain’ in case the actual file type is unknown. |
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.
Instantiate a new Commit. All keyword arguments taking None as default will be implicitly set on first query.
Parameters: |
|
---|---|
Returns: | git.Commit |
Note: | Timezone information is in the same format and in the same sign as what time.altzone returns. The sign is inverted compared to git’s UTC timezone. |
Count the number of commits reachable from this commit
Parameters: |
|
---|---|
Returns: | int defining the number of reachable commits |
Commit the given tree, creating a commit object.
Parameters: |
|
---|---|
Returns: | Commit object representing the new commit |
Note: | Additional information about the committer and Author are taken from the environment or from the git configuration, see git-commit-tree for more information |
Find all commits matching the given criteria.
Parameters: |
|
---|---|
Returns: | iterator yielding Commit items |
Iterate _all_ parents of this commit.
Parameters: |
|
---|---|
Returns: | Iterator yielding Commit objects which are parents of self |
Returns: | String describing the commits hex sha based on the closest Reference. Mostly useful for UI purposes |
---|
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.
Returns: | git.Stats |
---|
Returns: | First line of the commit message |
---|
Module containing all object based types.
Non-Lightweight tag carrying additional information about an object we are pointing to.
Initialize a tag object with additional data
Parameters: |
|
---|
A utility class providing methods to alter the underlying cache in a list-like fashion.
Once all adjustments are complete, the _cache, which really is a reference to the cache of a tree, will be sorted. Assuring it will be in a serializable state
Deletes an item with the given name if it exists
Add the given item to the tree. If an item with the given name already exists, nothing will be done, but a ValueError will be raised if the sha and mode of the existing item do not match the one you add, unless force is True
Parameters: |
|
---|---|
Returns: | self |
Add the given item to the tree, its correctness is assumed, which puts the caller into responsibility to assure the input is correct. For more information on the parameters, see add :param binsha: 20 byte binary sha
Call this method once you are done modifying the tree information. It may be called several times, but be aware that each call will cause a sort operation :return self:
Tree objects represent an ordered list of Blobs and other Trees.
Tree as a list:
Access a specific blob using the
tree['filename'] notation.
You may as well access by index
blob = tree[0]
For PY2 only
For PY3 only
Returns: | list(Blob, ...) list of blobs directly below this tree |
---|
Returns: | An object allowing to modify the internal cache. This can be used to change the tree’s contents. When done, make sure you call set_done on the tree modifier, or serialization behaviour will be incorrect. See the TreeModifier for more information on how to alter the cache |
---|
Find the named object in this tree’s contents :return: git.Blob or git.Tree or git.Submodule
Raises KeyError: | |
---|---|
if given file or tree does not exist in tree |
For documentation, see util.Traversable.traverse Trees are set to visit_once = False to gain more performance in the traversal
Returns: | list(Tree, ...) list of trees directly below this tree |
---|
Module with functions which are supposed to be as fast as possible
Write the give list of entries into a stream using its write method :param entries: sorted list of tuples with (binsha, mode, name) :param write: write method which takes a data string
Reads the binary representation of a tree and returns tuples of Tree items :param data: data block with tree data (as bytes) :return: list(tuple(binsha, mode, tree_relative_path), ...)
Returns: | list with entries according to the given binary tree-shas. The result is encoded in a list of n tuple|None per blob/commit, (n == len(tree_shas)), where * [0] == 20 byte sha * [1] == mode as int * [2] == path relative to working tree root The entry tuple is None if the respective blob/commit did not exist in the given tree. |
---|---|
Parameters: |
|
Note: | The ordering of the returned items will be partially lost |
Returns: | list of entries of the tree pointed to by the binary tree_sha. An entry has the following format: * [0] 20 byte sha * [1] mode as int * [2] path relative to the repository |
---|---|
Parameters: | path_prefix – prefix to prepend to the front of all returned paths |
Implements access to a git submodule. They are special in that their sha represents a commit in the submodule’s repository which is to be checked out at the path of this instance. The submodule type does not have a string type associated with it, as it exists solely as a marker in the tree and index.
All methods work in bare and non-bare repositories.
Compare with another submodule
Hash this instance using its logical id, not the sha
Initialize this instance with its attributes. We only document the ones that differ from IndexObject
Parameters: |
|
---|
Compare with another submodule for inequality
list of weak references to the object (if defined)
Add a new submodule to the given repository. This will alter the index as well as the .gitmodules file, but will not create a new commit. If the submodule already exists, no matter if the configuration differs from the one provided, the existing submodule will be returned.
Parameters: |
|
---|---|
Returns: | The newly created submodule instance |
Note: | works atomically, such that no change will be done if the repository update fails for instance |
Returns: | The branch instance that we are to checkout |
---|---|
Raises InvalidGitRepositoryError: | |
if our module is not yet checked out |
Returns: | the name of the branch, which is the shortest possible branch name |
---|
Returns: | full (relative) path as string to the branch we would checkout from the remote and track |
---|
Returns: | IterableList(Submodule, ...) an iterable list of submodules instances which are children of this submodule or 0 if the submodule is not checked out |
---|
Returns: | ConfigReader instance which allows you to qurey the configuration values of this submodule, as provided by the .gitmodules file |
---|---|
Note: | The config reader will actually read the data directly from the repository and thus does not need nor care about your working tree. |
Note: | Should be cached by the caller and only kept as long as needed |
Raises IOError: | If the .gitmodules file/blob could not be read |
Returns: | a config writer instance allowing you to read and write the data |
---|
belonging to this submodule into the .gitmodules file.
Parameters: |
|
---|---|
Note: | the parameters allow for a more efficient writing of the index, as you can pass in a modified index on your own, prevent automatic writing, and write yourself once the whole operation is complete |
Raises: |
|
Returns: | True if the submodule exists, False otherwise. Please note that a submodule may exist (in the .gitmodules file) even though its module doesn’t exist on disk |
---|
Returns: | iterator yielding Submodule instances available in the given repository |
---|
Returns: | Repo instance initialized from the repository at our submodule path |
---|---|
Raises InvalidGitRepositoryError: | |
if a repository was not available. This could also mean that it was not yet initialized |
Returns: | True if our module exists and is a valid git repository. See module() method |
---|
Move the submodule to a another module path. This involves physically moving the repository at our current path, changing the configuration, as well as adjusting our index entry accordingly.
Parameters: |
|
---|---|
Returns: | self |
Raises ValueError: | |
if the module path existed and was not empty, or was a file |
|
Note: | Currently the method is not atomic, and it could leave the repository in an inconsistent state if a sub-step fails for some reason |
Returns: | The name of this submodule. It is used to identify it within the .gitmodules file. |
---|---|
Note: | by default, the name is the path at which to find the submodule, but in git-python it should be a unique identifier similar to the identifiers used for remotes, which allows to change the path of the submodule easily |
Returns: | Commit instance with the tree containing the .gitmodules file |
---|---|
Note: | will always point to the current head’s commit if it was not set explicitly |
Remove this submodule from the repository. This will remove our entry from the .gitmodules file and the entry in the .git/config file.
Parameters: |
|
---|---|
Returns: | self |
Note: | doesn’t work in bare repositories |
Note: | doesn’t work atomically, as failure to remove any part of the submodule will leave an inconsistent state |
Raises: |
|
Rename this submodule :note: This method takes care of renaming the submodule in various places, such as
- $parent_git_dir/config
- $working_tree_dir/.gitmodules
- (git >=v1.8.0: move submodule repository to new name)
As .gitmodules will be changed, you would need to make a commit afterwards. The changed .gitmodules file will already be added to the index
Returns: | this submodule instance |
---|
Set this instance to use the given commit whose tree is supposed to contain the .gitmodules blob.
Parameters: |
|
---|---|
Raises: |
|
Returns: | self |
Update the repository of this submodule to point to the checkout we point at with the binsha of this instance.
Parameters: |
|
---|---|
Note: | does nothing in bare repositories |
Note: | method is definitely not atomic if recurisve is True |
Returns: | self |
Returns: | The url to the repository which our module-repository refers to |
---|
A (virtual) Root of all submodules in the given repository. It can be used to more easily traverse all submodules of the master repository
Returns: | the actual repository containing the submodules |
---|
Update the submodules of this repository to the current HEAD commit. This method behaves smartly by determining changes of the path of a submodules repository, next to changes to the to-be-checked-out commit or the branch to be checked out. This works if the submodules ID does not change. Additionally it will detect addition and removal of submodules, which will be handled gracefully.
Parameters: |
|
---|---|
Returns: | self |
Returns: | section title used in .gitmodules configuration file |
---|
Returns: | name of the submodule as parsed from the section name |
---|
Returns: | New branch/head instance |
---|
Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError
Catches calls to _write, and updates the .gitmodules blob in the index with the new data, if we have written into a stream. Otherwise it will add the local file to the index to make it correspond with the working tree. Additionally, the cache must be cleared
Please note that no mutating method will work in bare mode
Flush changes in our configuration file to the index
Set this instance’s submodule. It must be called before the first write operation begins
Module for general utility functions
Returns: | type suitable to handle the given object type name. Use the type to create new instances. |
---|---|
Parameters: | object_type_name – Member of TYPES |
Raises ValueError: | |
In case object_type_name is unknown |
Parse the given date as one of the following
Git internal format: timestamp offset
RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200.
- ISO 8601 2005-04-07T22:13:13
The T can be a space as well
Returns: | Tuple(int(timestamp_UTC), int(offset)), both in seconds since epoch |
---|---|
Raises ValueError: | |
If the format could not be understood | |
Note: | Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. |
Parse out the actor (author or committer) info from a line like:
author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
Returns: | [Actor, int_seconds_since_epoch, int_timezone_offset] |
---|
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 perform depth-first or breadth-first traversals into one direction. Subclasses only need to implement one function. Instances of the Subclass must be hashable
Returns: | IterableList with the results of the traversal as produced by traverse() |
---|
Returns: | iterator yielding of items found when traversing self |
---|---|
Parameters: |
|
As above, but inverses the operation, returning a string that can be used in commit objects
we convert utctz to the timezone in seconds, it is the format time.altzone returns. Git stores it as UTC timezone which has the opposite sign as well, which explains the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200
Raises ValueError: | |
---|---|
if offset is incorrect | |
Returns: | offset |
Actors hold information about a person acting on the repository. They can be committers and authors or anything with a name and an email as mentioned in the git log entries.
Same as committer(), but defines the main author. It may be specified in the environment, but defaults to the committer
Returns: | Actor instance corresponding to the configured committer. It behaves similar to the git implementation, such that the environment will override configuration values of config_reader. If no value is set at all, it will be generated |
---|---|
Parameters: | config_reader – ConfigReader to use to retrieve the values from in case they are not set in the environment |
list of weak references to the object (if defined)
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.
You may read the entries dict or manipulate it using IndexEntry instance, i.e.:
index.entries[index.entry_key(index_entry_instance)] = index_entry_instance
Make sure you use index.write() once you are done manipulating the index directly before operating on it using the git command
Initialize this Index instance, optionally from the given file_path. If no file_path is given, we will be created from the current index file.
If a stream is not given, the stream will be initialized from the current repository’s index on demand.
Add files from the working tree, specific blobs or BaseIndexEntries to the index.
Parameters: |
|
---|---|
Returns: | List(BaseIndexEntries) representing the entries just actually added. |
Raises OSError: | if a supplied Path did not exist. Please note that BaseIndexEntry Objects that do not have a null sha will be added even if their paths do not exist. |
Checkout the given paths or all files from the version known to the index into the working tree.
Note: | Be sure you have written pending changes using the write method in case you have altered the enties dictionary directly |
---|---|
Parameters: |
|
Returns: | iterable yielding paths to files which have been checked out and are guaranteed to match the version stored in the index |
Raises CheckoutError: | |
If at least one file failed to be checked out. This is a summary, hence it will checkout as many files as it can anyway. If one of files or directories do not exist in the index ( as opposed to the original git command who ignores them ). Raise GitCommandError if error lines could not be parsed - this truly is an exceptional state |
Note
The checkout is limited to checking out the files in the index. Files which are not in the index anymore and exist in the working tree will not be deleted. This behaviour is fundamentally different to head.checkout, i.e. if you want git-checkout like behaviour, use head.checkout instead of index.checkout.
Commit the current default index file, creating a commit object. For more information on the arguments, see tree.commit.
Note: | If you have manually altered the .entries member of this instance, don’t forget to write() your changes to disk beforehand. Passing skip_hooks=True is the equivalent of using -n or –no-verify on the command line. |
---|---|
Returns: | Commit object representing the new commit |
Diff this index against the working copy or a Tree or Commit object
For a documentation of the parameters and return values, see Diffable.diff
Note: | Will only work with indices that represent the default git index as they have not been initialized with a stream. |
---|
Merge the given treeish revisions into a new index which is returned. The original index will remain unaltered
Parameters: |
|
---|---|
Returns: | New IndexFile instance. It will point to a temporary index location which does not exist anymore. If you intend to write such a merged Index, supply an alternate file_path to its ‘write’ method. |
Note: | 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. |
Returns: | Iterator yielding tuples of Blob objects and stages, tuple(stage, Blob) |
---|---|
Parameters: | predicate – Function(t) returning True if tuple(stage, Blob) should be yielded by the iterator. A default filter, the BlobFilter, allows you to yield blobs only if they match a given list of paths. |
Merge the given rhs treeish into the current index, possibly taking a common base treeish into account.
As opposed to the from_tree_ method, this allows you to use an already existing tree as the left side of the merge
Parameters: |
|
---|---|
Returns: | self ( containing the merge and possibly unmerged entries in case of conflicts ) |
Raises GitCommandError: | |
If there is a merge conflict. The error will be raised at the first conflicting path. If you want to have proper merge resolution to be done by yourself, you have to commit the changed index ( or make a valid tree from it ) and retry with a three-way index.from_tree call. |
Rename/move the items, whereas the last item is considered the destination of the move operation. If the destination is a file, the first item ( of two ) must be a file as well. If the destination is a directory, it may be preceded by one or more directories or files.
The working tree will be affected in non-bare repositories.
Parma items: | Multiple types of items are supported, please see the ‘remove’ method for reference. |
---|---|
Parameters: |
|
Raises ValueError: | |
---|---|
If only one item was given GitCommandError: If git could not handle your request |
Merge the given treeish revisions into a new index which is returned. This method behaves like git-read-tree –aggressive when doing the merge.
Parameters: |
|
---|---|
Returns: | New IndexFile instance. Its path will be undefined. If you intend to write such a merged Index, supply an alternate file_path to its ‘write’ method. |
Returns: | Path to the index file we are representing |
---|
Remove the given items from the index and optionally from the working tree as well.
Parameters: |
|
---|---|
Returns: | List(path_string, ...) list of repository relative paths that have been removed effectively. This is interesting to know in case you have provided a directory or globs. Paths are relative to the repository. |
Reset the index to reflect the tree at the given commit. This will not adjust our HEAD reference as opposed to HEAD.reset by default.
Parameters: |
|
---|
Note
IndexFile.reset, as opposed to HEAD.reset, will not delete anyfiles in order to maintain a consistent working tree. Instead, it will just checkout the files according to their state in the index. If you want git-reset like behaviour, use HEAD.reset instead.
Returns: | self |
---|
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.
Raises ValueError: | |
---|---|
if one of the blobs already existed at stage 0 | |
Returns: | self |
Note: | You will have to write the index manually once you are done, i.e. index.resolve_blobs(blobs).write() |
Returns: | Iterator yielding dict(path : list( tuple( stage, Blob, ...))), being a dictionary associating a path in the index with a list containing sorted stage/blob pairs |
---|---|
Note: | Blobs that have been removed in one side simply do not exist in the given stage. I.e. a file removed on the ‘other’ branch whose entries are at stage 3 will not have a stage 3 entry. |
Reread the contents of our index file, discarding all cached information we might have.
Note: | This is a possibly dangerious operations as it will discard your changes to index.entries |
---|---|
Returns: | self |
Write the current state to our file path or to the given one
Parameters: |
|
---|---|
Returns: | self |
Writes this index to a corresponding Tree object into the repository’s object database and return it.
Returns: | Tree object representing this index |
---|---|
Note: | The tree will be written even if one or more objects the tree refers to does not yet exist in the object database. This could happen if you added Entries to the index directly. |
Raises: |
|
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
list of weak references to the object (if defined)
Write the cache represented by entries to a stream
Parameters: |
|
---|
Read a cache file from the given stream :return: tuple(version, entries_dict, extension_data, content_sha) * version is the integer version number * entries dict is a dictionary which maps IndexEntry instances to a path at a stage * extension_data is ‘’ or 4 bytes of type + 4 bytes of size + size bytes * content_sha is a 20 byte sha on all cache file contents
Create a tree from the given sorted list of entries and put the respective trees into the given object database
Parameters: |
|
---|---|
Returns: | tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of tree entries being a tuple of hexsha, mode, name |
Returns: | Key suitable to be used for the index.entries dictionary |
---|---|
Parameters: | entry – One instance of type BaseIndexEntry or the path and the stage |
Convert the given mode from a stat call to the corresponding index mode and return it
Run the commit hook of the given name. Silently ignores hooks that do not exist. :param name: name of hook, like ‘pre-commit’ :param index: IndexFile instance :raises HookExecutionError:
Returns: | path to the given named hook in the given git repository directory |
---|
Module with additional types used by the index
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.
Parameters: | paths – tuple or list of paths which are either pointing to directories or to files relative to the current repository |
---|
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.
binary sha of the blob
Returns: | flags stored with this entry |
---|
Returns: | Fully equipped BaseIndexEntry at the given stage |
---|
hex version of our sha
File Mode, compatible to stat module constants
Returns: | our path relative to the repository working tree root |
---|
Stage of the entry, either:
- 0 = default stage
- 1 = stage before a merge or common ancestor entry in case of a 3 way merge
- 2 = stage of entries from the ‘left’ side of the merge
- 3 = stage of entries from the right side of the merge
Note: | For more information, see http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html |
---|
Returns: | Blob using the information of this index entry |
---|
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.
Returns: | Tuple(int_time_seconds_since_epoch, int_nano_seconds) of the file’s creation time |
---|
Device ID
Returns: | Minimal entry as created from the given BaseIndexEntry instance. Missing values will be set to null-like values |
---|---|
Parameters: | base – Instance of type BaseIndexEntry |
Returns: | Minimal entry resembling the given blob object |
---|
Group ID
Inode ID
See ctime property, but returns modification time
Returns: | Uncompressed size of the blob |
---|
User ID
Module containing index utilities
Utility class moving a file to a temporary location within the same directory and moving it back on to where on object deletion.
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.
Note: | This decorator will not be required once all functions are implemented natively which in fact is possible, but probably not feasible performance wise. |
---|
Decorator assuring the wrapped method may only run if we are the default repository index. This is as we rely on git commands that operate on that index only.
Decorator which changes the current working dir to the one of the git repository in order to assure relative paths are handled correctly
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.
Parameters: | stderr – Previously read value of stderr, in case stderr is already closed. |
---|---|
Warn: | may deadlock if output or error pipes are used and not handled separately. |
Raises GitCommandError: | |
if the return status is not 0 |
Object representing a sized read-only stream returning the contents of an object. It behaves like a stream, but counts the data read and simulates an empty stream once our sized content region is empty. If not all data is read to the end of the objects’s lifetime, we read the rest to assure the underlying stream continues to work
Specify command line options to the git executable for a subcommand call
Parameters: | kwargs – is a dict of keyword arguments. these arguments are passed as in _call_process but will be passed to the git command rather than the subcommand. |
---|
A convenience method as it allows to call the command as if it was an object. :return: Callable object that will execute call _call_process with your arguments.
Initialize this instance with:
Parameters: | working_dir – Git directory we should work in. If None, we always work in the current directory as returned by os.getcwd(). It is meant to be the working tree directory if available, or the .git directory in case of bare repositories. |
---|
Clear all kinds of internal caches to release resources.
Currently persistent commands will be interrupted.
Returns: | self |
---|
A context manager around the above update_environment method to restore the environment back to its previous state after operation.
Examples:
with self.custom_environment(GIT_SSH='/bin/ssh_wrapper'):
repo.remotes.origin.fetch()
Parameters: | kwargs – see update_environment |
---|
Handles executing the command on the shell and consumes and returns the returned information (stdout)
Parameters: |
|
---|---|
Returns: |
if ouput_stream is True, the stdout value will be your output stream: * output_stream if extended_output = False * tuple(int(status), output_stream, str(stderr)) if extended_output = True Note git is executed with LC_MESSAGES=”C” to ensure consistent output regardless of system language. |
Raises GitCommandError: | |
Note: | If you add additional keyword arguments to the signature of this method, you must update the execute_kwargs tuple housed in this module. |
As get_object_header, but returns object data as well :return: (hexsha, type_string, size_as_int,data_string) :note: not threadsafe
Use this method to quickly examine the type and size of the object behind the given ref.
Note: | The method will only suffer from the costs of command invocation once and reuses the command in subsequent calls. |
---|---|
Returns: | (hexsha, type_string, size_as_int) |
Specify command line options to the git executable for subsequent subcommand calls
Parameters: | kwargs – is a dict of keyword arguments. these arguments are passed as in _call_process but will be passed to the git command rather than the subcommand. |
---|
As get_object_header, but returns the data as a stream
Returns: | (hexsha, type_string, size_as_int, stream) |
---|---|
Note: | This method is not threadsafe, you need one independent Command instance per thread to be safe ! |
Transforms Python style kwargs into git command line options.
Set environment variables for future git invocations. Return all changed values in a format that can be passed back into this function to revert the changes:
Examples:
old_env = self.update_environment(PWD='/tmp')
self.update_environment(**old_env)
Parameters: | kwargs – environment variables to use for git processes |
---|---|
Returns: | dict that maps environment variables to their old values |
Returns: | tuple(int, int, int, int) tuple with integers representing the major, minor and additional version numbers as parsed from git version. This value is generated on demand and is cached |
---|
Returns: | Git directory we are working on |
---|
Module containing module parser implementation able to properly read and write configuration files
alias of write
Constrains a ConfigParser to only option commands which are constrained to always use the section we have been initialized with.
It supports all ConfigParser methods that operate on an option.
Note: | If used as a context manager, will release the wrapped ConfigParser. |
---|
return: Configparser instance we constrain
Equivalent to GitConfigParser.release(), which is called on our underlying parser instance
Common interface for all object that can be diffed against another object of compatible type.
Note: | Subclasses require a repo member as it is the case for Object instances, for practical reasons we do not derive from Object. |
---|
list of weak references to the object (if defined)
Creates diffs between two items being trees, trees and index or an index and the working tree. It will detect renames automatically.
Parameters: |
|
---|---|
Returns: | git.DiffIndex |
Note: | On a bare repository, ‘other’ needs to be provided as Index or as as Tree/Commit, or a git command error will occur |
Implements an Index for diffs, allowing a list of Diffs to be queried by the diff properties.
The class improves the diff handling convenience
list of weak references to the object (if defined)
Returns: | iterator yielding Diff instances that match the given change_type |
---|---|
Parameters: | change_type – Member of DiffIndex.change_type, namely:
|
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
a_path is None
Deleted File:
b_mode is None
b_blob is None
b_path 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.
Returns: | True if the blob of our diff has been renamed |
---|---|
Note: | This property is deprecated, please use renamed_file instead. |
Returns: | True if the blob of our diff has been renamed |
---|---|
Note: | This property is deprecated, please use renamed_file instead. |
Module containing all exceptions thrown throughout the git package,
Base for all errors related to the git index, which is called cache internally
list of weak references to the object (if defined)
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
list of weak references to the object (if defined)
Base class for exceptions thrown at every stage of Popen() execution.
Parameters: | command – A non-empty list of argv comprising the command-line. |
---|
list of weak references to the object (if defined)
Thrown if execution of the git command fails with non-zero status code.
Thrown if we cannot find the git executable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable
Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned via standard output
Thrown if the given repository appears to have an invalid format.
list of weak references to the object (if defined)
Thrown if a path could not be access by the system.
list of weak references to the object (if defined)
Thrown whenever an operation on a repository fails as it has uncommited changes that would be overwritten
list of weak references to the object (if defined)
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.
Query or set commits directly
Create a new symbolic reference, hence a reference pointing to another reference.
Parameters: |
|
---|---|
Returns: | Newly created symbolic Reference |
Raises OSError: | If a (Symbolic)Reference with the same name but different contents already exists. |
Note: | This does not alter the current HEAD, index or Working Tree |
Delete the reference at the given path
Parameters: |
|
---|
Returns: | hexsha stored in the reference at the given ref_path, recursively dereferencing all intermediate references as required |
---|---|
Parameters: | repo – the repository containing the reference at ref_path |
Parameters: | path – full .git-directory-relative path name to the Reference to instantiate |
---|---|
Note: | use to_full_path() if you only have a partial path of a known Reference Type |
Returns: | Instance of type Reference, Head, or Tag depending on the given path |
Returns: | True if we are a detached reference, hence we point to a specific commit instead to another reference |
---|
Returns: | True if this symbolic reference points to a remote branch |
---|
Returns: | True if the reference is valid, hence it can be read and points to a valid object or reference. |
---|
Find all refs in the repository
Parameters: |
|
---|---|
Returns: | git.SymbolicReference[], each of them is guaranteed to be a symbolic ref which is not detached and pointing to a valid ref List is lexicographically sorted The returned objects represent actual subclasses, such as Head or TagReference |
Returns: | RefLog for this reference. Its last entry reflects the latest change applied to this reference |
---|
Note
As the log is parsed every time, its recommended to cache it for use instead of calling this method repeatedly. It should be considered read-only.
Append a logentry to the logfile of this ref
Parameters: |
|
---|---|
Returns: | added RefLogEntry instance |
Returns: | RefLogEntry at the given index |
---|---|
Parameters: | index – python list compatible positive or negative index |
Note
This method must read part of the reflog during execution, hence it should be used sparringly, or only if you need just one index. In that case, it will be faster than the log() method
Returns: | In case of symbolic references, the shortest assumable name is the path itself. |
---|
Return the object our ref currently refers to
Returns the Reference we point to
Returns the Reference we point to
Rename self to a new path
Parameters: |
|
---|---|
Returns: | self |
Raises OSError: | In case a file at path but a different contents already exists |
As set_object, but restricts the type of object to be a Commit
Raises ValueError: | |
---|---|
If commit is not a Commit object or doesn’t point to a commit | |
Returns: | self |
Set the object we point to, possibly dereference our symbolic reference first. If the reference does not exist, it will be created
Parameters: |
|
---|---|
Note: | plain SymbolicReferences may not actually point to objects by convention |
Returns: | self |
Set ourselves to the given ref. It will stay a symbol if the ref is a Reference. Otherwise an Object, given as Object instance or refspec, is assumed and if valid, will be set which effectively detaches the refererence if it was a purely symbolic one.
Parameters: |
|
---|---|
Returns: | self |
Note: | This symbolic reference will not be dereferenced. For that, see set_object(...) |
Returns: | string with a full repository-relative path which can be used to initialize a Reference instance, for instance by using Reference.from_path |
---|
Represents a named reference to any object. Subclasses may apply restrictions though, i.e. Heads can only point to commits.
Initialize this instance :param repo: Our parent repository
Parameters: |
|
---|
Equivalent to SymbolicReference.iter_items, but will return non-detached references as well.
Returns: | (shortest) Name of this reference - it may contain path components |
---|
Special version which checks if the head-log needs an update as well :return: self
Special case of a Symbolic Reference as it represents the repository’s HEAD reference.
Returns: | SymbolicReference pointing at the ORIG_HEAD, which is maintained to contain the previous value of HEAD |
---|
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.
Parameters: |
|
---|---|
Returns: | self |
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.hexsha
'1c09f116cbc2cb4100fb6935bb162daa4723f455'
list of weak references to the object (if defined)
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.
Parameters: |
|
---|---|
Returns: | The active branch after the checkout operation, usually self unless a new branch has been created. If there is no active branch, as the HEAD is now detached, the HEAD reference will be returned instead. |
Note: | By default it is only allowed to checkout heads - everything else will leave the HEAD detached which is allowed and possible, but remains a special state that some tools might not be able to handle. |
Returns: | A configuration parser instance constrained to only read this instance’s values |
---|
Returns: | A configuration writer instance with read-and write access to options of this head |
---|
Delete the given heads
Parameters: | force – If True, the heads will be deleted even if they are not yet merged into the main development stream. Default False |
---|
Rename self to a new path
Parameters: |
|
---|---|
Returns: | self |
Note: | respects the ref log as git commands are used |
Parameters: | remote_reference – The remote reference to track or None to untrack any references |
---|---|
Returns: | self |
Returns: | The remote_reference we are tracking, or None if we are not a tracking branch |
---|
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 carry 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)
Returns: | Commit object the tag ref points to |
---|
Create a new tag reference.
Parameters: |
|
---|---|
Returns: | A new TagReference |
Delete the given existing tag or tags
Returns: | The object our ref currently refers to. Refs can be cached, they will always point to the actual object as it gets re-created on each query |
---|
Returns: | Tag object this tag ref points to or None in case we are a light weight tag |
---|
alias of TagReference
Represents a reference pointing to a remote head.
Used to disable this method
Delete the given remote references
Note: | kwargs are given for comparability with the base class method as we should not narrow the signature. |
---|
Iterate remote references, and if given, constrain them to the given remote
A reflog contains reflog entries, each of which defines a certain state of the head in question. Custom query methods allow to retrieve log entries by date or by other criteria.
Reflog entries are orded, the first added entry is first in the list, the last entry, i.e. the last change of the head or reference, is last in the list.
Initialize this instance with an optional filepath, from which we will initialize our data. The path is also used to write changes back using the write() method
Append a new log entry to the revlog at filepath.
Parameters: |
|
---|---|
Returns: | RefLogEntry objects which was appended to the log |
Note: | As we are append-only, concurrent access is not a problem as we do not interfere with readers. |
Returns: | RefLogEntry at the given index |
---|---|
Parameters: |
|
Raises IndexError: | |
If the entry didn’t exist |
Note
This method is faster as it only parses the entry at index, skipping all other lines. Nonetheless, the whole file has to be read if the index is negative
Returns: | a new RefLog instance containing all entries from the reflog at the given filepath |
---|---|
Parameters: | filepath – path to reflog |
Raises ValueError: | |
If the file could not be read or was corrupted in some way |
Returns: | Iterator yielding RefLogEntry instances, one for each line read sfrom the given stream. |
---|---|
Parameters: | stream – file-like object containing the revlog in its native format or basestring instance pointing to a file to read |
Returns: | string to absolute path at which the reflog of the given ref instance would be found. The path is not guaranteed to point to a valid file though. |
---|---|
Parameters: | ref – SymbolicReference instance |
Write the contents of the reflog instance to a file at the given filepath. :param filepath: path to file, parent directories are assumed to exist
Write this instance’s data to the file we are originating from :return: self
Named tuple allowing easy access to the revlog data fields
Representation of ourselves in git reflog format
Actor instance, providing access
Returns: | a string suitable to be placed in a reflog file |
---|
Returns: | New RefLogEntry instance from the given revlog line. |
---|---|
Parameters: | line – line bytes without trailing newline |
Raises ValueError: | |
If line could not be parsed |
Message describing the operation that acted on the reference
Returns: | New instance of a RefLogEntry |
---|
The hexsha to the commit the ref now points to, after the change
The hexsha to the commit the ref pointed to before the change
time as tuple:
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 a line could not be understood and was therefore dropped.
Returns: | a progress handler suitable for handle_process_output(), passing lines on to this Progress handler in a suitable format |
---|
Called whenever the progress changes
Parameters: |
|
---|
You may read the contents of the current line in self._cur_line
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
Initialize a new instance
Returns: | Remote Reference or TagReference in the local repository corresponding to the remote_ref_string kept in this instance. |
---|
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
info.remote_ref_path # The path from which we fetched on the remote. It's the remote's version of our info.ref
Initialize a new instance
Returns: | Commit of our remote ref |
---|
Returns: | Name of our remote ref |
---|
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.
Allows to call this instance like remote.special( *args, **kwargs) to call git-remote special self.name
Initialize a remote instance
Parameters: |
|
---|
Create a new remote to the given repository :param repo: Repository instance that is to receive the new remote :param name: Desired name of the remote :param url: URL which corresponds to the remote’s name :param kwargs: Additional arguments to be passed to the git-remote add command :return: New Remote instance :raise GitCommandError: in case an origin with that name already exists
Adds a new url on current remote (special case of git remote set_url)
This command adds new URLs to a given remote, making it possible to have multiple URLs for a single remote.
Parameters: | url – string being the URL to add as an extra remote URL |
---|---|
Returns: | self |
Returns: | GitConfigParser compatible object able to read options for only our remote. Hence you may simple type config.get(“pushurl”) to obtain the information |
---|
Returns: | GitConfigParser compatible object able to write options for this remote. |
---|---|
Note: | You can only own one writer at a time - delete it to release the configuration file and make it usable 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 :param repo: Repository instance that is to receive the new remote :param name: Desired name of the remote :param url: URL which corresponds to the remote’s name :param kwargs: Additional arguments to be passed to the git-remote add command :return: New Remote instance :raise GitCommandError: in case an origin with that name already exists
Deletes a new url on current remote (special case of git remote set_url)
This command deletes new URLs to a given remote, making it possible to have multiple URLs for a single remote.
Parameters: | url – string being the URL to delete from the remote |
---|---|
Returns: | self |
Returns: | True if this is a valid, existing remote. Valid remotes have an entry in the repository’s configuration |
---|
Fetch the latest changes for this remote
Parameters: |
|
---|---|
Returns: | IterableList(FetchInfo, ...) list of FetchInfo instances providing detailed information about the fetch results |
Note: | As fetch does not provide progress information to non-ttys, we cannot make it available here unfortunately as in the ‘push’ method. |
Returns: | Iterator yielding Remote objects of the given repository |
---|
Pull changes from the given branch, being the same as a fetch followed by a merge of branch with your local branch.
Parameters: |
|
---|---|
Returns: | Please see ‘fetch’ method |
Push changes from source branch in refspec to target branch in refspec.
Parameters: |
|
---|---|
Note: | No further progress information is returned after push returns. |
Returns: | IterableList(PushInfo, ...) iterable list of PushInfo instances, each one informing about an individual head which had been updated on the remote side. If the push contains rejected heads, these will have the PushInfo.ERROR bit set in their flags. If the operation fails completely, the length of the returned IterableList will be null. |
Returns: | 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’) |
---|
Remove the remote with the given name :return: the passed remote name to remove
Rename self to the given new_name :return: self
Remove the remote with the given name :return: the passed remote name to remove
Configure URLs on current remote (cf command git remote set_url)
This command manages URLs on the remote.
Parameters: |
|
---|---|
Returns: | self |
Returns: | 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. To make things more complicated, it can be possible for the list to include other kinds of references, for example, tag references, if these are stale as well. This is a fix for the issue described here: https://github.com/gitpython-developers/GitPython/issues/260 |
---|
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 ).
Parameters: | kwargs – Additional arguments passed to git-remote update |
---|---|
Returns: | self |
Returns: | Iterator yielding all configured URL targets on a remote as strings |
---|
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, which 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 directory, which is always set.
alias of Git
Create a new Repo instance
Parameters: |
|
---|---|
Raises: |
|
Returns: | git.Repo |
list of weak references to the object (if defined)
The name of the currently active branch.
Returns: | Head to the active branch |
---|
Retrieve a list of alternates paths or set a list paths to be used as alternates
Archive the tree at the given revision.
Parm ostream: | file compatible stream object to which the archive will be written as bytes |
---|---|
Parm treeish: | is the treeish name/id, defaults to active branch |
Parm prefix: | is the optional prefix to prepend to each filename in the archive |
Parm kwargs: | Additional arguments passed to git-archive
|
Raises GitCommandError: | |
in case something went wrong |
|
Returns: | self |
Returns: | True if the repository is bare |
---|
The blame information for the given file at the given revision.
Parm rev: | revision specifier, see git-rev-parse for viable options. |
---|---|
Returns: | list: [git.Commit, list: [<line>]] A list of tuples associating a Commit object with a list of lines that changed within the given commit. The Commit objects will be given in order of appearance. |
Iterator for blame information for the given file at the given revision.
Unlike .blame(), this does not return the actual file’s contents, only a stream of BlameEntry tuples.
Parm rev: | revision specifier, see git-rev-parse for viable options. |
---|---|
Returns: | lazy iterator of BlameEntry tuples, where the commit indicates the commit to blame for the line, and range indicates a span of line numbers in the resulting file. |
If you combine all line number ranges outputted by this command, you should get a continuous range spanning all line numbers in the file.
A list of Head objects representing the branch heads in this repo
Returns: | git.IterableList(Head, ...) |
---|
Create a clone from this repository.
Parameters: |
|
---|---|
Returns: | git.Repo (the newly cloned repo) |
Create a clone from the given URL
Parameters: |
|
---|---|
Returns: | Repo instance pointing to the cloned directory |
The Commit object for the specified revision :param rev: revision specifier, see git-rev-parse for viable options. :return: git.Commit
Returns: | 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. |
---|---|
Parameters: | config_level – For possible values, see config_writer method If None, all applicable levels will be used. Specify a level in case you know which exact file you whish to read to prevent reading multiple files for instance |
Note: | On windows, system configuration cannot currently be read as the path is unknown, instead the global path will be used. |
Returns: | GitConfigParser allowing to write values of the specified configuration file level. Config writers should be retrieved, used to change the configuration, and written right away as they will lock the configuration file in question and prevent other’s to write it. |
---|---|
Parameters: | config_level – One of the following values system = sytem wide configuration file global = user level configuration file repository = configuration file for this repostory only |
Create a new head within the repository. For more documentation, please see the Head.create method.
Returns: | newly created Head Reference |
---|
Create a new remote.
For more information, please see the documentation of the Remote.create methods
Returns: | Remote reference |
---|
Create a new submodule
Note: | See the documentation of Submodule.add for a description of the applicable parameters |
---|---|
Returns: | created submodules |
Create a new tag reference. For more documentation, please see the TagReference.create method.
Returns: | TagReference object |
---|
If True, git-daemon may export this repository
Delete the given heads
Parameters: | kwargs – Additional keyword arguments to be passed to git-branch |
---|
Delete the given remote.
Delete the given tag references
the project’s description
Returns: | True if our git_dir is not at the root of our working_tree_dir, but a .git file with a platform agnositic symbolic link. Our git_dir will be whereever the .git file points to |
---|---|
Note: | bare repositories will always return False here |
Returns: | HEAD Object pointing to the current head reference |
---|
A list of Head objects representing the branch heads in this repo
Returns: | git.IterableList(Head, ...) |
---|
Returns: | IndexFile representing this repository’s index. |
---|---|
Note: | This property can be expensive, as the returned IndexFile will be reinitialized. It’s recommended to re-use the object. |
Initialize a git repository at the given path if specified
Parameters: |
|
---|---|
Parm mkdir: | if specified will create the repository directory if it doesn’t already exists. Creates the directory with a mode=0755. Only effective if a path is explicitly given |
Parm kwargs: | keyword arguments serving as additional options to the git-init command |
Returns: | git.Repo (the newly created repo) |
Check if a commit is an ancestor of another
Parameters: |
|
---|---|
Returns: | True, ancestor_rev is an accestor to rev. |
Returns: | True, the repository is considered dirty. By default it will react like a git-status without untracked files, hence it is dirty if the index or the working copy have changes. |
---|
A list of Commit objects representing the history of a given ref/commit
Parm rev: | revision specifier, see git-rev-parse for viable options. If None, the active branch will be used. |
---|---|
Parm paths: | is an optional path or a list of paths to limit the returned commits to Commits that do not contain that path or the paths will not be returned. |
Parm kwargs: | Arguments to be passed to git-rev-list - common ones are max_count and skip |
Note: | to receive only commits between two named revisions, use the “revA...revB” revision specifier |
:return git.Commit[]
An iterator yielding Submodule instances, see Traversable interface for a description of args and kwargs :return: Iterator
Returns: | Iterator yielding Tree objects |
---|---|
Note: | Takes all arguments known to iter_commits method |
Find the closest common ancestor for the given revision (e.g. Commits, Tags, References, etc)
Parameters: |
|
---|---|
Returns: | A list of Commit objects. If –all was not specified as kwarg, the list will have at max one Commit, or is empty if no common merge base exists. |
Raises ValueError: | |
If not at least two revs are provided |
A list of Reference objects representing tags, heads and remote references.
Returns: | IterableList(Reference, ...) |
---|
A list of Reference objects representing tags, heads and remote references.
Returns: | IterableList(Reference, ...) |
---|
Returns: | Remote with the specified name |
---|---|
Raises ValueError: | |
if no remote with such a name exists |
A list of Remote objects allowing to access and manipulate remotes :return: git.IterableList(Remote, ...)
Returns: | Object at the given revision, either Commit, Tag, Tree or Blob |
---|---|
Parameters: | rev – git-rev-parse compatible revision specification as string, please see http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html for details |
Raises: |
|
Returns: | Submodule with the given name |
---|---|
Raises ValueError: | |
If no such submodule exists |
Update the submodules, keeping the repository consistent as it will take the previous state into consideration. For more information, please see the documentation of RootModule.update
Returns: | git.IterableList(Submodule, ...) of direct submodules available from the current head |
---|
Returns: | TagReference Object, reference pointing to a Commit or Tag |
---|---|
Parameters: | path – path to the tag reference, i.e. 0.1.5 or tags/0.1.5 |
A list of Tag objects that are available in this repo :return: git.IterableList(TagReference, ...)
The Tree object for the given treeish revision Examples:
repo.tree(repo.heads[0])
Parameters: | rev – is a revision pointing to a Treeish ( being a commit or tree ) |
---|---|
Returns: | git.Tree |
Note: | If you need a non-root level tree, find it by iterating the root tree. Otherwise it cannot know about its path relative to the repository root and subsequent operations might have unexpected results. |
Returns: | list(str,...) Files currently untracked as they have not been staged yet. Paths are relative to the current working directory of the git command. |
---|---|
Note: | ignored files will not appear here, i.e. files mentioned in .gitignore |
Note: | This property is expensive, as no cache is involved. To process the result, please consider caching it yourself. |
Returns: | The working tree directory of our git repository. If this is a bare repository, None is returned. |
---|
Package with general repository related functions
Returns: | Object at the given revision, either Commit, Tag, Tree or Blob |
---|---|
Parameters: | rev – git-rev-parse compatible revision specification as string, please see http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html for details |
Raises: |
|
This is taken from the git setup.c:is_git_directory function.
Search for a submodule repo.
Returns: | object specified by the given name, hexshas ( short and long ) as well as references are supported |
---|---|
Parameters: | return_ref – if name specifies a reference, we will return the reference instead of the object. Otherwise it will raise BadObject or BadName |
Returns: | long hexadecimal sha1 from the given less-than-40 byte hexsha or None if no candidate could be found. |
---|---|
Parameters: | hexsha – hexsha with less than 40 byte |
Recursively dereference a tag and return the resulting object
Convert the given object to a commit if possible and return it
Copy all data from the source stream into the destination stream in chunks of size chunk_size
Returns: | amount of bytes written |
---|
Join path tokens together similar to osp.join, but always use ‘/’ instead of possibly ‘’ on windows.
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
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 using write_sha.
Only useful to the indexfile
Note: | Based on the dulwich project |
---|
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 |
---|
:return:list(Item,...) list of item instances
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.
The lock file will block until a lock could be obtained, or fail after a specified timeout.
Note: | If the directory containing the lock was removed, an exception will be raised during the blocking period, preventing hangs as the lock can never be obtained. |
---|
Configure the instance
Parm check_interval_s: | |
---|---|
Period of time to sleep until the lock is checked the next time. By default, it waits a nearly unlimited time | |
Parm max_block_time_s: | |
Maximum amount of seconds we may lock |
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
Actors hold information about a person acting on the repository. They can be committers and authors or anything with a name and an email as mentioned in the git log entries.
Same as committer(), but defines the main author. It may be specified in the environment, but defaults to the committer
Returns: | Actor instance corresponding to the configured committer. It behaves similar to the git implementation, such that the environment will override configuration values of config_reader. If no value is set at all, it will be generated |
---|---|
Parameters: | config_reader – ConfigReader to use to retrieve the values from in case they are not set in the environment |
Assure that the directory pointed to by path exists.
Parameters: | is_file – If True, path is assumed to be a file and handled correctly. Otherwise it must be a directory |
---|---|
Returns: | True if the directory was created, False if it already existed |
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 a line could not be understood and was therefore dropped.
Returns: | a progress handler suitable for handle_process_output(), passing lines on to this Progress handler in a suitable format |
---|
Called whenever the progress changes
Parameters: |
|
---|
You may read the contents of the current line in self._cur_line
An implementation forwarding updates to any callable
Remove the given recursively.
Note: | we use shutil rmtree but adjust its behaviour to see whether files that couldn’t be deleted are read-only. Windows will not remove them in that case |
---|
Methods with this decorator raise InvalidGitRepositoryError if they encounter a bare repository
We need an easy way to see if Appveyor TCs start failing, so the errors marked with this var are considered “acknowledged” ones, awaiting remedy, till then, we wish to hide them.