cathy_tools.Repo#
- class cathy_tools.Repo(path: str | ~os.PathLike[str] | None = None, odbt: ~typing.Type[~gitdb.db.loose.LooseObjectDB] = <class 'git.db.GitCmdObjectDB'>, search_parent_directories: bool = False, expand_vars: bool = True)[source]#
Represents a git repository and allows you to query references, create commit information, generate diffs, create and clone repositories, and 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 returnNone
if we are a bare repository.git_dir
is the.git
repository directory, which is always set.
- __init__(path: str | ~os.PathLike[str] | None = None, odbt: ~typing.Type[~gitdb.db.loose.LooseObjectDB] = <class 'git.db.GitCmdObjectDB'>, search_parent_directories: bool = False, expand_vars: bool = True) None [source]#
Create a new
Repo
instance.- Parameters:
path –
The path to either the root git directory or the bare git repo:
repo = Repo("/Users/mtrier/Development/git-python") repo = Repo("/Users/mtrier/Development/git-python.git") repo = Repo("~/Development/git-python.git") repo = Repo("$REPOSITORIES/Development/git-python.git") repo = Repo(R"C:\Users\mtrier\Development\git-python\.git")
In Cygwin, path may be a
cygdrive/...
prefixed path.If path is
None
or an empty string,GIT_DIR
is used. If that environment variable is absent or empty, the current directory is used.
odbt – Object DataBase type - a type which is constructed by providing the directory containing the database objects, i.e.
.git/objects
. It will be used to access all object data.search_parent_directories –
If
True
, all parent directories will be searched for a valid repo as well.Please note that this was the default behaviour in older versions of GitPython, which is considered a bug though.
- Raises:
git.exc.InvalidGitRepositoryError –
git.exc.NoSuchPathError –
- Returns:
Methods
__init__
([path, odbt, ...])Create a new
Repo
instance.archive
(ostream[, treeish, prefix])Archive the tree at the given revision.
blame
(rev, file[, incremental, rev_opts])The blame information for the given file at the given revision.
blame_incremental
(rev, file, **kwargs)Iterator for blame information for the given file at the given revision.
clone
(path[, progress, multi_options, ...])Create a clone from this repository.
clone_from
(url, to_path[, progress, env, ...])Create a clone from the given URL.
close
()commit
([rev])The
Commit
object for the specified revision.config_reader
([config_level])config_writer
([config_level])create_head
(path[, commit, force, logmsg])Create a new head within the repository.
create_remote
(name, url, **kwargs)Create a new remote.
create_submodule
(*args, **kwargs)Create a new submodule.
create_tag
(path[, ref, message, force])Create a new tag reference.
currently_rebasing_on
()delete_head
(*heads, **kwargs)Delete the given heads.
delete_remote
(remote)Delete the given remote.
delete_tag
(*tags)Delete the given tag references.
has_separate_working_tree
()ignored
(*paths)Checks if paths are ignored via
.gitignore
.init
([path, mkdir, odbt, expand_vars])Initialize a git repository at the given path if specified.
is_ancestor
(ancestor_rev, rev)Check if a commit is an ancestor of another.
is_dirty
([index, working_tree, ...])is_valid_object
(sha[, object_type])iter_commits
([rev, paths])An iterator of
Commit
objects representing the history of a given ref/commit.iter_submodules
(*args, **kwargs)An iterator yielding Submodule instances.
iter_trees
(*args, **kwargs)merge_base
(*rev, **kwargs)Find the closest common ancestor for the given revision (
Commit
s,Tag
s,Reference
s, etc.).remote
([name])rev_parse
(rev)Parse a revision string.
submodule
(name)submodule_update
(*args, **kwargs)Update the submodules, keeping the repository consistent as it will take the previous state into consideration.
tag
(path)tree
([rev])The
Tree
object for the given tree-ish revision.Attributes
DAEMON_EXPORT_FILE
active_branch
The name of the currently active branch.
alternates
Retrieve a list of alternates paths or set a list paths to be used as alternates
bare
True
if the repository is barebranches
A list of
Head
objects representing the branch heads in this repo.common_dir
return: The git dir that holds everything except possibly HEAD, FETCH_HEAD, ORIG_HEAD, COMMIT_EDITMSG, index, and logs/.
config_level
Represents the configuration level of a configuration file.
daemon_export
If True, git-daemon may export this repository
description
the project's description
git
head
return:
HEAD
object pointing to the current head referenceheads
A list of
Head
objects representing the branch heads in this repo.index
re_author_committer_start
re_envvars
re_hexsha_only
re_hexsha_shortened
re_tab_full_line
re_whitespace
references
A list of
Reference
objects representing tags, heads and remote references.refs
A list of
Reference
objects representing tags, heads and remote references.remotes
A list of
Remote
objects allowing to access and manipulate remotes.submodules
return: git.IterableList(Submodule, ...) of direct submodules available from the current head
tags
A list of
TagReference
objects that are available in this repo.unsafe_git_clone_options
Options to git-clone(1) that allow arbitrary commands to be executed.
untracked_files
working_tree_dir
return: The working tree directory of our git repository.
working_dir
The working directory of the git command.
git_dir
The
.git
repository directory.