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

git cz just opens the local editor #558

Open
MartinMuzatko opened this issue Aug 31, 2018 · 25 comments · Fixed by #613
Open

git cz just opens the local editor #558

MartinMuzatko opened this issue Aug 31, 2018 · 25 comments · Fixed by #613
Labels

Comments

@MartinMuzatko
Copy link

git cz is broken for me.

I wanted to get started but it does not work.

I'm using Windows WSL (ubuntu shell on windows) together with zsh.

This is my gitconfig:

[alias]
        l = log --graph --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
        ls = ls-files
        st = status
        amend = commit --amend
        amendn = ammend --no-edit
        diffs = diff --staged
        ch = checkout
        f = fetch
        p = push
        c = commit
        a = add -p
        r = reset -p
        aliases = !git config -l | grep alias | cut -c 7-
        whois = !sh -c 'git log -i -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -
[diff]
        tool = meld
[push]
        default = simple
[core]
        autocrlf = input
[branch]
        autosetuprebase = always

Even with my gitconfig removed, I get the following:

cz

Is there a known bug?

@jimthedev
Copy link
Member

I suspect you might not have an adapter configured in your repo and thus git-cz is operating as if there is no package. This means that you should either pass it -m "My commit message" in order to avoid having your editor open or set a global adapter on your system. Just a guess.

@sfauvart
Copy link

sfauvart commented Oct 1, 2018

Hello, I have the same issue (but on real Linux system 😃)
I think it's the same problem in issue #558
You have to run

commitizen init cz-conventional-changelog --save-dev --save-exact

before to make your repo comittizen friendly

I think the readme should be updated to indicate the command to be executed for new projects
as a commitizen beginner, it did not seem very clear to me 😉

@jimthedev
Copy link
Member

@sfauvart I agree that this could be more clear.

@achillesrasquinha
Copy link

Faced the same issue. You can enforce this globally as mentioned within the README. Here's a one-liner fix:

$ npm install -g commitizen cz-conventional-changelog && echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

@mrchief
Copy link
Contributor

mrchief commented Jan 31, 2019

IMO, the readme needs an update to mention this "first". The current sequence creates this confusion:

image

And this little gem gets easily ignored:

If you're not working in a Commitizen friendly repository, then git cz will work just the same as git commit.

So if the readme can emphasise the repo needs to be commitizen friendly first (and if not, how to make it so), I think this confusion will go away.

I just had to explain the same to my colleague and I'm sure many others face the same problem.

@jimthedev
Copy link
Member

@mrchief agreed! Would you be open to submitting a docs pr for the readme in a format that makes more sense to you given the scenario you described?

@mrchief
Copy link
Contributor

mrchief commented Feb 22, 2019

Sure! Although it may take me a while for me so if anyone else wants to pitch in, please feel free.

@filippopiconese
Copy link

Following this guide, I solved this problem. I hope it can help you.
https://medium.com/@lorenzen.jacob/standardize-git-commit-messages-b3f938f078be

@ozum
Copy link

ozum commented May 22, 2019

Same issue, and I installed adapter. git cz --hook opens editor whereas git-cz does not:

git cz --hook

This opens editor:

.czrc (local)

{ "path": "cz-conventional-changelog" }

.huskyrc

{
  hooks: {
    "prepare-commit-msg": "exec < /dev/tty && git cz --hook",
    "pre-commit": "echo 'some message' && npm run doc && git add README.md && lint-staged",
    "commit-msg": "commitlint -e $GIT_PARAMS"
  }
}

git-cz

If I delete prepare-commit-msg hook and use git-cz directly, no editor opens:
package.json

{
  "scripts": {    
    "commit": "git-cz"
  }
}

I want to have prepare-commit-msg for those unaware of commitizen in project.

Thanks,

@semoal
Copy link

semoal commented Jun 10, 2019

@ozum did you find any solution? I don't like to run npm run x for just git commit ... Integration with commit hook is the best.

@ozum
Copy link

ozum commented Jun 11, 2019

@semoal unfortunately no.

@commitizen-bot
Copy link

🎉 This issue has been resolved in version 3.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ozum
Copy link

ozum commented Jul 21, 2019

Using 3.1.2, my issue still persists... Is it possible to reopen this case?

@jimthedev jimthedev reopened this Jul 21, 2019
@mrchief
Copy link
Contributor

mrchief commented Jul 21, 2019

@ozum Is your repo commitizen friendly?

@ozum
Copy link

ozum commented Jul 22, 2019

@mrchief, yes it is commitizen friendly, you can see my repo here to see configuration: https://github.com/ozum/scrap/tree/v0.0.37

I'm experimenting a few things for the workflow in that repo.

With "prepare-commit-msg": "exec < /dev/tty && git cz --hook";

  • When I execute git commit, editor opens,
  • When I execute npm run commit, then commitizen prompts/questions executed more than once. (It asks again when I finished to answer questions)

Note: In v.0.0.38, I disabled "prepare-commit-msg": "exec < /dev/tty && git cz --hook", then npm run commit works as expected. Of course git commit by-passes commitizen.

@itninja-hue
Copy link

can i pass a adapter path in command , for example , git cz path-to-adapter ?

@mrchief
Copy link
Contributor

mrchief commented Oct 1, 2019

When I execute git commit, editor opens,

@ozum cz-cli doesn't hook into git commit. So what you're seeing is normal.

@mrchief
Copy link
Contributor

mrchief commented Oct 1, 2019

@itninja-hue That seems like a separate question altogether. You should open up a new issue.

@zhangshichuan
Copy link

@achillesrasquinha thx

@benjaminaplin
Copy link

I also had trouble with the editor popping up when using the prepare-commit-msg hook. git commit would result in the editor popping up, but git commit -m '<any message>' would work correctly. Adding this function to my .bashrc seems to work because it overrides git commit with git commit -m ''.

function git {
  if [[ "$1" == "commit" && "$@" != *"--help"* ]]; then
    shift 1
    command git commit -m ''
  else
    command git "$@"
  fi
}

@ozum
Copy link

ozum commented May 8, 2020

Lots of time passed, I returned to adjust my workflow.

Using `"prepare-commit-msg": "exec < /dev/tty && git cz --hook";

Is there a solution not to open local editor?

@yeegor
Copy link

yeegor commented Mar 5, 2021

Still relevant for me, I have a commitzen-friendly repository and I want commitzen to be enforced for people unaware of it. Is there any way to achieve it?

christian-hawk added a commit to GluuFederation/gluu-passport that referenced this issue Mar 26, 2021
Developer can run it, if desired, using `npx cz`.

Also there are known issues using Husky and Commitizen together
- commitizen/cz-cli#558 (comment)
- commitizen/cz-cli#432 (wont fix)
- typicode/husky#99
@dmwelch
Copy link
Contributor

dmwelch commented Jul 27, 2021

@yeegor #161 (comment)

@atomicrobokid
Copy link

Any update to this? I'm facing exactly the same issue as described above, tried various combinations and commands and it either runs twice, or opens vim at the end. Frustrating and makes the prompt part of commitzen useless for me

@Zhengqbbb
Copy link
Contributor

When I execute git commit, editor opens

!!!
ref: #934 (comment)

git config --local core.editor cat

image

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

Successfully merging a pull request may close this issue.