commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter
http://commitizen.github.io/cz-cli/
MIT License
16.89k stars 552 forks source link

git cz just opens the local editor #558

Open MartinMuzatko opened 6 years ago

MartinMuzatko commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Hello, I have the same issue (but on real Linux system :smiley:) 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 :wink:

jimthedev commented 6 years ago

@sfauvart I agree that this could be more clear.

achillesrasquinha commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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

filippopiconese commented 5 years ago

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

ozum commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

@semoal unfortunately no.

commitizen-bot commented 5 years ago

:tada: This issue has been resolved in version 3.1.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

ozum commented 5 years ago

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

mrchief commented 5 years ago

@ozum Is your repo commitizen friendly?

ozum commented 5 years ago

@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";

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 commented 5 years ago

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

mrchief commented 5 years ago

When I execute git commit, editor opens,

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

mrchief commented 5 years ago

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

zhangshichuan commented 4 years ago

@achillesrasquinha thx

benjaminaplin commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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?

dmwelch commented 3 years ago

@yeegor https://github.com/commitizen/cz-cli/issues/161#issuecomment-199448830

atomicrobokid commented 2 years ago

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 commented 8 months ago

When I execute git commit, editor opens

!!! ref: https://github.com/commitizen/cz-cli/issues/934#issuecomment-1982811302

git config --local core.editor cat

image