Author:
Hash:
Timestamp:
+41 -13 +/-7 browse
Kevin Schoon [me@kevinschoon.com]
a41f2f70b41d5345decb2bf26ec70fc7dea84662
Wed, 13 May 2026 09:13:45 +0000 (4 weeks ago)
| 1 | diff --git a/ayllu-shell/src/config.rs b/ayllu-shell/src/config.rs |
| 2 | index 1fccdd1..7203530 100644 |
| 3 | --- a/ayllu-shell/src/config.rs |
| 4 | +++ b/ayllu-shell/src/config.rs |
| 5 | @@ -32,6 +32,8 @@ impl Shell { |
| 6 | pub struct Config { |
| 7 | #[serde(default = "Config::default_log_level")] |
| 8 | pub log_level: String, |
| 9 | + #[serde(default = "Config::default_branch")] |
| 10 | + pub default_branch: String, |
| 11 | pub base_dir: Option<PathBuf>, |
| 12 | #[serde(default = "Vec::new")] |
| 13 | pub identities: Vec<Identity>, |
| 14 | @@ -45,6 +47,10 @@ impl Config { |
| 15 | fn default_log_level() -> String { |
| 16 | String::from("INFO") |
| 17 | } |
| 18 | + |
| 19 | + fn default_branch() -> String { |
| 20 | + ayllu_git::DEFAULT_GIT_BRANCH.to_string() |
| 21 | + } |
| 22 | } |
| 23 | |
| 24 | impl Configurable for Config { |
| 25 | diff --git a/ayllu-shell/src/main.rs b/ayllu-shell/src/main.rs |
| 26 | index 11ad2e7..9f2e3dc 100644 |
| 27 | --- a/ayllu-shell/src/main.rs |
| 28 | +++ b/ayllu-shell/src/main.rs |
| 29 | @@ -36,7 +36,7 @@ fn execute(args: Command) -> Result<(), Box<dyn std::error::Error>> { |
| 30 | if ayllu_git::git_dir(&resolved).is_ok_and(|is_git_dir| is_git_dir) { |
| 31 | Wrapper::new(&resolved)? |
| 32 | } else { |
| 33 | - Wrapper::create(&resolved, true)? |
| 34 | + Wrapper::create(&resolved, Some(&config.default_branch), true)? |
| 35 | }; |
| 36 | repository.receive_pack()?; |
| 37 | } |
| 38 | diff --git a/ayllu-shell/src/ui.rs b/ayllu-shell/src/ui.rs |
| 39 | index 654b61c..04da7ae 100644 |
| 40 | --- a/ayllu-shell/src/ui.rs |
| 41 | +++ b/ayllu-shell/src/ui.rs |
| 42 | @@ -95,11 +95,12 @@ mod helpers { |
| 43 | |
| 44 | pub fn create( |
| 45 | collection: &Collection, |
| 46 | + default_branch: &str, |
| 47 | config: &ayllu_git::Config, |
| 48 | name: &str, |
| 49 | bare: bool, |
| 50 | ) -> Result<Wrapper, Error> { |
| 51 | - let repository = Wrapper::create(&collection.path.join(Path::new(name)), bare)?; |
| 52 | + let repository = Wrapper::create(&collection.path.join(Path::new(name)), Some(name), bare)?; |
| 53 | repository.apply_config(config)?; |
| 54 | Ok(repository) |
| 55 | } |
| 56 | @@ -292,7 +293,13 @@ impl Prompt<'_> { |
| 57 | branch: Some(branch), |
| 58 | }); |
| 59 | } |
| 60 | - helpers::create(collection, &configuration, &name, bare)?; |
| 61 | + helpers::create( |
| 62 | + collection, |
| 63 | + &self.config.default_branch, |
| 64 | + &configuration, |
| 65 | + &name, |
| 66 | + bare, |
| 67 | + )?; |
| 68 | println!("Repository Created Successfully"); |
| 69 | self.execute(None, None) |
| 70 | } |
| 71 | diff --git a/config.example.toml b/config.example.toml |
| 72 | index 9a47096..9af4a8f 100644 |
| 73 | --- a/config.example.toml |
| 74 | +++ b/config.example.toml |
| 75 | @@ -1,6 +1,10 @@ |
| 76 | # site name used in various places across the instance |
| 77 | site_name = "🌄 Ayllu" |
| 78 | |
| 79 | + # Default branch to use when creating new repositories. |
| 80 | + default_branch = "master" |
| 81 | + # default_branch = "main" |
| 82 | + |
| 83 | # A valid URI that identifies this server on the global internet |
| 84 | origin = "localhost:10000" |
| 85 | |
| 86 | diff --git a/crates/git/src/lib.rs b/crates/git/src/lib.rs |
| 87 | index 8576ed5..42d1da5 100644 |
| 88 | --- a/crates/git/src/lib.rs |
| 89 | +++ b/crates/git/src/lib.rs |
| 90 | @@ -20,6 +20,10 @@ mod wrapper; |
| 91 | |
| 92 | pub mod testing; |
| 93 | |
| 94 | + /// Branch used by default on all new repositories, mirrors the same as Git's |
| 95 | + /// own default branch. |
| 96 | + pub const DEFAULT_GIT_BRANCH: &str = "master"; |
| 97 | + |
| 98 | /// A Collection is a directory of Git repositories on disk |
| 99 | #[derive(Clone, Debug, Serialize, Deserialize)] |
| 100 | pub struct Collection { |
| 101 | diff --git a/crates/git/src/testing.rs b/crates/git/src/testing.rs |
| 102 | index c342848..23543aa 100644 |
| 103 | --- a/crates/git/src/testing.rs |
| 104 | +++ b/crates/git/src/testing.rs |
| 105 | @@ -11,6 +11,7 @@ const DEFAULT_GIT_CONFIG: &str = r#" |
| 106 | |
| 107 | [init] |
| 108 | defaultBranch = main |
| 109 | + |
| 110 | "#; |
| 111 | |
| 112 | pub const DEFAULT_TIMESTAMP: &str = "Sun Sep 13 12:26:40 PM UTC 2020"; // @160000000 |
| 113 | @@ -34,14 +35,15 @@ pub fn init(base_dir: &Path, bare: bool, commands: &[&str]) -> Result<PathBuf, s |
| 114 | let git_config_path = base_dir.join("gitconfig"); |
| 115 | let git_config_path = git_config_path.as_path(); |
| 116 | fs::write(git_config_path, DEFAULT_GIT_CONFIG)?; |
| 117 | - let repository = |
| 118 | - Wrapper::create(source_path.as_path(), bare).expect("Could not initialize repository"); |
| 119 | + let repository = Wrapper::create(source_path.as_path(), Some("main"), bare) |
| 120 | + .expect("Could not initialize repository"); |
| 121 | commands.iter().try_for_each(|command| { |
| 122 | - Command::new("/bin/sh") |
| 123 | + let output = Command::new("/bin/sh") |
| 124 | .args(vec!["-c", command]) |
| 125 | .env("GIT_CONFIG_GLOBAL", git_config_path) |
| 126 | .current_dir(repository.path()) |
| 127 | .output()?; |
| 128 | + println!("Git: {output:?}"); |
| 129 | Ok::<(), std::io::Error>(()) |
| 130 | })?; |
| 131 | Ok(source_path) |
| 132 | diff --git a/crates/git/src/wrapper.rs b/crates/git/src/wrapper.rs |
| 133 | index 4178d01..f6c2a03 100644 |
| 134 | --- a/crates/git/src/wrapper.rs |
| 135 | +++ b/crates/git/src/wrapper.rs |
| 136 | @@ -59,13 +59,18 @@ impl Wrapper { |
| 137 | } |
| 138 | |
| 139 | /// Create a new git repository at the given path |
| 140 | - pub fn create(path: &Path, bare: bool) -> Result<Self, Error> { |
| 141 | - let repository = |
| 142 | - Repository::init_opts(path, RepositoryInitOptions::new().bare(bare).mkdir(true)) |
| 143 | - .map_err(|e| Error::CannotCreateRepository { |
| 144 | - path: path.to_path_buf(), |
| 145 | - git_error: e, |
| 146 | - })?; |
| 147 | + pub fn create(path: &Path, default_branch: Option<&str>, bare: bool) -> Result<Self, Error> { |
| 148 | + let repository = Repository::init_opts( |
| 149 | + path, |
| 150 | + RepositoryInitOptions::new() |
| 151 | + .initial_head(default_branch.unwrap_or(crate::DEFAULT_GIT_BRANCH)) |
| 152 | + .bare(bare) |
| 153 | + .mkdir(true), |
| 154 | + ) |
| 155 | + .map_err(|e| Error::CannotCreateRepository { |
| 156 | + path: path.to_path_buf(), |
| 157 | + git_error: e, |
| 158 | + })?; |
| 159 | Ok(Wrapper { |
| 160 | path: path.to_path_buf(), |
| 161 | repository: Box::new(repository), |