Skip to content

fix(project): skip defaultBranch late-init for empty repo - #459

Open
henrysachs wants to merge 1 commit into
masterfrom
fix/project-empty-repo-default-branch
Open

henrysachs wants to merge 1 commit into
masterfrom
fix/project-empty-repo-default-branch

Conversation

@henrysachs

Copy link
Copy Markdown
Collaborator

Description of your changes

Fixes #444

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review. Ran go build ./..., go test ./pkg/... ./apis/..., go generate for apis and pkg (no diff), and golangci-lint on touched packages.

Why

A Project without a repository goes Synced: False on its first update. GitLab reports default_branch: main and empty_repo: true for an empty project. Observe late-initialized defaultBranch from that value. Every later update sent default_branch=main back, and GitLab rejects it with Could not change HEAD: branch 'main' does not exist.

What changed

  • lateInitialize skips defaultBranch while empty_repo is true. It late-inits as before once the repo has a commit.
  • An explicitly set defaultBranch is kept on empty repos, so GitLab's error still surfaces instead of being dropped.
  • New table test TestLateInitializeDefaultBranch for empty/non-empty repo with unset/explicit spec.
  • Cluster-scoped copies regenerated.

Scope

Project controller late-init only. No API or CRD change. Drift check for defaultBranch is unchanged; an unset spec is never compared.

Verification

  • API on GitLab 19.4.2-ee: empty project returns default_branch: main, empty_repo: true. PUT default_branch=main returns 400 Could not change HEAD. PUT description=x returns 200.
  • Mutation: forcing the late-init unconditionally fails TestLateInitializeDefaultBranch/EmptyRepoUnset.
  • Live on kind with a local provider against the same GitLab:
    • Project with only name: Ready, defaultBranch unset. Description change: Synced=True, GitLab shows the new description.
    • After creating README.md on main via API: empty_repo: false, defaultBranch late-inits to main. A further description change stays Synced=True.
    • Project with explicit defaultBranch: main on an empty repo: update fails with GitLab's Could not change HEAD error, as intended.
    • Delete removes the project.

How has this code been tested

See Verification.

GitLab reports default_branch for empty repos although the branch does not exist and rejects it on edit.

Signed-off-by: Henry Sachs <henry.sachs@deutschebahn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(project): update fails on empty project after defaultBranch late-init

1 participant