use std::ffi::OsString;
use crate::index_writer_forward::CoordinatedForward;
use crate::worktree_copy_forward::CopyFacts;
use std::path::PathBuf;
pub const ENGINE_FAILURE_EXIT_CODE: i32 = 2;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PushForward {
pub real_git: PathBuf,
pub arguments: Vec<OsString>,
pub overlay: Vec<(OsString, OsString)>,
pub copy: Option<Box<CopyFacts>>,
pub subcommand_index: usize,
pub environment: Vec<(OsString, OsString)>,
pub lfs: bool,
pub lfs_settings: Option<Vec<(String, String)>>,
pub stack: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Action {
Forward {
real_git: PathBuf,
arguments: Vec<OsString>,
overlay: Vec<(OsString, OsString)>,
stderr: String,
},
ForwardCoordinated {
forward: Box<CoordinatedForward>,
stderr: String,
},
ForwardSettled {
real_git: PathBuf,
arguments: Vec<OsString>,
overlay: Vec<(OsString, OsString)>,
copy: Box<CopyFacts>,
stderr: String,
},
ForwardPush {
forward: Box<PushForward>,
stderr: String,
},
ForwardAnnounced {
real_git: PathBuf,
arguments: Vec<OsString>,
overlay: Vec<(OsString, OsString)>,
announcement: String,
stderr: String,
},
Exit {
code: i32,
stdout: String,
stderr: String,
},
}
pub fn with_leading_notice(action: Action, notice: Option<&str>) -> Action {
let Some(lead) = notice else {
return action;
};
match action {
Action::Forward { real_git, arguments, overlay, stderr } => {
return Action::Forward { real_git, arguments, overlay, stderr: format!("{lead}{stderr}") };
}
Action::ForwardCoordinated { forward, stderr } => {
return Action::ForwardCoordinated { forward, stderr: format!("{lead}{stderr}") };
}
Action::ForwardSettled { real_git, arguments, overlay, copy, stderr } => {
return Action::ForwardSettled { real_git, arguments, overlay, copy, stderr: format!("{lead}{stderr}") };
}
Action::ForwardPush { forward, stderr } => {
return Action::ForwardPush { forward, stderr: format!("{lead}{stderr}") };
}
Action::ForwardAnnounced { real_git, arguments, overlay, announcement, stderr } => {
return Action::ForwardAnnounced {
real_git,
arguments,
overlay,
announcement,
stderr: format!("{lead}{stderr}"),
};
}
Action::Exit { code, stdout, stderr } => {
return Action::Exit { code, stdout, stderr: format!("{lead}{stderr}") };
}
}
}
pub fn failure(message: &str) -> Action {
return Action::Exit {
code: ENGINE_FAILURE_EXIT_CODE,
stdout: String::new(),
stderr: format!("cli-git: {message}\n"),
};
}