Beispiel #1
0
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected,
                     bool exists, bool removed)
 {
     Assert.AreEqual(exists, db.getAllRefs().ContainsKey(@ref.Name));
     Assert.AreEqual(expected, @ref.Delete());
     Assert.AreEqual(!removed, db.getAllRefs().ContainsKey(@ref.Name));
 }
Beispiel #2
0
 /// <exception cref="System.IO.IOException"></exception>
 private void Delete(RefUpdate @ref, RefUpdate.Result expected, bool exists, bool
                     removed)
 {
     NUnit.Framework.Assert.AreEqual(exists, db.GetAllRefs().ContainsKey(@ref.GetName()));
     NUnit.Framework.Assert.AreEqual(expected, @ref.Delete());
     NUnit.Framework.Assert.AreEqual(!removed, db.GetAllRefs().ContainsKey(@ref.GetName()));
 }
Beispiel #3
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
                                               ());
        }
Beispiel #4
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);
            }
        }
Beispiel #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));
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void TestPullEmptyRepository()
        {
            Repository empty  = CreateWorkRepository();
            RefUpdate  delete = empty.UpdateRef(Constants.HEAD, true);

            delete.SetForceUpdate(true);
            delete.Delete();
            Git.Wrap(empty).Pull().Call();
        }
Beispiel #7
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));
     }
 }
Beispiel #8
0
        public virtual void DeleteBranch_historyPruned()
        {
            RevCommit tip = CommitChain(10);

            tr.Branch("b").Update(tip);
            RefUpdate update = repo.UpdateRef("refs/heads/b");

            update.SetForceUpdate(true);
            update.Delete();
            gc.SetExpireAgeMillis(0);
            gc.Prune(Collections.EmptySet <ObjectId>());
            NUnit.Framework.Assert.IsTrue(gc.GetStatistics().numberOfLooseObjects == 0);
        }
Beispiel #9
0
        public virtual void TestDeleteLoosePacked()
        {
            ObjectId  pid       = db.Resolve("refs/heads/c^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/c");

            updateRef.SetNewObjectId(pid);
            updateRef.SetForceUpdate(true);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, update);
            // internal
            // The real test here
            RefUpdate updateRef2 = db.UpdateRef("refs/heads/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/c"));
        }
Beispiel #10
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.RejectedCurrentBranch, 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);
        }
Beispiel #11
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"));
        }
Beispiel #12
0
        public virtual void TestDeleteHEADreferencedRef()
        {
            ObjectId  pid       = db.Resolve("refs/heads/master^");
            RefUpdate updateRef = db.UpdateRef("refs/heads/master");

            updateRef.SetNewObjectId(pid);
            updateRef.SetForceUpdate(true);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, update);
            // internal
            RefUpdate updateRef2 = db.UpdateRef("refs/heads/master");

            RefUpdate.Result delete = updateRef2.Delete();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.REJECTED_CURRENT_BRANCH, delete);
            NUnit.Framework.Assert.AreEqual(pid, db.Resolve("refs/heads/master"));
            NUnit.Framework.Assert.AreEqual(1, db.GetReflogReader("refs/heads/master").GetReverseEntries
                                                ().Count);
            NUnit.Framework.Assert.AreEqual(0, db.GetReflogReader("HEAD").GetReverseEntries()
                                            .Count);
        }
        /// <summary>Execute this command during a receive-pack session.</summary>
        /// <remarks>
        /// Execute this command during a receive-pack session.
        /// <p>
        /// Sets the status of the command as a side effect.
        /// </remarks>
        /// <param name="rp">receive-pack session.</param>
        /// <since>2.0</since>
        public virtual void Execute(BaseReceivePack rp)
        {
            try
            {
                RefUpdate ru = rp.GetRepository().UpdateRef(GetRefName());
                ru.SetRefLogIdent(rp.GetRefLogIdent());
                switch (GetType())
                {
                case ReceiveCommand.Type.DELETE:
                {
                    if (!ObjectId.ZeroId.Equals(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(GetOldId());
                    }
                    ru.SetForceUpdate(true);
                    SetResult(ru.Delete(rp.GetRevWalk()));
                    break;
                }

                case ReceiveCommand.Type.CREATE:
                case ReceiveCommand.Type.UPDATE:
                case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                {
                    ru.SetForceUpdate(rp.IsAllowNonFastForwards());
                    ru.SetExpectedOldObjectId(GetOldId());
                    ru.SetNewObjectId(GetNewId());
                    ru.SetRefLogMessage("push", true);
                    SetResult(ru.Update(rp.GetRevWalk()));
                    break;
                }
                }
            }
            catch (IOException err)
            {
                Reject(err);
            }
        }
Beispiel #14
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);
        }
Beispiel #15
0
        /// <exception cref="NGit.Api.Errors.NotMergedException">
        /// when trying to delete a branch which has not been merged into
        /// the currently checked out branch without force
        /// </exception>
        /// <exception cref="NGit.Api.Errors.CannotDeleteCurrentBranchException">NGit.Api.Errors.CannotDeleteCurrentBranchException
        ///     </exception>
        /// <returns>the list with the (full) names of the deleted branches</returns>
        /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
        public override IList <string> Call()
        {
            CheckCallable();
            IList <string> result = new AList <string>();

            if (branchNames.IsEmpty())
            {
                return(result);
            }
            try
            {
                string currentBranch = repo.GetFullBranch();
                if (!force)
                {
                    // check if the branches to be deleted
                    // are all merged into the current branch
                    RevWalk   walk = new RevWalk(repo);
                    RevCommit tip  = walk.ParseCommit(repo.Resolve(Constants.HEAD));
                    foreach (string branchName in branchNames)
                    {
                        if (branchName == null)
                        {
                            continue;
                        }
                        Ref currentRef = repo.GetRef(branchName);
                        if (currentRef == null)
                        {
                            continue;
                        }
                        RevCommit @base = walk.ParseCommit(repo.Resolve(branchName));
                        if (!walk.IsMergedInto(@base, tip))
                        {
                            throw new NotMergedException();
                        }
                    }
                }
                SetCallable(false);
                foreach (string branchName_1 in branchNames)
                {
                    if (branchName_1 == null)
                    {
                        continue;
                    }
                    Ref currentRef = repo.GetRef(branchName_1);
                    if (currentRef == null)
                    {
                        continue;
                    }
                    string fullName = currentRef.GetName();
                    if (fullName.Equals(currentBranch))
                    {
                        throw new CannotDeleteCurrentBranchException(MessageFormat.Format(JGitText.Get().
                                                                                          cannotDeleteCheckedOutBranch, branchName_1));
                    }
                    RefUpdate update = repo.UpdateRef(fullName);
                    update.SetRefLogMessage("branch deleted", false);
                    update.SetForceUpdate(true);
                    RefUpdate.Result deleteResult = update.Delete();
                    bool             ok           = true;
                    switch (deleteResult)
                    {
                    case RefUpdate.Result.IO_FAILURE:
                    case RefUpdate.Result.LOCK_FAILURE:
                    case RefUpdate.Result.REJECTED:
                    {
                        ok = false;
                        break;
                    }

                    default:
                    {
                        break;
                        break;
                    }
                    }
                    if (ok)
                    {
                        result.AddItem(fullName);
                        if (fullName.StartsWith(Constants.R_HEADS))
                        {
                            string shortenedName = Sharpen.Runtime.Substring(fullName, Constants.R_HEADS.Length
                                                                             );
                            // remove upstream configuration if any
                            StoredConfig cfg = repo.GetConfig();
                            cfg.UnsetSection(ConfigConstants.CONFIG_BRANCH_SECTION, shortenedName);
                            cfg.Save();
                        }
                    }
                    else
                    {
                        throw new JGitInternalException(MessageFormat.Format(JGitText.Get().deleteBranchUnexpectedResult
                                                                             , deleteResult.ToString()));
                    }
                }
                return(result);
            }
            catch (IOException ioe)
            {
                throw new JGitInternalException(ioe.Message, ioe);
            }
        }
Beispiel #16
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual void Delete(RevWalk walk)
 {
     update.Delete(walk);
 }
Beispiel #17
0
 public void Delete(RevWalk.RevWalk walk)
 {
     update.Delete(walk);
 }
Beispiel #18
0
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected, bool exists, bool removed)
 {
     Assert.AreEqual(exists, db.getRef(@ref.Name) != null);
     Assert.AreEqual(expected, @ref.Delete());
     Assert.AreEqual(!removed, db.getRef(@ref.Name) != null);
 }
Beispiel #19
0
        /// <returns>the list with the full names of the deleted tags</returns>
        /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
        public override IList <string> Call()
        {
            CheckCallable();
            IList <string> result = new AList <string>();

            if (tags.IsEmpty())
            {
                return(result);
            }
            try
            {
                SetCallable(false);
                foreach (string tagName in tags)
                {
                    if (tagName == null)
                    {
                        continue;
                    }
                    Ref currentRef = repo.GetRef(tagName);
                    if (currentRef == null)
                    {
                        continue;
                    }
                    string    fullName = currentRef.GetName();
                    RefUpdate update   = repo.UpdateRef(fullName);
                    update.SetForceUpdate(true);
                    RefUpdate.Result deleteResult = update.Delete();
                    bool             ok           = true;
                    switch (deleteResult)
                    {
                    case RefUpdate.Result.IO_FAILURE:
                    case RefUpdate.Result.LOCK_FAILURE:
                    case RefUpdate.Result.REJECTED:
                    {
                        ok = false;
                        break;
                    }

                    default:
                    {
                        break;
                        break;
                    }
                    }
                    if (ok)
                    {
                        result.AddItem(fullName);
                    }
                    else
                    {
                        throw new JGitInternalException(MessageFormat.Format(JGitText.Get().deleteTagUnexpectedResult
                                                                             , deleteResult.ToString()));
                    }
                }
                return(result);
            }
            catch (IOException ioe)
            {
                throw new JGitInternalException(ioe.Message, ioe);
            }
        }
Beispiel #20
0
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected,
     bool exists, bool removed)
 {
     Assert.AreEqual(exists, db.getAllRefs().ContainsKey(@ref.Name));
     Assert.AreEqual(expected, @ref.Delete());
     Assert.AreEqual(!removed, db.getAllRefs().ContainsKey(@ref.Name));
 }