Commit

Author:

Hash:

Timestamp:

+44 -7 +/-4 browse

Kevin Schoon [me@kevinschoon.com]

d4da3b10ed18ac7a275e7ea18cdf1ad55dcc5676

Wed, 09 Sep 2026 08:19:57 +0000 (2 months ago)

fix quipu so it resolves global state automatically
1diff --git a/crates/git/src/lib.rs b/crates/git/src/lib.rs
2index 493db05..f09b584 100644
3--- a/crates/git/src/lib.rs
4+++ b/crates/git/src/lib.rs
5 @@ -10,7 +10,9 @@ pub use clone::clone;
6 pub use config::{ChatKind, ChatLink, Config, Sites};
7 pub use error::Error;
8 pub use lite::{Blob, Branch, Commit, Kind, Note, Reference, Stats, Tag, TreeEntry};
9- pub use scanner::{Scanner, collection, collection_and_name, contains, find, git_dir, name};
10+ pub use scanner::{
11+ Scanner, collection, collection_and_name, contains, find, git_dir, name, resolve,
12+ };
13 pub use wrapper::{Selector, Wrapper};
14
15 mod bundle;
16 diff --git a/crates/git/src/scanner.rs b/crates/git/src/scanner.rs
17index 64654f9..27b171e 100644
18--- a/crates/git/src/scanner.rs
19+++ b/crates/git/src/scanner.rs
20 @@ -2,7 +2,7 @@ use std::fs::{ReadDir, metadata, read_dir};
21 use std::io::Error;
22 use std::path::{Path, PathBuf};
23
24- use crate::{Collection, Repository};
25+ use crate::{Collection, Repository, Wrapper};
26
27 /// Represents the variant of git repository (bare or non-bare)
28 pub(crate) enum Kind {
29 @@ -88,6 +88,32 @@ pub fn collection_and_name(path: &Path) -> (String, String) {
30 (collection(path), name(path))
31 }
32
33+ /// Return the collection and repository at the path if it is part of a managed
34+ /// collection, otherwise return None.
35+ pub fn resolve(
36+ collections: &[Collection],
37+ path: &Path,
38+ ) -> Result<Option<(Collection, crate::Repository)>, Error> {
39+ let abs = std::fs::canonicalize(path)?;
40+ collections
41+ .iter()
42+ .find(|collection| abs.starts_with(&collection.path))
43+ .map_or(Ok(None), |collection| {
44+ Ok(Some((
45+ collection.clone(),
46+ crate::Repository {
47+ name: path
48+ .file_name()
49+ .map(|name| name.to_str().unwrap().to_string())
50+ .unwrap(),
51+ path: path.to_path_buf(),
52+ reference: None,
53+ commit: None,
54+ },
55+ )))
56+ })
57+ }
58+
59 /// Find the file system path of the collection/repository name
60 pub fn find(
61 collections: &[Collection],
62 diff --git a/quipu/src/main.rs b/quipu/src/main.rs
63index 70af929..8215b1c 100644
64--- a/quipu/src/main.rs
65+++ b/quipu/src/main.rs
66 @@ -98,7 +98,7 @@ async fn main() -> Result<(), error::QuipuError> {
67 let mut db = Database::new_ro(&cfg.database.path)?;
68 let blob = Blob::new(&cfg.database.path)?;
69 let mut conn = db.call();
70- let scope = Scope::new(cli.global)?;
71+ let scope = Scope::new(&cfg.collections, cli.global)?;
72 match build {
73 ayllu_cmd::quipu::Build::List { limit, offset } => {
74 let manifests =
75 diff --git a/quipu/src/scope.rs b/quipu/src/scope.rs
76index f5f14a6..e1800fc 100644
77--- a/quipu/src/scope.rs
78+++ b/quipu/src/scope.rs
79 @@ -1,3 +1,5 @@
80+ use ayllu_git::Collection;
81+
82 use crate::error::QuipuError;
83
84 pub enum Scope {
85 @@ -6,13 +8,20 @@ pub enum Scope {
86 }
87
88 impl Scope {
89- pub fn new(global: bool) -> Result<Self, QuipuError> {
90+ pub fn new(collections: &[Collection], global: bool) -> Result<Self, QuipuError> {
91 if global {
92 Ok(Self::Global)
93 } else {
94- let current_path = std::env::current_dir()?.canonicalize()?;
95- let (collection, name) = ayllu_git::collection_and_name(current_path.as_path());
96- Ok(Self::Repository { collection, name })
97+ if let Some((collection, repository)) =
98+ ayllu_git::resolve(collections, &(std::env::current_dir()?))?
99+ {
100+ Ok(Self::Repository {
101+ collection: collection.name.to_string(),
102+ name: repository.name.to_string(),
103+ })
104+ } else {
105+ Ok(Self::Global)
106+ }
107 }
108 }
109