Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def rmfile(path: PathLike) -> None:
treatment."""
if osp.isfile(path):
if sys.platform == "win32":
os.chmod(path, 0o777)
os.chmod(path, stat.S_IWUSR)
os.remove(path)


Expand Down
16 changes: 16 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
is_cygwin_git,
join_path,
remove_password_if_present,
rmfile,
rmtree,
stream_copy,
)
Expand Down Expand Up @@ -213,6 +214,21 @@ def preen_dir2():
assert old_mode == new_mode, f"Should stay {old_mode:#o}, became {new_mode:#o}."


class TestRmfile:
"""Tests for :func:`git.util.rmfile`."""

def test_deletes_readonly_file(self):
# Automatically works on Unix, but requires special handling on Windows.
with writable_fixture("rmfile.sh") as temporary:
file = temporary.path().resolve() / "readonly"
# rmfile ignores missing paths, so check that the fixture made a read-only file.
assert file.is_file()
assert not file.stat().st_mode & stat.S_IWUSR

rmfile(file)
assert not file.exists()


def _xfail_param(*values, **xfail_kwargs):
"""Build a pytest.mark.parametrize parameter that carries an xfail mark."""
return pytest.param(*values, marks=pytest.mark.xfail(**xfail_kwargs))
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/rmfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eu
touch readonly
chmod a-w readonly
Loading