Example #1
0
 /// <summary>Set the message to include in the reflog.</summary>
 /// <remarks>Set the message to include in the reflog.</remarks>
 /// <param name="msg">the message to describe this change.</param>
 public virtual void SetRefLogMessage(string msg)
 {
     if (msg == null)
     {
         DisableRefLog();
     }
     else
     {
         destination.SetRefLogMessage(msg, false);
     }
 }
Example #2
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();
        }
Example #3
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);
        }
Example #4
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;
            }
            }
        }
Example #5
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;
		}