Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(main): #82 edit and confirm with editor #83

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Owner Author

@Everduin94 Everduin94 Feb 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a type for {shell, stdio} (but there are types for each individually). Not sure if they're incompatible together, or I'm just missing a type casting?

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