Exemple #1
0
        public virtual void TestParseNonGitDescribe()
        {
            ObjectId  id = Id("49322bb17d3acc9146f98c97d078513228bbf3c0");
            RefUpdate ru = db.UpdateRef("refs/heads/foo-g032c");

            ru.SetNewObjectId(id);
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, ru.Update());
            NUnit.Framework.Assert.AreEqual(id, db.Resolve("refs/heads/foo-g032c"));
            NUnit.Framework.Assert.AreEqual(id, db.Resolve("foo-g032c"));
            ru = db.UpdateRef("refs/heads/foo-g032c-dev");
            ru.SetNewObjectId(id);
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, ru.Update());
            NUnit.Framework.Assert.AreEqual(id, db.Resolve("refs/heads/foo-g032c-dev"));
            NUnit.Framework.Assert.AreEqual(id, db.Resolve("foo-g032c-dev"));
        }
Exemple #2
0
        public virtual void TestReadAllIncludingSymrefs()
        {
            ObjectId  masterId  = db.Resolve("refs/heads/master");
            RefUpdate updateRef = db.UpdateRef("refs/remotes/origin/master");

            updateRef.SetNewObjectId(masterId);
            updateRef.SetForceUpdate(true);
            updateRef.Update();
            WriteSymref("refs/remotes/origin/HEAD", "refs/remotes/origin/master");
            ObjectId r = db.Resolve("refs/remotes/origin/HEAD");

            NUnit.Framework.Assert.AreEqual(masterId, r);
            IDictionary <string, Ref> allRefs = db.GetAllRefs();
            Ref refHEAD = allRefs.Get("refs/remotes/origin/HEAD");

            NUnit.Framework.Assert.IsNotNull(refHEAD);
            NUnit.Framework.Assert.AreEqual(masterId, refHEAD.GetObjectId());
            NUnit.Framework.Assert.IsFalse(refHEAD.IsPeeled());
            NUnit.Framework.Assert.IsNull(refHEAD.GetPeeledObjectId());
            Ref refmaster = allRefs.Get("refs/remotes/origin/master");

            NUnit.Framework.Assert.AreEqual(masterId, refmaster.GetObjectId());
            NUnit.Framework.Assert.IsFalse(refmaster.IsPeeled());
            NUnit.Framework.Assert.IsNull(refmaster.GetPeeledObjectId());
        }
        public virtual void ResolveUpstream()
        {
            Git git = new Git(db);

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

            WriteTrashFile("file2.txt", "content");
            RefUpdate updateRemoteRef = db.UpdateRef("refs/remotes/origin/main");

            updateRemoteRef.SetNewObjectId(c1);
            updateRemoteRef.Update();
            ((FileBasedConfig)db.GetConfig()).SetString("branch", "master", "remote", "origin"
                                                        );
            ((FileBasedConfig)db.GetConfig()).SetString("branch", "master", "merge", "refs/heads/main"
                                                        );
            ((FileBasedConfig)db.GetConfig()).SetString("remote", "origin", "url", "git://example.com/here"
                                                        );
            ((FileBasedConfig)db.GetConfig()).SetString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"
                                                        );
            git.Add().AddFilepattern("file2.txt").Call();
            git.Commit().SetMessage("create file").Call();
            NUnit.Framework.Assert.AreEqual("refs/remotes/origin/main", db.Simplify("@{upstream}"
                                                                                    ));
        }
Exemple #4
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal virtual void CreateBranch(ObjectId objectId, string branchName
                                                     )
        {
            RefUpdate updateRef = db.UpdateRef(branchName);

            updateRef.SetNewObjectId(objectId);
            updateRef.Update();
        }
Exemple #5
0
        public virtual void TestReadLooseRef()
        {
            RefUpdate updateRef = db.UpdateRef("ref/heads/new");

            updateRef.SetNewObjectId(db.Resolve("refs/heads/master"));
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update);
            Ref @ref = db.GetRef("ref/heads/new");

            NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, @ref.GetStorage());
        }
Exemple #6
0
        public virtual void TestReadSimplePackedRefSameRepo()
        {
            Ref      @ref = db.GetRef("refs/heads/master");
            ObjectId pid  = db.Resolve("refs/heads/master^");

            NUnit.Framework.Assert.AreEqual(RefStorage.PACKED, @ref.GetStorage());
            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);
            @ref = db.GetRef("refs/heads/master");
            NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, @ref.GetStorage());
        }
Exemple #7
0
        public virtual void TestReadSymRefToLoosePacked()
        {
            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
            WriteSymref("HEAD", "refs/heads/master");
            Ref @ref = db.GetRef("HEAD");

            NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, @ref.GetStorage());
            @ref = @ref.GetTarget();
            NUnit.Framework.Assert.AreEqual("refs/heads/master", @ref.GetName());
            NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, @ref.GetStorage());
        }
Exemple #8
0
        /// <summary>Execute this batch update.</summary>
        /// <remarks>
        /// Execute this batch update.
        /// <p>
        /// The default implementation of this method performs a sequential reference
        /// update over each reference.
        /// </remarks>
        /// <param name="walk">
        /// a RevWalk to parse tags in case the storage system wants to
        /// store them pre-peeled, a common performance optimization.
        /// </param>
        /// <param name="update">progress monitor to receive update status on.</param>
        /// <exception cref="System.IO.IOException">
        /// the database is unable to accept the update. Individual
        /// command status must be tested to determine if there is a
        /// partial failure, or a total failure.
        /// </exception>
        public virtual void Execute(RevWalk walk, ProgressMonitor update)
        {
            update.BeginTask(JGitText.Get().updatingReferences, commands.Count);
            foreach (ReceiveCommand cmd in commands)
            {
                try
                {
                    update.Update(1);
                    if (cmd.GetResult() == ReceiveCommand.Result.NOT_ATTEMPTED)
                    {
                        cmd.UpdateType(walk);
                        RefUpdate ru = NewUpdate(cmd);
                        switch (cmd.GetType())
                        {
                        case ReceiveCommand.Type.DELETE:
                        {
                            cmd.SetResult(ru.Delete(walk));
                            continue;
                            goto case ReceiveCommand.Type.CREATE;
                        }

                        case ReceiveCommand.Type.CREATE:
                        case ReceiveCommand.Type.UPDATE:
                        case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                        {
                            cmd.SetResult(ru.Update(walk));
                            continue;
                        }
                        }
                    }
                }
                catch (IOException err)
                {
                    cmd.SetResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, MessageFormat.Format(JGitText
                                                                                                    .Get().lockError, err.Message));
                }
            }
            update.EndTask();
        }