Exemplo n.º 1
0
        public void testRefsCacheAfterUpdate()
        {
            // Do not use the defalt repo for this case.
            Dictionary <string, Core.Ref> allRefs = db.getAllRefs();
            ObjectId oldValue = db.Resolve("HEAD");
            ObjectId newValue = db.Resolve("HEAD^");
            // first make HEAD refer to loose ref
            RefUpdate updateRef = db.UpdateRef(Constants.HEAD);

            updateRef.IsForceUpdate = true;
            updateRef.NewObjectId   = newValue;
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update);

            // now update that ref
            updateRef = db.UpdateRef(Constants.HEAD);
            updateRef.IsForceUpdate = true;
            updateRef.NewObjectId   = oldValue;
            update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.FastForward, update);
            allRefs = db.getAllRefs();
            Assert.AreEqual("refs/heads/master", allRefs.GetValue("refs/heads/master").Name);
            Assert.AreEqual("refs/heads/master", allRefs.GetValue("refs/heads/master").OriginalName);
            Assert.AreEqual("refs/heads/master", allRefs.GetValue("HEAD").Name);
            Assert.AreEqual("HEAD", allRefs.GetValue("HEAD").OriginalName);
        }
Exemplo n.º 2
0
        public virtual void TestRefsCacheAfterUpdate()
        {
            // Do not use the defalt repo for this case.
            IDictionary <string, Ref> allRefs = db.GetAllRefs();
            ObjectId oldValue = db.Resolve("HEAD");
            ObjectId newValue = db.Resolve("HEAD^");
            // first make HEAD refer to loose ref
            RefUpdate updateRef = db.UpdateRef(Constants.HEAD);

            updateRef.SetForceUpdate(true);
            updateRef.SetNewObjectId(newValue);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, update);
            // now update that ref
            updateRef = db.UpdateRef(Constants.HEAD);
            updateRef.SetForceUpdate(true);
            updateRef.SetNewObjectId(oldValue);
            update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FAST_FORWARD, update);
            allRefs = db.GetAllRefs();
            Ref master = allRefs.Get("refs/heads/master");
            Ref head   = allRefs.Get("HEAD");

            NUnit.Framework.Assert.AreEqual("refs/heads/master", master.GetName());
            NUnit.Framework.Assert.AreEqual("HEAD", head.GetName());
            NUnit.Framework.Assert.IsTrue(head.IsSymbolic(), "is symbolic reference");
            NUnit.Framework.Assert.AreSame(master, head.GetTarget());
        }
Exemplo n.º 3
0
        public virtual void TestNoCacheObjectIdSubclass()
        {
            string    newRef = "refs/heads/abc";
            RefUpdate ru     = UpdateRef(newRef);

            RefUpdateTest.SubclassedId newid = new RefUpdateTest.SubclassedId(ru.GetNewObjectId
                                                                                  ());
            ru.SetNewObjectId(newid);
            RefUpdate.Result update = ru.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update);
            Ref r = db.GetAllRefs().Get(newRef);

            NUnit.Framework.Assert.IsNotNull(r);
            NUnit.Framework.Assert.AreEqual(newRef, r.GetName());
            NUnit.Framework.Assert.IsNotNull(r.GetObjectId());
            NUnit.Framework.Assert.AreNotSame(newid, r.GetObjectId());
            NUnit.Framework.Assert.AreSame(typeof(ObjectId), r.GetObjectId().GetType());
            NUnit.Framework.Assert.AreEqual(newid, r.GetObjectId());
            IList <ReflogEntry> reverseEntries1 = db.GetReflogReader("refs/heads/abc").GetReverseEntries
                                                      ();
            ReflogEntry entry1 = reverseEntries1[0];

            NUnit.Framework.Assert.AreEqual(1, reverseEntries1.Count);
            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry1.GetOldId());
            NUnit.Framework.Assert.AreEqual(r.GetObjectId(), entry1.GetNewId());
            NUnit.Framework.Assert.AreEqual(new PersonIdent(db).ToString(), entry1.GetWho().ToString
                                                ());
            NUnit.Framework.Assert.AreEqual(string.Empty, entry1.GetComment());
            IList <ReflogEntry> reverseEntries2 = db.GetReflogReader("HEAD").GetReverseEntries
                                                      ();

            NUnit.Framework.Assert.AreEqual(0, reverseEntries2.Count);
        }
        public virtual void MultipleStashedCommits()
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("file.txt", "content");
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit commit1 = git.Commit().SetMessage("create file").Call();

            WriteTrashFile("file.txt", "content2");
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit commit2 = git.Commit().SetMessage("edit file").Call();
            RefUpdate create  = db.UpdateRef(Constants.R_STASH);

            create.SetNewObjectId(commit1);
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, create.Update());
            RefUpdate update = db.UpdateRef(Constants.R_STASH);

            update.SetNewObjectId(commit2);
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FAST_FORWARD, update.Update());
            StashListCommand        command = git.StashList();
            ICollection <RevCommit> stashed = command.Call();

            NUnit.Framework.Assert.IsNotNull(stashed);
            NUnit.Framework.Assert.AreEqual(2, stashed.Count);
            Iterator <RevCommit> iter = stashed.Iterator();

            NUnit.Framework.Assert.AreEqual(commit2, iter.Next());
            NUnit.Framework.Assert.AreEqual(commit1, iter.Next());
        }
Exemplo n.º 5
0
        public virtual void DeleteMergedBranch_historyNotPruned()
        {
            RevCommit parent = tr.Commit().Create();
            RevCommit b1Tip  = tr.Branch("b1").Commit().Parent(parent).Add("x", "x").Create();
            RevCommit b2Tip  = tr.Branch("b2").Commit().Parent(parent).Add("y", "y").Create();
            // merge b1Tip and b2Tip and update refs/heads/b1 to the merge commit
            Merger merger = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger(repo
                                                                                            ));

            merger.Merge(b1Tip, b2Tip);
            NGit.Junit.CommitBuilder cb = tr.Commit();
            cb.Parent(b1Tip).Parent(b2Tip);
            cb.SetTopLevelTree(merger.GetResultTreeId());
            RevCommit mergeCommit = cb.Create();
            RefUpdate u           = repo.UpdateRef("refs/heads/b1");

            u.SetNewObjectId(mergeCommit);
            u.Update();
            RefUpdate update = repo.UpdateRef("refs/heads/b2");

            update.SetForceUpdate(true);
            update.Delete();
            gc.SetExpireAgeMillis(0);
            gc.Prune(Collections.EmptySet <ObjectId>());
            NUnit.Framework.Assert.IsTrue(repo.HasObject(b2Tip));
        }
Exemplo n.º 6
0
        private void UpdateRef(Ref stashRef, ObjectId newId)
        {
            try
            {
                RefUpdate update = CreateRefUpdate(stashRef);
                update.SetNewObjectId(newId);
                RefUpdate.Result result = update.Update();
                switch (result)
                {
                case RefUpdate.Result.FORCED:
                case RefUpdate.Result.NEW:
                case RefUpdate.Result.NO_CHANGE:
                {
                    return;
                }

                default:
                {
                    throw new JGitInternalException(MessageFormat.Format(JGitText.Get().updatingRefFailed
                                                                         , Constants.R_STASH, newId, result));
                }
                }
            }
            catch (IOException e)
            {
                throw new JGitInternalException(JGitText.Get().stashDropFailed, e);
            }
        }
Exemplo n.º 7
0
        /// <exception cref="System.IO.IOException"></exception>
        private void CommitNoteMap(RevWalk walk, NoteMap map, RevCommit notesCommit, ObjectInserter
                                   inserter, string msg)
        {
            // commit the note
            NGit.CommitBuilder builder = new NGit.CommitBuilder();
            builder.TreeId    = map.WriteTree(inserter);
            builder.Author    = new PersonIdent(repo);
            builder.Committer = builder.Author;
            builder.Message   = msg;
            if (notesCommit != null)
            {
                builder.SetParentIds(notesCommit);
            }
            ObjectId commit = inserter.Insert(builder);

            inserter.Flush();
            RefUpdate refUpdate = repo.UpdateRef(notesRef);

            if (notesCommit != null)
            {
                refUpdate.SetExpectedOldObjectId(notesCommit);
            }
            else
            {
                refUpdate.SetExpectedOldObjectId(ObjectId.ZeroId);
            }
            refUpdate.SetNewObjectId(commit);
            refUpdate.Update(walk);
        }
Exemplo n.º 8
0
        public void testRenameRefNameColission1avoided()
        {
            // setup
            ObjectId rb = db.Resolve("refs/heads/b");

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

            updateRef.NewObjectId = rb;
            updateRef.SetRefLogMessage("Setup", false);
            Assert.AreEqual(RefUpdate.RefUpdateResult.FastForward, updateRef.Update());
            ObjectId oldHead = db.Resolve(Constants.HEAD);

            Assert.IsTrue(rb.Equals(oldHead)); // assumption for this test
            RefLogWriter.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.º 9
0
        public virtual void TestDeleteLooseAndItsDirectory()
        {
            ObjectId  pid       = db.Resolve("refs/heads/c^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/z/c");

            updateRef.SetNewObjectId(pid);
            updateRef.SetForceUpdate(true);
            updateRef.SetRefLogMessage("new test ref", false);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update);
            // internal
            NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, Constants.R_HEADS + "z")
                                          .Exists());
            NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, "logs/refs/heads/z").Exists
                                              ());
            // The real test here
            RefUpdate updateRef2 = db.UpdateRef("refs/heads/z/c");

            updateRef2.SetForceUpdate(true);
            RefUpdate.Result delete = updateRef2.Delete();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, delete);
            NUnit.Framework.Assert.IsNull(db.Resolve("refs/heads/z/c"));
            NUnit.Framework.Assert.IsFalse(new FilePath(db.Directory, Constants.R_HEADS + "z"
                                                        ).Exists());
            NUnit.Framework.Assert.IsFalse(new FilePath(db.Directory, "logs/refs/heads/z").Exists
                                               ());
        }
Exemplo n.º 10
0
        private void Execute(ReceiveCommand cmd)
        {
            try
            {
                RefUpdate ru = db.UpdateRef(cmd.getRefName());
                ru.RefLogIdent = getRefLogIdent();
                switch (cmd.getType())
                {
                case ReceiveCommand.Type.DELETE:
                    if (!ObjectId.ZeroId.Equals(cmd.getOldId()))
                    {
                        ru.ExpectedOldObjectId = cmd.getOldId();
                    }
                    ru.IsForceUpdate = true;
                    Status(cmd, ru.Delete(walk));
                    break;

                case ReceiveCommand.Type.CREATE:
                case ReceiveCommand.Type.UPDATE:
                case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                    ru.IsForceUpdate       = isAllowNonFastForwards();
                    ru.ExpectedOldObjectId = cmd.getOldId();
                    ru.NewObjectId         = 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.º 11
0
        public void testNewNamespaceConflictWithLoosePrefixOfExisting()
        {
            string    newRef = "refs/heads/z/a";
            RefUpdate ru     = updateRef(newRef);
            RevCommit newid  = new RevCommit(ru.NewObjectId)
            {
                // empty
            };

            ru.NewObjectId = newid;
            RefUpdate.RefUpdateResult update = ru.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.New, update);
            // end setup
            string    newRef2 = "refs/heads/z";
            RefUpdate ru2     = updateRef(newRef2);
            RevCommit newid2  = new RevCommit(ru2.NewObjectId)
            {
                // empty
            };

            ru.NewObjectId = newid2;
            RefUpdate.RefUpdateResult update2 = ru2.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.LockFailure, update2);
            Assert.AreEqual(1, db.ReflogReader("refs/heads/z/a").getReverseEntries().Count);
            Assert.IsNull(db.ReflogReader("refs/heads/z"));
            Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count);
        }
Exemplo n.º 12
0
        /// <exception cref="System.IO.IOException"></exception>
        private void CreateBranch(ObjectId objectId, string branchName)
        {
            RefUpdate updateRef = db.UpdateRef(branchName);

            updateRef.SetNewObjectId(objectId);
            updateRef.Update();
        }
Exemplo n.º 13
0
        public virtual void testReadAllIncludingSymrefs()
        {
            ObjectId  masterId  = db.Resolve("refs/heads/master");
            RefUpdate updateRef = db.UpdateRef("refs/remotes/origin/master");

            updateRef.NewObjectId   = masterId;
            updateRef.IsForceUpdate = true;
            updateRef.Update();
            db.WriteSymref("refs/remotes/origin/HEAD", "refs/remotes/origin/master");

            ObjectId r = db.Resolve("refs/remotes/origin/HEAD");

            Assert.AreEqual(masterId, r);

            IDictionary <string, Core.Ref> allRefs = db.getAllRefs();

            Core.Ref refHEAD = allRefs["refs/remotes/origin/HEAD"];
            Assert.IsNotNull(refHEAD);
            Assert.AreEqual(masterId, refHEAD.ObjectId);
            Assert.IsTrue(refHEAD.Peeled);
            Assert.IsNull(refHEAD.PeeledObjectId);

            Core.Ref refmaster = allRefs["refs/remotes/origin/master"];
            Assert.AreEqual(masterId, refmaster.ObjectId);
            Assert.IsFalse(refmaster.Peeled);
            Assert.IsNull(refmaster.PeeledObjectId);
        }
Exemplo n.º 14
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
        private void UpdateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId
                                oldHeadID)
        {
            RefUpdate refUpdate = repo.UpdateRef(Constants.HEAD);

            refUpdate.SetNewObjectId(newHeadId);
            refUpdate.SetRefLogMessage(refLogMessage.ToString(), false);
            refUpdate.SetExpectedOldObjectId(oldHeadID);
            RefUpdate.Result rc = refUpdate.Update();
            switch (rc)
            {
            case RefUpdate.Result.NEW:
            case RefUpdate.Result.FAST_FORWARD:
            {
                return;
            }

            case RefUpdate.Result.REJECTED:
            case RefUpdate.Result.LOCK_FAILURE:
            {
                throw new ConcurrentRefUpdateException(JGitText.Get().couldNotLockHEAD, refUpdate
                                                       .GetRef(), rc);
            }

            default:
            {
                throw new JGitInternalException(MessageFormat.Format(JGitText.Get().updatingRefFailed
                                                                     , Constants.HEAD, newHeadId.ToString(), rc));
            }
            }
        }
Exemplo n.º 15
0
        public virtual void TestUpdateRefLockFailureLocked()
        {
            ObjectId  opid      = db.Resolve("refs/heads/master");
            ObjectId  pid       = db.Resolve("refs/heads/master^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.SetNewObjectId(pid);
            LockFile lockFile1 = new LockFile(new FilePath(db.Directory, "refs/heads/master")
                                              , db.FileSystem);

            try
            {
                NUnit.Framework.Assert.IsTrue(lockFile1.Lock());
                // precondition to test
                RefUpdate.Result update = updateRef.Update();
                NUnit.Framework.Assert.AreEqual(RefUpdate.Result.LOCK_FAILURE, update);
                NUnit.Framework.Assert.AreEqual(opid, db.Resolve("refs/heads/master"));
                LockFile lockFile2 = new LockFile(new FilePath(db.Directory, "refs/heads/master")
                                                  , db.FileSystem);
                NUnit.Framework.Assert.IsFalse(lockFile2.Lock());
            }
            finally
            {
                // was locked, still is
                lockFile1.Unlock();
            }
        }
Exemplo n.º 16
0
        public virtual void TestUpdateRefDetachedUnbornHead()
        {
            ObjectId ppid = db.Resolve("refs/heads/master^");

            WriteSymref("HEAD", "refs/heads/unborn");
            RefUpdate updateRef = db.UpdateRef("HEAD", true);

            updateRef.SetForceUpdate(true);
            updateRef.SetNewObjectId(ppid);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update);
            NUnit.Framework.Assert.AreEqual(ppid, db.Resolve("HEAD"));
            Ref @ref = db.GetRef("HEAD");

            NUnit.Framework.Assert.AreEqual("HEAD", @ref.GetName());
            NUnit.Framework.Assert.IsTrue([email protected](), "is detached");
            // the branch HEAD referred to is left untouched
            NUnit.Framework.Assert.IsNull(db.Resolve("refs/heads/unborn"));
            ReflogReader reflogReader = new ReflogReader(db, "HEAD");
            ReflogEntry  e            = reflogReader.GetReverseEntries()[0];

            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ppid, e.GetNewId());
            NUnit.Framework.Assert.AreEqual("GIT_COMMITTER_EMAIL", e.GetWho().GetEmailAddress
                                                ());
            NUnit.Framework.Assert.AreEqual("GIT_COMMITTER_NAME", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual(1250379778000L, e.GetWho().GetWhen().GetTime());
        }
Exemplo n.º 17
0
        public void testNoCacheObjectIdSubclass()
        {
            string    newRef = "refs/heads/abc";
            RefUpdate ru     = updateRef(newRef);
            RevCommit newid  = new RevCommit(ru.NewObjectId)
            {
                // empty
            };

            ru.NewObjectId = newid;
            RefUpdate.RefUpdateResult update = ru.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.New, update);
            Core.Ref r = db.getAllRefs()[newRef];
            Assert.IsNotNull(r);
            Assert.AreEqual(newRef, r.Name);
            Assert.IsNotNull(r.ObjectId);
            Assert.AreNotSame(newid, r.ObjectId);
            Assert.AreSame(typeof(ObjectId), r.ObjectId.GetType());
            Assert.AreEqual(newid.Copy(), r.ObjectId);
            IList <ReflogReader.Entry> reverseEntries1 = db.ReflogReader("refs/heads/abc").getReverseEntries();

            ReflogReader.Entry entry1 = reverseEntries1[0];
            Assert.AreEqual(1, reverseEntries1.Count);
            Assert.AreEqual(ObjectId.ZeroId, entry1.getOldId());
            Assert.AreEqual(r.ObjectId, entry1.getNewId());
            Assert.AreEqual(new PersonIdent(db).ToString(), entry1.getWho().ToString());
            Assert.AreEqual("", entry1.getComment());
            IList <ReflogReader.Entry> reverseEntries2 = db.ReflogReader("HEAD").getReverseEntries();

            Assert.AreEqual(0, reverseEntries2.Count);
        }
Exemplo n.º 18
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
        private RevCommit TryFastForward(string headName, RevCommit oldCommit, RevCommit
                                         newCommit)
        {
            bool tryRebase = false;

            foreach (RevCommit parentCommit in newCommit.Parents)
            {
                if (parentCommit.Equals(oldCommit))
                {
                    tryRebase = true;
                }
            }
            if (!tryRebase)
            {
                return(null);
            }
            CheckoutCommand co = new CheckoutCommand(repo);

            try
            {
                co.SetName(newCommit.Name).Call();
                if (headName.StartsWith(Constants.R_HEADS))
                {
                    RefUpdate rup = repo.UpdateRef(headName);
                    rup.SetExpectedOldObjectId(oldCommit);
                    rup.SetNewObjectId(newCommit);
                    rup.SetRefLogMessage("Fast-foward from " + oldCommit.Name + " to " + newCommit.Name
                                         , false);
                    RefUpdate.Result res = rup.Update(walk);
                    switch (res)
                    {
                    case RefUpdate.Result.FAST_FORWARD:
                    case RefUpdate.Result.NO_CHANGE:
                    case RefUpdate.Result.FORCED:
                    {
                        break;
                    }

                    default:
                    {
                        throw new IOException("Could not fast-forward");
                    }
                    }
                }
                return(newCommit);
            }
            catch (RefAlreadyExistsException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            catch (RefNotFoundException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            catch (InvalidRefNameException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
        }
Exemplo n.º 19
0
        public void testLooseDelete()
        {
            string    newRef = "refs/heads/abc";
            RefUpdate @ref   = updateRef(newRef);

            @ref.Update();            // create loose ref
            @ref = updateRef(newRef); // refresh
            delete(@ref, RefUpdate.RefUpdateResult.NoChange);
            Assert.IsNull(db.ReflogReader("refs/heads/abc"));
        }
Exemplo n.º 20
0
        public virtual void TestUpdateRefNoChange()
        {
            ObjectId  pid       = db.Resolve("refs/heads/master");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.SetNewObjectId(pid);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NO_CHANGE, update);
            NUnit.Framework.Assert.AreEqual(pid, db.Resolve("refs/heads/master"));
        }
Exemplo n.º 21
0
        public void testUpdateRefNoChange()
        {
            ObjectId  pid       = db.Resolve("refs/heads/master");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.NewObjectId = pid;
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.NoChange, update);
            Assert.AreEqual(pid, db.Resolve("refs/heads/master"));
        }
Exemplo n.º 22
0
        public void testReadLooseRef()
        {
            RefUpdate updateRef = db.UpdateRef("ref/heads/new");

            updateRef.NewObjectId = db.Resolve("refs/heads/master");
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.New, update);
            Core.Ref @ref = db.getRef("ref/heads/new");
            Assert.AreEqual(Core.Ref.Storage.Loose, @ref.StorageFormat);
        }
Exemplo n.º 23
0
        public virtual void TestUpdateRefLockFailureWrongOldValue()
        {
            ObjectId  pid       = db.Resolve("refs/heads/master");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.SetNewObjectId(pid);
            updateRef.SetExpectedOldObjectId(db.Resolve("refs/heads/master^"));
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.LOCK_FAILURE, update);
            NUnit.Framework.Assert.AreEqual(pid, db.Resolve("refs/heads/master"));
        }
Exemplo n.º 24
0
        public virtual void TestNewNamespaceConflictWithPackedPrefixOfExisting()
        {
            string    newRef = "refs/heads/prefix";
            RefUpdate ru     = UpdateRef(newRef);

            RefUpdate.Result update = ru.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.LOCK_FAILURE, update);
            NUnit.Framework.Assert.IsNull(db.GetReflogReader("refs/heads/prefix"));
            NUnit.Framework.Assert.AreEqual(0, db.GetReflogReader("HEAD").GetReverseEntries()
                                            .Count);
        }
Exemplo n.º 25
0
        public virtual void TestDeleteLoosePackedRejected()
        {
            ObjectId  pid       = db.Resolve("refs/heads/c^");
            ObjectId  oldpid    = db.Resolve("refs/heads/c");
            RefUpdate updateRef = db.UpdateRef("refs/heads/c");

            updateRef.SetNewObjectId(pid);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.REJECTED, update);
            NUnit.Framework.Assert.AreEqual(oldpid, db.Resolve("refs/heads/c"));
        }
Exemplo n.º 26
0
 /// <summary>Update locally stored tracking branch with the new object.</summary>
 /// <remarks>Update locally stored tracking branch with the new object.</remarks>
 /// <param name="walk">walker used for checking update properties.</param>
 /// <exception cref="System.IO.IOException">when I/O error occurred during update</exception>
 protected internal virtual void UpdateTrackingRef(RevWalk walk)
 {
     if (IsDelete())
     {
         trackingRefUpdate.SetResult(localUpdate.Delete(walk));
     }
     else
     {
         trackingRefUpdate.SetResult(localUpdate.Update(walk));
     }
 }
Exemplo n.º 27
0
        public void testUpdateRefLockFailureWrongOldValue()
        {
            ObjectId  pid       = db.Resolve("refs/heads/master");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.NewObjectId         = pid;
            updateRef.ExpectedOldObjectId = db.Resolve("refs/heads/master^");
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.LockFailure, update);
            Assert.AreEqual(pid, db.Resolve("refs/heads/master"));
        }
Exemplo n.º 28
0
        public void testDeleteLoosePackedRejected()
        {
            ObjectId  pid       = db.Resolve("refs/heads/c^");
            ObjectId  oldpid    = db.Resolve("refs/heads/c");
            RefUpdate updateRef = db.UpdateRef("refs/heads/c");

            updateRef.NewObjectId = pid;
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Rejected, update);
            Assert.AreEqual(oldpid, db.Resolve("refs/heads/c"));
        }
Exemplo n.º 29
0
        public virtual void TestLooseDelete()
        {
            string    newRef = "refs/heads/abc";
            RefUpdate @ref   = UpdateRef(newRef);

            @ref.Update();
            // create loose ref
            @ref = UpdateRef(newRef);
            // refresh
            Delete(@ref, RefUpdate.Result.NO_CHANGE);
            NUnit.Framework.Assert.IsNull(db.GetReflogReader("refs/heads/abc"));
        }
Exemplo n.º 30
0
        public virtual void TestCreateFromLightweightTag()
        {
            RefUpdate rup = db.UpdateRef("refs/tags/V10");

            rup.SetNewObjectId(initialCommit);
            rup.SetExpectedOldObjectId(ObjectId.ZeroId);
            rup.Update();
            Ref branch = git.BranchCreate().SetName("FromLightweightTag").SetStartPoint("refs/tags/V10"
                                                                                        ).Call();

            NUnit.Framework.Assert.AreEqual(initialCommit.Id, branch.GetObjectId());
        }