Skip to content

Commit

Permalink
Merge pull request #236 from jacebrowning/hotfix/v1.2.1
Browse files Browse the repository at this point in the history
Hotfix v1.2.1
  • Loading branch information
jacebrowning committed Feb 26, 2017
2 parents 1005c69 + b413f27 commit b1e9be0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision History

## 1.2.1 (2017/02/25)

- Fixed issue where could `doorstop create` deleting the whole project.

## 1.2 (2017/02/11)

- Disabled excessive text cleanup in items. (credit: [@michaelnt](https://github.com/michaelnt))
Expand Down
2 changes: 1 addition & 1 deletion doorstop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

__project__ = 'Doorstop'
__version__ = '1.2'
__version__ = '1.2.1'

CLI = 'doorstop'
GUI = 'doorstop-gui'
Expand Down
10 changes: 7 additions & 3 deletions doorstop/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ def wrapped(self, *args, **kwargs):
"""Wrapped method to remove and expunge the returned document."""
document = func(self, *args, **kwargs) or self
if settings.ADDREMOVE_FILES and document.tree:
document.tree.vcs.delete(document.path)
document.tree.vcs.delete(document.config)
# pylint: disable=W0212
if settings.CACHE_DOCUMENTS and document.tree:
document.tree._document_cache[document.prefix] = None
log.trace("expunged document: {}".format(document))
BaseFileObject.delete(document, document.path)
try:
os.rmdir(document.path)
except OSError:
# Directory wasn't empty
pass
return document
return wrapped

Expand Down Expand Up @@ -346,7 +350,7 @@ def set(self, name, value):
def delete(self, path):
"""Delete the object's file from the file system."""
if self._exists:
log.info("deleting {}...".format(self))
log.info("deleting {}...".format(path))
common.delete(path)
self._loaded = False # force the object to reload
self._exists = False # but, prevent future access
Expand Down
18 changes: 14 additions & 4 deletions doorstop/core/test/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,22 @@ def test_validate_hook(self):
self.assertEqual(5, mock_hook.call_count)

@patch('doorstop.core.item.Item.delete')
@patch('doorstop.common.delete')
def test_delete(self, mock_common_delete, mock_item_delete):
@patch('os.rmdir')
def test_delete(self, mock_delete, mock_item_delete):
"""Verify a document can be deleted."""
self.document.delete()
self.assertEqual(1, mock_common_delete.call_count)
self.assertEqual(6, mock_item_delete.call_count)
self.assertEqual(1, mock_delete.call_count)
self.document.delete() # ensure a second delete is ignored

@patch('doorstop.core.item.Item.delete')
@patch('os.rmdir')
def test_delete_with_assets(self, mock_delete, mock_item_delete):
"""Verify a document's assets aren't deleted."""
mock_delete.side_effect = OSError
self.document.delete()
self.assertEqual(6, mock_item_delete.call_count)
self.assertEqual(1, mock_delete.call_count)
self.document.delete() # ensure a second delete is ignored

@patch('doorstop.core.item.Item.delete', Mock())
Expand All @@ -548,7 +558,7 @@ def test_delete_cache(self):
self.document.tree._document_cache = {}
self.document.delete()
self.document.tree.vcs.delete.assert_called_once_with(
self.document.path)
self.document.config)
self.assertIs(
None, self.document.tree._document_cache[self.document.prefix])

Expand Down
2 changes: 1 addition & 1 deletion doorstop/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def add(self, path):
self.call('git', 'add', self.relpath(path))

def delete(self, path):
self.call('git', 'rm', '-r', self.relpath(path), '--force', '--quiet')
self.call('git', 'rm', self.relpath(path), '--force', '--quiet')

def commit(self, message=None):
message = message or input("Commit message: ") # pylint: disable=W0141
Expand Down
5 changes: 3 additions & 2 deletions doorstop/core/vcs/mockvcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Plug-in module to simulate the storage of requirements in a repository."""

import os

from doorstop import common
from doorstop.core.vcs.base import BaseWorkingCopy
Expand All @@ -26,7 +26,8 @@ def add(self, path):
log.debug("$ simulated add on: {}...".format(path))

def delete(self, path):
log.debug("$ simulated delete on: {}...".format(path))
os.remove(path)
log.debug("$ Deleted {}...".format(path))

def commit(self, message=None):
log.debug("$ simulated commit")
8 changes: 5 additions & 3 deletions doorstop/core/vcs/test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_add(self, mock_call):
def test_delete(self, mock_call):
"""Verify Git can delete files."""
self.delete()
calls = [call(("git", "rm", "-r", self.path, "--force", "--quiet"))]
calls = [call(("git", "rm", self.path, "--force", "--quiet"))]
mock_call.assert_has_calls(calls)

def test_commit(self, mock_call):
Expand Down Expand Up @@ -102,11 +102,13 @@ def test_add(self, mock_call):
calls = []
mock_call.assert_has_calls(calls)

def test_delete(self, mock_call):
"""Verify the placeholder VCS does not delete files."""
@patch('os.remove')
def test_delete(self, mock_remove, mock_call):
"""Verify the placeholder VCS deletes files, as required by document.delete."""
self.delete()
calls = []
mock_call.assert_has_calls(calls)
mock_remove.assert_called_once_with(self.path)

def test_commit(self, mock_call):
"""Verify the placeholder VCS does not commit files."""
Expand Down

0 comments on commit b1e9be0

Please sign in to comment.