Skip to content

Commit

Permalink
improve what changed parser. Fix #29
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaitan committed Nov 17, 2014
1 parent 8678c8d commit 8997c58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
30 changes: 24 additions & 6 deletions tests/test_git.py
Expand Up @@ -210,17 +210,35 @@ def test_history_log(self):
self.assertTrue(str(history[0]['insertion_relative']).startswith('16.6'))
self.assertEqual(history[1]['message'], u'"10 lines ñoñas"')


def test_whatchanged(self):
self.page.raw = 'line\n'
Git().commit(self.page, message=u'//')
Git().commit(self.page, message=u'"//"')
another_page = PageFactory(path='another-page.rst')
another_page.raw = "hello!"
Git().commit(another_page, message=u'hello history')
response = self.client.get(reverse('waliki_whatchanged'))
import ipdb; ipdb.set_trace()
changes = response.context[0]['changes']

self.assertEqual(len(changes), 2)
self.assertEqual(changes[0]['page'], another_page)
self.assertEqual(changes[1]['page'], self.page)
self.assertEqual(changes[0]['message'], 'hello history')
self.assertEqual(changes[1]['message'], '"//"')

def test_whatchanged_multiples_files_in_one_commit(self):
git_dir = os.path.join(WALIKI_DATA_DIR, '.git')
shutil.rmtree(git_dir)
Git()

def test_whatchanged_multiples_files_in_commit(self):
self.page.raw = 'line\n'
another_page = PageFactory(path='another-page.rst')
another_page.raw = "hello!"
git.commit('-am', 'commit todo')
git.add('.')
git.commit('-am', 'commit all')
response = self.client.get(reverse('waliki_whatchanged'))
import ipdb; ipdb.set_trace()
changes = response.context[0]['changes']
self.assertEqual(len(changes), 2)
self.assertEqual(changes[0]['page'], another_page)
self.assertEqual(changes[1]['page'], self.page)
self.assertEqual(changes[0]['message'], 'commit all')
self.assertEqual(changes[1]['message'], 'commit all')
8 changes: 6 additions & 2 deletions waliki/git/__init__.py
Expand Up @@ -107,8 +107,12 @@ def whatchanged(self):
raw_log = git.whatchanged("--pretty=format:%s" % GIT_LOG_FORMAT).stdout.decode('utf8')
logs = re.findall(r'((.*)\x1f(.*)\x1f(.*)\x1f(.*)\x1f(.*))?\n:.*\t(.*)', raw_log, flags=re.MULTILINE | re.UNICODE)
for log in logs:
import ipdb; ipdb.set_trace()
pages.append(log[1:])
if log[0]:
log = list(log[1:])
log[-1] = [log[-1]]
pages.append(list(log))
else:
pages[-1][-1].append(log[-1])
return pages

def pull(self, remote):
Expand Down

0 comments on commit 8997c58

Please sign in to comment.