Skip to content

[WinError 123] The syntax for filename, directory name, or volume label is incorrect: '' #1219

Closed

Description

@Nusserdt

I try to install pre-commit with the manual from pre-commit.com.

At step 3 I get the following error message on a Windows 10 machine:

[WinError 123] The syntax for filename, directory name, or volume label is incorrect: ''


.pre-commit-config.yaml

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
-   repo: https://server/Sandbox/Repo/_git/Repo
    rev: v2.4.0
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-added-large-files

error information

An unexpected error has occurred: OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: ''
Traceback (most recent call last):
  File "c:\user\programme\python\python37-32\lib\site-packages\pre_commit\error_handler.py", line 72, in error_handler
    yield
  File "c:\user\programme\python\python37-32\lib\site-packages\pre_commit\main.py", line 294, in main
    _adjust_args_and_chdir(args)
  File "c:\user\programme\python\python37-32\lib\site-packages\pre_commit\main.py", line 125, in _adjust_args_and_chdir
    os.chdir(git.get_root())
OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: ''

--version
Python 3.7.3
pre-commit 1.20.0

Activity

  1. asottile commented on Nov 12, 2019

    @asottile
    Member

    This looks like your git is broken, what does the following say:

    which -a git
    git rev-parse --show-toplevel

    you should get something like

    asott@asottile-laptop MINGW64 ~/workspace/pre-commit (master)
    $ which -a git
    /mingw64/bin/git
    /mingw64/bin/git
    /cmd/git
    /mingw64/bin/git
    
    asott@asottile-laptop MINGW64 ~/workspace/pre-commit (master)
    $ git rev-parse --show-toplevel
    C:/Users/asott/workspace/pre-commit

    Also could you please include the command you ran, the full unedited output, and the contents of the log file it mentions?

  2. Nusserdt commented on Nov 13, 2019

    @Nusserdt
    Author

    Sorry I forget to mention.

    $ which -a git
    /mingw64/bin/git
    /mingw64/bin/git
    /cmd/git
    
    $ git rev-parse --show-toplevel
    C:/Users/user/Desktop/Sandbox/Repo
    

    Command

    pre-commit install
    

    Output

    An unexpected error has occurred: OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: ''
    Check the log at C:\Users\user/.cache\pre-commit\pre-commit.log
    

    Log File

    version information

    pre-commit version: 1.20.0
    sys.version:
        3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]
    sys.executable: c:\user\programme\python\python37-32\python.exe
    os.name: nt
    sys.platform: win32
    

    error information

    An unexpected error has occurred: OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: ''
    
    Traceback (most recent call last):
      File "c:\user\programme\python\python37-32\lib\site-packages\pre_commit\error_handler.py", line 72, in error_handler
        yield
      File "c:\user\programme\python\python37-32\lib\site-packages\pre_commit\main.py", line 294, in main
        _adjust_args_and_chdir(args)
      File "c:\user\programme\python\python37-32\lib\site-packages\pre_commit\main.py", line 125, in _adjust_args_and_chdir
        os.chdir(git.get_root())
    OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: ''
    
    
  3. asottile commented on Nov 13, 2019

    @asottile
    Member

    that's very strange! from the trace it looks like the same command being called from python is returning 0 but not printing the git root -- can you try a few more things for me?

    python -c "from pre_commit.util import cmd_output; print(cmd_output('git', 'rev-parse', '--show-toplevel'))"

    For me it produces something like:

    $ python -c "from pre_commit.util import cmd_output; print(cmd_output('git', 'rev-parse', '--show-toplevel'))"
    (0, 'C:/Users/asott/AppData/Local/Temp/astpretty\n', '')
  4. Nusserdt commented on Nov 13, 2019

    @Nusserdt
    Author

    Input

    python -c "from pre_commit.util import cmd_output; print(cmd_output('git', 'rev-parse', '--show-toplevel'))"
    

    Output

    (0, '', '')
    
  5. asottile commented on Nov 13, 2019

    @asottile
    Member

    How about this one?

    python -c "from pre_commit.parse_shebang import find_executable; print(find_executable('git'))"
    $ python -c "from pre_commit.parse_shebang import find_executable; print(find_executable('git'))"
    C:\Program Files\Git\mingw64\bin\git.exe
  6. Nusserdt commented on Nov 14, 2019

    @Nusserdt
    Author

    Input

    python -c "from pre_commit.parse_shebang import find_executable; print(find_executable('git'))"
    

    Output

    C:\Username\Programme\Git\cmd\git.exe
    

    (custom path)

  7. asottile commented on Nov 14, 2019

    @asottile
    Member

    what happens if you run the rev-parse --show-toplevel command with that executable?

  8. Nusserdt commented on Nov 15, 2019

    @Nusserdt
    Author

    Input

    C:\Username\Programme\Git\cmd\git.exe rev-parse --show-toplevel
    

    Output

    "" (null)
    
  9. asottile commented on Nov 15, 2019

    @asottile
    Member

    that seems to be the problem then! could you try reinstalling git maybe?

  10. Nusserdt commented on Nov 18, 2019

    @Nusserdt
    Author

    @asottile I reinstall git, when I execute pre-commit install inside Repo\.git\hooks (where .pre-commit-config.yaml stored) I still get null as output when I execute git rev-parse --show-toplevel.

    If I excute git rev-parse --show-toplevel in Repo it returns C:/Users/user/Desktop/Sandbox/Repo. Does this change something?

  11. asottile commented on Nov 18, 2019

    @asottile
    Member

    the pre-commit configuration should be inside the root of your repository (also where you'll run pre-commit install from) -- does that change things?

    oh wow I just tried this, git is the wackiest thing!?

  12. asottile commented on Nov 18, 2019

    @asottile
    Member

    The next release (probably v1.20.1 when I have some time to release) will include a better error message for this:

    $ pre-commit install
    An error has occurred: FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
    Check the log at /home/asottile/.cache/pre-commit/pre-commit.log

    I'm also seeing if I can fix this from the git side, since the behaviour seems quite strange!

  13. asottile commented on Jan 2, 2020

    @asottile
    Member

    This has been released as part of v1.21.0 (it was also fixed in git 1.24 I believe) -- thanks again for the issue 🎉!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions