cz-cli icon indicating copy to clipboard operation
cz-cli copied to clipboard

git cz just opens the local editor

Open MartinMuzatko opened this issue 7 years ago • 25 comments

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?

MartinMuzatko avatar Aug 31 '18 14:08 MartinMuzatko

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.

jimthedev avatar Sep 18 '18 14:09 jimthedev

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:

sfauvart avatar Oct 01 '18 20:10 sfauvart

@sfauvart I agree that this could be more clear.

jimthedev avatar Oct 01 '18 21:10 jimthedev

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

achillesrasquinha avatar Dec 09 '18 03:12 achillesrasquinha

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.

mrchief avatar Jan 31 '19 19:01 mrchief

@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?

jimthedev avatar Feb 21 '19 18:02 jimthedev

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

mrchief avatar Feb 22 '19 16:02 mrchief

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

filippopiconese avatar Apr 19 '19 21:04 filippopiconese

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,

ozum avatar May 22 '19 16:05 ozum

@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.

semoal avatar Jun 10 '19 11:06 semoal

@semoal unfortunately no.

ozum avatar Jun 11 '19 11:06 ozum

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

The release is available on:

Your semantic-release bot :package::rocket:

commitizen-bot avatar Jul 17 '19 22:07 commitizen-bot

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

ozum avatar Jul 21 '19 15:07 ozum

@ozum Is your repo commitizen friendly?

mrchief avatar Jul 21 '19 19:07 mrchief

@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.

ozum avatar Jul 22 '19 06:07 ozum

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

itninja-hue avatar Oct 01 '19 08:10 itninja-hue

When I execute git commit, editor opens,

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

mrchief avatar Oct 01 '19 16:10 mrchief

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

mrchief avatar Oct 01 '19 16:10 mrchief

@achillesrasquinha thx

zhangshichuan avatar Nov 27 '19 14:11 zhangshichuan

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
}

benjaminaplin avatar Mar 11 '20 14:03 benjaminaplin

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?

ozum avatar May 08 '20 14:05 ozum

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?

yeegor avatar Mar 05 '21 10:03 yeegor

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

dmwelch avatar Jul 27 '21 20:07 dmwelch

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

atomicrobokid avatar Jan 31 '22 21:01 atomicrobokid

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

Zhengqbbb avatar Mar 13 '24 15:03 Zhengqbbb