commit-wizard 0.0.2

A lightweight CLI assistant for Conventional Commits, semantic versioning, and changelog automation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
use std::path::PathBuf;

use crate::engine::{
    LoggerTrait,
    config::{
        BaseConfig,
        env::build_env_config,
        registry::{RegistrySpec, load_registry, resolve_registry_spec},
        resolver::{resolve_global_configs, resolve_project_configs},
    },
    constants::resolve_project_config_path,
    models::policy::Policy,
};

pub mod mode;
pub mod options;
pub mod resolution;
pub use options::*;
pub use resolution::*;

#[derive(Debug, Clone)]
pub struct Runtime {
    // the mode we are running in, determined at runtime based on args and environment
    mode: mode::RunMode,
    // options that affect how we run, determined at runtime based on args and environment
    options: RuntimeOptions,
    // paths and environment information, determined at runtime
    paths: RuntimePaths,
    // the config options we have available, determined at runtime
    resolution: RuntimeResolution,
}

impl Default for Runtime {
    fn default() -> Self {
        Self::new()
    }
}

impl Runtime {
    pub fn output_config(&self) -> scriba::Config {
        scriba::Config {
            interactive: matches!(self.mode, mode::RunMode::Interactive),
            format: self.options.output_format(),
            color: self.options.output_color(),
            level: self.options.log_level(),
            auto_yes: self.options.auto_yes(),
        }
    }

    // -------------------------
    // getters
    // -------------------------

    pub fn is_ci(&self) -> bool {
        matches!(self.mode, mode::RunMode::Ci)
    }

    pub fn is_non_interactive(&self) -> bool {
        matches!(self.mode, mode::RunMode::NonInteractive)
    }

    pub fn is_interactive(&self) -> bool {
        matches!(self.mode, mode::RunMode::Interactive)
    }

    pub fn mode(&self) -> &mode::RunMode {
        &self.mode
    }

    pub fn options(&self) -> &RuntimeOptions {
        &self.options
    }

    pub fn options_mut(&mut self) -> &mut RuntimeOptions {
        &mut self.options
    }

    pub fn cwd(&self) -> &PathBuf {
        &self.paths.cwd
    }

    pub fn in_git_repo(&self) -> bool {
        self.paths.in_git_repo
    }

    pub fn repo_root(&self) -> &PathBuf {
        self.paths.repo_root.as_ref().unwrap_or(&self.paths.cwd)
    }

    pub fn global_paths(&self) -> &RuntimeGlobalPaths {
        &self.paths.global
    }

    pub fn global_config_path(&self) -> &PathBuf {
        &self.paths.global.config
    }

    pub fn global_cache_path(&self) -> &PathBuf {
        &self.paths.global.cache
    }

    pub fn global_state_path(&self) -> &PathBuf {
        &self.paths.global.state
    }

    pub fn state_file_path(&self) -> PathBuf {
        use crate::engine::constants::STATE_FILE_NAME;
        self.paths.global.state.join(STATE_FILE_NAME)
    }

    pub fn sources(&self) -> &AvailableConfigOptions {
        &self.resolution.sources
    }

    pub fn sources_mut(&mut self) -> &mut AvailableConfigOptions {
        &mut self.resolution.sources
    }

    pub fn config(&self) -> Option<&ResolvedConfig> {
        self.resolution.config.as_ref()
    }

    pub fn config_mut(&mut self) -> Option<&mut ResolvedConfig> {
        self.resolution.config.as_mut()
    }

    pub fn policy(&self) -> &Policy {
        &self.resolution.policy
    }

    pub fn policy_mut(&mut self) -> &mut Policy {
        &mut self.resolution.policy
    }

    // -------------------------
    // setters
    // -------------------------

    pub fn set_mode(&mut self, mode: mode::RunMode) -> &mut Self {
        self.mode = mode;
        self
    }

    pub fn set_dry_run(&mut self, dry_run: bool) -> &mut Self {
        self.options.set_dry_run(dry_run);
        self
    }

    pub fn set_auto_yes(&mut self, auto_yes: bool) -> &mut Self {
        self.options.set_auto_yes(auto_yes);
        self
    }

    pub fn set_force(&mut self, force: bool) -> &mut Self {
        self.options.set_force(force);
        self
    }

    pub fn set_output_envelope(&mut self, envelope: scriba::EnvelopeMode) -> &mut Self {
        self.options.set_output_envelope(envelope);
        self
    }

    pub fn set_output_format(&mut self, format: scriba::Format) -> &mut Self {
        self.options.set_output_format(format);
        self
    }

    pub fn set_output_color(&mut self, color: scriba::ColorMode) -> &mut Self {
        self.options.set_output_color(color);
        self
    }

    pub fn set_log_level(&mut self, level: scriba::Level) -> &mut Self {
        self.options.set_log_level(level);
        self
    }

    pub fn set_cwd(&mut self, cwd: PathBuf) -> &mut Self {
        // needs to resolve to full path to ensure consistency when comparing with repo root
        self.paths.cwd = std::fs::canonicalize(&cwd).unwrap_or_else(|e| {
            eprintln!(
                "[warn] Failed to canonicalize cwd {:?}: {e} — using path as-is",
                cwd
            );
            cwd
        });
        self
    }

    pub fn set_in_git_repo(&mut self, in_git_repo: bool) -> &mut Self {
        self.paths.in_git_repo = in_git_repo;
        self
    }

    pub fn set_repo_root(&mut self, repo_root: PathBuf) -> &mut Self {
        // needs to resolve to full path to ensure consistency when comparing with cwd
        self.paths.repo_root = Some(std::fs::canonicalize(&repo_root).unwrap_or_else(|e| {
            eprintln!(
                "[warn] Failed to canonicalize repo_root {:?}: {e} — using path as-is",
                repo_root
            );
            repo_root
        }));
        self
    }

    pub fn set_sources(&mut self, sources: AvailableConfigOptions) -> &mut Self {
        self.resolution.sources = sources;
        self
    }

    pub fn set_config(&mut self, config: ResolvedConfig) -> &mut Self {
        self.resolution.config = Some(config);
        self
    }

    pub fn set_policy(&mut self, policy: Policy) -> &mut Self {
        self.resolution.policy = policy;
        self
    }

    pub fn new() -> Self {
        Self {
            mode: mode::RunMode::Interactive,
            options: RuntimeOptions::new(),
            paths: RuntimePaths::new(),
            resolution: RuntimeResolution {
                sources: AvailableConfigOptions {
                    cli_config: None,
                    env_config: None,
                    repo_config: None,
                    global_config: None,
                    registries: Vec::new(),
                },
                config: None,
                policy: Policy::default(),
            },
        }
    }

    pub fn resolve_cli_source(&mut self, logger: Option<&dyn LoggerTrait>) {
        if let Some(path) = self.explicit_config_path().cloned() {
            let (base_config, rules_config) = resolve_project_configs(&path, logger);
            self.resolution.sources.cli_config =
                Some(resolve_available_config(base_config, rules_config));
        }
    }

    pub fn resolve_repo_source(&mut self, logger: &dyn LoggerTrait) {
        let cwd = self.cwd().clone();
        let repo_root = self.repo_root().clone();
        let in_git = self.in_git_repo();

        let msg = format!(
            "Resolving repo config: cwd={:?}, repo_root={:?}, in_git_repo={}",
            cwd, repo_root, in_git
        );
        logger.debug(&msg);

        if let Some(path) = resolve_project_config_path(&cwd, Some(&repo_root), in_git, None) {
            let msg = format!("Found config path: {:?}", path);
            logger.debug(&msg);
            let (base_config, rules_config) = resolve_project_configs(&path, Some(logger));
            let msg = format!(
                "Config loaded: base={}, rules={}",
                base_config.is_some(),
                rules_config.is_some()
            );
            logger.debug(&msg);
            self.resolution.sources.repo_config =
                Some(resolve_available_config(base_config, rules_config));
        } else {
            logger.info("No project config found");
        }
    }

    pub fn resolve_global_source(&mut self) {
        let (base_config, rules_config) = resolve_global_configs();
        self.resolution.sources.global_config =
            Some(resolve_available_config(base_config, rules_config));
    }

    pub fn resolve_env_source(&mut self) {
        if let Some(base) = build_env_config() {
            self.resolution.sources.env_config = Some(resolve_available_config(Some(base), None));
        }
    }

    /// Resolve and load all available registries from every config layer,
    /// marking the one selected via precedence (CLI > ENV > repo > global) as active.
    pub fn resolve_registry_source(&mut self, logger: &dyn LoggerTrait) {
        let partial_base = self.build_partial_config_for_registry();

        let cli_url = self.explicit_registry().map(String::to_owned);
        let cli_ref = self.explicit_registry_ref().map(String::to_owned);
        let cli_section = self.explicit_registry_section().map(String::to_owned);

        // Determine which registry is ACTIVE (via precedence: CLI > ENV > repo > global)
        let active_spec = resolve_registry_spec(
            cli_url.as_deref(),
            cli_ref.as_deref(),
            cli_section.as_deref(),
            Some(&partial_base),
        );

        // Resolve rule references in the active spec URL so it can be compared with the
        // collected specs (which have already had their URLs resolved from rules).
        let partial_rules = self.build_partial_rules_for_registry();
        let active_spec = active_spec.map(|mut spec| {
            if let Some(rules) = &partial_rules
                && let Ok(resolved) = rules.resolve_string(&spec.url)
            {
                spec.url = resolved;
            }
            spec
        });

        // Collect and deduplicate all registry specs from all config layers
        let mut all_specs = self.collect_all_registry_specs();

        // If the active spec was supplied via CLI or ENV and doesn't appear in the pool
        // (e.g. the user passed --registry for an ad-hoc URL not in the config), inject
        // it so it gets loaded and marked active.
        if let Some(ref a) = active_spec {
            let already_present = all_specs.iter().any(|(_, s)| {
                // Match on URL + ref only; section is resolved separately for active registry
                s.url == a.url && s.r#ref == a.r#ref
            });
            if !already_present {
                all_specs.push(("cli".to_string(), a.clone()));
            }
        }

        // Load each registry and add it to the pool
        let cache_dir = self.global_cache_path().clone();
        let state_file_path = self.state_file_path();

        for (name, spec) in all_specs {
            // For the active registry, use the fully-resolved active_spec (with section)
            // For others, use their spec as-is (which may have no section)
            let spec_to_load = if let Some(ref a) = active_spec {
                if spec.url == a.url && spec.r#ref == a.r#ref {
                    a.clone()
                } else {
                    spec.clone()
                }
            } else {
                spec.clone()
            };

            let is_active = active_spec
                .as_ref()
                .is_some_and(|a| a.url == spec.url && a.r#ref == spec.r#ref);

            // Build the stable registry id: url#ref or url#ref/section
            let registry_id = match &spec_to_load.section {
                Some(section) => {
                    format!("{}##{}/{}", spec_to_load.url, spec_to_load.r#ref, section)
                }
                None => format!("{}##{}", spec_to_load.url, spec_to_load.r#ref),
            };

            match load_registry(&spec_to_load, &cache_dir, &state_file_path, logger) {
                Ok(result) => {
                    let status = if is_active { "[ACTIVE]" } else { "[available]" };
                    logger.debug(&format!(
                        "Registry loaded: url={}, ref={}, section={} {status}",
                        spec_to_load.url,
                        spec_to_load.r#ref,
                        spec_to_load.section.as_deref().unwrap_or("(root)")
                    ));

                    // Save state for active registry
                    if is_active {
                        use crate::engine::config::registry::registry_cache_path;
                        let cache_path =
                            registry_cache_path(&spec_to_load.url, &spec_to_load.r#ref, &cache_dir);

                        use crate::engine::models::state::{AppState, RegistryState};
                        let mut state = AppState::new();
                        state.registry = Some(RegistryState::new(
                            Some(name.clone()),
                            spec_to_load.url.clone(),
                            spec_to_load.r#ref.clone(),
                            spec_to_load.section.clone(),
                            result.resolved_commit.clone(),
                            cache_path,
                        ));

                        if let Err(e) = state.save(&state_file_path) {
                            logger.warn(&format!("Failed to save registry state: {e}"));
                        }
                    }

                    self.resolution.sources.registries.push(RegistryOptions {
                        id: registry_id,
                        tag: name,
                        url: spec_to_load.url,
                        r#ref: spec_to_load.r#ref,
                        section: spec_to_load.section,
                        config: Some(result.config),
                        sections: None,
                        is_active,
                    });
                }
                Err(e) => logger.error(&format!("Registry load failed ({name}): {e}")),
            }
        }
    }

    /// Build a merged BaseConfig from all layers except CLI (used to resolve the active registry
    /// before the full config is available).
    fn build_partial_config_for_registry(&self) -> BaseConfig {
        let global = self
            .resolution
            .sources
            .global_config
            .as_ref()
            .and_then(|c| c.base.clone());
        let env = self
            .resolution
            .sources
            .env_config
            .as_ref()
            .and_then(|c| c.base.clone());
        let repo = self
            .resolution
            .sources
            .repo_config
            .as_ref()
            .and_then(|c| c.base.clone());
        let cli = self
            .resolution
            .sources
            .cli_config
            .as_ref()
            .and_then(|c| c.base.clone());
        let base = global.unwrap_or_else(BaseConfig::empty);
        let base = if let Some(r) = repo {
            r.merge(base)
        } else {
            base
        };
        let base = if let Some(e) = env {
            e.merge(base)
        } else {
            base
        };
        if let Some(c) = cli {
            c.merge(base)
        } else {
            base
        }
    }

    /// Return the highest-precedence rules available before registries are loaded.
    /// Used to resolve @rules.* references in the active registry spec URL.
    fn build_partial_rules_for_registry(&self) -> Option<crate::engine::config::RulesConfig> {
        self.resolution
            .sources
            .cli_config
            .as_ref()
            .and_then(|c| c.rules.clone())
            .or_else(|| {
                self.resolution
                    .sources
                    .repo_config
                    .as_ref()
                    .and_then(|c| c.rules.clone())
            })
            .or_else(|| {
                self.resolution
                    .sources
                    .global_config
                    .as_ref()
                    .and_then(|c| c.rules.clone())
            })
    }

    /// Collect all uniquely-identifiable registry specs from every config layer (global + repo).
    /// Deduplicates by (name, url) to avoid loading the same registry twice.
    /// Resolves rule references in URLs (e.g., @rules.vars.cw_registry).
    fn collect_all_registry_specs(&self) -> Vec<(String, RegistrySpec)> {
        let mut specs: Vec<(String, RegistrySpec)> = Vec::new();

        for available_config in [
            self.resolution.sources.global_config.as_ref(),
            self.resolution.sources.repo_config.as_ref(),
        ]
        .into_iter()
        .flatten()
        {
            if let Some(cfg) = available_config.base.as_ref() {
                for (name, reg) in cfg.registries_map() {
                    if let Some(url) = reg.url {
                        // Resolve rule references in URL if rules are available.
                        // Failure to resolve MUST error (SRS §4.3) — no silent fallback.
                        let resolved_url = if let Some(rules) = &available_config.rules {
                            match rules.resolve_string(&url) {
                                Ok(s) => s,
                                Err(_) => {
                                    // Rule reference could not be resolved — skip this registry
                                    // with a note; error will surface clearly if this was the active one.
                                    continue;
                                }
                            }
                        } else {
                            url.clone()
                        };

                        // Only include explicit section field, NOT sections array
                        // (sections array is only for documentation/validation, not for pool deduplication)
                        specs.push((
                            name,
                            RegistrySpec {
                                url: resolved_url,
                                r#ref: reg.r#ref.unwrap_or_else(|| "HEAD".to_string()),
                                section: reg.section,
                            },
                        ));
                    }
                }
            }
        }

        // Deduplicate: keep first occurrence of each (name, url) pair
        let mut seen = std::collections::HashSet::new();
        specs.retain(|(name, spec)| seen.insert((name.clone(), spec.url.clone())));
        specs
    }

    pub fn resolve_available_sources(&mut self, logger: &dyn LoggerTrait) {
        self.resolve_cli_source(Some(logger));
        self.resolve_env_source();
        self.resolve_repo_source(logger);
        self.resolve_global_source();
        self.resolve_registry_source(logger);
    }

    pub fn resolve_active_config(
        &mut self,
        logger: &dyn LoggerTrait,
    ) -> crate::engine::error::Result<()> {
        // Precedence rules:
        // 1. If no config sources: use policy::default (do nothing).
        // 2. If only global: use global as-is (no merging with defaults).
        // 3-4. If registry/repo/cli: registry is base, repo/cli applied as overrides.
        // 5-6. If registry/repo/cli exists: never use global or defaults as base.
        // 7-9. Rules: cli > repo > registry > global (global only if registry has no rules).

        let global_base = self
            .resolution
            .sources
            .global_config
            .as_ref()
            .and_then(|c| c.base.clone());
        let registry_base = self
            .resolution
            .sources
            .registries
            .iter()
            .find(|r| r.is_active)
            .and_then(|r| r.config.as_ref())
            .and_then(|c| c.base.clone());
        let repo_base = self
            .resolution
            .sources
            .repo_config
            .as_ref()
            .and_then(|c| c.base.clone());
        let cli_base = self
            .resolution
            .sources
            .cli_config
            .as_ref()
            .and_then(|c| c.base.clone());

        // Check if any project-level (registry/repo/cli) config exists (Rules 5-6).
        let has_registry_repo_or_cli =
            registry_base.is_some() || repo_base.is_some() || cli_base.is_some();

        if has_registry_repo_or_cli {
            // Rules 3-4: Registry as base, then apply repo and cli as overrides.
            let base = {
                let base = registry_base.unwrap_or_else(BaseConfig::empty);
                let base = if let Some(r) = repo_base {
                    r.merge(base)
                } else {
                    base
                };
                if let Some(c) = cli_base {
                    c.merge(base)
                } else {
                    base
                }
            };

            // Rules 7-9: Determine which rules to use.
            // cli > repo > registry > global (global only if registry has no rules).
            let registry_rules = self
                .resolution
                .sources
                .registries
                .iter()
                .find(|r| r.is_active)
                .and_then(|r| r.config.as_ref())
                .and_then(|c| c.rules.clone());

            let rules = self
                .resolution
                .sources
                .cli_config
                .as_ref()
                .and_then(|c| c.rules.clone())
                .or_else(|| {
                    self.resolution
                        .sources
                        .repo_config
                        .as_ref()
                        .and_then(|c| c.rules.clone())
                })
                .or_else(|| registry_rules.clone());

            // Rule 8: Only use global rules if registry doesn't have rules.
            let rules = if registry_rules.is_none() {
                rules.or_else(|| {
                    self.resolution
                        .sources
                        .global_config
                        .as_ref()
                        .and_then(|c| c.rules.clone())
                })
            } else {
                rules
            }
            .unwrap_or_default();

            // Merge rules into base: ResolvedConfig.base becomes the single source of truth
            // with all @rules.* references resolved. Failure to resolve MUST error (SRS §4.3).
            use crate::engine::config::resolver::merge_rules_into_base;
            let base = merge_rules_into_base(base, &rules)?;

            logger.debug(&format!(
                "[config] resolved commit.types: {:?}",
                base.commit
                    .as_ref()
                    .and_then(|c| c.types.as_ref())
                    .map(|t| t.keys().cloned().collect::<Vec<_>>()),
            ));

            let path = self.project_config_path();
            self.resolution.config = Some(ResolvedConfig { path, rules, base });
            self.resolve_policy();
        } else if global_base.is_some() {
            // Rule 2: Only global exists, use it as-is (no merging with defaults).
            let base = global_base.unwrap();
            let rules = self
                .resolution
                .sources
                .global_config
                .as_ref()
                .and_then(|c| c.rules.clone())
                .unwrap_or_default();

            use crate::engine::config::resolver::merge_rules_into_base;
            let base = merge_rules_into_base(base, &rules)?;

            logger.debug(&format!(
                "[config] resolved commit.types: {:?}",
                base.commit
                    .as_ref()
                    .and_then(|c| c.types.as_ref())
                    .map(|t| t.keys().cloned().collect::<Vec<_>>()),
            ));

            let path = self.project_config_path();
            self.resolution.config = Some(ResolvedConfig { path, rules, base });
            self.resolve_policy();
        }
        // Rule 1: If no config sources, do nothing—policy remains at engine defaults.

        Ok(())
    }

    pub fn resolve_policy(&mut self) {
        let policy = resolve_policy(self.config());
        self.resolution.policy = policy;
    }

    pub fn explicit_config_path(&self) -> Option<&PathBuf> {
        self.paths.explicit_config_path.as_ref()
    }

    pub fn explicit_registry(&self) -> Option<&String> {
        self.paths.explicit_registry.as_ref()
    }

    pub fn explicit_registry_ref(&self) -> Option<&String> {
        self.paths.explicit_registry_ref.as_ref()
    }

    pub fn explicit_registry_section(&self) -> Option<&String> {
        self.paths.explicit_registry_section.as_ref()
    }

    pub fn set_explicit_config_path(&mut self, path: Option<PathBuf>) -> &mut Self {
        self.paths.explicit_config_path = path;
        self
    }

    pub fn set_explicit_registry(&mut self, registry: Option<String>) -> &mut Self {
        self.paths.explicit_registry = registry;
        self
    }

    pub fn set_explicit_registry_ref(&mut self, registry_ref: Option<String>) -> &mut Self {
        self.paths.explicit_registry_ref = registry_ref;
        self
    }

    pub fn set_explicit_registry_section(&mut self, registry_section: Option<String>) -> &mut Self {
        self.paths.explicit_registry_section = registry_section;
        self
    }

    pub fn project_config_path(&self) -> Option<PathBuf> {
        resolve_project_config_path(
            self.cwd(),
            Some(self.repo_root().as_path()),
            self.in_git_repo(),
            self.explicit_config_path().map(|p| p.as_path()),
        )
    }
}