{"record":{"id":"b212017ce85279d2","repo":"dagger/dagger","slug":"find-git-ref-w","errorCode":null,"errorMessage":"find git ref: %w","messagePattern":"find git ref: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/dagger/workspace.go","lineNumber":975,"sourceCode":"\t\treturn workspaceRemoteAddress{}, \"\", false, err\n\t}\n\tif !ok {\n\t\treturn workspaceRemoteAddress{}, \"\", false, fmt.Errorf(\"inferred git origin %q is not a remote workspace address\", info.cloneRef)\n\t}\n\treturn remote, inferred, false, nil\n}\n\n// This is intentionally narrower than the workspace-git API: it only projects\n// a local checkout into a copy/pasteable remote workspace address, without\n// starting the engine or modeling full Git state.\nfunc currentGitRef(ctx context.Context, repoRoot string) (string, error) {\n\tref, err := gitOutput(ctx, repoRoot, \"symbolic-ref\", \"--quiet\", \"--short\", \"HEAD\")\n\tif err == nil && ref != \"\" {\n\t\treturn ref, nil\n\t}\n\tsha, err := gitOutput(ctx, repoRoot, \"rev-parse\", \"HEAD\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"find git ref: %w\", err)\n\t}\n\treturn sha, nil\n}\n\nfunc currentGitCommit(ctx context.Context, repoRoot string) (string, error) {\n\tsha, err := gitOutput(ctx, repoRoot, \"rev-parse\", \"--verify\", \"HEAD\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"find git commit: %w\", err)\n\t}\n\treturn sha, nil\n}\n\nfunc gitWorktreeDirty(ctx context.Context, repoRoot string) (bool, error) {\n\tstatus, err := gitOutput(ctx, repoRoot, \"status\", \"--porcelain\")\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"check git status: %w\", err)\n\t}\n\treturn status != \"\", nil","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/internal/cmd/dagger/workspace.go#L957-L993","documentation":"currentGitRef wraps a failure of `git rev-parse HEAD` with the message \"find git ref: ...\". It is reached only when `git symbolic-ref --quiet --short HEAD` fails (detached HEAD or not a git repo) AND the fallback `git rev-parse HEAD` also fails. This means the directory is not a valid git repository or has no commits at all.","triggerScenarios":"Running `dagger` workspace commands in a directory where .git is missing, corrupted, or where the repo has no commits (fresh `git init` with nothing committed), so rev-parse HEAD fails.","commonSituations":"Running in a freshly initialized repo before the first commit; running outside any repo; a corrupted .git directory; running in a CI workspace checked out without git metadata.","solutions":["Commit at least once in the repository (git commit) so HEAD resolves","Verify you are in a git repo: run `git rev-parse HEAD` yourself and fix per its message","Re-initialize or repair the repo: git init / git clone the project","Point the command at the correct repo root directory"],"exampleFix":"// shell\n# before: fresh git init, no commit -> error\n# after\ngit init && git add . && git commit -m initial","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(filepath.Join(repoRoot, \".git\")); err != nil {\n    return fmt.Errorf(\"%s is not a git repository\", repoRoot)\n}\nout, err := exec.CommandContext(ctx, \"git\", \"-C\", repoRoot, \"rev-parse\", \"HEAD\").CombinedOutput()\nif err != nil {\n    return fmt.Errorf(\"git repo has no commits: %s\", out)\n}","typeGuard":"func hasGitCommits(ctx context.Context, dir string) bool {\n    return exec.CommandContext(ctx, \"git\", \"-C\", dir, \"rev-parse\", \"--verify\", \"HEAD\").Run() == nil\n}","tryCatchPattern":"ref, err := currentGitRef(ctx, repoRoot)\nif errors.Is(err, exec.ErrNotFound) || strings.Contains(err.Error(), \"not a git repository\") {\n    // fall back to non-git workspace handling\n}","preventionTips":["Always run inside a committed git repository","Add a pre-flight `git rev-parse --verify HEAD` check in CI scripts","Avoid CI checkouts that strip .git metadata"],"tags":["git","cli","repository"],"backgroundTag":"not-a-git-repository","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}