Skip to content

Commit

Permalink
git: Add option for no_config in git shell
Browse files Browse the repository at this point in the history
This causes git commands to run without considering any
system or user configuration. In some cases it's easier to
ban all overrides rather than have to override things on
a flag by flag basis.

Topic: gitconfig
  • Loading branch information
jerry-skydio committed Jul 3, 2024
1 parent 740c5cd commit 1d315c5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions revup/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,33 @@ def get_scratch_dir(self) -> str:
"""
return f"{self.repo_root}/.revup" if self.keep_temp else self.temp_dir.name

async def git(self, *args: str, **kwargs: Any) -> Tuple[int, str]:
async def git(
self,
*args: str,
no_config: bool = False,
env: Optional[Dict[str, str]] = None,
**kwargs: Any,
) -> Tuple[int, str]:
"""
Run a git command. The returned stdout has trailing newlines stripped.
Args:
*args: Arguments to git
**kwargs: Any valid kwargs for sh()
"""
git_env = {}
if no_config:
git_env.update({
"HOME": "/dev/null",
"GIT_CONFIG_NOSYSTEM": "1",
})
if env is not None:
git_env.update(env)

def _maybe_rstrip(s: Tuple[int, str]) -> Tuple[int, str]:
return (s[0], s[1].rstrip())

return _maybe_rstrip(await self.sh.sh(*((self.git_path,) + args), **kwargs))
return _maybe_rstrip(await self.sh.sh(*((self.git_path,) + args), env=git_env, **kwargs))

async def git_return_code(self, *args: str, **kwargs: Any) -> int:
return (await self.git(raiseonerror=False, *args, **kwargs))[0]
Expand Down

0 comments on commit 1d315c5

Please sign in to comment.