예제 #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"));
        }
예제 #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());
        }
예제 #3
0
        /// <exception cref="System.IO.IOException"></exception>
        private void Commit(string commitMsg, PersonIdent author, PersonIdent committer)
        {
            NGit.CommitBuilder commit = new NGit.CommitBuilder();
            commit.Author    = author;
            commit.Committer = committer;
            commit.Message   = commitMsg;
            ObjectInserter inserter = db.NewObjectInserter();
            ObjectId       id;

            try
            {
                commit.TreeId = inserter.Insert(new TreeFormatter());
                id            = inserter.Insert(commit);
                inserter.Flush();
            }
            finally
            {
                inserter.Release();
            }
            int       nl = commitMsg.IndexOf('\n');
            RefUpdate ru = db.UpdateRef(Constants.HEAD);

            ru.SetNewObjectId(id);
            ru.SetRefLogMessage("commit : " + ((nl == -1) ? commitMsg : Sharpen.Runtime.Substring
                                                   (commitMsg, 0, nl)), false);
            ru.ForceUpdate();
        }
예제 #4
0
        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}"
                                                                                    ));
        }
예제 #5
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();
        }
예제 #6
0
        /// <exception cref="System.IO.IOException"></exception>
        internal TrackingRefUpdate(Repository db, string localName, string remoteName, bool
			 forceUpdate, AnyObjectId nv, string msg)
        {
            this.remoteName = remoteName;
            update = db.UpdateRef(localName);
            update.SetForceUpdate(forceUpdate);
            update.SetNewObjectId(nv);
            update.SetRefLogMessage(msg, true);
        }
예제 #7
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());
        }
예제 #8
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());
        }
예제 #9
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());
        }
예제 #10
0
        /// <summary>Create a new RefUpdate copying the batch settings.</summary>
        /// <remarks>Create a new RefUpdate copying the batch settings.</remarks>
        /// <param name="cmd">specific command the update should be created to copy.</param>
        /// <returns>a single reference update command.</returns>
        /// <exception cref="System.IO.IOException">
        /// the reference database cannot make a new update object for
        /// the given reference.
        /// </exception>
        protected internal virtual RefUpdate NewUpdate(ReceiveCommand cmd)
        {
            RefUpdate ru = refdb.NewUpdate(cmd.GetRefName(), false);

            if (IsRefLogDisabled())
            {
                ru.DisableRefLog();
            }
            else
            {
                ru.SetRefLogIdent(refLogIdent);
                ru.SetRefLogMessage(refLogMessage, refLogIncludeResult);
            }
            switch (cmd.GetType())
            {
            case ReceiveCommand.Type.DELETE:
            {
                if (!ObjectId.ZeroId.Equals(cmd.GetOldId()))
                {
                    ru.SetExpectedOldObjectId(cmd.GetOldId());
                }
                ru.SetForceUpdate(true);
                return(ru);
            }

            case ReceiveCommand.Type.CREATE:
            case ReceiveCommand.Type.UPDATE:
            case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
            default:
            {
                ru.SetForceUpdate(IsAllowNonFastForwards());
                ru.SetExpectedOldObjectId(cmd.GetOldId());
                ru.SetNewObjectId(cmd.GetNewId());
                return(ru);

                break;
            }
            }
        }
예제 #11
0
		/// <summary>Construct remote ref update request by providing an update specification.
		/// 	</summary>
		/// <remarks>
		/// Construct remote ref update request by providing an update specification.
		/// Object is created with default
		/// <see cref="Status.NOT_ATTEMPTED">Status.NOT_ATTEMPTED</see>
		/// status and no
		/// message.
		/// </remarks>
		/// <param name="localDb">local repository to push from.</param>
		/// <param name="srcRef">
		/// source revision to label srcId with. If null srcId.name() will
		/// be used instead.
		/// </param>
		/// <param name="srcId">
		/// The new object that the caller wants remote ref to be after
		/// update. Use null or
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// for delete
		/// request.
		/// </param>
		/// <param name="remoteName">
		/// full name of a remote ref to update, e.g. "refs/heads/master"
		/// (no wildcard, no short name).
		/// </param>
		/// <param name="forceUpdate">
		/// true when caller want remote ref to be updated regardless
		/// whether it is fast-forward update (old object is ancestor of
		/// new object).
		/// </param>
		/// <param name="localName">
		/// optional full name of a local stored tracking branch, to
		/// update after push, e.g. "refs/remotes/zawir/dirty" (no
		/// wildcard, no short name); null if no local tracking branch
		/// should be updated.
		/// </param>
		/// <param name="expectedOldObjectId">
		/// optional object id that caller is expecting, requiring to be
		/// advertised by remote side before update; update will take
		/// place ONLY if remote side advertise exactly this expected id;
		/// null if caller doesn't care what object id remote side
		/// advertise. Use
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// when expecting no
		/// remote ref with this name.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// when I/O error occurred during creating
		/// <see cref="TrackingRefUpdate">TrackingRefUpdate</see>
		/// for local tracking branch or srcRef
		/// can't be resolved to any object.
		/// </exception>
		/// <exception cref="System.ArgumentException">if some required parameter was null</exception>
		public RemoteRefUpdate(Repository localDb, string srcRef, ObjectId srcId, string 
			remoteName, bool forceUpdate, string localName, ObjectId expectedOldObjectId)
		{
			if (remoteName == null)
			{
				throw new ArgumentException(JGitText.Get().remoteNameCantBeNull);
			}
			if (srcId == null && srcRef != null)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().sourceRefDoesntResolveToAnyObject
					, srcRef));
			}
			if (srcRef != null)
			{
				this.srcRef = srcRef;
			}
			else
			{
				if (srcId != null && !srcId.Equals(ObjectId.ZeroId))
				{
					this.srcRef = srcId.Name;
				}
				else
				{
					this.srcRef = null;
				}
			}
			if (srcId != null)
			{
				this.newObjectId = srcId;
			}
			else
			{
				this.newObjectId = ObjectId.ZeroId;
			}
			this.remoteName = remoteName;
			this.forceUpdate = forceUpdate;
			if (localName != null && localDb != null)
			{
				localUpdate = localDb.UpdateRef(localName);
				localUpdate.SetForceUpdate(true);
				localUpdate.SetRefLogMessage("push", true);
				localUpdate.SetNewObjectId(newObjectId);
				trackingRefUpdate = new TrackingRefUpdate(true, remoteName, localName, localUpdate
					.GetOldObjectId() != null ? localUpdate.GetOldObjectId() : ObjectId.ZeroId, newObjectId
					);
			}
			else
			{
				trackingRefUpdate = null;
			}
			this.localDb = localDb;
			this.expectedOldObjectId = expectedOldObjectId;
			this.status = RemoteRefUpdate.Status.NOT_ATTEMPTED;
		}