Skip to content

Commit a23eeb4

Browse files
committed
feat(config): discover the configuration file when run in a sub directory
1 parent ceda1f7 commit a23eeb4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

git-cliff/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub fn run(mut args: Opt) -> Result<()> {
405405
}
406406
}
407407

408-
// Parse the configuration file.
408+
// Set path for the configuration file.
409409
let mut path = args.config.clone();
410410
if !path.exists() {
411411
if let Some(config_path) = dirs::config_dir()
@@ -415,6 +415,7 @@ pub fn run(mut args: Opt) -> Result<()> {
415415
}
416416
}
417417

418+
// Parse the configuration file.
418419
// Load the default configuration if necessary.
419420
let mut config = if let Ok((config, name)) = builtin_config {
420421
info!("Using built-in configuration file: {name}");
@@ -423,6 +424,20 @@ pub fn run(mut args: Opt) -> Result<()> {
423424
Config::parse(&path)?
424425
} else if let Some(contents) = Config::read_from_manifest()? {
425426
Config::parse_from_str(&contents)?
427+
} else if let Some(discovered_path) =
428+
env::current_dir()?.ancestors().find_map(|dir| {
429+
let path = dir.join(DEFAULT_CONFIG);
430+
if path.is_file() {
431+
Some(path)
432+
} else {
433+
None
434+
}
435+
}) {
436+
info!(
437+
"Using configuration from parent directory: {}",
438+
discovered_path.display()
439+
);
440+
Config::parse(&discovered_path)?
426441
} else {
427442
if !args.context {
428443
warn!(

0 commit comments

Comments
 (0)