Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

70 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Utilities for extracting the actual branch delta from a merge commit."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
def run_git_command(command: list[str], cwd: str | Path | None = None) -> str:
try:
result = subprocess.run(
command,
capture_output=True,
text=True,
check=True,
cwd=str(cwd) if cwd is not None else None,
)
return result.stdout.strip()
except subprocess.CalledProcessError as exc:
print(f"Error running git command: {' '.join(command)}", file=sys.stderr)
print(exc.stderr, file=sys.stderr)
raise SystemExit(1) from exc
def get_merge_base(first_parent: str, second_parent: str, cwd: str | Path | None = None) -> str:
return run_git_command(["git", "merge-base", first_parent, second_parent], cwd=cwd)
def get_branch_changed_files(
first_parent: str, second_parent: str, cwd: str | Path | None = None
) -> list[str]:
merge_base = get_merge_base(first_parent, second_parent, cwd=cwd)
return [
line
for line in run_git_command(
["git", "diff", "--name-only", merge_base, second_parent],
cwd=cwd,
).splitlines()
if line.strip()
]
def get_branch_diff_stat(
first_parent: str, second_parent: str, cwd: str | Path | None = None
) -> str:
merge_base = get_merge_base(first_parent, second_parent, cwd=cwd)
return run_git_command(["git", "diff", "--stat", merge_base, second_parent], cwd=cwd)
def get_branch_commit_subjects(
first_parent: str, second_parent: str, cwd: str | Path | None = None
) -> list[str]:
merge_base = get_merge_base(first_parent, second_parent, cwd=cwd)
return [
line
for line in run_git_command(
[
"git",
"log",
"--no-merges",
"--pretty=format:- %s (%h)",
f"{merge_base}..{second_parent}",
],
cwd=cwd,
).splitlines()
if line.strip()
]