|
@@ -31,6 +31,7 @@ import tempfile
|
|
|
import warnings
|
|
|
|
|
|
from dulwich import errors
|
|
|
+from dulwich import porcelain
|
|
|
from dulwich.object_store import (
|
|
|
tree_lookup_path,
|
|
|
)
|
|
@@ -1226,6 +1227,87 @@ class BuildRepoRootTests(TestCase):
|
|
|
r.stage(["c"])
|
|
|
self.assertEqual([b"a"], list(r.open_index()))
|
|
|
|
|
|
+ def test_unstage_midify_file_with_dir(self):
|
|
|
+ os.mkdir(os.path.join(self._repo.path, 'new_dir'))
|
|
|
+ full_path = os.path.join(self._repo.path, 'new_dir', 'foo')
|
|
|
+
|
|
|
+ with open(full_path, 'w') as f:
|
|
|
+ f.write('hello')
|
|
|
+ porcelain.add(self._repo, paths=[full_path])
|
|
|
+ porcelain.commit(
|
|
|
+ self._repo,
|
|
|
+ message=b"unitest",
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>",
|
|
|
+ )
|
|
|
+ with open(full_path, 'a') as f:
|
|
|
+ f.write('something new')
|
|
|
+ self._repo.unstage(['new_dir/foo'])
|
|
|
+ status = list(porcelain.status(self._repo))
|
|
|
+ self.assertEqual([{'add': [], 'delete': [], 'modify': []}, [b'new_dir/foo'], []], status)
|
|
|
+
|
|
|
+ def test_unstage_while_no_commit(self):
|
|
|
+ file = 'foo'
|
|
|
+ full_path = os.path.join(self._repo.path, file)
|
|
|
+ with open(full_path, 'w') as f:
|
|
|
+ f.write('hello')
|
|
|
+ porcelain.add(self._repo, paths=[full_path])
|
|
|
+ self._repo.unstage([file])
|
|
|
+ status = list(porcelain.status(self._repo))
|
|
|
+ self.assertEqual([{'add': [], 'delete': [], 'modify': []}, [], ['foo']], status)
|
|
|
+
|
|
|
+ def test_unstage_add_file(self):
|
|
|
+ file = 'foo'
|
|
|
+ full_path = os.path.join(self._repo.path, file)
|
|
|
+ porcelain.commit(
|
|
|
+ self._repo,
|
|
|
+ message=b"unitest",
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>",
|
|
|
+ )
|
|
|
+ with open(full_path, 'w') as f:
|
|
|
+ f.write('hello')
|
|
|
+ porcelain.add(self._repo, paths=[full_path])
|
|
|
+ self._repo.unstage([file])
|
|
|
+ status = list(porcelain.status(self._repo))
|
|
|
+ self.assertEqual([{'add': [], 'delete': [], 'modify': []}, [], ['foo']], status)
|
|
|
+
|
|
|
+ def test_unstage_modify_file(self):
|
|
|
+ file = 'foo'
|
|
|
+ full_path = os.path.join(self._repo.path, file)
|
|
|
+ with open(full_path, 'w') as f:
|
|
|
+ f.write('hello')
|
|
|
+ porcelain.add(self._repo, paths=[full_path])
|
|
|
+ porcelain.commit(
|
|
|
+ self._repo,
|
|
|
+ message=b"unitest",
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>",
|
|
|
+ )
|
|
|
+ with open(full_path, 'a') as f:
|
|
|
+ f.write('broken')
|
|
|
+ porcelain.add(self._repo, paths=[full_path])
|
|
|
+ self._repo.unstage([file])
|
|
|
+ status = list(porcelain.status(self._repo))
|
|
|
+ self.assertEqual([{'add': [], 'delete': [], 'modify': []}, [b'foo'], []], status)
|
|
|
+
|
|
|
+ def test_unstage_remove_file(self):
|
|
|
+ file = 'foo'
|
|
|
+ full_path = os.path.join(self._repo.path, file)
|
|
|
+ with open(full_path, 'w') as f:
|
|
|
+ f.write('hello')
|
|
|
+ porcelain.add(self._repo, paths=[full_path])
|
|
|
+ porcelain.commit(
|
|
|
+ self._repo,
|
|
|
+ message=b"unitest",
|
|
|
+ committer=b"Jane <jane@example.com>",
|
|
|
+ author=b"John <john@example.com>",
|
|
|
+ )
|
|
|
+ os.remove(full_path)
|
|
|
+ self._repo.unstage([file])
|
|
|
+ status = list(porcelain.status(self._repo))
|
|
|
+ self.assertEqual([{'add': [], 'delete': [], 'modify': []}, [b'foo'], []], status)
|
|
|
+
|
|
|
@skipIf(
|
|
|
sys.platform in ("win32", "darwin"),
|
|
|
"tries to implicitly decode as utf8",
|