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_diris the working directory of the git command, which is the working tree directory if available or the.gitdirectory in case of bare repositories.working_tree_diris the working tree directory, but will returnNoneif we are a bare repository.git_diris the.gitrepository 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
Repoinstance.- Parameters:
path –
The path to either the worktree directory or the .git directory itself:
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
Noneor an empty string,GIT_DIRis 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
Repoinstance.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
Commitobject 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
Commitobjects 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 (
Commits,Tags,References, 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
Treeobject for the given tree-ish revision.Attributes
DAEMON_EXPORT_FILEactive_branchThe name of the currently active branch.
alternatesRetrieve a list of alternates paths or set a list paths to be used as alternates
bareTrueif the repository is barebranchesAlias for heads.
common_dirreturn: The git dir that holds everything except possibly HEAD, FETCH_HEAD, ORIG_HEAD, COMMIT_EDITMSG, index, and logs/.
config_levelRepresents the configuration level of a configuration file.
daemon_exportIf True, git-daemon may export this repository
descriptionThe project's description
githeadreturn:
HEADobject pointing to the current head referenceheadsA list of
Headobjects representing the branch heads in this repo.indexre_author_committer_startre_envvarsre_hexsha_onlyre_hexsha_shortenedre_tab_full_linere_whitespacereferencesA list of
Referenceobjects representing tags, heads and remote references.refsAlias for references.
remotesA list of
Remoteobjects allowing to access and manipulate remotes.submodulesreturn: git.IterableList(Submodule, ...) of direct submodules available from the current head
tagsA list of
TagReferenceobjects that are available in this repo.unsafe_git_clone_optionsOptions to git-clone(1) that allow arbitrary commands to be executed.
untracked_filesworking_tree_dirreturn: The working tree directory of our git repository.
working_dirThe working directory of the git command.
git_dirThe
.gitrepository directory.