Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn get_model_name(repository: &Repository, file_name: &str) -> Result<Option
toml::from_str(&std::fs::read_to_string(config_path).map_err(|err| err.to_string())?)
.map_err(|err| err.to_string())?;

Ok(Some(repo_config.model))
Ok(repo_config.model)
} else {
Ok(None)
}
Expand All @@ -86,7 +86,11 @@ pub fn get_model<P: AsRef<Path> + AsRef<OsStr>>(
)
.map_err(|err| err.to_string())?;

read_model(&repo_config.model, app_model_path)
match repo_config.model {
None => Ok(read_model("git-flow", app_model_path)
.unwrap_or_else(|_| BranchSettingsDef::git_flow())),
Some(model) => read_model(&model, app_model_path),
}
} else {
Ok(read_model("git-flow", app_model_path)
.unwrap_or_else(|_| BranchSettingsDef::git_flow()))
Expand Down Expand Up @@ -141,7 +145,7 @@ pub fn set_model<P: AsRef<Path>>(
config_path.push(repo_config_file);

let config = RepoSettings {
model: model.to_string(),
model: Some(model.to_string()),
};

let str = toml::to_string_pretty(&config).map_err(|err| err.to_string())?;
Expand Down
23 changes: 22 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ use std::time::Instant;

const REPO_CONFIG_FILE: &str = "git-graph.toml";

#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
pub struct CommitFormatToml {
pub format: Option<String>,
}

fn main() {
std::process::exit(match from_args() {
Ok(_) => 0,
Expand Down Expand Up @@ -289,7 +294,23 @@ fn from_args() -> Result<(), String> {
)?;

let format = match matches.get_one::<String>("format") {
None => CommitFormat::OneLine,
None => {
let mut config_path = std::path::PathBuf::from(repository.path());
config_path.push(REPO_CONFIG_FILE);
if config_path.exists() {
let commit_format_toml: CommitFormatToml = toml::from_str(
&std::fs::read_to_string(config_path).map_err(|err| err.to_string())?,
)
.map_err(|err| err.to_string())
.unwrap();
match commit_format_toml.format {
None => CommitFormat::OneLine,
Some(format) => CommitFormat::from_str(&format)?,
}
} else {
CommitFormat::OneLine
}
}
Some(str) => CommitFormat::from_str(str)?,
};

Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::str::FromStr;
#[derive(Serialize, Deserialize)]
pub struct RepoSettings {
/// The repository's branching model
pub model: String,
pub model: Option<String>,
}

/// Ordering policy for branches in visual columns.
Expand Down