I could be doing something completely incorrect here but I am running up against numerous issues when using a git repo as a directory argument.
type GitChange struct{}
// ChangedFiles returns a list of files that have changed
func (g *GitChange) ChangedFiles(
ctx context.Context,
// The source git repository. Can be a local path or a git url
// +required
src *dagger.Directory,
// ssh auth socket to use for private repositories
// +required
sshAuthSock *dagger.Socket,
// The base ref that headRef is compared against . Can be a branch, tag, or commit hash
// +optional
// +default="HEAD"
baseRef string,
// The current ref. Can be a branch, tag, or commit hash
// +optional
// +default="main"
headRef string,
) (string, error) {
repoPath := "/repo"
sockPath := "/ssh-agent/agent.sock"
output, err := dag.Container().
From(dockerImage).
WithDirectory(repoPath, src).
WithWorkdir(repoPath).
WithUnixSocket(sockPath, sshAuthSock).
WithEnvVariable("SSH_AUTH_SOCK", sockPath).
WithExec([]string{"sh", "-c", "mkdir ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts"}).
WithExec([]string{"git", "fetch"}).
WithExec([]string{"git", "tag", "-d", "main"}).
Terminal().
WithExec([]string{"git", "diff", "--name-only", fmt.Sprintf("%s..%s", baseRef, headRef)}).
Stdout(ctx)
if err != nil {
return "", err
}
return output, nil
}
- There seems to a random
git tagcreated e.g.main- hence having to dogit tag -d main - This fails as any commit hash passed as base ref is not in the git history e.g. running
git checkout HASHreturnsfatal: unable to read tree
I have tried git fetch orgin and git reset --hard origin/main to no avail. If I clone the repo directly on the container then it works as expected.
Im happy to be pointed as skills issue with git here....