Repository navigation
fix: handle BEADS_DB pointing to directory instead of file - #2549
Merged
Merged
Conversation
When BEADS_DB is set to a directory path (like .beads/) rather than a .db file, FindDatabasePath() returned the directory itself. The caller at main.go:476 does filepath.Dir(dbPath) to derive beadsDir, which resolves one level too high when dbPath is a directory — creating stray dolt/ directories and broken server connections. Fix: when BEADS_DB points to a directory, treat it like BEADS_DIR by calling findDatabaseInBeadsDir() to return the dolt/ subdirectory path. This makes filepath.Dir() in the caller resolve correctly. Includes two regression tests: - TestFindDatabasePath_BEADS_DB_Directory: verifies BEADS_DB pointing to a directory produces the same filepath.Dir() result as BEADS_DIR - TestFindDatabasePath_BEADS_DB_DirectoryTrailingSlash: verifies trailing slash doesn't change the outcome Fixes #2548
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FindDatabasePath()to detect whenBEADS_DBpoints to a directory and delegate tofindDatabaseInBeadsDir(), matchingBEADS_DIRbehaviorFixes #2548
Problem
When
BEADS_DBis set to a directory path (like.beads/),FindDatabasePath()returns the directory itself. The caller atmain.go:476doesbeadsDir := filepath.Dir(dbPath), which strips one level too many — yielding the parent of.beads/instead of.beads/. This causes:ResolveDoltDir()to create a straydolt/directory at the parent levelThe
BEADS_DIRcode path works correctly becausefindDatabaseInBeadsDir()returns.beads/dolt(a path inside.beads/), sofilepath.Dir()yields.beads/.Fix
When
BEADS_DBpoints to a directory (not a file), treat it likeBEADS_DIRby callingfindDatabaseInBeadsDir()to look for the database inside it. This is a 6-line change ininternal/beads/beads.go.Test plan
TestFindDatabasePath_BEADS_DB_Directory— verifiesfilepath.Dir(FindDatabasePath())resolves to.beads/for bothBEADS_DIRandBEADS_DB-as-directory (failed before fix, passes after)TestFindDatabasePath_BEADS_DB_DirectoryTrailingSlash— verifies trailing slash doesn't bypass the fixFindDatabasePathtests pass (-shortmode)golangci-lintpasses with 0 issues