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

git: Add option for no_config in git shell #188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 24 additions & 4 deletions revup/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"-U1",
]

GIT_ENV_NOCONFIG = {
"HOME": "/dev/null",
"GIT_CONFIG_NOSYSTEM": "1",
}

COMMON_MAIN_BRANCHES = ["main", "master"] # Below logic assumes 2 values here


Expand Down Expand Up @@ -269,19 +274,30 @@ 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(GIT_ENV_NOCONFIG)
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 Expand Up @@ -596,6 +612,8 @@ async def get_patch_id(
await self.sh.piped_sh(
patch_source,
[self.git_path, "patch-id", "--verbatim"],
env1=GIT_ENV_NOCONFIG,
env2=GIT_ENV_NOCONFIG,
)
)[1].split()
# If the diff is empty, patch id will return nothing. We just use that as the patch-id since
Expand All @@ -610,7 +628,9 @@ async def get_diff_summary(
"""
Return the summary of the diff (files and lines changed)
"""
return (await self.git_stdout("diff", "--shortstat", parent, commit)).rstrip()
return (
await self.git_stdout("diff", "--shortstat", parent, commit, no_config=True)
).rstrip()

async def merge_tree_commit(
self,
Expand All @@ -628,7 +648,7 @@ async def merge_tree_commit(
args.extend(["--merge-base", merge_base])
args.extend([branch1, branch2])

ret, stdout = await self.git(*args, raiseonerror=False)
ret, stdout = await self.git(*args, no_config=True, raiseonerror=False)

# See man page for git merge-tree for a complete breakdown of the output format
sections = stdout.split("\0\0")
Expand Down
Loading