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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Can use 'prepare-commit-msg' hook --no-edit #87

Closed
FatehAK opened this issue Dec 8, 2022 · 11 comments
Closed

[Feature Request] Can use 'prepare-commit-msg' hook --no-edit #87

FatehAK opened this issue Dec 8, 2022 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@FatehAK
Copy link

FatehAK commented Dec 8, 2022

馃挱 Describe the feature

We are using czg as part of husky's 'prepare-commit-msg' hook like so -

exec < /dev/tty && npx --no-install czg --hook || true

It works as expected but it open the vim editor unnecessarily at the end.

Is it possible to add a flag --no-edit so that the editor is not opened at the end?

馃挕 Proposed Solution

Add a preventEditorOpen flag which can be false by default and we can set it to true from .commitlintrc.js

If the preventEditorOpen flag is true then the git commit command will be git commit --no-edit

@FatehAK FatehAK added the enhancement New feature or request label Dec 8, 2022
@Zhengqbbb
Copy link
Owner

I will try git commit --no-edit

@FatehAK
Copy link
Author

FatehAK commented Dec 8, 2022

We can, it's just we work in a team setting and making every dev do that is cumbersome. So thought of having a config preventEditorOpen in .commitlintrc.js would make it much easier. Your thoughts?

@Zhengqbbb
Copy link
Owner

We can, it's just we work in a team setting and making every dev do that is cumbersome. So thought of having a config preventEditorOpen in .commitlintrc.js would make it much easier. Your thoughts?

It will be nice. I will consider adding it if it can work. Of course I also need to consider the version number of git

@FatehAK
Copy link
Author

FatehAK commented Dec 8, 2022

Great! This feature would be extremely helpful in our situation. Thanks in advance.

@Zhengqbbb
Copy link
Owner

I'm very sorry to tell you, I tried many ways, but it didn't work.

  1. https://git-scm.com/docs/githooks#_pre_merge_commit This hook is invoked by git-commit[1] right after preparing the default log message, and before the editor is started.
    I did not call the command to push the message, just the way to write the .git/COMMIT_EDITMSG file

  2. Can you close the editor directly (core.editor = false), No

image

image

@FatehAK
Copy link
Author

FatehAK commented Dec 8, 2022

Ah interesting, I see. Thanks for trying.

I think I'll set up an alias or npm script for this.

@Zhengqbbb Zhengqbbb changed the title [Feature Request] [Feature Request] Can use 'prepare-commit-msg' hook --no-edit Dec 8, 2022
@Zhengqbbb
Copy link
Owner

Yep

In the future if I find out the solution I will reopen the ISSUE

@FatehAK
Copy link
Author

FatehAK commented Dec 8, 2022

Will do the same thanks!

@Zhengqbbb
Copy link
Owner

work~
TIP: This hook has a characteristic of merging messages.
VIM can be circumvented, and I will write an article later on why use git commit -m ''

add .bashrc or .zshrc

git() {
  local _cmd="$*"
  if [ "$1" = "commit" ] && [ "${_cmd%%"--help"}" = "$_cmd"  ]; then
    shift 1; command git commit -m ''
  else
    command git "$@"
  fi
}

@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Mar 7, 2024

Finally !!! We find out a way to resolve open editor !!! 馃ぉ @FatehAK

  1. Change you project core editor from default vi to cat~
git config core.editor cat
git commit # try it !
  1. Can add project scripts (like pnpm's postinstall) to help other project collaborator
// package.json
"scripts": {
  "postinstall": "git config core.editor cat",
}

@ItsTarik
Copy link

@Zhengqbbb this works as expected 馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants