Skip to content

Commit

Permalink
merge_tools: extract function that doesn't look up :builtin merge tool
Browse files Browse the repository at this point in the history
The :builtin tool only applies to merge or diff editor.
  • Loading branch information
yuja committed Feb 29, 2024
1 parent 3563bed commit 3575c9f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cli/src/merge_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,24 @@ fn editor_args_from_settings(
}
}

/// Loads merge tool options from `[merge-tools.<name>]`.
/// Resolves builtin merge tool name or loads external tool options from
/// `[merge-tools.<name>]`.
pub fn get_tool_config(
settings: &UserSettings,
name: &str,
) -> Result<Option<MergeTool>, ConfigError> {
if name == BUILTIN_EDITOR_NAME {
return Ok(Some(MergeTool::Builtin));
Ok(Some(MergeTool::Builtin))
} else {
Ok(get_external_tool_config(settings, name)?.map(MergeTool::External))
}
}

/// Loads external diff/merge tool options from `[merge-tools.<name>]`.
pub fn get_external_tool_config(
settings: &UserSettings,
name: &str,
) -> Result<Option<ExternalMergeTool>, ConfigError> {
const TABLE_KEY: &str = "merge-tools";
let tools_table = settings.config().get_table(TABLE_KEY)?;
if let Some(v) = tools_table.get(name) {
Expand All @@ -204,7 +213,7 @@ pub fn get_tool_config(
if result.program.is_empty() {
result.program.clone_from(&name.to_string());
};
Ok(Some(MergeTool::External(result)))
Ok(Some(result))
} else {
Ok(None)
}
Expand Down

0 comments on commit 3575c9f

Please sign in to comment.