Skip to content

bug: Artifact generation fails for read-write repositories when default branch is not "main" #8749

Description

@dgarros

Component

Git Integration

Infrahub Version

1.8.2

Current Behavior

When a repository is configured in read-write mode with a default branch other than main (e.g., master, develop), Infrahub fails to generate artifacts from that repository. The repository's operational state transitions to an error.

Expected Behavior

Artifact generation should work regardless of the repository's default branch name. The system should respect the default_branch attribute configured on the repository object.

Steps to Reproduce

  1. Create an external Git repository with a default branch named something other than main (e.g., master)
  2. Add it to Infrahub as a read-write repository, setting default_branch to match
  3. Configure an artifact definition that pulls data from this repository
  4. Trigger artifact generation
  5. Observe that the repository operational state becomes an error

Analysis

Several locations in the codebase have hardcoded assumptions about "main" as the branch name:

  • backend/infrahub/git/base.py:204directory_default property hardcodes "main" as the directory name for the primary branch worktree
  • backend/infrahub/git/base.py:868-870 — worktree identifier mapping uses "main" as a fallback identifier when the repository's default branch differs from the system default
  • backend/infrahub/git/repository.py:194rebase() defaults source_branch to "main"
  • backend/infrahub/core/schema/definitions/core/repository.py:44 — schema default_value="main" (this one is expected as a default, but the runtime code should honor the configured value)

The default_branch property in base.py:187-189 correctly falls back from default_branch_name to registry.default_branch, but downstream code that hardcodes "main" as a directory or identifier bypasses this logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    group/sync-engineIssue related to the Synchronization enginepriority/2This issue stalls work on the project or its dependents, it's a blocker for a releasestate/need-triageThis issue needs to be triagedtype/bugSomething isn't working as expected

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions