aind_behavior_experiment_launcher.launcher.git_manager.GitRepository¶
- class aind_behavior_experiment_launcher.launcher.git_manager.GitRepository(*args, **kwargs)[source]¶
Bases:
Repo
- __init__(*args, **kwargs)[source]¶
Create a new
Repo
instance.- 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
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:
Repo
Methods
__init__
(*args, **kwargs)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.
clean_repo
()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])- return:
config_writer
([config_level])- return:
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.
- return:
delete_head
(*heads, **kwargs)Delete the given heads.
delete_remote
(remote)Delete the given remote.
delete_tag
(*tags)Delete the given tag references.
force_update_submodules
()full_reset
()- return:
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, ...])- return:
is_dirty_with_submodules
()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)- return:
Iterator yielding
Tree
objects
merge_base
(*rev, **kwargs)Find the closest common ancestor for the given revision (
Commit
s,Tag
s,Reference
s, etc.).remote
([name])- return:
The remote with the specified name
reset_repo
()rev_parse
(rev)Parse a revision string.
submodule
(name)- return:
The submodule with the given name
submodule_update
(*args, **kwargs)Update the submodules, keeping the repository consistent as it will take the previous state into consideration.
submodules_sync
()tag
(path)- return:
tree
([rev])The
Tree
object for the given tree-ish revision.try_prompt_full_reset
(ui_helper[, force_reset])untracked_files_with_submodules
()Attributes
DAEMON_EXPORT_FILE
The name of the currently active branch.
Retrieve a list of alternates paths or set a list paths to be used as alternates
True
if the repository is bareAlias for heads.
return: The git dir that holds everything except possibly HEAD, FETCH_HEAD, ORIG_HEAD, COMMIT_EDITMSG, index, and logs/.
Represents the configuration level of a configuration file.
If True, git-daemon may export this repository
the project's description
git
return:
HEAD
object pointing to the current head referenceA list of
Head
objects representing the branch heads in this repo.- returns:
A
IndexFile
representing this repository's index.
re_author_committer_start
re_envvars
re_hexsha_only
re_hexsha_shortened
re_tab_full_line
re_whitespace
A list of
Reference
objects representing tags, heads and remote references.Alias for references.
A list of
Remote
objects allowing to access and manipulate remotes.return: git.IterableList(Submodule, ...) of direct submodules available from the current head
A list of
TagReference
objects that are available in this repo.Options to git-clone(1) that allow arbitrary commands to be executed.
- returns:
list(str,...)
return: The working tree directory of our git repository.
The working directory of the git command.
The
.git
repository directory.- property active_branch: Head[source]¶
The name of the currently active branch.
- Raises:
TypeError – If HEAD is detached.
- Returns:
Head
to the active branch
- property alternates: List[str][source]¶
Retrieve a list of alternates paths or set a list paths to be used as alternates
- archive(ostream: TextIO | BinaryIO, treeish: str | None = None, prefix: str | None = None, **kwargs: Any) Repo [source]¶
Archive the tree at the given revision.
- Parameters:
ostream – File-compatible stream object to which the archive will be written as bytes.
treeish – The treeish name/id, defaults to active branch.
prefix – The optional prefix to prepend to each filename in the archive.
kwargs –
Additional arguments passed to git-archive(1):
Use the
format
argument to define the kind of format. Use specialized ostreams to write any format supported by Python.You may specify the special
path
keyword, which may either be a repository-relative path to a directory or file to place into the archive, or a list or tuple of multiple paths.
- Raises:
git.exc.GitCommandError – If something went wrong.
- Returns:
self
- blame(rev: str | HEAD | None, file: str, incremental: bool = False, rev_opts: List[str] | None = None, **kwargs: Any) List[List[Commit | List[str | bytes] | None]] | Iterator[BlameEntry] | None [source]¶
The blame information for the given file at the given revision.
- Parameters:
rev – Revision specifier. If
None
, the blame will include all the latest uncommitted changes. Otherwise, anything successfully parsed by git-rev-parse(1) is a valid option.- Returns:
list: [git.Commit, list: [<line>]]
A list of lists associating a
Commit
object with a list of lines that changed within the given commit. TheCommit
objects will be given in order of appearance.
- blame_incremental(rev: str | HEAD | None, file: str, **kwargs: Any) Iterator[BlameEntry] [source]¶
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 ofBlameEntry
tuples.- Parameters:
rev – Revision specifier. If
None
, the blame will include all the latest uncommitted changes. Otherwise, anything successfully parsed by git-rev-parse(1) is a valid option.- 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.
- property branches: IterableList[Head][source]¶
Alias for heads. A list of
Head
objects representing the branch heads in this repo.- Returns:
git.IterableList(Head, ...)
- clone(path: str | PathLike[str], progress: Callable[[int, str | float, str | float | None, str], None] | None = None, multi_options: List[str] | None = None, allow_unsafe_protocols: bool = False, allow_unsafe_options: bool = False, **kwargs: Any) Repo [source]¶
Create a clone from this repository.
- Parameters:
path – The full path of the new repo (traditionally ends with
./<name>.git
).progress – See
Remote.push
.multi_options –
A list of git-clone(1) options that can be provided multiple times.
One option per list item which is passed exactly as specified to clone. For example:
[ "--config core.filemode=false", "--config core.ignorecase", "--recurse-submodule=repo1_path", "--recurse-submodule=repo2_path", ]
allow_unsafe_protocols – Allow unsafe protocols to be used, like
ext
.allow_unsafe_options – Allow unsafe options to be used, like
--upload-pack
.kwargs –
odbt
= ObjectDatabase Type, allowing to determine the object database implementation used by the returnedRepo
instance.All remaining keyword arguments are given to the git-clone(1) command.
- Returns:
Repo
(the newly cloned repo)
- classmethod clone_from(url: str | PathLike[str], to_path: str | PathLike[str], progress: Callable[[int, str | float, str | float | None, str], None] | None = None, env: Mapping[str, str] | None = None, multi_options: List[str] | None = None, allow_unsafe_protocols: bool = False, allow_unsafe_options: bool = False, **kwargs: Any) Repo [source]¶
Create a clone from the given URL.
- Parameters:
url – Valid git url, see: https://git-scm.com/docs/git-clone#URLS
to_path – Path to which the repository should be cloned to.
progress – See
Remote.push
.env –
Optional dictionary containing the desired environment variables.
Note: Provided variables will be used to update the execution environment for
git
. If some variable is not specified in env and is defined inos.environ
, value fromos.environ
will be used. If you want to unset some variable, consider providing empty string as its value.multi_options – See the
clone()
method.allow_unsafe_protocols – Allow unsafe protocols to be used, like
ext
.allow_unsafe_options – Allow unsafe options to be used, like
--upload-pack
.kwargs – See the
clone()
method.
- Returns:
Repo
instance pointing to the cloned directory.
- commit(rev: str | Commit_ish | None = None) Commit [source]¶
The
Commit
object for the specified revision.- Parameters:
rev – Revision specifier, see git-rev-parse(1) for viable options.
- Returns:
Commit
- property common_dir: str | PathLike[str][source]¶
return: The git dir that holds everything except possibly HEAD, FETCH_HEAD, ORIG_HEAD, COMMIT_EDITMSG, index, and logs/.
- config_level: ConfigLevels_Tup = ('system', 'user', 'global', 'repository')[source]¶
Represents the configuration level of a configuration file.
- config_reader(config_level: Literal['system', 'global', 'user', 'repository'] | None = None) GitConfigParser [source]¶
- 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 the
config_writer()
method. IfNone
, all applicable levels will be used. Specify a level in case you know which file you wish to read to prevent reading multiple files.- Note:
On Windows, system configuration cannot currently be read as the path is unknown, instead the global path will be used.
- config_writer(config_level: Literal['system', 'global', 'user', 'repository'] = 'repository') GitConfigParser [source]¶
- Returns:
A
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"
= system wide configuration file"global"
= user level configuration file"`repository"
= configuration file for this repository only
- create_head(path: PathLike, commit: 'SymbolicReference' | 'str' = 'HEAD', force: bool = False, logmsg: str | None = None) Head [source]¶
Create a new head within the repository.
- Note:
For more documentation, please see the
Head.create
method.- Returns:
Newly created
Head
Reference.
- create_remote(name: str, url: str, **kwargs: Any) Remote [source]¶
Create a new remote.
For more information, please see the documentation of the
Remote.create
method.- Returns:
Remote
reference
- create_submodule(*args: Any, **kwargs: Any) Submodule [source]¶
Create a new submodule.
- Note:
For a description of the applicable parameters, see the documentation of
Submodule.add
.- Returns:
The created submodule.
- create_tag(path: PathLike, ref: str | 'SymbolicReference' = 'HEAD', message: str | None = None, force: bool = False, **kwargs: Any) TagReference [source]¶
Create a new tag reference.
- Note:
For more documentation, please see the
TagReference.create
method.- Returns:
TagReference
object
- currently_rebasing_on() Commit | None [source]¶
- Returns:
The commit which is currently being replayed while rebasing.
None
if we are not currently rebasing.
- delete_head(*heads: str | Head, **kwargs: Any) None [source]¶
Delete the given heads.
- Parameters:
kwargs – Additional keyword arguments to be passed to git-branch(1).
- has_separate_working_tree() bool [source]¶
- Returns:
True if our
git_dir
is not at the root of ourworking_tree_dir
, but a.git
file with a platform-agnostic symbolic link. Ourgit_dir
will be wherever the.git
file points to.- Note:
Bare repositories will always return
False
here.
- property heads: IterableList[Head][source]¶
A list of
Head
objects representing the branch heads in this repo.- Returns:
git.IterableList(Head, ...)
- ignored(*paths: str | PathLike[str]) List[str] [source]¶
Checks if paths are ignored via
.gitignore
.This does so using the git-check-ignore(1) method.
- Parameters:
paths – List of paths to check whether they are ignored or not.
- Returns:
Subset of those paths which are ignored
- property index: IndexFile[source]¶
- Returns:
A
IndexFile
representing this repository’s index.- Note:
This property can be expensive, as the returned
IndexFile
will be reinitialized. It is recommended to reuse the object.
- classmethod init(path: str | ~os.PathLike[str] | None = None, mkdir: bool = True, odbt: ~typing.Type[~git.db.GitCmdObjectDB] = <class 'git.db.GitCmdObjectDB'>, expand_vars: bool = True, **kwargs: ~typing.Any) Repo [source]¶
Initialize a git repository at the given path if specified.
- Parameters:
path – The full path to the repo (traditionally ends with
/<name>.git
). OrNone
, in which case the repository will be created in the current working directory.mkdir – If specified, will create the repository directory if it doesn’t already exist. Creates the directory with a mode=0755. Only effective if a path is explicitly given.
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.expand_vars – If specified, environment variables will not be escaped. This can lead to information disclosure, allowing attackers to access the contents of environment variables.
kwargs – Keyword arguments serving as additional options to the git-init(1) command.
- Returns:
Repo
(the newly created repo)
- is_ancestor(ancestor_rev: Commit, rev: Commit) bool [source]¶
Check if a commit is an ancestor of another.
- Parameters:
ancestor_rev – Rev which should be an ancestor.
rev – Rev to test against ancestor_rev.
- Returns:
True
if ancestor_rev is an ancestor to rev.
- is_dirty(index: bool = True, working_tree: bool = True, untracked_files: bool = False, submodules: bool = True, path: str | PathLike[str] | None = None) bool [source]¶
- Returns:
True
if the repository is considered dirty. By default it will react like a git-status(1) without untracked files, hence it is dirty if the index or the working copy have changes.
- iter_commits(rev: str | Commit | 'SymbolicReference' | None = None, paths: PathLike | Sequence[PathLike] = '', **kwargs: Any) Iterator[Commit] [source]¶
An iterator of
Commit
objects representing the history of a given ref/commit.- Parameters:
rev – Revision specifier, see git-rev-parse(1) for viable options. If
None
, the active branch will be used.paths – An optional path or a list of paths. If set, only commits that include the path or paths will be returned.
kwargs – Arguments to be passed to git-rev-list(1). Common ones are
max_count
andskip
.
- Note:
To receive only commits between two named revisions, use the
"revA...revB"
revision specifier.- Returns:
Iterator of
Commit
objects
- iter_submodules(*args: Any, **kwargs: Any) Iterator[Submodule] [source]¶
An iterator yielding Submodule instances.
See the ~git.objects.util.Traversable interface for a description of args and kwargs.
- Returns:
Iterator
- iter_trees(*args: Any, **kwargs: Any) Iterator['Tree'] [source]¶
- Returns:
Iterator yielding
Tree
objects- Note:
Accepts all arguments known to the
iter_commits()
method.
- merge_base(*rev: Any, **kwargs: Any) List[Commit] [source]¶
Find the closest common ancestor for the given revision (
Commit
s,Tag
s,Reference
s, etc.).- Parameters:
rev – At least two revs to find the common ancestor for.
kwargs – Additional arguments to be passed to the
repo.git.merge_base()
command which does all the work.
- Returns:
A list of
Commit
objects. If--all
was not passed as a keyword argument, the list will have at max oneCommit
, or is empty if no common merge base exists.- Raises:
ValueError – If fewer than two revisions are provided.
- property references: IterableList[Reference][source]¶
A list of
Reference
objects representing tags, heads and remote references.- Returns:
git.IterableList(Reference, ...)
- property refs: IterableList[Reference][source]¶
Alias for references. A list of
Reference
objects representing tags, heads and remote references.- Returns:
git.IterableList(Reference, ...)
- remote(name: str = 'origin') Remote [source]¶
- Returns:
The remote with the specified name
- Raises:
ValueError – If no remote with such a name exists.
- property remotes: IterableList[Remote][source]¶
A list of
Remote
objects allowing to access and manipulate remotes.- Returns:
git.IterableList(Remote, ...)
- rev_parse(rev: str) AnyGitObject [source]¶
Parse a revision string. Like git-rev-parse(1).
- Returns:
~git.objects.base.Object at the given revision.
This may be any type of git object:
Commit
TagObject
Tree
Blob
- Parameters:
rev – git-rev-parse(1)-compatible revision specification as string. Please see git-rev-parse(1) for details.
- Raises:
gitdb.exc.BadObject – If the given revision could not be found.
ValueError – If rev couldn’t be parsed.
IndexError – If an invalid reflog index is specified.
- submodule(name: str) Submodule [source]¶
- Returns:
The submodule with the given name
- Raises:
ValueError – If no such submodule exists.
- submodule_update(*args: Any, **kwargs: Any) Iterator[Submodule] [source]¶
Update the submodules, keeping the repository consistent as it will take the previous state into consideration.
- Note:
For more information, please see the documentation of
RootModule.update
.
- property submodules: IterableList[Submodule][source]¶
return: git.IterableList(Submodule, …) of direct submodules available from the current head
- tag(path: str | PathLike[str]) TagReference [source]¶
- Returns:
TagReference
object, reference pointing to aCommit
or tag- Parameters:
path – Path to the tag reference, e.g.
0.1.5
ortags/0.1.5
.
- property tags: IterableList[TagReference][source]¶
A list of
TagReference
objects that are available in this repo.- Returns:
git.IterableList(TagReference, ...)
- tree(rev: Tree_ish | str | None = None) Tree [source]¶
The
Tree
object for the given tree-ish revision.Examples:
repo.tree(repo.heads[0])
- Parameters:
rev – A revision pointing to a Treeish (being a commit or tree).
- Returns:
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.
- unsafe_git_clone_options = ['--upload-pack', '-u', '--config', '-c'][source]¶
Options to git-clone(1) that allow arbitrary commands to be executed.
The
--upload-pack
/-u
option allows users to execute arbitrary commands directly: https://git-scm.com/docs/git-clone#Documentation/git-clone.txt—upload-packltupload-packgtThe
--config
/-c
option allows users to override configuration variables likeprotocol.allow
andcore.gitProxy
to execute arbitrary commands: https://git-scm.com/docs/git-clone#Documentation/git-clone.txt—configltkeygtltvaluegt
- property untracked_files: List[str][source]¶
- 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.