Skip to content

Cloning fails for repos using 'main' as the default branch name #286

Closed
@marcomicera

Description

@marcomicera

Bug description

When omitting the branch name (GIT_SYNC_BRANCH/--branch), I would assume that the default branch would be synced.
The default branch name has been hardcoded as "master", but that's not always the case (junit uses "main", for instance).

MWE

Just cloning a repo and listing its content.

apiVersion: batch/v1
kind: Job
metadata:
  name: clone-main-branch
spec:
  backoffLimit: 1
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: lister
        image: alpine
        command: [ "sh", "-c", "ls /home/project" ]
        volumeMounts:
        - name: repo-volume
          mountPath: /home
      initContainers:
      - name: cloner
        image: k8s.gcr.io/git-sync/git-sync:v3.1.7
        env:
#          - name: GIT_SYNC_REPO
#            value: https://github.com/google/guava # Works. Default branch name: master.
          - name: GIT_SYNC_REPO
            value: http://github.com/junit-team/junit # Doesn't work. Default branch name: main.
          - name: GIT_SYNC_ROOT
            value: /home
          - name: GIT_SYNC_DEST
            value: project
          - name: GIT_SYNC_ONE_TIME
            value: "1"
          - name: GIT_SYNC_DEPTH
            value: "1"
          - name: GIT_SYNC_SUBMODULES
            value: "shallow"
        volumeMounts:
          - name: repo-volume
            mountPath: /home
      volumes:
      - name: repo-volume
        emptyDir: {}

Proposed solution

  1. Set the default branch name to an empty string or nil.
  2. Avoid using git's -b flag when the previous variable is empty/nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions