Skip to content

Identity

identity

Git identity resolution with schedule-based profile switching.

GitIdentity

Bases: BaseModel

A git author identity.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
class GitIdentity(BaseModel):
    """A git author identity."""

    name: str
    email: str

GitProfileConfig

Bases: BaseModel

Full git-profiles.toml configuration.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
class GitProfileConfig(BaseModel):
    """Full git-profiles.toml configuration."""

    default: GitIdentity
    profiles: dict[str, GitIdentity] = {}
    schedule: Schedule = Schedule()

Schedule

Bases: BaseModel

Schedule configuration with rules.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
class Schedule(BaseModel):
    """Schedule configuration with rules."""

    rules: list[ScheduleRule] = []

ScheduleRule

Bases: BaseModel

A time-based rule mapping to a profile.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
class ScheduleRule(BaseModel):
    """A time-based rule mapping to a profile."""

    profile: str
    days: list[str]
    start: str
    end: str

author_args(identity)

Build --author arguments for a git command.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
def author_args(identity: GitIdentity | None) -> list[str]:
    """Build ``--author`` arguments for a git command."""
    if identity is None:
        return []
    return ["--author", f"{identity.name} <{identity.email}>"]

load_config(config_path=None)

Load and validate a git-profiles TOML config file.

Returns None if the file is missing, empty, or invalid.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
def load_config(config_path: Path | None = None) -> GitProfileConfig | None:
    """Load and validate a git-profiles TOML config file.

    Returns ``None`` if the file is missing, empty, or invalid.
    """
    path = config_path or _DEFAULT_CONFIG_PATH
    try:
        data = path.read_bytes()
        if not data:
            return None
        parsed: dict[str, Any] = tomllib.loads(data.decode())
        return GitProfileConfig.model_validate(parsed)
    except (OSError, tomllib.TOMLDecodeError, ValueError, KeyError):
        return None

resolve_identity(workspace_path, *, now=None, profile_override=None, config_path=None)

Resolve the git identity for the given workspace.

Returns None when no config is available or an unknown profile is requested via profile_override.

Source code in packages/axm-git/src/axm_git/core/identity.py
Python
def resolve_identity(
    workspace_path: Path,
    *,
    now: datetime | None = None,
    profile_override: str | None = None,
    config_path: Path | None = None,
) -> GitIdentity | None:
    """Resolve the git identity for the given workspace.

    Returns ``None`` when no config is available or an unknown profile
    is requested via *profile_override*.
    """
    config = load_config(config_path)
    if config is None:
        return None

    if profile_override is not None:
        if profile_override == "default":
            return config.default
        if profile_override in config.profiles:
            return config.profiles[profile_override]
        return None

    if _is_axm_workspace(workspace_path):
        effective_now = now or datetime.now()
        for rule in config.schedule.rules:
            if _matches_schedule(rule, effective_now):
                if rule.profile in config.profiles:
                    return config.profiles[rule.profile]

    return config.default