diff options
author | Michael Mulich <michael.mulich@gmail.com> | 2021-08-17 12:57:53 -0700 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-08-18 09:10:38 +0800 |
commit | 1207747121a79a0cd14426e595f5fe72ccc1d51a (patch) | |
tree | 9e486d263e52c64076fa98c809821593ce8d3f7f /git/repo/base.py | |
parent | bd0fa882f6c8fd2ab907e9f5988f32f466d75bdf (diff) | |
download | gitpython-1207747121a79a0cd14426e595f5fe72ccc1d51a.tar.gz |
Use the Git class type definition within Repo classmethods
Allow the GitCommandWrapperType definition to be used within the Repo
classmethods. This change follows the intended purpose as stated in
the code, "Subclasses may easily bring in their own custom types by
placing a constructor or type here."
The usecase that prompted this change has to do with
`GIT_SSH_COMMAND`. The goal is to setup a custom `Git` class with
knowledge of the value, something like as follows
```python
from git import Git as BaseGit, Repo as BaseRepo
class Git(BaseGit):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# For example, assign the SSH command using the current flask
# app's configured setting.
self.update_environment(GIT_SSH_COMMAND=current_app.config['GIT_SSH_COMMAND'])
class Repo(BaseRepo):
GitCommandWrapperType = _Git
```
With this change, the above example will allow the developer to use
`Repo.clone_from(...)` with the indended outcome. Otherwise the
developer will have two differing result when using `Repo(...)` vs
`Repo.clone_from(...)`.
Diffstat (limited to 'git/repo/base.py')
-rw-r--r-- | git/repo/base.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index c0229a84..e308fd8a 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -1042,7 +1042,7 @@ class Repo(object): os.makedirs(path, 0o755) # git command automatically chdir into the directory - git = Git(path) + git = cls.GitCommandWrapperType(path) git.init(**kwargs) return cls(path, odbt=odbt) @@ -1142,7 +1142,7 @@ class Repo(object): :param multi_options: See ``clone`` method :param kwargs: see the ``clone`` method :return: Repo instance pointing to the cloned directory""" - git = Git(os.getcwd()) + git = cls.GitCommandWrapperType(os.getcwd()) if env is not None: git.update_environment(**env) return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs) |