Exemple #1
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void Want(Ref src, RefSpec spec)
        {
            ObjectId newId = src.GetObjectId();

            if (spec.GetDestination() != null)
            {
                try
                {
                    TrackingRefUpdate tru = CreateUpdate(spec, newId);
                    if (newId.Equals(tru.GetOldObjectId()))
                    {
                        return;
                    }
                    localUpdates.AddItem(tru);
                }
                catch (IOException err)
                {
                    // Bad symbolic ref? That is the most likely cause.
                    //
                    throw new TransportException(MessageFormat.Format(JGitText.Get().cannotResolveLocalTrackingRefForUpdating
                                                                      , spec.GetDestination()), err);
                }
            }
            askFor.Put(newId, src);
            FetchHeadRecord fhr = new FetchHeadRecord();

            fhr.newValue    = newId;
            fhr.notForMerge = spec.GetDestination() != null;
            fhr.sourceName  = src.GetName();
            fhr.sourceURI   = transport.GetURI();
            fetchHeadUpdates.AddItem(fhr);
        }
Exemple #2
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;
 }
Exemple #3
0
        private void DeleteTrackingRef(FetchResult result, BatchRefUpdate batch, RefSpec
                                       spec, Ref localRef)
        {
            if (localRef.GetObjectId() == null)
            {
                return;
            }
            TrackingRefUpdate update = new TrackingRefUpdate(true, spec.GetSource(), localRef
                                                             .GetName(), localRef.GetObjectId(), ObjectId.ZeroId);

            result.Add(update);
            batch.AddCommand(update.AsReceiveCommand());
        }
Exemple #4
0
        private void RemoveTrackingRefUpdate(ObjectId want)
        {
            Iterator <TrackingRefUpdate> i = localUpdates.Iterator();

            while (i.HasNext())
            {
                TrackingRefUpdate u = i.Next();
                if (u.GetNewObjectId().Equals(want))
                {
                    i.Remove();
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// Perform push operation between local and remote repository - set remote
 /// refs appropriately, send needed objects and update local tracking refs.
 /// </summary>
 /// <remarks>
 /// Perform push operation between local and remote repository - set remote
 /// refs appropriately, send needed objects and update local tracking refs.
 /// <p>
 /// When
 /// <see cref="Transport.IsDryRun()">Transport.IsDryRun()</see>
 /// is true, result of this operation is
 /// just estimation of real operation result, no real action is performed.
 /// </remarks>
 /// <param name="monitor">progress monitor used for feedback about operation.</param>
 /// <returns>result of push operation with complete status description.</returns>
 /// <exception cref="System.NotSupportedException">when push operation is not supported by provided transport.
 ///     </exception>
 /// <exception cref="NGit.Errors.TransportException">
 /// when some error occurred during operation, like I/O, protocol
 /// error, or local database consistency error.
 /// </exception>
 internal virtual PushResult Execute(ProgressMonitor monitor)
 {
     try
     {
         monitor.BeginTask(PROGRESS_OPENING_CONNECTION, ProgressMonitor.UNKNOWN);
         PushResult res = new PushResult();
         connection = transport.OpenPush();
         try
         {
             res.SetAdvertisedRefs(transport.GetURI(), connection.GetRefsMap());
             res.SetRemoteUpdates(toPush);
             monitor.EndTask();
             IDictionary <string, RemoteRefUpdate> preprocessed = PrepareRemoteUpdates();
             if (transport.IsDryRun())
             {
                 ModifyUpdatesForDryRun();
             }
             else
             {
                 if (!preprocessed.IsEmpty())
                 {
                     connection.Push(monitor, preprocessed);
                 }
             }
         }
         finally
         {
             connection.Close();
             res.AddMessages(connection.GetMessages());
         }
         if (!transport.IsDryRun())
         {
             UpdateTrackingRefs();
         }
         foreach (RemoteRefUpdate rru in toPush.Values)
         {
             TrackingRefUpdate tru = rru.GetTrackingRefUpdate();
             if (tru != null)
             {
                 res.Add(tru);
             }
         }
         return(res);
     }
     finally
     {
         walker.Release();
     }
 }
Exemple #6
0
        public virtual void TestFindRemoteRefUpdatesTrackingRef()
        {
            remoteConfig.AddFetchRefSpec(new RefSpec("refs/heads/*:refs/remotes/test/*"));
            transport = NGit.Transport.Transport.Open(db, remoteConfig);
            ICollection <RemoteRefUpdate> result = transport.FindRemoteRefUpdatesFor(Sharpen.Collections
                                                                                     .NCopies(1, new RefSpec("+refs/heads/a:refs/heads/a")));

            NUnit.Framework.Assert.AreEqual(1, result.Count);
            TrackingRefUpdate tru = result.Iterator().Next().GetTrackingRefUpdate();

            NUnit.Framework.Assert.AreEqual("refs/remotes/test/a", tru.GetLocalName());
            NUnit.Framework.Assert.AreEqual("refs/heads/a", tru.GetRemoteName());
            NUnit.Framework.Assert.AreEqual(db.Resolve("refs/heads/a"), tru.GetNewObjectId());
            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, tru.GetOldObjectId());
        }
Exemple #7
0
        public virtual void TestTrackingRefUpdateEnabled()
        {
            RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9"
                                                      , "refs/heads/master", false, "refs/remotes/test/master", null);
            Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId
                                                .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef"));

            refUpdates.AddItem(rru);
            advertisedRefs.AddItem(@ref);
            PushResult        result = ExecutePush();
            TrackingRefUpdate tru    = result.GetTrackingRefUpdate("refs/remotes/test/master");

            NUnit.Framework.Assert.IsNotNull(tru);
            NUnit.Framework.Assert.AreEqual("refs/remotes/test/master", tru.GetLocalName());
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, tru.GetResult());
        }
Exemple #8
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void Want(Ref src, RefSpec spec)
        {
            ObjectId newId = src.GetObjectId();

            if (spec.GetDestination() != null)
            {
                TrackingRefUpdate tru = CreateUpdate(spec, newId);
                if (newId.Equals(tru.GetOldObjectId()))
                {
                    return;
                }
                localUpdates.AddItem(tru);
            }
            askFor.Put(newId, src);
            FetchHeadRecord fhr = new FetchHeadRecord();

            fhr.newValue    = newId;
            fhr.notForMerge = spec.GetDestination() != null;
            fhr.sourceName  = src.GetName();
            fhr.sourceURI   = transport.GetURI();
            fetchHeadUpdates.AddItem(fhr);
        }
Exemple #9
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void DeleteTrackingRef(FetchResult result, Repository db, RevWalk walk, RefSpec
                                       spec, Ref localRef)
        {
            string name = localRef.GetName();

            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.GetSource(), true, ObjectId
                                                            .ZeroId, "deleted");
                result.Add(u);
                if (transport.IsDryRun())
                {
                    return;
                }
                u.Delete(walk);
                switch (u.GetResult())
                {
                case RefUpdate.Result.NEW:
                case RefUpdate.Result.NO_CHANGE:
                case RefUpdate.Result.FAST_FORWARD:
                case RefUpdate.Result.FORCED:
                {
                    break;
                }

                default:
                {
                    throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                                                                                              ().cannotDeleteStaleTrackingRef2, name, u.GetResult().ToString()));
                }
                }
            }
            catch (IOException e)
            {
                throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                                                                                          ().cannotDeleteStaleTrackingRef, name), e);
            }
        }
Exemple #10
0
 internal virtual void Add(TrackingRefUpdate u)
 {
     updates.Put(u.GetLocalName(), u);
 }
Exemple #11
0
 internal virtual void Add(TrackingRefUpdate u)
 {
     updates.Put(u.GetLocalName(), u);
 }
		/// <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 - any string resolvable by
		/// <see cref="NGit.Repository.Resolve(string)">NGit.Repository.Resolve(string)</see>
		/// . This resolves to the new
		/// object that the caller want remote ref to be after update. Use
		/// null or
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// string 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, string remoteName, bool
			 forceUpdate, string localName, ObjectId expectedOldObjectId)
		{
			if (remoteName == null)
			{
				throw new ArgumentException(JGitText.Get().remoteNameCantBeNull);
			}
			this.srcRef = srcRef;
			this.newObjectId = (srcRef == null ? ObjectId.ZeroId : localDb.Resolve(srcRef));
			if (newObjectId == null)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().sourceRefDoesntResolveToAnyObject
					, srcRef));
			}
			this.remoteName = remoteName;
			this.forceUpdate = forceUpdate;
			if (localName != null && localDb != null)
			{
				trackingRefUpdate = new TrackingRefUpdate(localDb, localName, remoteName, true, newObjectId
					, "push");
			}
			else
			{
				trackingRefUpdate = null;
			}
			this.localDb = localDb;
			this.expectedOldObjectId = expectedOldObjectId;
			this.status = RemoteRefUpdate.Status.NOT_ATTEMPTED;
		}
Exemple #13
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void DeleteTrackingRef(FetchResult result, Repository db, RevWalk walk, RefSpec
			 spec, Ref localRef)
        {
            string name = localRef.GetName();
            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.GetSource(), true, ObjectId
                    .ZeroId, "deleted");
                result.Add(u);
                if (transport.IsDryRun())
                {
                    return;
                }
                u.Delete(walk);
                switch (u.GetResult())
                {
                    case RefUpdate.Result.NEW:
                    case RefUpdate.Result.NO_CHANGE:
                    case RefUpdate.Result.FAST_FORWARD:
                    case RefUpdate.Result.FORCED:
                    {
                        break;
                    }

                    default:
                    {
                        throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                            ().cannotDeleteStaleTrackingRef2, name, u.GetResult().ToString()));
                    }
                }
            }
            catch (IOException e)
            {
                throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                    ().cannotDeleteStaleTrackingRef, name), e);
            }
        }
Exemple #14
0
 public Command(TrackingRefUpdate _enclosing) : base(_enclosing.oldObjectId,
                                                     _enclosing.newObjectId, _enclosing.localName)
 {
     this._enclosing = _enclosing;
 }
Exemple #15
0
		private void DeleteTrackingRef(FetchResult result, BatchRefUpdate batch, RefSpec 
			spec, Ref localRef)
		{
			if (localRef.GetObjectId() == null)
			{
				return;
			}
			TrackingRefUpdate update = new TrackingRefUpdate(true, spec.GetSource(), localRef
				.GetName(), localRef.GetObjectId(), ObjectId.ZeroId);
			result.Add(update);
			batch.AddCommand(update.AsReceiveCommand());
		}
Exemple #16
0
            public Command(TrackingRefUpdate _enclosing)
                : base(_enclosing.oldObjectId, 
				_enclosing.newObjectId, _enclosing.localName)
            {
                this._enclosing = _enclosing;
            }
Exemple #17
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;
		}