LinusU / emoji-commit

44 stars 6 forks source link

Emoji-commit always overwrite commit message (.git/COMMIT_EDITMSG) #15

Closed oscarjohansson94 closed 2 years ago

oscarjohansson94 commented 2 years ago

Background When emoji-commit receives the path .git/COMMIT_EDITMSG it assumes that the file is empty and it will initialize a new commit message by displaying the emoji-picker. This is the typical and desired behavior when invoking git commit. This will overwrite the content of .git/COMMIT_EDITMSG .

Issue I have found some cases where emoji-commit will receive .git/COMMIT_EDITMSG and it is not desired to overwrite the content of .git/COMMIT_EDITMSG.

  1. After doing a git pull --rebase that results in one or more conflicts, the final step of resolving those conflicts are by running git rebase --continue. Git wants to give the user the option to edit the commit message (as documented in https://git-scm.com/docs/git-rebase#_commit_rewording) which results in .git/COMMIT_EDITMSG being sent to emoji-commit.
    1. After running git rebase --interactive and selecting reword on one or more commits, the previous message will be written to .git/COMMIT_EDITMSG and provided to emoji-commit.
  2. When running git commit --amend.

Solution I propose that we solve this by checking if the git message is empty (either each line is empty or starts with a #) before displaying the emoji-picker. If the message is empty we proceed as always and show the emoji-picker. Otherwise we launch the default editor with the given path, which will give the user the option to edit or keep the current message. I will create a PR with a solution proposal.

LinusU commented 2 years ago

Fixed in 🚢 0.1.9 / 2022-10-11