Skip to content

Commit

Permalink
feat(main): #82 edit and confirm with editor (#83)
Browse files Browse the repository at this point in the history
Added config confirm_with_editor to open GIT_EDITOR / EDITOR. Default false.

Closes: #82
  • Loading branch information
Everduin94 authored Feb 11, 2024
1 parent 1773883 commit 69d9d98
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
"add_exclamation_to_title": true
},
"confirm_commit": true,
"confirm_with_editor": false,
"print_commit_output": true,
"branch_pre_commands": [],
"branch_post_commands": [],
Expand Down Expand Up @@ -307,6 +308,7 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
| `commit_footer.options` | Footer options |
| `breaking_change.add_exclamation_to_title` | If true adds exclamation mark to title for breaking changes |
| `confirm_commit` | If true manually confirm commit at end |
| `confirm_with_editor` | Confirm / Edit commit with $GIT_EDITOR / $EDITOR |
| `print_commit_output` | If true pretty print commit preview |
| `overrides.shell` | Override default shell, useful for windows users |

Expand Down Expand Up @@ -405,6 +407,10 @@ If you're using Github issues to track your work, and select the `closes` footer

`better-commits` uses native `git` commands under the hood. So any hooks, tools, or staging should work as if it was a normal commit.

Setting `confirm_with_editor=true` will allow you to edit/confirm a commit with your editor.
- For example, to edit with Neovim: `git config --global core.editor "nvim"`
- For VS Code, `git config --global core.editor "code -n --wait"`

You can add this badge to your repository to display that you're using a better-commits repository config

| Markdown | Result |
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ export async function main(config: z.infer<typeof Config>) {
commit_state.trailer = '';
}
}


if (config.confirm_with_editor) {
const options = config.overrides.shell ? { shell: config.overrides.shell, stdio: 'inherit' } : { stdio: 'inherit' }
const trailer = commit_state.trailer ? `--trailer="${commit_state.trailer}"` : '';
execSync(`git commit -m "${build_commit_string(commit_state, config, false, true, false)}" ${trailer} --edit`, options);
process.exit(0);
}

let continue_commit = true;
p.note(build_commit_string(commit_state, config, true, false, true), 'Commit Preview')
Expand Down
1 change: 1 addition & 0 deletions src/zod-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const Config = z
add_exclamation_to_title: z.boolean().default(true),
})
.default({}),
confirm_with_editor: z.boolean().default(false),
confirm_commit: z.boolean().default(true),
print_commit_output: z.boolean().default(true),
branch_pre_commands: z.array(z.string()).default([]),
Expand Down

0 comments on commit 69d9d98

Please sign in to comment.