예제 #1
0
        /// <summary>Write the given ref update to the ref's log</summary>
        /// <param name="update"></param>
        /// <param name="msg"></param>
        /// <param name="deref"></param>
        /// <returns>this writer</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual NGit.Storage.File.ReflogWriter Log(RefUpdate update, string msg, bool
                                                          deref)
        {
            ObjectId    oldId = update.GetOldObjectId();
            ObjectId    newId = update.GetNewObjectId();
            Ref         @ref  = update.GetRef();
            PersonIdent ident = update.GetRefLogIdent();

            if (ident == null)
            {
                ident = new PersonIdent(parent);
            }
            else
            {
                ident = new PersonIdent(ident);
            }
            byte[] rec = Encode(oldId, newId, ident, msg);
            if (deref && @ref.IsSymbolic())
            {
                Log(@ref.GetName(), rec);
                Log(@ref.GetLeaf().GetName(), rec);
            }
            else
            {
                Log(@ref.GetName(), rec);
            }
            return(this);
        }
예제 #2
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);
        }
예제 #3
0
        public virtual void RepositoryWithDifferentRevCheckedOutSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_317(id, path));
            editor.Commit();
            string       url    = "git://server/repo.git";
            StoredConfig config = ((FileBasedConfig)db.GetConfig());

            config.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.
                             CONFIG_KEY_URL, url);
            config.Save();
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), db.FileSystem);

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_PATH, path);
            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            modulesConfig.Save();
            Repository subRepo = Git.Init().SetBare(false).SetDirectory(new FilePath(db.WorkTree
                                                                                     , path)).Call().GetRepository();

            NUnit.Framework.Assert.IsNotNull(subRepo);
            RefUpdate update = subRepo.UpdateRef(Constants.HEAD, true);

            update.SetNewObjectId(ObjectId.FromString("aaaa0000aaaa0000aaaa0000aaaa0000aaaa0000"
                                                      ));
            update.ForceUpdate();
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.AreEqual(1, statuses.Count);
            KeyValuePair <string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
                                                                ();

            NUnit.Framework.Assert.IsNotNull(module);
            NUnit.Framework.Assert.AreEqual(path, module.Key);
            SubmoduleStatus status = module.Value;

            NUnit.Framework.Assert.IsNotNull(status);
            NUnit.Framework.Assert.AreEqual(path, status.GetPath());
            NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
            NUnit.Framework.Assert.AreEqual(update.GetNewObjectId(), status.GetHeadId());
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.REV_CHECKED_OUT, status.GetType
                                                ());
        }
예제 #4
0
 /// <summary>Get the new value the ref will be (or was) updated to.</summary>
 /// <remarks>Get the new value the ref will be (or was) updated to.</remarks>
 /// <returns>new value. Null if the caller has not configured it.</returns>
 public virtual ObjectId GetNewObjectId()
 {
     return(update.GetNewObjectId());
 }