#Using Git in CircleCI within Function adds random `main` tag

1 messages · Page 1 of 1 (latest)

forest mural
#

I am running the following as I could not replicate an issue locally on Macbook with what was going on in CircleCI:

func (s *Service) Checkout(ctx context.Context, sshAuthSock *dagger.Socket) {
  git := dag.Git("git@github.com:company/my-repo.git", dagger.GitOpts{
        SSHAuthSocket: sshAuthSock,
    })

    container, err := dag.Container().
        From("alpine").
        WithUnixSocket("/ssh-agent/agent.sock", sshAuthSock).
        WithEnvVariable("SSH_AUTH_SOCK", "/ssh-agent/agent.sock").
        WithExec([]string{"apk", "add", "curl", "jq", "aws-cli", "git", "openssh-client"}).
        WithDirectory("/my-repo", git.Head().Tree()). // Also tried this with `git.Branch("main").Tree()
        WithExec([]string{"sh", "-c", "git checkout main"}).
        Terminal().Sync(ctx)
}

In the terminal if I try and checkout main I am presented with the following:

warning: refname 'main' is ambiguous.
Switched to branch 'main'

And this seems to be caused by a tag being created called main. This tag does not exist and this issue is not happening when running the same locally. I have tried to use the machine executor within circleci but still got the same issue

pliant bobcat
forest mural
#

I have tried both

#

Both add a main tag

#

This is a secondary issue to the main one when I was trying to tag and push back to repo. I was getting

xxxxx@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access right

Confused me and initially thought it was this tag that was causing it but seems like looking into the git config the remote.origin.url is not being correctly set. i.e. it is

remote.origin.url=ssh://xxxxx@github.com/company/my-repo
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
#

This doesnt happen on my Mac. Both are running dagger v0.14.0 - Im starting to think the issue is with the circleci image and not dagger

#

I did the same locally using the cimg:base-2024.11 docker image and getting exact same