Skip to content

[Windows] Create_submodule fails due to use of hidden files #516

Closed
@matthewwardrop

Description

@matthewwardrop

On Windows, the .git files are given the hidden attribute. If a file is marked as hidden, it cannot be written to using the standard Python open(..., 'w') command. This is because the underlying win32 api errors unless the attributes of the open command match the attributes of the file, and this is not exposed in the Python API

For example, consider the following snippet:

import git
r = git.Repo('test')
r.create_submodule(name='testing', path='testing', url='https://github.com/matthewwardrop/python-parampy')

On Unix, this works fine. In Windows, however, it will crash with the following stack trace:

Traceback (most recent call last):
  ...
  File "c:\program files\python35\lib\site-packages\git\repo\base.py", line 306, in create_submodule
    return Submodule.add(self, *args, **kwargs)
  File "c:\program files\python35\lib\site-packages\git\objects\submodule\base.py", line 389, in add
    mrepo = cls._clone_repo(repo, url, path, name, **kwargs)
  File "c:\program files\python35\lib\site-packages\git\objects\submodule\base.py", line 253, in _clone_repo
    cls._write_git_file_and_module_config(module_checkout_path, module_abspath)
  File "c:\program files\python35\lib\site-packages\git\objects\submodule\base.py", line 292, in _write_git_file_and_mod
ule_config
    fp = open(git_file, 'wb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\matthewwardrop\\test\\testing\\.git'

There's probably a workaround using the raw git commands, but it would be nice to have this cleaned up.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions