Skip to content

WIP: Added ability to define git environment in submodule add/update methods #1085

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

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath):
#{ Edit Interface

@classmethod
def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=None):
def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=None, env=None):
"""Add a new submodule to the given repository. This will alter the index
as well as the .gitmodules file, but will not create a new commit.
If the submodule already exists, no matter if the configuration differs
Expand All @@ -336,6 +336,12 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N
no checkout will be performed
:param depth: Create a shallow clone with a history truncated to the
specified number of commits.
:param 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 in `os.environ`, value from `os.environ` will be used.
If you want to unset some variable, consider providing empty string
as its value.
:return: The newly created submodule instance
:note: works atomically, such that no change will be done if the repository
update fails for instance"""
Expand Down Expand Up @@ -404,7 +410,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N
raise ValueError("depth should be an integer")

# _clone_repo(cls, repo, url, path, name, **kwargs):
mrepo = cls._clone_repo(repo, url, path, name, **kwargs)
mrepo = cls._clone_repo(repo, url, path, name, env=env, **kwargs)
# END verify url

## See #525 for ensuring git urls in config-files valid under Windows.
Expand Down Expand Up @@ -436,7 +442,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N
return sm

def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, dry_run=False,
force=False, keep_going=False):
force=False, keep_going=False, env=None):
"""Update the repository of this submodule to point to the checkout
we point at with the binsha of this instance.

Expand All @@ -461,6 +467,12 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
Unless dry_run is set as well, keep_going could cause subsequent/inherited errors you wouldn't see
otherwise.
In conjunction with dry_run, it can be useful to anticipate all errors when updating submodules
:param 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 in `os.environ`, value from `os.environ` will be used.
If you want to unset some variable, consider providing empty string
as its value.
:note: does nothing in bare repositories
:note: method is definitely not atomic if recurisve is True
:return: self"""
Expand Down Expand Up @@ -527,7 +539,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
progress.update(BEGIN | CLONE, 0, 1, prefix + "Cloning url '%s' to '%s' in submodule %r" %
(self.url, checkout_module_abspath, self.name))
if not dry_run:
mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True)
mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env)
# END handle dry-run
progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % checkout_module_abspath)

Expand Down