Fix the __nonzero__ method for WikiPage

This commit is contained in:
Chase Sterling 2016-07-05 20:29:01 -04:00
parent 7a20135d55
commit 2e6db650f2

View file

@ -5,8 +5,9 @@ import ghdiff
import gittle.utils import gittle.utils
import yaml import yaml
from gittle import Gittle from gittle import Gittle
from dulwich.object_store import tree_lookup_path
from dulwich.repo import NotGitRepository from dulwich.repo import NotGitRepository
from realms.lib.util import to_canonical, cname_to_filename, filename_to_cname from realms.lib.util import cname_to_filename, filename_to_cname
from realms import cache from realms import cache
from realms.lib.hook import HookMixin from realms.lib.hook import HookMixin
@ -311,5 +312,10 @@ class WikiPage(object):
return ghdiff.diff(old.data, self.data) return ghdiff.diff(old.data, self.data)
def __nonzero__(self): def __nonzero__(self):
# TODO: Check if page is in index of self.sha # Verify this file is in the tree for the given commit sha
return bool(self.data) try:
tree_lookup_path(self.wiki.repo.get_object, self.wiki.repo[self.sha].tree, self.filename)
except KeyError:
# We'll get a KeyError if self.sha isn't in the repo, or if self.filename isn't in the tree of our commit
return False
return True