Skip to content

Commit

Permalink
Add --git-config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ShamrockLee committed Nov 13, 2024
1 parent 6bcf207 commit 58114ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions nixpkgs_review/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def common_flags() -> list[CommonFlag]:
CommonFlag(
"--build-args", default="", help="arguments passed to nix when building"
),
CommonFlag(
"--git-config",
action="append",
default=[],
help="additional Git configuration to use (accept multiple specification)",
),
CommonFlag(
"--no-shell",
action="store_true",
Expand Down
1 change: 1 addition & 0 deletions nixpkgs_review/cli/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def pr_command(args: argparse.Namespace) -> str:
review = Review(
builddir=builddir,
build_args=args.build_args,
git_configs=args.git_config,
no_shell=args.no_shell,
run=args.run,
remote=args.remote,
Expand Down
18 changes: 14 additions & 4 deletions nixpkgs_review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile
from dataclasses import dataclass, field
from enum import Enum
from itertools import chain
from pathlib import Path
from re import Pattern
from typing import IO
Expand Down Expand Up @@ -92,6 +93,7 @@ def __init__(
self,
builddir: Builddir,
build_args: str,
git_configs: list[str],
no_shell: bool,
run: str,
remote: str,
Expand All @@ -112,6 +114,7 @@ def __init__(
) -> None:
self.builddir = builddir
self.build_args = build_args
self.git_configs = git_configs
self.no_shell = no_shell
self.run = run
self.remote = remote
Expand Down Expand Up @@ -146,17 +149,23 @@ def __init__(
def worktree_dir(self) -> str:
return str(self.builddir.worktree_dir)

def form_git_command(self, main_args: [str]) -> [str]:
result = ["git"]
result.extend(chain(*(["-c", c] for c in self.git_configs)))
result.extend(main_args)
return result

def git_merge(self, commit: str) -> None:
res = sh(
["git", "merge", "--no-commit", "--no-ff", commit], cwd=self.worktree_dir()
self.form_git_command(["merge", "--no-commit", "--no-ff", commit]), cwd=self.worktree_dir()
)
if res.returncode != 0:
raise NixpkgsReviewError(
f"Failed to merge {commit} into {self.worktree_dir()}. git merge failed with exit code {res.returncode}"
)

def apply_unstaged(self, staged: bool = False) -> None:
args = ["git", "--no-pager", "diff", "--no-ext-diff"]
args = self.form_git_command(["--no-pager", "diff", "--no-ext-diff"])
args.extend(["--staged"] if staged else [])
with subprocess.Popen(args, stdout=subprocess.PIPE) as diff_proc:
assert diff_proc.stdout
Expand All @@ -167,7 +176,7 @@ def apply_unstaged(self, staged: bool = False) -> None:
sys.exit(0)

info("Applying `nixpkgs` diff...")
result = subprocess.run(["git", "apply"], cwd=self.worktree_dir(), input=diff)
result = subprocess.run(self.form_git_command(["apply"]), cwd=self.worktree_dir(), input=diff)

if result.returncode != 0:
warn(f"Failed to apply diff in {self.worktree_dir()}")
Expand Down Expand Up @@ -222,7 +231,7 @@ def build_commit(
return self.build(changed_attrs, self.build_args)

def git_worktree(self, commit: str) -> None:
res = sh(["git", "worktree", "add", self.worktree_dir(), commit])
res = sh(self.form_git_command(["worktree", "add", self.worktree_dir(), commit]))
if res.returncode != 0:
raise NixpkgsReviewError(
f"Failed to add worktree for {commit} in {self.worktree_dir()}. git worktree failed with exit code {res.returncode}"
Expand Down Expand Up @@ -637,6 +646,7 @@ def review_local_revision(
review = Review(
builddir=builddir,
build_args=args.build_args,
git_configs=args.git_config,
no_shell=args.no_shell,
run=args.run,
remote=args.remote,
Expand Down

0 comments on commit 58114ec

Please sign in to comment.