-
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stash-drop' of git://github.com/pmrowla/dulwich
- Loading branch information
Showing
3 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,14 @@ | |
|
||
"""Tests for dulwich.reflog.""" | ||
|
||
from io import BytesIO | ||
|
||
from dulwich.objects import ZERO_SHA | ||
from dulwich.reflog import ( | ||
drop_reflog_entry, | ||
format_reflog_line, | ||
parse_reflog_line, | ||
read_reflog, | ||
) | ||
|
||
from dulwich.tests import ( | ||
|
@@ -82,3 +86,61 @@ def test_parse(self): | |
), | ||
parse_reflog_line(reflog_line), | ||
) | ||
|
||
|
||
_TEST_REFLOG = ( | ||
b"0000000000000000000000000000000000000000 " | ||
b"49030649db3dfec5a9bc03e5dde4255a14499f16 Jelmer Vernooij " | ||
b"<[email protected]> 1446552482 +0000 " | ||
b"clone: from git://jelmer.uk/samba\n" | ||
b"49030649db3dfec5a9bc03e5dde4255a14499f16 " | ||
b"42d06bd4b77fed026b154d16493e5deab78f02ec Jelmer Vernooij " | ||
b"<[email protected]> 1446552483 +0000 " | ||
b"clone: from git://jelmer.uk/samba\n" | ||
b"42d06bd4b77fed026b154d16493e5deab78f02ec " | ||
b"df6800012397fb85c56e7418dd4eb9405dee075c Jelmer Vernooij " | ||
b"<[email protected]> 1446552484 +0000 " | ||
b"clone: from git://jelmer.uk/samba\n" | ||
) | ||
|
||
|
||
class ReflogDropTests(TestCase): | ||
def setUp(self): | ||
TestCase.setUp(self) | ||
self.f = BytesIO(_TEST_REFLOG) | ||
self.original_log = list(read_reflog(self.f)) | ||
self.f.seek(0) | ||
|
||
def _read_log(self): | ||
self.f.seek(0) | ||
return list(read_reflog(self.f)) | ||
|
||
def test_invalid(self): | ||
self.assertRaises(ValueError, drop_reflog_entry, self.f, -1) | ||
|
||
def test_drop_entry(self): | ||
drop_reflog_entry(self.f, 0) | ||
log = self._read_log() | ||
self.assertEqual(len(log), 2) | ||
self.assertEqual(self.original_log[0:2], log) | ||
|
||
self.f.seek(0) | ||
drop_reflog_entry(self.f, 1) | ||
log = self._read_log() | ||
self.assertEqual(len(log), 1) | ||
self.assertEqual(self.original_log[1], log[0]) | ||
|
||
def test_drop_entry_with_rewrite(self): | ||
drop_reflog_entry(self.f, 1, True) | ||
log = self._read_log() | ||
self.assertEqual(len(log), 2) | ||
self.assertEqual(self.original_log[0], log[0]) | ||
self.assertEqual(self.original_log[0].new_sha, log[1].old_sha) | ||
self.assertEqual(self.original_log[2].new_sha, log[1].new_sha) | ||
|
||
self.f.seek(0) | ||
drop_reflog_entry(self.f, 1, True) | ||
log = self._read_log() | ||
self.assertEqual(len(log), 1) | ||
self.assertEqual(ZERO_SHA, log[0].old_sha) | ||
self.assertEqual(self.original_log[2].new_sha, log[0].new_sha) |