Skip to content

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

Closed
@schmi-schmi

Description

@schmi-schmi

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions