Skip to content

Commit 1d315c5

Browse files
committed
git: Add option for no_config in git shell
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
1 parent 740c5cd commit 1d315c5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

revup/git.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,33 @@ def get_scratch_dir(self) -> str:
269269
"""
270270
return f"{self.repo_root}/.revup" if self.keep_temp else self.temp_dir.name
271271

272-
async def git(self, *args: str, **kwargs: Any) -> Tuple[int, str]:
272+
async def git(
273+
self,
274+
*args: str,
275+
no_config: bool = False,
276+
env: Optional[Dict[str, str]] = None,
277+
**kwargs: Any,
278+
) -> Tuple[int, str]:
273279
"""
274280
Run a git command. The returned stdout has trailing newlines stripped.
275281
276282
Args:
277283
*args: Arguments to git
278284
**kwargs: Any valid kwargs for sh()
279285
"""
286+
git_env = {}
287+
if no_config:
288+
git_env.update({
289+
"HOME": "/dev/null",
290+
"GIT_CONFIG_NOSYSTEM": "1",
291+
})
292+
if env is not None:
293+
git_env.update(env)
280294

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

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

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

0 commit comments

Comments
 (0)