Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Git class type definition within Repo classmethods #1322

Merged
merged 1 commit into from
Aug 18, 2021

Conversation

mmulich
Copy link
Contributor

@mmulich mmulich commented Aug 17, 2021

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

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 intended outcome. Otherwise the
developer will have two differing result when using Repo(...) vs
Repo.clone_from(...).

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(...)`.
@mmulich
Copy link
Contributor Author

mmulich commented Aug 17, 2021

I believe this could help address issues around confusing usage of an SSH key when using Repo.clone_from. For example, #400 #725 #866 and #916 to name a few. Or at least this may be a step towards it. The use of Repo.GitCommandWrapperType as stated in my example would need to be documented, but first things first... fix the implementation.

Thanks for having simple contribution instructions.

Byron added a commit that referenced this pull request Aug 18, 2021
@Byron
Copy link
Member

Byron commented Aug 18, 2021

Thanks a lot for the fix for this long-standing oversight, it's much appreciated!

And thanks for the hint, I looked at the contribution guidelines and found it outdated, that's fixed now to hopefully further improve the experience.

@Byron Byron merged commit 1207747 into gitpython-developers:main Aug 18, 2021
@Byron Byron added this to the v3.1.21 - Bugfixes milestone Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants