Skip to content

Commit

Permalink
feat(util): #84 merge partial global props (#88)
Browse files Browse the repository at this point in the history
This PR changes the flow when pulling configurations. Global will always be pulled, and then merge specific properties into the repository config if it exists.

Closes: #84
  • Loading branch information
Everduin94 authored Mar 23, 2024
1 parent 13bc3ce commit 8e71e1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ Your first time running `better-commits`, a default config will be generated in
### Repository

To create a **repository-specific config**, navigate to the root of your project.
- run `better-commits-init`
- Run `better-commits-init`
- This will create a default config named `.better-commits.json`
- Properties such as `confirm_with_editor` and `overrides` will prefer the global config

### Options

Expand Down
20 changes: 14 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,26 @@ export function load_setup(
console.clear();
p.intro(`${color.bgCyan(color.black(cli_name))}`);

let global_config = null
const home_path = get_default_config_path();
if (fs.existsSync(home_path)) {
p.log.step("Found global config");
global_config = read_config_from_path(home_path);
}

const root = get_git_root();
const root_path = `${root}/${CONFIG_FILE_NAME}`;
if (fs.existsSync(root_path)) {
p.log.step("Found repository config");
return read_config_from_path(root_path);
const repo_config = read_config_from_path(root_path);
return global_config ? {
...repo_config,
overrides: global_config.overrides.shell ? global_config.overrides : repo_config.overrides,
confirm_with_editor: global_config.confirm_with_editor
} : repo_config
}

const home_path = get_default_config_path();
if (fs.existsSync(home_path)) {
p.log.step("Found global config");
return read_config_from_path(home_path);
}
if (global_config) return global_config

const default_config = Config.parse({});
p.log.step(
Expand Down

0 comments on commit 8e71e1c

Please sign in to comment.