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

Cannot commit using tmp file if computer name has a space in it #572

Closed
schmi-schmi opened this issue Aug 29, 2022 · 4 comments
Closed

Cannot commit using tmp file if computer name has a space in it #572

schmi-schmi opened this issue Aug 29, 2022 · 4 comments

Comments

@schmi-schmi
Copy link

Description

When cz c is used, the questions appear as they should. Only when all questions are answered does the same error appear:
error: pathspec 'Micks\AppData\Local\Temp\tmpsxrs5lc0' did not match any file(s) known to git

I discovered within Commitizen a tmp file is being generated to save the commit message is a converted format so that it can be committed using the contents of the file.

I found the bug on my side so I can suggest a solution. In the git.py:95 file, the code looked as follows:

def commit(message: str, args: str = "") -> cmd.Command:
    f = NamedTemporaryFile("wb", delete=False)
    f.write(message.encode("utf-8"))
    f.close()
    c = cmd.run(f"git commit {args} -F {f.name}")
    os.unlink(f.name)
    return c

This should be changed to:

def commit(message: str, args: str = "") -> cmd.Command:
    f = NamedTemporaryFile("wb", delete=False)
    f.write(message.encode("utf-8"))
    f.close()
    c = cmd.run(f'git commit {args} -F "{f.name}"')
    os.unlink(f.name)
    return c

The error stopped appearing and I was able to complete the commit successfully. Hope this helps. :)

Steps to reproduce

cz c

Note: the computer name must include a space.

Current behavior

Produces a pathspec error ( common in git when a file cannot be found but is being used to commit )

Desired behavior

cz c should complete without the error appearing.

Screenshots

I printed out the full pathspec as it is stored after creating the tmp file. The actual pathspec is above, while the error shows what is being used for the commit.
image

Environment

  • commitizen version: 2.32.2
  • python version: 3.9.10
  • Operating System: Windows

Additional environment setup required:

  • computer name must include a space
@woile
Copy link
Member

woile commented Aug 29, 2022

Hey thanks for finding this error! if you want feel free to send us a PR with this fix.

@Cliying94
Copy link

Cliying94 commented Mar 30, 2024

Take this issue.
c.c. @Lee-W

@Lee-W
Copy link
Member

Lee-W commented Mar 30, 2024

@Cliying94 Sure. Let me assign it to you. Thanks for your help!

ttw225 added a commit to ttw225/commitizen that referenced this issue Mar 30, 2024
…es issue in git commit function

This test verifies parameter passing using markers to ensure that function arguments are correctly handled and propagated.

commitizen-tools#572
ttw225 added a commit to ttw225/commitizen that referenced this issue Mar 30, 2024
…es issue in git commit function

This test verifies parameter passing using markers to ensure that function arguments are correctly handled and propagated.

commitizen-tools#572
Lee-W pushed a commit that referenced this issue Mar 30, 2024
…es issue in git commit function

This test verifies parameter passing using markers to ensure that function arguments are correctly handled and propagated.

#572
@Lee-W
Copy link
Member

Lee-W commented Mar 30, 2024

Closed by: #1039

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

No branches or pull requests

4 participants