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

[BUG] temporary file for cog commit -e should have fixed extension #334

Open
brainplot opened this issue Oct 31, 2023 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@brainplot
Copy link
Contributor

Describe the bug
The temporary file that cog commit -e opens in order to compose a new commit message should have a fixed extension so that it can be associated with a file format in a text editor.

My text editor of choice is neovim and whenever I run git commit normally, it knows how to enable the correct syntax highlighting and a few extra custom options by virtue of the fact the file being edited is COMMIT_MSG.

This does not happen when I run cog commit -e because the file cocogitto opens under the hood is a temporary file with a name such as .tmpGjG8hc. That doesn't mean anything for my text editor, nor does it have a useful extension I can associate with a Git commit message file type.

Right now all I can do is run :setfiletype gitcommit whenever a new temporary buffer opens up, which is not ideal.

If you agree that this is something worth fixing, I can attempt a PR!

@brainplot brainplot added the bug Something isn't working label Oct 31, 2023
@brainplot brainplot changed the title [BUG] temporary file for git commit should have fixed extension [BUG] temporary file for cog commit -e should have fixed extension Oct 31, 2023
@oknozor
Copy link
Collaborator

oknozor commented Nov 16, 2023

That's definitely worth fixing, please go ahead and make a PR !

@brainplot
Copy link
Contributor Author

Thank you. I can attempt fixing this over the weekend. In the meantime, what do you think the new format for the file name should be?

@oknozor
Copy link
Collaborator

oknozor commented Nov 16, 2023

No need for a custom filename, COMMIT_EDITMSG should be recognized by any editor.
The current issue is that we use a temp file to edit the commit message here:

pub fn edit_message<P: AsRef<Path>>(
path: P,
breaking: bool,
) -> Result<(Option<String>, Option<String>, bool)> {
let template = fs::read_to_string(path.as_ref())?;
let edited = edit::edit(template)?;

Instead we should use edit::edit_file to directly edit COMMIT_EDITMSG file then, read it back so it can be parsed as a conventional commit. The remaining COMMIT_EDITMSG file should then be removed so it's not picked by later git commit usage.

Also a nice addition would be to generate a git like commit message template containing the current changes:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Your branch is up to date with 'origin/main'.
#
# Changes to be committed:
#	new file:   package-lock.json
#	new file:   package.json
#	modified:   web/nami/src/lib/index.ts
#

@brainplot
Copy link
Contributor Author

Yes, I was indeed asking myself why cocogitto didn't use COMMIT_EDITMSG in the first place and what the purpose of the temporary file actually was. I can try to implement this change.

As for your second point, leaving the COMMIT_EDITMSG file, to my knowledge and from what I have observed using Git, shouldn't be an issue since Git will clean it up and overwrite it, before letting you edit it. However, I would like to confirm this by reading Git's source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants