Skip to content

Conversation

zhangfengcdt
Copy link
Owner

@zhangfengcdt zhangfengcdt commented Aug 24, 2025

Summary

  • Fixed init function in versioned_store.rs to detect and load existing stores instead of reinitializing them
  • Prevents data loss when init is called on directories with existing ProllyTree data
  • Adds proper test coverage for this scenario

Problem

The init function was always creating a new store with default configuration and an "Initial commit", even when prolly config files already existed in the directory. This could lead to:

  • Data loss as existing trees would be overwritten
  • Duplicate "Initial commit" entries in git history
  • Confusion when existing stores appeared to be reset

Solution

Added a check in the init function to detect existing prolly config files (prolly_config_tree_config and prolly_hash_mappings). When either file exists, the function now calls open() to load the existing configuration instead of creating a new one.

Test Plan

  • Added unit test test_init_with_existing_store that verifies data persistence across multiple init calls
  • Manually tested with git-prolly CLI to confirm existing data is preserved
  • All existing tests pass
  • cargo fmt and clippy checks pass

Example

# First initialization
git-prolly init
git-prolly set key1 value1
git-prolly commit -m "Add key1"

# Second init (previously would reset, now loads existing)
git-prolly init
git-prolly get key1  # Returns "value1" - data preserved!

The init function in versioned_store.rs was creating a new store even when one already existed, potentially causing data loss. This fix adds a check for existing prolly config files before initialization.

Changes:
- Added check for prolly_config_tree_config and prolly_hash_mappings files in init()
- If either file exists, calls open() to load the existing store instead of creating a new one
- Added comprehensive test to verify the behavior

This ensures that repeatedly calling init on the same directory preserves existing data and doesn't create duplicate Initial commit entries.

Fixes the issue where init would overwrite an existing store configuration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@zhangfengcdt zhangfengcdt merged commit 897803d into main Aug 24, 2025
4 checks passed
@zhangfengcdt zhangfengcdt deleted the bugfix/fixVersionedStore.init branch August 26, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant