fix: show diverged-history guidance on auto-push failure (#3138)

* fix: show diverged-history guidance on auto-push failure

When dolt auto-push fails with a 'no common ancestor' error, the user
only sees a cryptic warning. The explicit 'bd dolt push' and 'bd dolt
pull' commands already detect this and print recovery guidance via
printDivergedHistoryGuidance(), but the auto-push path did not.

Now auto-push also calls isDivergedHistoryErr() and prints the same
actionable recovery options (bootstrap, force-push, or re-init).

Amp-Thread-ID: https://ampcode.com/threads/T-019d6ee7-e46d-74f8-8b6e-2a0fc1b2d4d7
Co-authored-by: Amp <amp@ampcode.com>

* fix: store secret config keys in config.yaml, not Dolt DB

Keys like github.token and linear.api_key were stored in the Dolt
database's config table. When auto-push sends that data to a GitHub
remote, GitHub's push protection blocks the push because it detects
embedded secrets in the Dolt data files.

Fix: add github.token and linear.api_key to YamlOnlyKeys so they're
written to .beads/config.yaml (local-only, gitignored) instead of
the Dolt database. Update the read paths in getGitHubConfigValue()
and getLinearConfig() to check YAML config first for these keys.

Amp-Thread-ID: https://ampcode.com/threads/T-019d6ee7-e46d-74f8-8b6e-2a0fc1b2d4d7
Co-authored-by: Amp <amp@ampcode.com>

---------

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
matt wilkie 2026-04-08 15:55:37 -07:00 • committed by GitHub
commit 64678bcb34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 8 deletions

View file

@ -142,6 +142,9 @@ func maybeAutoPush(ctx context.Context) {
if err := st.Push(ctx); err != nil {
if !isQuiet() && !jsonOutput {
fmt.Fprintf(os.Stderr, "Warning: dolt auto-push failed: %v\n", err)
if isDivergedHistoryErr(err) {
printDivergedHistoryGuidance("push")
}
}
debug.Logf("dolt auto-push: push error: %v\n", err)
return

View file

@ -187,6 +187,22 @@ func getGitHubConfig() GitHubConfig {
// getGitHubConfigValue reads a GitHub configuration value from store or environment.
func getGitHubConfigValue(ctx context.Context, key string) string {
// Secret keys (e.g. github.token) are stored in config.yaml, not the
// Dolt database, to avoid leaking secrets when pushing to remotes.
if config.IsYamlOnlyKey(key) {
if value := config.GetString(key); value != "" {
return value
}
// Fall back to environment variable
envKey := githubConfigToEnvVar(key)
if envKey != "" {
if value := os.Getenv(envKey); value != "" {
return value
}
}
return ""
}
// Try to read from store (works in direct mode)
if store != nil {
value, _ := store.GetConfig(ctx, key)

View file

@ -557,6 +557,21 @@ func maskAPIKey(key string) string {
// getLinearConfig reads a Linear configuration value. Returns the value and its source.
// Priority: project config > environment variable.
func getLinearConfig(ctx context.Context, key string) (value string, source string) {
// Secret keys (e.g. linear.api_key) are stored in config.yaml, not the
// Dolt database, to avoid leaking secrets when pushing to remotes.
if config.IsYamlOnlyKey(key) {
if value := config.GetString(key); value != "" {
return value, "project config (config.yaml)"
}
envKey := linearConfigToEnvVar(key)
if envKey != "" {
if value := os.Getenv(envKey); value != "" {
return value, fmt.Sprintf("environment variable (%s)", envKey)
}
}
return "", ""
}
// Try to read from store (works in direct mode)
if store != nil {
value, _ = store.GetConfig(ctx, key) // Best effort: empty value is valid fallback

View file

@ -151,6 +151,9 @@ func TestResolveCommandBeadsDir_NoCWDFallbackForExplicitPath(t *testing.T) {
}
func TestGetGitHubConfigValue_UsesMetadataWhenStoreNil(t *testing.T) {
// github.token is now a YAML-only key (not stored in Dolt DB) to avoid
// leaking secrets when pushing to remotes. Test that the env-var fallback
// still works when the store is nil.
originalStore := store
originalDBPath := dbPath
defer func() {
@ -159,14 +162,10 @@ func TestGetGitHubConfigValue_UsesMetadataWhenStoreNil(t *testing.T) {
}()
ctx := context.Background()
testDBPath := filepath.Join(t.TempDir(), "dolt")
testStore := newTestStoreIsolatedDB(t, testDBPath, "cfg")
if err := testStore.SetConfig(ctx, "github.token", "ghp_test_token"); err != nil {
t.Fatalf("SetConfig: %v", err)
}
store = nil
dbPath = testDBPath
dbPath = ""
t.Setenv("GITHUB_TOKEN", "ghp_test_token")
if got := getGitHubConfigValue(ctx, "github.token"); got != "ghp_test_token" {
t.Fatalf("getGitHubConfigValue() = %q, want %q", got, "ghp_test_token")

View file

@ -65,6 +65,12 @@ var YamlOnlyKeys = map[string]bool{
// Dolt server settings
"dolt.idle-timeout": true, // Idle auto-stop timeout (default "30m", "0" disables)
"dolt.shared-server": true, // Shared Dolt server at ~/.beads/shared-server/ (GH#2377)
// Secrets: tokens and API keys must NOT be stored in the Dolt database
// because that data is pushed to remotes, triggering secret-scanning
// blocks on GitHub. Store them in local config.yaml instead.
"github.token": true,
"linear.api_key": true,
}
// IsYamlOnlyKey returns true if the given key should be stored in config.yaml

View file

@ -37,10 +37,13 @@ func TestIsYamlOnlyKey(t *testing.T) {
{"backup.git-repo", true},
{"backup.future-key", true}, // prefix match
// Secret keys (stored in yaml to avoid leaking via Dolt push)
{"github.token", true},
{"linear.api_key", true},
// Non-yaml keys (should return false)
{"jira.url", false},
{"jira.project", false},
{"linear.api_key", false},
{"github.org", false},
{"custom.setting", false},
{"status.custom", false},