Skip to content

Commit 8e71e1c

Browse files
authored
feat(util): #84 merge partial global props (#88)
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
1 parent 13bc3ce commit 8e71e1c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ Your first time running `better-commits`, a default config will be generated in
6565
### Repository
6666

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

7172
### Options
7273

src/utils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,26 @@ export function load_setup(
148148
console.clear();
149149
p.intro(`${color.bgCyan(color.black(cli_name))}`);
150150

151+
let global_config = null
152+
const home_path = get_default_config_path();
153+
if (fs.existsSync(home_path)) {
154+
p.log.step("Found global config");
155+
global_config = read_config_from_path(home_path);
156+
}
157+
151158
const root = get_git_root();
152159
const root_path = `${root}/${CONFIG_FILE_NAME}`;
153160
if (fs.existsSync(root_path)) {
154161
p.log.step("Found repository config");
155-
return read_config_from_path(root_path);
162+
const repo_config = read_config_from_path(root_path);
163+
return global_config ? {
164+
...repo_config,
165+
overrides: global_config.overrides.shell ? global_config.overrides : repo_config.overrides,
166+
confirm_with_editor: global_config.confirm_with_editor
167+
} : repo_config
156168
}
157169

158-
const home_path = get_default_config_path();
159-
if (fs.existsSync(home_path)) {
160-
p.log.step("Found global config");
161-
return read_config_from_path(home_path);
162-
}
170+
if (global_config) return global_config
163171

164172
const default_config = Config.parse({});
165173
p.log.step(

0 commit comments

Comments
 (0)