Exemplo n.º 1
0
        public void testRenameRefNameColission1avoided()
        {
            // setup
            ObjectId rb = db.Resolve("refs/heads/b");

            writeSymref(Constants.HEAD, "refs/heads/a");
            RefUpdate updateRef = db.UpdateRef("refs/heads/a");

            updateRef.NewObjectId = rb;
            updateRef.setRefLogMessage("Setup", false);
            Assert.AreEqual(RefUpdate.RefUpdateResult.FAST_FORWARD, updateRef.update());
            ObjectId oldHead = db.Resolve(Constants.HEAD);

            Assert.IsTrue(rb.Equals(oldHead)); // assumption for this test
            writeReflog(db, rb, rb, "Just a message", "refs/heads/a");
            Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/a")).Exists, "internal check, we have a log");

            // Now this is our test
            RefRename renameRef = db.RenameRef("refs/heads/a", "refs/heads/a/b");

            RefUpdate.RefUpdateResult result = renameRef.rename();
            Assert.AreEqual(RefUpdate.RefUpdateResult.RENAMED, result);
            Assert.IsNull(db.Resolve("refs/heads/a"));
            Assert.AreEqual(rb, db.Resolve("refs/heads/a/b"));
            Assert.AreEqual(3, db.ReflogReader("a/b").getReverseEntries().Count);
            Assert.AreEqual("Branch: renamed a to a/b", db.ReflogReader("a/b")
                            .getReverseEntries()[0].getComment());
            Assert.AreEqual("Just a message", db.ReflogReader("a/b")
                            .getReverseEntries()[1].getComment());
            Assert.AreEqual("Setup", db.ReflogReader("a/b").getReverseEntries()
                            [2].getComment());
            // same thing was logged to HEAD
            Assert.AreEqual("Branch: renamed a to a/b", db.ReflogReader("HEAD")
                            .getReverseEntries()[0].getComment());
        }
Exemplo n.º 2
0
 public TrackingRefUpdate(Repository db, string localName, string remoteName, bool forceUpdate, AnyObjectId nv, string msg)
 {
     if (db == null)
         throw new System.ArgumentNullException("db");
     if (nv == null)
         throw new System.ArgumentNullException("nv");
     RemoteName = remoteName;
     update = db.UpdateRef(localName);
     update.IsForceUpdate = forceUpdate;
     update.NewObjectId = nv.Copy();
     update.setRefLogMessage(msg, true);
 }
Exemplo n.º 3
0
 public TrackingRefUpdate(Repository db, string localName, string remoteName, bool forceUpdate, AnyObjectId nv, string msg)
 {
     if (db == null)
     {
         throw new System.ArgumentNullException("db");
     }
     if (nv == null)
     {
         throw new System.ArgumentNullException("nv");
     }
     RemoteName           = remoteName;
     update               = db.UpdateRef(localName);
     update.IsForceUpdate = forceUpdate;
     update.NewObjectId   = nv.Copy();
     update.setRefLogMessage(msg, true);
 }
Exemplo n.º 4
0
        private void commit(Core.Tree t, string commitMsg, PersonIdent author,
                            PersonIdent committer)
        {
            Core.Commit commit = new Core.Commit(db);
            commit.Author    = (author);
            commit.Committer = (committer);
            commit.Message   = (commitMsg);
            commit.TreeEntry = (t);
            //ObjectWriter writer = new ObjectWriter(db);
            //commit.CommitId = (writer.WriteCommit(commit));
            commit.Save();

            int       nl = commitMsg.IndexOf('\n');
            RefUpdate ru = db.UpdateRef(Constants.HEAD);

            ru.NewObjectId = (commit.CommitId);
            ru.setRefLogMessage("commit : "
                                + ((nl == -1) ? commitMsg : commitMsg.Slice(0, nl)), false);
            ru.forceUpdate();
        }
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);
            }
        }