refactor(doctor): simplify shared-store beads resolution

intent(doctor): keep the bare worktree fix readable after the behavior change landed
decision(shared-store): extract small helpers for resolved beads directories and local-dolt requirements instead of repeating nil and config checks
constraint(doctor): simplification must preserve the same server-mode behavior and test coverage added in the previous fix
This commit is contained in:
Osamu Okano 2026-03-23 17:37:20 +09:00
commit 693c714328
No known key found for this signature in database
GPG key ID: 7C170795EE6DE82B
3 changed files with 28 additions and 20 deletions

View file

@ -91,14 +91,10 @@ func CheckDatabaseVersion(path string, cliVersion string) DoctorCheck {
// CheckDatabaseVersionWithStore checks the database version using a shared store (GH#2636).
func CheckDatabaseVersionWithStore(ss *SharedStore, cliVersion string) DoctorCheck {
beadsDir := ""
if ss != nil {
beadsDir = ss.BeadsDir()
}
beadsDir := sharedStoreBeadsDir(ss)
store := ss.Store()
if store == nil {
cfg, err := configfile.Load(beadsDir)
if err == nil && cfg != nil && cfg.IsDoltServerMode() {
if !sharedStoreNeedsLocalDoltDir(beadsDir) {
return DoctorCheck{
Name: "Database",
Status: StatusError,

View file

@ -93,10 +93,8 @@ func CheckPermissions(path string) DoctorCheck {
// CheckPermissionsWithStore verifies permissions using a shared store (GH#2636).
// If the shared store was opened successfully, the database is accessible.
func CheckPermissionsWithStore(path string, ss *SharedStore) DoctorCheck {
beadsDir := ResolveBeadsDirForRepo(path)
if ss != nil && ss.BeadsDir() != "" {
beadsDir = ss.BeadsDir()
}
beadsDir := beadsDirFromSharedStore(path, ss)
store := ss.Store()
// Check if .beads/ is writable
testFile := filepath.Join(beadsDir, ".doctor-test-write")
@ -113,9 +111,8 @@ func CheckPermissionsWithStore(path string, ss *SharedStore) DoctorCheck {
// Check Dolt database directory permissions
cfg, err := configfile.Load(beadsDir)
if err == nil && cfg != nil && cfg.GetBackend() == configfile.BackendDolt {
doltPath := getDatabasePath(beadsDir)
if cfg.IsDoltServerMode() {
if ss == nil || ss.Store() == nil {
if store == nil {
return DoctorCheck{
Name: "Permissions",
Status: StatusError,
@ -129,6 +126,8 @@ func CheckPermissionsWithStore(path string, ss *SharedStore) DoctorCheck {
Message: "All permissions OK",
}
}
doltPath := getDatabasePath(beadsDir)
if info, err := os.Stat(doltPath); err == nil {
if !info.IsDir() {
return DoctorCheck{
@ -139,7 +138,7 @@ func CheckPermissionsWithStore(path string, ss *SharedStore) DoctorCheck {
}
}
// If shared store is nil, the database could not be opened
if ss.Store() == nil {
if store == nil {
return DoctorCheck{
Name: "Permissions",
Status: StatusError,

View file

@ -26,6 +26,25 @@ type SharedStore struct {
beadsDir string
}
func beadsDirFromSharedStore(path string, ss *SharedStore) string {
if beadsDir := sharedStoreBeadsDir(ss); beadsDir != "" {
return beadsDir
}
return ResolveBeadsDirForRepo(path)
}
func sharedStoreBeadsDir(ss *SharedStore) string {
if ss == nil {
return ""
}
return ss.BeadsDir()
}
func sharedStoreNeedsLocalDoltDir(beadsDir string) bool {
cfg, err := configfile.Load(beadsDir)
return err != nil || cfg == nil || !cfg.IsDoltServerMode()
}
// NewSharedStore opens a single read-only DoltStore for the given repo path.
// If the database doesn't exist or can't be opened, Store() will return nil.
// The caller MUST call Close() when done (typically via defer).
@ -33,13 +52,7 @@ func NewSharedStore(path string) *SharedStore {
beadsDir := ResolveBeadsDirForRepo(path)
ss := &SharedStore{beadsDir: beadsDir}
cfg, err := configfile.Load(beadsDir)
if err != nil || cfg == nil {
doltPath := getDatabasePath(beadsDir)
if _, err := os.Stat(doltPath); os.IsNotExist(err) {
return ss // No database, store stays nil
}
} else if !cfg.IsDoltServerMode() {
if sharedStoreNeedsLocalDoltDir(beadsDir) {
doltPath := getDatabasePath(beadsDir)
if _, err := os.Stat(doltPath); os.IsNotExist(err) {
return ss // No database, store stays nil