mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
make haze git checkout pick the correct branch by default
This commit is contained in:
parent
755573ba4b
commit
b2a7b22676
4 changed files with 78 additions and 11 deletions
14
README.md
14
README.md
|
|
@ -227,6 +227,20 @@ haze [match] edit <path>
|
||||||
haze [match] reload
|
haze [match] reload
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The php configuration can edit changed with `haze edit /php.ini`
|
||||||
|
|
||||||
|
#### Checkout a branch for all local apps
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze git checkout [branch]
|
||||||
|
```
|
||||||
|
|
||||||
|
Checks out the branch in all git repositories within the apps folder.
|
||||||
|
|
||||||
|
Defaults to the branch matching the current checked out server versions (e.g. `master` or `stable33`).
|
||||||
|
|
||||||
|
`master` and `main` can be used interchangeably.
|
||||||
|
|
||||||
## Federation
|
## Federation
|
||||||
|
|
||||||
Multiple instances can reach each other by using their instance name as domain
|
Multiple instances can reach each other by using their instance name as domain
|
||||||
|
|
|
||||||
16
src/args.rs
16
src/args.rs
|
|
@ -123,8 +123,10 @@ pub enum GitOperation {
|
||||||
/// Checkout a branch in all apps
|
/// Checkout a branch in all apps
|
||||||
///
|
///
|
||||||
/// "main" and "master" can be used interchangeably.
|
/// "main" and "master" can be used interchangeably.
|
||||||
#[strum(props(Args = "[branch] branch to checkout"))]
|
#[strum(props(
|
||||||
Checkout { branch: String },
|
Args = "[branch] branch to checkout, defaults to the branch matching the current server version"
|
||||||
|
))]
|
||||||
|
Checkout { branch: Option<String> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SubCommand for GitOperation {
|
impl SubCommand for GitOperation {
|
||||||
|
|
@ -316,10 +318,7 @@ impl HazeArgs {
|
||||||
HazeCommand::Unpin => Ok(HazeArgs::Unpin { filter }),
|
HazeCommand::Unpin => Ok(HazeArgs::Unpin { filter }),
|
||||||
HazeCommand::Proxy => Ok(HazeArgs::Proxy),
|
HazeCommand::Proxy => Ok(HazeArgs::Proxy),
|
||||||
HazeCommand::Checkout => {
|
HazeCommand::Checkout => {
|
||||||
let branch = args
|
let branch = args.next().map(S::into);
|
||||||
.next()
|
|
||||||
.map(S::into)
|
|
||||||
.ok_or_else(|| Report::msg("No branch provided"))?;
|
|
||||||
Ok(HazeArgs::Git {
|
Ok(HazeArgs::Git {
|
||||||
operation: GitOperation::Checkout { branch },
|
operation: GitOperation::Checkout { branch },
|
||||||
})
|
})
|
||||||
|
|
@ -330,10 +329,7 @@ impl HazeArgs {
|
||||||
.ok_or_else(|| Report::msg("No git operation provided"))?;
|
.ok_or_else(|| Report::msg("No git operation provided"))?;
|
||||||
match operation.as_ref() {
|
match operation.as_ref() {
|
||||||
"checkout" => {
|
"checkout" => {
|
||||||
let branch = args
|
let branch = args.next().map(S::into);
|
||||||
.next()
|
|
||||||
.map(S::into)
|
|
||||||
.ok_or_else(|| Report::msg("No branch provided"))?;
|
|
||||||
Ok(HazeArgs::Git {
|
Ok(HazeArgs::Git {
|
||||||
operation: GitOperation::Checkout { branch },
|
operation: GitOperation::Checkout { branch },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ use crate::php::PhpVersion;
|
||||||
use crate::proxy::proxy;
|
use crate::proxy::proxy;
|
||||||
use crate::service::ServiceTrait;
|
use crate::service::ServiceTrait;
|
||||||
use crate::service::{RedisTls, Service};
|
use crate::service::{RedisTls, Service};
|
||||||
|
use crate::sources::Sources;
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||||
|
|
@ -35,6 +36,7 @@ mod network;
|
||||||
mod php;
|
mod php;
|
||||||
mod proxy;
|
mod proxy;
|
||||||
mod service;
|
mod service;
|
||||||
|
mod sources;
|
||||||
|
|
||||||
static FORWARD_ENV: &[&str] = &[
|
static FORWARD_ENV: &[&str] = &[
|
||||||
"OCC_LOG",
|
"OCC_LOG",
|
||||||
|
|
@ -385,7 +387,11 @@ async fn main() -> Result<ExitCode> {
|
||||||
}
|
}
|
||||||
HazeArgs::Git { operation } => match operation {
|
HazeArgs::Git { operation } => match operation {
|
||||||
GitOperation::Checkout { branch } => {
|
GitOperation::Checkout { branch } => {
|
||||||
checkout_all(&config.sources_root, &branch)?;
|
let sources = Sources::new(&config.sources_root)?;
|
||||||
|
checkout_all(
|
||||||
|
&config.sources_root,
|
||||||
|
&branch.unwrap_or_else(|| sources.get_server_version_branch()),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
GitOperation::Pull => {
|
GitOperation::Pull => {
|
||||||
pull_all(&config.sources_root)?;
|
pull_all(&config.sources_root)?;
|
||||||
|
|
|
||||||
51
src/sources.rs
Normal file
51
src/sources.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
use miette::{Context, IntoDiagnostic, Report, Result};
|
||||||
|
use std::fs::read_to_string;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
pub struct Sources {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
base_dir: PathBuf,
|
||||||
|
server_version: u8,
|
||||||
|
server_branched_off: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sources {
|
||||||
|
pub fn new<P: AsRef<Path>>(base_dir: P) -> Result<Self> {
|
||||||
|
let base_dir = base_dir.as_ref();
|
||||||
|
let versions_source = read_to_string(base_dir.join("version.php"))
|
||||||
|
.into_diagnostic()
|
||||||
|
.wrap_err("failed to read version.php")?;
|
||||||
|
let version_line = versions_source
|
||||||
|
.lines()
|
||||||
|
.find(|line| line.starts_with("$OC_Version"))
|
||||||
|
.ok_or_else(|| Report::msg("failed to find line containing $OC_Version"))?;
|
||||||
|
let version_str_line = versions_source
|
||||||
|
.lines()
|
||||||
|
.find(|line| line.starts_with("$OC_VersionString"))
|
||||||
|
.ok_or_else(|| Report::msg("failed to find line containing $OC_VersionString"))?;
|
||||||
|
let (major, _) = version_line
|
||||||
|
.split_once('[')
|
||||||
|
.and_then(|(_, line)| line.split_once(','))
|
||||||
|
.ok_or_else(|| Report::msg("failed to find version number in line"))?;
|
||||||
|
let server_version = major
|
||||||
|
.trim()
|
||||||
|
.parse()
|
||||||
|
.into_diagnostic()
|
||||||
|
.wrap_err("failed to parse version number")?;
|
||||||
|
let server_branched_off = !version_str_line.contains("dev");
|
||||||
|
|
||||||
|
Ok(Sources {
|
||||||
|
base_dir: base_dir.into(),
|
||||||
|
server_version,
|
||||||
|
server_branched_off,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_server_version_branch(&self) -> String {
|
||||||
|
if self.server_branched_off {
|
||||||
|
format!("stable{}", self.server_version)
|
||||||
|
} else {
|
||||||
|
"master".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue