summaryrefslogtreecommitdiff
path: root/morphlib/gitindex_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-11-11 17:38:16 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-11-22 13:49:25 +0000
commit0b4e147009bffa7b720ee767633e3acf3bb68c3a (patch)
tree12448f87519c8738444618f53eb6ed49f632de92 /morphlib/gitindex_tests.py
parentd83d6ad7230eb27afae4169330681967bb20dcfa (diff)
downloadmorph-0b4e147009bffa7b720ee767633e3acf3bb68c3a.tar.gz
GitDir: Add GitIndex class
This represents the state of the index of a GitDirectory. Methods that use the index are now used via the GitIndex class, rather than using the default index, as previously used when the methods were in GitDirectory. GitIndex may be constructed with an alternative path, which can be used to manipulate a git checkout without altering a developer's view of the repository i.e. The working tree and default index. This is needed for `morph build` and `morph deploy` to handle the build without commit logic.
Diffstat (limited to 'morphlib/gitindex_tests.py')
-rw-r--r--morphlib/gitindex_tests.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/morphlib/gitindex_tests.py b/morphlib/gitindex_tests.py
new file mode 100644
index 00000000..db1e0e9b
--- /dev/null
+++ b/morphlib/gitindex_tests.py
@@ -0,0 +1,56 @@
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# =*= License: GPL-2 =*=
+
+
+import os
+import shutil
+import tempfile
+import unittest
+
+import morphlib
+
+
+class GitIndexTests(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+ self.dirname = os.path.join(self.tempdir, 'foo')
+ os.mkdir(self.dirname)
+ gd = morphlib.gitdir.init(self.dirname)
+ with open(os.path.join(self.dirname, 'foo'), 'w') as f:
+ f.write('dummy text\n')
+ gd._runcmd(['git', 'add', '.'])
+ gd._runcmd(['git', 'commit', '-m', 'Initial commit'])
+ self.mirror = os.path.join(self.tempdir, 'mirror')
+ gd._runcmd(['git', 'clone', '--mirror', self.dirname, self.mirror])
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def test_uncommitted_changes(self):
+ idx = morphlib.gitdir.GitDirectory(self.dirname).get_index()
+ self.assertEqual(list(idx.get_uncommitted_changes()), [])
+ os.unlink(os.path.join(self.dirname, 'foo'))
+ self.assertEqual(sorted(idx.get_uncommitted_changes()),
+ [(' D', 'foo', None)])
+
+ def test_uncommitted_alt_index(self):
+ gd = morphlib.gitdir.GitDirectory(self.dirname)
+ idx = gd.get_index(os.path.join(self.tempdir, 'index'))
+ self.assertEqual(sorted(idx.get_uncommitted_changes()),
+ [('D ', 'foo', None)])
+ # 'D ' means not in the index, but in the working tree