|
@@ -45,6 +45,7 @@ from dulwich.tests import (
|
|
|
)
|
|
|
from dulwich.tests.utils import (
|
|
|
build_commit_graph,
|
|
|
+ make_commit,
|
|
|
make_object,
|
|
|
)
|
|
|
|
|
@@ -66,12 +67,13 @@ class ArchiveTests(PorcelainTestCase):
|
|
|
"""Tests for the archive command."""
|
|
|
|
|
|
def test_simple(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"refs/heads/master"] = c3.id
|
|
|
out = BytesIO()
|
|
|
err = BytesIO()
|
|
|
porcelain.archive(self.repo.path, b"refs/heads/master", outstream=out,
|
|
|
- errstream=err)
|
|
|
+ errstream=err)
|
|
|
self.assertEqual(b"", err.getvalue())
|
|
|
tf = tarfile.TarFile(fileobj=out)
|
|
|
self.addCleanup(tf.close)
|
|
@@ -81,22 +83,24 @@ class ArchiveTests(PorcelainTestCase):
|
|
|
class UpdateServerInfoTests(PorcelainTestCase):
|
|
|
|
|
|
def test_simple(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"refs/heads/foo"] = c3.id
|
|
|
porcelain.update_server_info(self.repo.path)
|
|
|
- self.assertTrue(os.path.exists(os.path.join(self.repo.controldir(),
|
|
|
- 'info', 'refs')))
|
|
|
+ self.assertTrue(os.path.exists(
|
|
|
+ os.path.join(self.repo.controldir(), 'info', 'refs')))
|
|
|
|
|
|
|
|
|
class CommitTests(PorcelainTestCase):
|
|
|
|
|
|
def test_custom_author(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"refs/heads/foo"] = c3.id
|
|
|
- sha = porcelain.commit(self.repo.path, message=b"Some message",
|
|
|
- author=b"Joe <joe@example.com>", committer=b"Bob <bob@example.com>")
|
|
|
+ sha = porcelain.commit(
|
|
|
+ self.repo.path, message=b"Some message",
|
|
|
+ author=b"Joe <joe@example.com>",
|
|
|
+ committer=b"Bob <bob@example.com>")
|
|
|
self.assertTrue(isinstance(sha, bytes))
|
|
|
self.assertEqual(len(sha), 40)
|
|
|
|
|
@@ -169,10 +173,12 @@ class CloneTests(PorcelainTestCase):
|
|
|
target_path = tempfile.mkdtemp()
|
|
|
errstream = BytesIO()
|
|
|
self.addCleanup(shutil.rmtree, target_path)
|
|
|
- r = porcelain.clone(self.repo.path, target_path,
|
|
|
- bare=True, errstream=errstream)
|
|
|
- self.assertEqual(r.path, target_path)
|
|
|
- self.assertRaises(KeyError, Repo(target_path).head)
|
|
|
+ with porcelain.clone(
|
|
|
+ self.repo.path, target_path, bare=True,
|
|
|
+ errstream=errstream) as r:
|
|
|
+ self.assertEqual(r.path, target_path)
|
|
|
+ with Repo(target_path) as r:
|
|
|
+ self.assertRaises(KeyError, r.head)
|
|
|
self.assertFalse(b'f1' in os.listdir(target_path))
|
|
|
self.assertFalse(b'f2' in os.listdir(target_path))
|
|
|
|
|
@@ -187,7 +193,8 @@ class CloneTests(PorcelainTestCase):
|
|
|
target_path = tempfile.mkdtemp()
|
|
|
errstream = BytesIO()
|
|
|
self.addCleanup(shutil.rmtree, target_path)
|
|
|
- self.assertRaises(ValueError, porcelain.clone, self.repo.path,
|
|
|
+ self.assertRaises(
|
|
|
+ ValueError, porcelain.clone, self.repo.path,
|
|
|
target_path, checkout=True, bare=True, errstream=errstream)
|
|
|
|
|
|
def test_no_head_no_checkout(self):
|
|
@@ -198,10 +205,11 @@ class CloneTests(PorcelainTestCase):
|
|
|
(c1, ) = build_commit_graph(self.repo.object_store, commit_spec, trees)
|
|
|
self.repo.refs[b"refs/heads/master"] = c1.id
|
|
|
target_path = tempfile.mkdtemp()
|
|
|
- errstream = BytesIO()
|
|
|
self.addCleanup(shutil.rmtree, target_path)
|
|
|
- porcelain.clone(self.repo.path, target_path, checkout=True,
|
|
|
- errstream=errstream)
|
|
|
+ errstream = BytesIO()
|
|
|
+ r = porcelain.clone(
|
|
|
+ self.repo.path, target_path, checkout=True, errstream=errstream)
|
|
|
+ r.close()
|
|
|
|
|
|
|
|
|
class InitTests(TestCase):
|
|
@@ -220,13 +228,13 @@ class InitTests(TestCase):
|
|
|
class AddTests(PorcelainTestCase):
|
|
|
|
|
|
def test_add_default_paths(self):
|
|
|
-
|
|
|
# create a file for initial commit
|
|
|
- with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, 'blah')
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write("\n")
|
|
|
- porcelain.add(repo=self.repo.path, paths=['blah'])
|
|
|
+ porcelain.add(repo=self.repo.path, paths=[fullpath])
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test',
|
|
|
- author=b'test', committer=b'test')
|
|
|
+ author=b'test', committer=b'test')
|
|
|
|
|
|
# Add a second test file and a file in a directory
|
|
|
with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
@@ -234,18 +242,57 @@ class AddTests(PorcelainTestCase):
|
|
|
os.mkdir(os.path.join(self.repo.path, 'adir'))
|
|
|
with open(os.path.join(self.repo.path, 'adir', 'afile'), 'w') as f:
|
|
|
f.write("\n")
|
|
|
- porcelain.add(self.repo.path)
|
|
|
+ cwd = os.getcwd()
|
|
|
+ try:
|
|
|
+ os.chdir(self.repo.path)
|
|
|
+ porcelain.add(self.repo.path)
|
|
|
+ finally:
|
|
|
+ os.chdir(cwd)
|
|
|
|
|
|
# Check that foo was added and nothing in .git was modified
|
|
|
index = self.repo.open_index()
|
|
|
self.assertEqual(sorted(index), [b'adir/afile', b'blah', b'foo'])
|
|
|
|
|
|
+ def test_add_default_paths_subdir(self):
|
|
|
+ os.mkdir(os.path.join(self.repo.path, 'foo'))
|
|
|
+ with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
|
|
|
+ f.write("\n")
|
|
|
+ with open(os.path.join(self.repo.path, 'foo', 'blie'), 'w') as f:
|
|
|
+ f.write("\n")
|
|
|
+
|
|
|
+ cwd = os.getcwd()
|
|
|
+ try:
|
|
|
+ os.chdir(os.path.join(self.repo.path, 'foo'))
|
|
|
+ porcelain.add(repo=self.repo.path)
|
|
|
+ porcelain.commit(repo=self.repo.path, message=b'test',
|
|
|
+ author=b'test', committer=b'test')
|
|
|
+ finally:
|
|
|
+ os.chdir(cwd)
|
|
|
+
|
|
|
+ index = self.repo.open_index()
|
|
|
+ self.assertEqual(sorted(index), [b'foo/blie'])
|
|
|
+
|
|
|
def test_add_file(self):
|
|
|
- with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, 'foo')
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write("BAR")
|
|
|
- porcelain.add(self.repo.path, paths=["foo"])
|
|
|
+ porcelain.add(self.repo.path, paths=[fullpath])
|
|
|
self.assertIn(b"foo", self.repo.open_index())
|
|
|
|
|
|
+ def test_add_ignored(self):
|
|
|
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
|
|
|
+ f.write("foo")
|
|
|
+ with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ f.write("BAR")
|
|
|
+ with open(os.path.join(self.repo.path, 'bar'), 'w') as f:
|
|
|
+ f.write("BAR")
|
|
|
+ (added, ignored) = porcelain.add(self.repo.path, paths=[
|
|
|
+ os.path.join(self.repo.path, "foo"),
|
|
|
+ os.path.join(self.repo.path, "bar")])
|
|
|
+ self.assertIn(b"bar", self.repo.open_index())
|
|
|
+ self.assertEqual(set(['bar']), set(added))
|
|
|
+ self.assertEqual(set(['foo']), ignored)
|
|
|
+
|
|
|
def test_add_file_absolute_path(self):
|
|
|
# Absolute paths are (not yet) supported
|
|
|
with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
@@ -257,25 +304,48 @@ class AddTests(PorcelainTestCase):
|
|
|
class RemoveTests(PorcelainTestCase):
|
|
|
|
|
|
def test_remove_file(self):
|
|
|
- with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, 'foo')
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
+ f.write("BAR")
|
|
|
+ porcelain.add(self.repo.path, paths=[fullpath])
|
|
|
+ porcelain.commit(repo=self.repo, message=b'test', author=b'test',
|
|
|
+ committer=b'test')
|
|
|
+ self.assertTrue(os.path.exists(os.path.join(self.repo.path, 'foo')))
|
|
|
+ cwd = os.getcwd()
|
|
|
+ try:
|
|
|
+ os.chdir(self.repo.path)
|
|
|
+ porcelain.remove(self.repo.path, paths=["foo"])
|
|
|
+ finally:
|
|
|
+ os.chdir(cwd)
|
|
|
+ self.assertFalse(os.path.exists(os.path.join(self.repo.path, 'foo')))
|
|
|
+
|
|
|
+ def test_remove_file_staged(self):
|
|
|
+ fullpath = os.path.join(self.repo.path, 'foo')
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write("BAR")
|
|
|
- porcelain.add(self.repo.path, paths=["foo"])
|
|
|
- porcelain.rm(self.repo.path, paths=["foo"])
|
|
|
+ cwd = os.getcwd()
|
|
|
+ try:
|
|
|
+ os.chdir(self.repo.path)
|
|
|
+ porcelain.add(self.repo.path, paths=[fullpath])
|
|
|
+ self.assertRaises(Exception, porcelain.rm, self.repo.path,
|
|
|
+ paths=["foo"])
|
|
|
+ finally:
|
|
|
+ os.chdir(cwd)
|
|
|
|
|
|
|
|
|
class LogTests(PorcelainTestCase):
|
|
|
|
|
|
def test_simple(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
outstream = StringIO()
|
|
|
porcelain.log(self.repo.path, outstream=outstream)
|
|
|
self.assertEqual(3, outstream.getvalue().count("-" * 50))
|
|
|
|
|
|
def test_max_entries(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
outstream = StringIO()
|
|
|
porcelain.log(self.repo.path, outstream=outstream, max_entries=1)
|
|
@@ -285,16 +355,16 @@ class LogTests(PorcelainTestCase):
|
|
|
class ShowTests(PorcelainTestCase):
|
|
|
|
|
|
def test_nolist(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
outstream = StringIO()
|
|
|
porcelain.show(self.repo.path, objects=c3.id, outstream=outstream)
|
|
|
self.assertTrue(outstream.getvalue().startswith("-" * 50))
|
|
|
|
|
|
def test_simple(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
outstream = StringIO()
|
|
|
porcelain.show(self.repo.path, objects=[c3.id], outstream=outstream)
|
|
@@ -307,44 +377,104 @@ class ShowTests(PorcelainTestCase):
|
|
|
porcelain.show(self.repo.path, objects=[b.id], outstream=outstream)
|
|
|
self.assertEqual(outstream.getvalue(), "The Foo\n")
|
|
|
|
|
|
+ def test_commit_no_parent(self):
|
|
|
+ a = Blob.from_string(b"The Foo\n")
|
|
|
+ ta = Tree()
|
|
|
+ ta.add(b"somename", 0o100644, a.id)
|
|
|
+ ca = make_commit(tree=ta.id)
|
|
|
+ self.repo.object_store.add_objects([(a, None), (ta, None), (ca, None)])
|
|
|
+ outstream = StringIO()
|
|
|
+ porcelain.show(self.repo.path, objects=[ca.id], outstream=outstream)
|
|
|
+ self.assertEqual(outstream.getvalue(), """\
|
|
|
+--------------------------------------------------
|
|
|
+commit: 344da06c1bb85901270b3e8875c988a027ec087d
|
|
|
+Author: Test Author <test@nodomain.com>
|
|
|
+Committer: Test Committer <test@nodomain.com>
|
|
|
+Date: Fri Jan 01 2010 00:00:00 +0000
|
|
|
+
|
|
|
+Test message.
|
|
|
+
|
|
|
+diff --git /dev/null b/somename
|
|
|
+new mode 100644
|
|
|
+index 0000000..ea5c7bf 100644
|
|
|
+--- /dev/null
|
|
|
++++ b/somename
|
|
|
+@@ -1,0 +1,1 @@
|
|
|
++The Foo
|
|
|
+""")
|
|
|
+
|
|
|
+ def test_commit_with_change(self):
|
|
|
+ a = Blob.from_string(b"The Foo\n")
|
|
|
+ ta = Tree()
|
|
|
+ ta.add(b"somename", 0o100644, a.id)
|
|
|
+ ca = make_commit(tree=ta.id)
|
|
|
+ b = Blob.from_string(b"The Bar\n")
|
|
|
+ tb = Tree()
|
|
|
+ tb.add(b"somename", 0o100644, a.id)
|
|
|
+ cb = make_commit(tree=tb.id)
|
|
|
+ self.repo.object_store.add_objects(
|
|
|
+ [(a, None), (b, None), (ta, None), (tb, None),
|
|
|
+ (ca, None), (cb, None)])
|
|
|
+ outstream = StringIO()
|
|
|
+ porcelain.show(self.repo.path, objects=[cb.id], outstream=outstream)
|
|
|
+ self.assertEqual(outstream.getvalue(), """\
|
|
|
+--------------------------------------------------
|
|
|
+commit: 344da06c1bb85901270b3e8875c988a027ec087d
|
|
|
+Author: Test Author <test@nodomain.com>
|
|
|
+Committer: Test Committer <test@nodomain.com>
|
|
|
+Date: Fri Jan 01 2010 00:00:00 +0000
|
|
|
+
|
|
|
+Test message.
|
|
|
+
|
|
|
+diff --git /dev/null b/somename
|
|
|
+new mode 100644
|
|
|
+index 0000000..ea5c7bf 100644
|
|
|
+--- /dev/null
|
|
|
++++ b/somename
|
|
|
+@@ -1,0 +1,1 @@
|
|
|
++The Foo
|
|
|
+""")
|
|
|
+
|
|
|
|
|
|
class SymbolicRefTests(PorcelainTestCase):
|
|
|
|
|
|
def test_set_wrong_symbolic_ref(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
|
|
|
- self.assertRaises(ValueError, porcelain.symbolic_ref, self.repo.path, b'foobar')
|
|
|
+ self.assertRaises(ValueError, porcelain.symbolic_ref, self.repo.path,
|
|
|
+ b'foobar')
|
|
|
|
|
|
def test_set_force_wrong_symbolic_ref(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
|
|
|
porcelain.symbolic_ref(self.repo.path, b'force_foobar', force=True)
|
|
|
|
|
|
- #test if we actually changed the file
|
|
|
+ # test if we actually changed the file
|
|
|
with self.repo.get_named_file('HEAD') as f:
|
|
|
new_ref = f.read()
|
|
|
self.assertEqual(new_ref, b'ref: refs/heads/force_foobar\n')
|
|
|
|
|
|
def test_set_symbolic_ref(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
|
|
|
porcelain.symbolic_ref(self.repo.path, b'master')
|
|
|
|
|
|
def test_set_symbolic_ref_other_than_master(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]], attrs=dict(refs='develop'))
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]],
|
|
|
+ attrs=dict(refs='develop'))
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
self.repo.refs[b"refs/heads/develop"] = c3.id
|
|
|
|
|
|
porcelain.symbolic_ref(self.repo.path, b'develop')
|
|
|
|
|
|
- #test if we actually changed the file
|
|
|
+ # test if we actually changed the file
|
|
|
with self.repo.get_named_file('HEAD') as f:
|
|
|
new_ref = f.read()
|
|
|
self.assertEqual(new_ref, b'ref: refs/heads/develop\n')
|
|
@@ -353,19 +483,20 @@ class SymbolicRefTests(PorcelainTestCase):
|
|
|
class DiffTreeTests(PorcelainTestCase):
|
|
|
|
|
|
def test_empty(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
outstream = BytesIO()
|
|
|
- porcelain.diff_tree(self.repo.path, c2.tree, c3.tree, outstream=outstream)
|
|
|
+ porcelain.diff_tree(self.repo.path, c2.tree, c3.tree,
|
|
|
+ outstream=outstream)
|
|
|
self.assertEqual(outstream.getvalue(), b"")
|
|
|
|
|
|
|
|
|
class CommitTreeTests(PorcelainTestCase):
|
|
|
|
|
|
def test_simple(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
b = Blob()
|
|
|
b.data = b"foo the bar"
|
|
|
t = Tree()
|
|
@@ -383,8 +514,8 @@ class CommitTreeTests(PorcelainTestCase):
|
|
|
class RevListTests(PorcelainTestCase):
|
|
|
|
|
|
def test_simple(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
outstream = BytesIO()
|
|
|
porcelain.rev_list(
|
|
|
self.repo.path, [c3.id], outstream=outstream)
|
|
@@ -398,12 +529,12 @@ class RevListTests(PorcelainTestCase):
|
|
|
class TagCreateTests(PorcelainTestCase):
|
|
|
|
|
|
def test_annotated(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
|
|
|
porcelain.tag_create(self.repo.path, b"tryme", b'foo <foo@bar.com>',
|
|
|
- b'bar', annotated=True)
|
|
|
+ b'bar', annotated=True)
|
|
|
|
|
|
tags = self.repo.refs.as_dict(b"refs/tags")
|
|
|
self.assertEqual(list(tags.keys()), [b"tryme"])
|
|
@@ -414,8 +545,8 @@ class TagCreateTests(PorcelainTestCase):
|
|
|
self.assertLess(time.time() - tag.tag_time, 5)
|
|
|
|
|
|
def test_unannotated(self):
|
|
|
- c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
|
|
|
- [3, 1, 2]])
|
|
|
+ c1, c2, c3 = build_commit_graph(
|
|
|
+ self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
|
|
|
self.repo.refs[b"HEAD"] = c3.id
|
|
|
|
|
|
porcelain.tag_create(self.repo.path, b"tryme", annotated=False)
|
|
@@ -454,12 +585,13 @@ class TagDeleteTests(PorcelainTestCase):
|
|
|
class ResetTests(PorcelainTestCase):
|
|
|
|
|
|
def test_hard_head(self):
|
|
|
- with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, 'foo')
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write("BAR")
|
|
|
- porcelain.add(self.repo.path, paths=["foo"])
|
|
|
+ porcelain.add(self.repo.path, paths=[fullpath])
|
|
|
porcelain.commit(self.repo.path, message=b"Some message",
|
|
|
- committer=b"Jane <jane@example.com>",
|
|
|
- author=b"John <john@example.com>")
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>")
|
|
|
|
|
|
with open(os.path.join(self.repo.path, 'foo'), 'wb') as f:
|
|
|
f.write(b"OOH")
|
|
@@ -474,19 +606,20 @@ class ResetTests(PorcelainTestCase):
|
|
|
self.assertEqual([], changes)
|
|
|
|
|
|
def test_hard_commit(self):
|
|
|
- with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, 'foo')
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write("BAR")
|
|
|
- porcelain.add(self.repo.path, paths=["foo"])
|
|
|
+ porcelain.add(self.repo.path, paths=[fullpath])
|
|
|
sha = porcelain.commit(self.repo.path, message=b"Some message",
|
|
|
- committer=b"Jane <jane@example.com>",
|
|
|
- author=b"John <john@example.com>")
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>")
|
|
|
|
|
|
- with open(os.path.join(self.repo.path, 'foo'), 'wb') as f:
|
|
|
+ with open(fullpath, 'wb') as f:
|
|
|
f.write(b"BAZ")
|
|
|
- porcelain.add(self.repo.path, paths=["foo"])
|
|
|
+ porcelain.add(self.repo.path, paths=[fullpath])
|
|
|
porcelain.commit(self.repo.path, message=b"Some other message",
|
|
|
- committer=b"Jane <jane@example.com>",
|
|
|
- author=b"John <john@example.com>")
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>")
|
|
|
|
|
|
porcelain.reset(self.repo, "hard", sha)
|
|
|
|
|
@@ -510,13 +643,13 @@ class PushTests(PorcelainTestCase):
|
|
|
errstream = BytesIO()
|
|
|
|
|
|
porcelain.commit(repo=self.repo.path, message=b'init',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
# Setup target repo cloned from temp test repo
|
|
|
clone_path = tempfile.mkdtemp()
|
|
|
self.addCleanup(shutil.rmtree, clone_path)
|
|
|
target_repo = porcelain.clone(self.repo.path, target=clone_path,
|
|
|
- errstream=errstream)
|
|
|
+ errstream=errstream)
|
|
|
try:
|
|
|
self.assertEqual(target_repo[b'HEAD'], self.repo[b'HEAD'])
|
|
|
finally:
|
|
@@ -525,9 +658,9 @@ class PushTests(PorcelainTestCase):
|
|
|
# create a second file to be pushed back to origin
|
|
|
handle, fullpath = tempfile.mkstemp(dir=clone_path)
|
|
|
os.close(handle)
|
|
|
- porcelain.add(repo=clone_path, paths=[os.path.basename(fullpath)])
|
|
|
+ porcelain.add(repo=clone_path, paths=[fullpath])
|
|
|
porcelain.commit(repo=clone_path, message=b'push',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
# Setup a non-checked out branch in the remote
|
|
|
refs_path = b"refs/heads/foo"
|
|
@@ -536,8 +669,8 @@ class PushTests(PorcelainTestCase):
|
|
|
self.repo.refs[refs_path] = new_id
|
|
|
|
|
|
# Push to the remote
|
|
|
- porcelain.push(clone_path, self.repo.path, b"HEAD:" + refs_path, outstream=outstream,
|
|
|
- errstream=errstream)
|
|
|
+ porcelain.push(clone_path, self.repo.path, b"HEAD:" + refs_path,
|
|
|
+ outstream=outstream, errstream=errstream)
|
|
|
|
|
|
# Check that the target and source
|
|
|
with Repo(clone_path) as r_clone:
|
|
@@ -546,14 +679,14 @@ class PushTests(PorcelainTestCase):
|
|
|
b'refs/heads/foo': r_clone[b'HEAD'].id,
|
|
|
b'refs/heads/master': new_id,
|
|
|
}, self.repo.get_refs())
|
|
|
- self.assertEqual(r_clone[b'HEAD'].id, self.repo.refs[refs_path])
|
|
|
+ self.assertEqual(r_clone[b'HEAD'].id, self.repo[refs_path].id)
|
|
|
|
|
|
# Get the change in the target repo corresponding to the add
|
|
|
# this will be in the foo branch.
|
|
|
change = list(tree_changes(self.repo, self.repo[b'HEAD'].tree,
|
|
|
self.repo[b'refs/heads/foo'].tree))[0]
|
|
|
self.assertEqual(os.path.basename(fullpath),
|
|
|
- change.new.path.decode('ascii'))
|
|
|
+ change.new.path.decode('ascii'))
|
|
|
|
|
|
def test_delete(self):
|
|
|
"""Basic test of porcelain push, removing a branch.
|
|
@@ -562,13 +695,13 @@ class PushTests(PorcelainTestCase):
|
|
|
errstream = BytesIO()
|
|
|
|
|
|
porcelain.commit(repo=self.repo.path, message=b'init',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
# Setup target repo cloned from temp test repo
|
|
|
clone_path = tempfile.mkdtemp()
|
|
|
self.addCleanup(shutil.rmtree, clone_path)
|
|
|
target_repo = porcelain.clone(self.repo.path, target=clone_path,
|
|
|
- errstream=errstream)
|
|
|
+ errstream=errstream)
|
|
|
target_repo.close()
|
|
|
|
|
|
# Setup a non-checked out branch in the remote
|
|
@@ -578,8 +711,8 @@ class PushTests(PorcelainTestCase):
|
|
|
self.repo.refs[refs_path] = new_id
|
|
|
|
|
|
# Push to the remote
|
|
|
- porcelain.push(clone_path, self.repo.path, b":" + refs_path, outstream=outstream,
|
|
|
- errstream=errstream)
|
|
|
+ porcelain.push(clone_path, self.repo.path, b":" + refs_path,
|
|
|
+ outstream=outstream, errstream=errstream)
|
|
|
|
|
|
self.assertEqual({
|
|
|
b'HEAD': new_id,
|
|
@@ -587,7 +720,6 @@ class PushTests(PorcelainTestCase):
|
|
|
}, self.repo.get_refs())
|
|
|
|
|
|
|
|
|
-
|
|
|
class PullTests(PorcelainTestCase):
|
|
|
|
|
|
def setUp(self):
|
|
@@ -595,8 +727,7 @@ class PullTests(PorcelainTestCase):
|
|
|
# create a file for initial commit
|
|
|
handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
|
|
|
os.close(handle)
|
|
|
- filename = os.path.basename(fullpath)
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test',
|
|
|
author=b'test', committer=b'test')
|
|
|
|
|
@@ -604,16 +735,15 @@ class PullTests(PorcelainTestCase):
|
|
|
self.target_path = tempfile.mkdtemp()
|
|
|
self.addCleanup(shutil.rmtree, self.target_path)
|
|
|
target_repo = porcelain.clone(self.repo.path, target=self.target_path,
|
|
|
- errstream=BytesIO())
|
|
|
+ errstream=BytesIO())
|
|
|
target_repo.close()
|
|
|
|
|
|
# create a second file to be pushed
|
|
|
handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
|
|
|
os.close(handle)
|
|
|
- filename = os.path.basename(fullpath)
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test2',
|
|
|
- author=b'test2', committer=b'test2')
|
|
|
+ author=b'test2', committer=b'test2')
|
|
|
|
|
|
self.assertTrue(b'refs/heads/master' in self.repo.refs)
|
|
|
self.assertTrue(b'refs/heads/master' in target_repo.refs)
|
|
@@ -624,7 +754,7 @@ class PullTests(PorcelainTestCase):
|
|
|
|
|
|
# Pull changes into the cloned repo
|
|
|
porcelain.pull(self.target_path, self.repo.path, b'refs/heads/master',
|
|
|
- outstream=outstream, errstream=errstream)
|
|
|
+ outstream=outstream, errstream=errstream)
|
|
|
|
|
|
# Check the target repo for pushed changes
|
|
|
with Repo(self.target_path) as r:
|
|
@@ -660,9 +790,9 @@ class StatusTests(PorcelainTestCase):
|
|
|
with open(fullpath, 'w') as f:
|
|
|
f.write('origstuff')
|
|
|
|
|
|
- porcelain.add(repo=self.repo.path, paths=['foo'])
|
|
|
+ porcelain.add(repo=self.repo.path, paths=[fullpath])
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
# modify access and modify time of path
|
|
|
os.utime(fullpath, (0, 0))
|
|
@@ -675,11 +805,12 @@ class StatusTests(PorcelainTestCase):
|
|
|
fullpath = os.path.join(self.repo.path, filename_add)
|
|
|
with open(fullpath, 'w') as f:
|
|
|
f.write('stuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename_add)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
|
|
|
results = porcelain.status(self.repo)
|
|
|
|
|
|
- self.assertEqual(results.staged['add'][0], filename_add.encode('ascii'))
|
|
|
+ self.assertEqual(results.staged['add'][0],
|
|
|
+ filename_add.encode('ascii'))
|
|
|
self.assertEqual(results.unstaged, [b'foo'])
|
|
|
|
|
|
def test_get_tree_changes_add(self):
|
|
@@ -687,16 +818,18 @@ class StatusTests(PorcelainTestCase):
|
|
|
|
|
|
# Make a dummy file, stage
|
|
|
filename = 'bar'
|
|
|
- with open(os.path.join(self.repo.path, filename), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, filename)
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write('stuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
filename = 'foo'
|
|
|
- with open(os.path.join(self.repo.path, filename), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, filename)
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write('stuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
changes = porcelain.get_tree_changes(self.repo.path)
|
|
|
|
|
|
self.assertEqual(changes['add'][0], filename.encode('ascii'))
|
|
@@ -712,12 +845,12 @@ class StatusTests(PorcelainTestCase):
|
|
|
fullpath = os.path.join(self.repo.path, filename)
|
|
|
with open(fullpath, 'w') as f:
|
|
|
f.write('stuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
with open(fullpath, 'w') as f:
|
|
|
f.write('otherstuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
changes = porcelain.get_tree_changes(self.repo.path)
|
|
|
|
|
|
self.assertEqual(changes['modify'][0], filename.encode('ascii'))
|
|
@@ -730,12 +863,18 @@ class StatusTests(PorcelainTestCase):
|
|
|
|
|
|
# Make a dummy file, stage, commit, remove
|
|
|
filename = 'foo'
|
|
|
- with open(os.path.join(self.repo.path, filename), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, filename)
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write('stuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
- porcelain.rm(repo=self.repo.path, paths=[filename])
|
|
|
+ author=b'', committer=b'')
|
|
|
+ cwd = os.getcwd()
|
|
|
+ try:
|
|
|
+ os.chdir(self.repo.path)
|
|
|
+ porcelain.remove(repo=self.repo.path, paths=[filename])
|
|
|
+ finally:
|
|
|
+ os.chdir(cwd)
|
|
|
changes = porcelain.get_tree_changes(self.repo.path)
|
|
|
|
|
|
self.assertEqual(changes['delete'][0], filename.encode('ascii'))
|
|
@@ -743,6 +882,39 @@ class StatusTests(PorcelainTestCase):
|
|
|
self.assertEqual(len(changes['modify']), 0)
|
|
|
self.assertEqual(len(changes['delete']), 1)
|
|
|
|
|
|
+ def test_get_untracked_paths(self):
|
|
|
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
|
|
|
+ f.write('ignored\n')
|
|
|
+ with open(os.path.join(self.repo.path, 'ignored'), 'w') as f:
|
|
|
+ f.write('blah\n')
|
|
|
+ with open(os.path.join(self.repo.path, 'notignored'), 'w') as f:
|
|
|
+ f.write('blah\n')
|
|
|
+ self.assertEqual(
|
|
|
+ set(['ignored', 'notignored', '.gitignore']),
|
|
|
+ set(porcelain.get_untracked_paths(self.repo.path, self.repo.path,
|
|
|
+ self.repo.open_index())))
|
|
|
+ self.assertEqual(set(['.gitignore', 'notignored']),
|
|
|
+ set(porcelain.status(self.repo).untracked))
|
|
|
+ self.assertEqual(set(['.gitignore', 'notignored', 'ignored']),
|
|
|
+ set(porcelain.status(self.repo, ignored=True)
|
|
|
+ .untracked))
|
|
|
+
|
|
|
+ def test_get_untracked_paths_nested(self):
|
|
|
+ with open(os.path.join(self.repo.path, 'notignored'), 'w') as f:
|
|
|
+ f.write('blah\n')
|
|
|
+ subrepo = Repo.init(os.path.join(self.repo.path, 'nested'), mkdir=True)
|
|
|
+ with open(os.path.join(subrepo.path, 'another'), 'w') as f:
|
|
|
+ f.write('foo\n')
|
|
|
+
|
|
|
+ self.assertEqual(
|
|
|
+ set(['notignored']),
|
|
|
+ set(porcelain.get_untracked_paths(self.repo.path, self.repo.path,
|
|
|
+ self.repo.open_index())))
|
|
|
+ self.assertEqual(
|
|
|
+ set(['another']),
|
|
|
+ set(porcelain.get_untracked_paths(subrepo.path, subrepo.path,
|
|
|
+ subrepo.open_index())))
|
|
|
+
|
|
|
|
|
|
# TODO(jelmer): Add test for dulwich.porcelain.daemon
|
|
|
|
|
@@ -752,7 +924,8 @@ class UploadPackTests(PorcelainTestCase):
|
|
|
|
|
|
def test_upload_pack(self):
|
|
|
outf = BytesIO()
|
|
|
- exitcode = porcelain.upload_pack(self.repo.path, BytesIO(b"0000"), outf)
|
|
|
+ exitcode = porcelain.upload_pack(
|
|
|
+ self.repo.path, BytesIO(b"0000"), outf)
|
|
|
outlines = outf.getvalue().splitlines()
|
|
|
self.assertEqual([b"0000"], outlines)
|
|
|
self.assertEqual(0, exitcode)
|
|
@@ -763,17 +936,21 @@ class ReceivePackTests(PorcelainTestCase):
|
|
|
|
|
|
def test_receive_pack(self):
|
|
|
filename = 'foo'
|
|
|
- with open(os.path.join(self.repo.path, filename), 'w') as f:
|
|
|
+ fullpath = os.path.join(self.repo.path, filename)
|
|
|
+ with open(fullpath, 'w') as f:
|
|
|
f.write('stuff')
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
self.repo.do_commit(message=b'test status',
|
|
|
- author=b'', committer=b'', author_timestamp=1402354300,
|
|
|
- commit_timestamp=1402354300, author_timezone=0, commit_timezone=0)
|
|
|
+ author=b'', committer=b'',
|
|
|
+ author_timestamp=1402354300,
|
|
|
+ commit_timestamp=1402354300, author_timezone=0,
|
|
|
+ commit_timezone=0)
|
|
|
outf = BytesIO()
|
|
|
- exitcode = porcelain.receive_pack(self.repo.path, BytesIO(b"0000"), outf)
|
|
|
+ exitcode = porcelain.receive_pack(
|
|
|
+ self.repo.path, BytesIO(b"0000"), outf)
|
|
|
outlines = outf.getvalue().splitlines()
|
|
|
self.assertEqual([
|
|
|
- b'00739e65bdcf4a22cdd4f3700604a275cd2aaf146b23 HEAD\x00 report-status '
|
|
|
+ b'00739e65bdcf4a22cdd4f3700604a275cd2aaf146b23 HEAD\x00 report-status ' # noqa: E501
|
|
|
b'delete-refs quiet ofs-delta side-band-64k no-done',
|
|
|
b'003f9e65bdcf4a22cdd4f3700604a275cd2aaf146b23 refs/heads/master',
|
|
|
b'0000'], outlines)
|
|
@@ -832,8 +1009,7 @@ class FetchTests(PorcelainTestCase):
|
|
|
# create a file for initial commit
|
|
|
handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
|
|
|
os.close(handle)
|
|
|
- filename = os.path.basename(fullpath)
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test',
|
|
|
author=b'test', committer=b'test')
|
|
|
|
|
@@ -841,22 +1017,21 @@ class FetchTests(PorcelainTestCase):
|
|
|
target_path = tempfile.mkdtemp()
|
|
|
self.addCleanup(shutil.rmtree, target_path)
|
|
|
target_repo = porcelain.clone(self.repo.path, target=target_path,
|
|
|
- errstream=errstream)
|
|
|
+ errstream=errstream)
|
|
|
|
|
|
# create a second file to be pushed
|
|
|
handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
|
|
|
os.close(handle)
|
|
|
- filename = os.path.basename(fullpath)
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test2',
|
|
|
- author=b'test2', committer=b'test2')
|
|
|
+ author=b'test2', committer=b'test2')
|
|
|
|
|
|
self.assertFalse(self.repo[b'HEAD'].id in target_repo)
|
|
|
target_repo.close()
|
|
|
|
|
|
# Fetch changes into the cloned repo
|
|
|
porcelain.fetch(target_path, self.repo.path, outstream=outstream,
|
|
|
- errstream=errstream)
|
|
|
+ errstream=errstream)
|
|
|
|
|
|
# Check the target repo for pushed changes
|
|
|
with Repo(target_path) as r:
|
|
@@ -871,8 +1046,7 @@ class RepackTests(PorcelainTestCase):
|
|
|
def test_simple(self):
|
|
|
handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
|
|
|
os.close(handle)
|
|
|
- filename = os.path.basename(fullpath)
|
|
|
- porcelain.add(repo=self.repo.path, paths=filename)
|
|
|
+ porcelain.add(repo=self.repo.path, paths=fullpath)
|
|
|
porcelain.repack(self.repo)
|
|
|
|
|
|
|
|
@@ -880,7 +1054,7 @@ class LsTreeTests(PorcelainTestCase):
|
|
|
|
|
|
def test_empty(self):
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
f = StringIO()
|
|
|
porcelain.ls_tree(self.repo, b"HEAD", outstream=f)
|
|
@@ -892,9 +1066,9 @@ class LsTreeTests(PorcelainTestCase):
|
|
|
with open(fullpath, 'w') as f:
|
|
|
f.write('origstuff')
|
|
|
|
|
|
- porcelain.add(repo=self.repo.path, paths=['foo'])
|
|
|
+ porcelain.add(repo=self.repo.path, paths=[fullpath])
|
|
|
porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
f = StringIO()
|
|
|
porcelain.ls_tree(self.repo, b"HEAD", outstream=f)
|
|
@@ -910,7 +1084,7 @@ class LsRemoteTests(PorcelainTestCase):
|
|
|
|
|
|
def test_some(self):
|
|
|
cid = porcelain.commit(repo=self.repo.path, message=b'test status',
|
|
|
- author=b'', committer=b'')
|
|
|
+ author=b'', committer=b'')
|
|
|
|
|
|
self.assertEqual({
|
|
|
b'refs/heads/master': cid,
|
|
@@ -932,4 +1106,31 @@ class RemoteAddTests(PorcelainTestCase):
|
|
|
porcelain.remote_add(
|
|
|
self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
|
|
|
self.assertRaises(porcelain.RemoteExists, porcelain.remote_add,
|
|
|
- self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
|
|
|
+ self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
|
|
|
+
|
|
|
+
|
|
|
+class CheckIgnoreTests(PorcelainTestCase):
|
|
|
+
|
|
|
+ def test_check_ignored(self):
|
|
|
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
|
|
|
+ f.write("foo")
|
|
|
+ with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ f.write("BAR")
|
|
|
+ with open(os.path.join(self.repo.path, 'bar'), 'w') as f:
|
|
|
+ f.write("BAR")
|
|
|
+ self.assertEqual(
|
|
|
+ ['foo'],
|
|
|
+ list(porcelain.check_ignore(self.repo, ['foo'])))
|
|
|
+ self.assertEqual([], list(porcelain.check_ignore(self.repo, ['bar'])))
|
|
|
+
|
|
|
+ def test_check_added(self):
|
|
|
+ with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
|
|
|
+ f.write("BAR")
|
|
|
+ self.repo.stage(['foo'])
|
|
|
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
|
|
|
+ f.write("foo\n")
|
|
|
+ self.assertEqual(
|
|
|
+ [], list(porcelain.check_ignore(self.repo, ['foo'])))
|
|
|
+ self.assertEqual(
|
|
|
+ ['foo'],
|
|
|
+ list(porcelain.check_ignore(self.repo, ['foo'], no_index=True)))
|