Exemple #1
0
 def test_remove_packed_without_peeled(self):
     refs_file = os.path.join(self._repo.path, 'packed-refs')
     f = GitFile(refs_file)
     refs_data = f.read()
     f.close()
     f = GitFile(refs_file, 'wb')
     f.write(b'\n'.join(l for l in refs_data.split(b'\n')
                        if not l or l[0] not in b'#^'))
     f.close()
     self._repo = Repo(self._repo.path)
     refs = self._repo.refs
     self.assertTrue(
         refs.remove_if_equals(b'refs/heads/packed',
                               b'42d06bd4b77fed026b154d16493e5deab78f02ec'))
Exemple #2
0
    def test_abort(self):
        foo = self.path('foo')
        foo_lock = '%s.lock' % foo

        orig_f = open(foo, 'rb')
        self.assertEqual(orig_f.read(), b'foo contents')
        orig_f.close()

        f = GitFile(foo, 'wb')
        f.write(b'new contents')
        f.abort()
        self.assertTrue(f.closed)
        self.assertFalse(os.path.exists(foo_lock))

        new_orig_f = open(foo, 'rb')
        self.assertEqual(new_orig_f.read(), b'foo contents')
        new_orig_f.close()
Exemple #3
0
    def test_open_twice(self):
        foo = self.path('foo')
        f1 = GitFile(foo, 'wb')
        f1.write(b'new')
        try:
            f2 = GitFile(foo, 'wb')
            self.fail()
        except FileLocked:
            pass
        else:
            f2.close()
        f1.write(b' contents')
        f1.close()

        # Ensure trying to open twice doesn't affect original.
        f = open(foo, 'rb')
        self.assertEqual(b'new contents', f.read())
        f.close()
    def set_symbolic_ref(self, name, other, committer=None, timestamp=None,
                         timezone=None, message=None):
        """Make a ref point at another ref.

        :param name: Name of the ref to set
        :param other: Name of the ref to point at
        :param message: Optional message to describe the change
        """
        self._check_refname(name)
        self._check_refname(other)
        filename = self.refpath(name)
        f = GitFile(filename, 'wb')
        try:
            f.write(SYMREF + other + b'\n')
            sha = self.follow(name)[-1]
            self._log(name, sha, sha, committer=committer,
                      timestamp=timestamp, timezone=timezone,
                      message=message)
        except BaseException:
            f.abort()
            raise
        else:
            f.close()
Exemple #5
0
    def test_write(self):
        foo = self.path('foo')
        foo_lock = '%s.lock' % foo

        orig_f = open(foo, 'rb')
        self.assertEqual(orig_f.read(), b'foo contents')
        orig_f.close()

        self.assertFalse(os.path.exists(foo_lock))
        f = GitFile(foo, 'wb')
        self.assertFalse(f.closed)
        self.assertRaises(AttributeError, getattr, f, 'not_a_file_property')

        self.assertTrue(os.path.exists(foo_lock))
        f.write(b'new stuff')
        f.seek(4)
        f.write(b'contents')
        f.close()
        self.assertFalse(os.path.exists(foo_lock))

        new_f = open(foo, 'rb')
        self.assertEqual(b'new contents', new_f.read())
        new_f.close()