From 820fd706a24be7a58554a27e411e120cfa28d9a6 Mon Sep 17 00:00:00 2001 From: m0wer Date: Sun, 29 Mar 2026 16:45:52 +0200 Subject: feat: git worktree support Git worktrees don't have a .git directory with a parent, so we need to look for the git dir via git2's Repository::discover() and then look for the cache database there. This allows the client to work correctly when run from a worktree, and also allows the cache database to be shared between the main repo and its worktrees (since they share the same git dir and thus the same cache path). --- src/lib/client.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/lib/client.rs') diff --git a/src/lib/client.rs b/src/lib/client.rs index 01662cd..86e4097 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -1325,14 +1325,22 @@ fn pb_after_style(succeed: bool) -> indicatif::ProgressStyle { } async fn get_local_cache_database(git_repo_path: &Path) -> Result { - NostrLMDB::open(git_repo_path.join(".git/nostr-cache.lmdb")) - .context("failed to open or create nostr cache database at .git/nostr-cache.lmdb") + let git_dir = git2::Repository::discover(git_repo_path) + .context("failed to discover git repository")? + .commondir() + .to_path_buf(); + NostrLMDB::open(git_dir.join("nostr-cache.lmdb")) + .context("failed to open or create nostr cache database at /nostr-cache.lmdb") } async fn get_global_cache_database(git_repo_path: Option<&Path>) -> Result { let path = if std::env::var("NGITTEST").is_ok() { if let Some(git_repo_path) = git_repo_path { - git_repo_path.join(".git/test-global-cache.lmdb") + let git_dir = git2::Repository::discover(git_repo_path) + .context("failed to discover git repository")? + .commondir() + .to_path_buf(); + git_dir.join("test-global-cache.lmdb") } else { bail!("git_repo must be supplied to get_global_cache_database during integration tests") } -- cgit v1.2.3