Skip to content

Commit 1d5507d

Browse files
gabe-campwoile
authored andcommitted
fix: removing folder in windows throwing a PermissionError
* #issue67 created handler for readonly files/dirs to be passed to shutil.rmtree(). will change permissions and retry operation if readonly dir/file found. * added reference for where handler code came from * prettied report of c.err * created exception to raise if unable to change permission in handler * tidy error report * correcting style mistakes Closes #67
1 parent 4346ef4 commit 1d5507d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

commitizen/commands/bump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __call__(self):
122122
bump.update_version_in_files(current_version, new_version.public, files)
123123
c = git.commit(message, args="-a")
124124
if c.err:
125-
out.error(c.err)
125+
out.error("git.commit errror: \"{}\"".format(c.err.strip()))
126126
raise SystemExit(COMMIT_FAILED)
127127
c = git.tag(new_tag_version)
128128
if c.err:

tests/test_bump_command.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import shutil
3+
import stat
4+
import errno
35
import sys
46
import uuid
57
from pathlib import Path
@@ -10,6 +12,20 @@
1012
from commitizen import cli, cmd, git
1113

1214

15+
def ReadOnlyException(Exception):
16+
pass
17+
18+
19+
# https://stackoverflow.com/questions/1213706/what-user-do-python-scripts-run-as-in-windows
20+
def handleRemoveReadOnly(func, path, exc):
21+
excvalue = exc[1]
22+
if func in (os.rmdir, os.remove, shutil.rmtree) and excvalue.errno == errno.EACCESS:
23+
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.IRWXO) # 744
24+
func(path)
25+
else:
26+
raise ReadOnlyException
27+
28+
1329
@pytest.fixture
1430
def create_project():
1531
current_directory = os.getcwd()
@@ -20,7 +36,7 @@ def create_project():
2036
os.chdir(full_tmp_path)
2137
yield
2238
os.chdir(current_directory)
23-
shutil.rmtree(full_tmp_path)
39+
shutil.rmtree(full_tmp_path, handleRemoveReadOnly)
2440

2541

2642
def create_file_and_commit(message: str, filename: Optional[str] = None):

0 commit comments

Comments
 (0)