{"record":{"id":"0c09fc0732b1dd0d","repo":"nektos/act","slug":"head-sha1-could-not-be-resolved","errorCode":null,"errorMessage":"HEAD sha1 could not be resolved","messagePattern":"HEAD sha1 could not be resolved","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/common/git/git.go","lineNumber":77,"sourceCode":"\t\tfile,\n\t\t&git.PlainOpenOptions{\n\t\t\tDetectDotGit:          true,\n\t\t\tEnableDotGitCommonDir: true,\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"path\", file, \"not located inside a git repository\")\n\t\treturn \"\", \"\", err\n\t}\n\n\thead, err := gitDir.Reference(plumbing.HEAD, true)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\tif head.Hash().IsZero() {\n\t\treturn \"\", \"\", fmt.Errorf(\"HEAD sha1 could not be resolved\")\n\t}\n\n\thash := head.Hash().String()\n\n\tlogger.Debugf(\"Found revision: %s\", hash)\n\treturn hash[:7], strings.TrimSpace(hash), nil\n}\n\n// FindGitRef get the current git ref\nfunc FindGitRef(ctx context.Context, file string) (string, error) {\n\tlogger := common.Logger(ctx)\n\n\tlogger.Debugf(\"Loading revision from git directory\")\n\t_, ref, err := FindGitRevision(ctx, file)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/nektos/act/blob/4f411281417e88660bea1c1a1749aa71ae0bd60f/pkg/common/git/git.go#L59-L95","documentation":"FindGitRevision resolves HEAD via go-git; if the HEAD reference exists but its hash is all-zero, the commit cannot be identified. A zero hash means the repository has no commits on the current branch — an 'unborn' HEAD, typical of a freshly git init'ed repo with everything still uncommitted.","triggerScenarios":"Running act in a directory that is a git repo with zero commits (git init; add files; never commit), or a worktree/repo whose HEAD symbolic ref points at a branch that was never created by a commit. Any act feature needing GITHUB_SHA (action ref checkout, default ref resolution) hits it.","commonSituations":"Quick experiments: user inits a repo, drops a workflow in .github/workflows/, runs act before the first commit; CI checkouts of empty repos; scaffolding tools that git init but defer the first commit.","solutions":["Make at least one commit in the repository (git add -A && git commit -m 'init') and rerun act","If testing workflow syntax only, bypass ref resolution features that need the SHA","Verify with 'git rev-parse HEAD' — it should print a hash, not fail"],"exampleFix":"# before\ngit init && cp -r myworkflow .github/workflows/ && act  # zero-hash HEAD\n\n# after\ngit init && git add -A && git commit -m 'init' && act","handlingStrategy":"validation","validationCode":"// before running act, ensure HEAD resolves\nif out, err := exec.Command(\"git\", \"-C\", dir, \"rev-parse\", \"HEAD\").Output(); err != nil {\n    return fmt.Errorf(\"repo has no commits; commit first: %w\", err)\n} else {\n    log.Printf(\"HEAD = %s\", strings.TrimSpace(string(out)))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always commit before running act in a new repo","Script 'git rev-parse HEAD' as a preflight check","In CI, run act only after the checkout step has fetched refs"],"tags":["git","revision","empty-repo","act"],"backgroundTag":null,"analyzedSha":"4f411281417e88660bea1c1a1749aa71ae0bd60f","analyzedAt":"2026-08-15T09:19:46.307Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}