Exemplo n.º 1
0
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected,
 bool exists, bool removed)
 {
     Assert.AreEqual(exists, db.getAllRefs().ContainsKey(@ref.getName()));
     Assert.AreEqual(expected, @ref.delete());
     Assert.AreEqual(!removed, db.getAllRefs().ContainsKey(@ref.getName()));
 }
Exemplo n.º 2
0
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected,
                     bool exists, bool removed)
 {
     Assert.AreEqual(exists, db.getAllRefs().ContainsKey(@ref.getName()));
     Assert.AreEqual(expected, @ref.delete());
     Assert.AreEqual(!removed, db.getAllRefs().ContainsKey(@ref.getName()));
 }
Exemplo n.º 3
0
        public void testDeleteLoosePacked()
        {
            ObjectId  pid       = db.Resolve("refs/heads/c^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/c");

            updateRef.NewObjectId   = pid;
            updateRef.IsForceUpdate = true;
            RefUpdate.RefUpdateResult update = updateRef.update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); // internal

            // The real test here
            RefUpdate updateRef2 = db.UpdateRef("refs/heads/c");

            updateRef2.IsForceUpdate = true;
            RefUpdate.RefUpdateResult delete = updateRef2.delete();
            Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, delete);
            Assert.IsNull(db.Resolve("refs/heads/c"));
        }
Exemplo n.º 4
0
        public void testDeleteHEADreferencedRef()
        {
            ObjectId  pid       = db.Resolve("refs/heads/master^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.NewObjectId   = pid;
            updateRef.IsForceUpdate = true;
            RefUpdate.RefUpdateResult update = updateRef.update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); // internal

            RefUpdate updateRef2 = db.UpdateRef("refs/heads/master");

            RefUpdate.RefUpdateResult delete = updateRef2.delete();
            Assert.AreEqual(RefUpdate.RefUpdateResult.REJECTED_CURRENT_BRANCH, delete);
            Assert.AreEqual(pid, db.Resolve("refs/heads/master"));
            Assert.AreEqual(1, db.ReflogReader("refs/heads/master").getReverseEntries().Count);
            Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count);
        }
Exemplo n.º 5
0
        public void testDeleteLooseAndItsDirectory()
        {
            ObjectId  pid       = db.Resolve("refs/heads/c^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/z/c");

            updateRef.NewObjectId   = pid;
            updateRef.IsForceUpdate = true;
            updateRef.setRefLogMessage("new test ref", false);
            RefUpdate.RefUpdateResult update = updateRef.update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.NEW, update); // internal
            Assert.IsTrue(new DirectoryInfo(Path.Combine(db.Directory.FullName, Constants.R_HEADS + "z")).Exists);
            Assert.IsTrue(new DirectoryInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/z")).Exists);

            // The real test here
            RefUpdate updateRef2 = db.UpdateRef("refs/heads/z/c");

            updateRef2.IsForceUpdate = true;
            RefUpdate.RefUpdateResult delete = updateRef2.delete();
            Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, delete);
            Assert.IsNull(db.Resolve("refs/heads/z/c"));
            Assert.IsFalse(new DirectoryInfo(Path.Combine(db.Directory.FullName, Constants.R_HEADS + "z")).Exists);
            Assert.IsFalse(new DirectoryInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/z")).Exists);
        }
Exemplo n.º 6
0
        private void Execute(ReceiveCommand cmd)
        {
            try
            {
                RefUpdate ru = db.UpdateRef(cmd.getRefName());
                ru.setRefLogIdent(getRefLogIdent());
                switch (cmd.getType())
                {
                case ReceiveCommand.Type.DELETE:
                    if (!ObjectId.ZeroId.Equals(cmd.getOldId()))
                    {
                        // We can only do a CAS style delete if the client
                        // didn't bork its delete request by sending the
                        // wrong zero id rather than the advertised one.
                        //
                        ru.setExpectedOldObjectId(cmd.getOldId());
                    }
                    ru.setForceUpdate(true);
                    Status(cmd, ru.delete(walk));
                    break;

                case ReceiveCommand.Type.CREATE:
                case ReceiveCommand.Type.UPDATE:
                case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                    ru.setForceUpdate(isAllowNonFastForwards());
                    ru.setExpectedOldObjectId(cmd.getOldId());
                    ru.setNewObjectId(cmd.getNewId());
                    ru.setRefLogMessage("push", true);
                    Status(cmd, ru.update(walk));
                    break;
                }
            }
            catch (IOException err)
            {
                cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, "lock error: " + err.Message);
            }
        }
Exemplo n.º 7
0
 public void Delete(RevWalk.RevWalk walk)
 {
     update.delete(walk);
 }