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
16
src/args.rs
16
src/args.rs
|
|
@ -123,8 +123,10 @@ pub enum GitOperation {
|
|||
/// Checkout a branch in all apps
|
||||
///
|
||||
/// "main" and "master" can be used interchangeably.
|
||||
#[strum(props(Args = "[branch] branch to checkout"))]
|
||||
Checkout { branch: String },
|
||||
#[strum(props(
|
||||
Args = "[branch] branch to checkout, defaults to the branch matching the current server version"
|
||||
))]
|
||||
Checkout { branch: Option<String> },
|
||||
}
|
||||
|
||||
impl SubCommand for GitOperation {
|
||||
|
|
@ -316,10 +318,7 @@ impl HazeArgs {
|
|||
HazeCommand::Unpin => Ok(HazeArgs::Unpin { filter }),
|
||||
HazeCommand::Proxy => Ok(HazeArgs::Proxy),
|
||||
HazeCommand::Checkout => {
|
||||
let branch = args
|
||||
.next()
|
||||
.map(S::into)
|
||||
.ok_or_else(|| Report::msg("No branch provided"))?;
|
||||
let branch = args.next().map(S::into);
|
||||
Ok(HazeArgs::Git {
|
||||
operation: GitOperation::Checkout { branch },
|
||||
})
|
||||
|
|
@ -330,10 +329,7 @@ impl HazeArgs {
|
|||
.ok_or_else(|| Report::msg("No git operation provided"))?;
|
||||
match operation.as_ref() {
|
||||
"checkout" => {
|
||||
let branch = args
|
||||
.next()
|
||||
.map(S::into)
|
||||
.ok_or_else(|| Report::msg("No branch provided"))?;
|
||||
let branch = args.next().map(S::into);
|
||||
Ok(HazeArgs::Git {
|
||||
operation: GitOperation::Checkout { branch },
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use crate::php::PhpVersion;
|
|||
use crate::proxy::proxy;
|
||||
use crate::service::ServiceTrait;
|
||||
use crate::service::{RedisTls, Service};
|
||||
use crate::sources::Sources;
|
||||
use bollard::Docker;
|
||||
use itertools::Itertools;
|
||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||
|
|
@ -35,6 +36,7 @@ mod network;
|
|||
mod php;
|
||||
mod proxy;
|
||||
mod service;
|
||||
mod sources;
|
||||
|
||||
static FORWARD_ENV: &[&str] = &[
|
||||
"OCC_LOG",
|
||||
|
|
@ -385,7 +387,11 @@ async fn main() -> Result<ExitCode> {
|
|||
}
|
||||
HazeArgs::Git { operation } => match operation {
|
||||
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 => {
|
||||
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