diff --git a/gitman/shell.py b/gitman/shell.py index 769a0cef..9654533e 100644 --- a/gitman/shell.py +++ b/gitman/shell.py @@ -80,12 +80,13 @@ def ln(source, target): def rm(path): - show('rm', '-rf', path) - if os.path.exists(path): - if os.path.isdir(path): - shutil.rmtree(path) - else: - os.remove(path) + if os.name == 'nt': + if os.path.isfile(path): + call('del', '/Q', '/F', path, _shell=True) + elif os.path.isdir(path): + call('rmdir', '/Q', '/S', path, _shell=True) + else: + call('rm', '-rf', path) def show(name, *args, stdout=True): diff --git a/gitman/tests/test_shell.py b/gitman/tests/test_shell.py index f3e7b74a..285dbfec 100644 --- a/gitman/tests/test_shell.py +++ b/gitman/tests/test_shell.py @@ -66,19 +66,20 @@ def test_ln_missing_parent(self, mock_call): shell.ln('mock/target', 'mock/source') assert_calls(mock_call, ["ln -s mock/target mock/source"]) - @patch('os.remove') - @patch('os.path.exists', Mock(return_value=True)) - def test_rm_file(self, mock_remove, mock_call): + @patch('os.path.isfile', Mock(return_value=True)) + def test_rm_file(self, mock_call): """Verify the commands to delete files.""" shell.rm('mock/path') - mock_remove.assert_called_once_with('mock/path') - assert_calls(mock_call, []) + if os.name == 'nt': + assert_calls(mock_call, ["del /Q /F mock/path"]) + else: + assert_calls(mock_call, ["rm -rf mock/path"]) - @patch('shutil.rmtree') - @patch('os.path.exists', Mock(return_value=True)) @patch('os.path.isdir', Mock(return_value=True)) - def test_rm_directory(self, mock_rmtree, mock_call): + def test_rm_directory(self, mock_call): """Verify the commands to delete directories.""" shell.rm('mock/dirpath') - mock_rmtree.assert_called_once_with('mock/dirpath') - assert_calls(mock_call, []) + if os.name == 'nt': + assert_calls(mock_call, ["rmdir /Q /S mock/dirpath"]) + else: + assert_calls(mock_call, ["rm -rf mock/dirpath"])