gastownhall/beads · warning

auto-export: git add failed: %w

Error message

auto-export: git add failed: %w

What it means

maybeAutoExport optionally stages the exported .beads/issues.jsonl with git when config export.git-add is true, no-git-ops is not set, and the directory is a git repo. If gitAddFile fails (git itself errored), the export state is not saved and this wrapped error is returned so the caller can warn/abort.

Source

Thrown at cmd/bd/export_auto.go:227

	if issueCount == 0 && memoryCount == 0 {
		_ = os.Remove(fullPath)
		saveExportAutoState(beadsDir, &exportAutoState{
			LastDoltCommit: currentCommit,
			LastDiffAnchor: anchorCommit,
			LastDirtyIDs:   dirtyIDs,
			Timestamp:      time.Now(),
			Issues:         0,
			Memories:       0,
		})
		return nil
	}
	warnJSONLWithoutDoltRemote("auto-export")

	// Optional git add — skip when no-git-ops is set (GH#3314), when not in a
	// git repo (standalone BEADS_DIR flow), or when export.git-add is false.
	if config.GetBool("export.git-add") && !config.GetBool("no-git-ops") && isGitRepo() {
		if err := gitAddFile(fullPath); err != nil {
			return fmt.Errorf("auto-export: git add failed: %w", err)
		}
	}

	// Save state
	newState := exportAutoState{
		LastDoltCommit: currentCommit,
		LastDiffAnchor: anchorCommit,
		LastDirtyIDs:   dirtyIDs,
		Timestamp:      time.Now(),
		Issues:         issueCount,
		Memories:       memoryCount,
	}
	saveExportAutoState(beadsDir, &newState)
	return nil
}

// storeStateHash returns the hash used for auto-export change detection.
// It prefers a working-set-aware hash (storage.StateHasher) over the HEAD

View on GitHub (pinned to 71377f2769)

Solutions

  1. Re-run after the competing git process exits (check for .git/index.lock and remove it only if stale)
  2. Ensure the working directory is a healthy git repo (`git status`) and git is installed
  3. Set `no-git-ops` or export.git-add=false to skip staging; the JSONL export itself still succeeded
  4. Check git's own stderr via the wrapped cause for safe.directory/permission hints
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-checks matching the command's own guards
if !isGitRepo() || config.GetBool("no-git-ops") || !config.GetBool("export.git-add") { skipGitAdd() }
if _, err := os.Stat(".git/index.lock"); err == nil { deferGitAdd() }

Try / catch

if err := maybeAutoExport(ctx); err != nil {
    if strings.Contains(err.Error(), "git add failed") {
        // export already written; stage later or disable export.git-add
        log.Warn("auto-export staged export failed", "err", err)
    }
}

Prevention

When it happens

Trigger: gitAddFile fails: git not on PATH, path not actually in a git repo despite isGitRepo race, git index.lock held by another process, or git hook/permission failures on add.

Common situations: Concurrent `bd` and IDE git operations contending for .git/index.lock; BEADS_DIR relocated outside the repo mid-run; bare-broken git install; ownership/safe.directory errors in containers.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/6c6c4bfcf4b5453a. Report an issue: GitHub.