Skip to main content

git_stk/
config.rs

1use anyhow::Result;
2
3use crate::git;
4
5/// Every `[stk]` setting the tool reads, with its default behavior.
6const SETTINGS: &[(&str, &str)] = &[
7    ("stk.provider", "auto-detect from the remote URL"),
8    ("stk.remote", "origin"),
9    ("stk.updateRefs", "false"),
10    ("stk.pushOnRestack", "false"),
11    ("stk.pushOnSubmit", "false"),
12];
13
14/// Print every stk-owned git config value: the `[stk]` settings (with
15/// defaults for unset keys) and the per-branch stack metadata.
16pub fn print_config() -> Result<()> {
17    for (key, default) in SETTINGS {
18        match git::config_get(key)? {
19            Some(value) => println!("{key} = {value}"),
20            None => println!("{key} (default: {default})"),
21        }
22    }
23
24    let metadata = git::config_get_regexp(r"^branch\..*\.stk(parent|base)$")?;
25    if metadata.is_empty() {
26        println!();
27        println!("no branch metadata (no stacked branches)");
28        return Ok(());
29    }
30
31    println!();
32    println!("branch metadata:");
33    for (key, value) in metadata {
34        println!("  {key} = {value}");
35    }
36    Ok(())
37}