/// <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(); } }
/// <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); } }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private void ExecuteImp(ProgressMonitor monitor, FetchResult result) { conn = transport.OpenFetch(); try { result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap()); ICollection <Ref> matched = new HashSet <Ref>(); foreach (RefSpec spec in toFetch) { if (spec.GetSource() == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec , spec)); } if (spec.IsWildcard()) { ExpandWildcard(spec, matched); } else { ExpandSingle(spec, matched); } } ICollection <Ref> additionalTags = Sharpen.Collections.EmptyList <Ref>(); TagOpt tagopt = transport.GetTagOpt(); if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = ExpandAutoFollowTags(); } else { if (tagopt == TagOpt.FETCH_TAGS) { ExpandFetchTags(); } } bool includedTags; if (!askFor.IsEmpty() && !AskForIsComplete()) { FetchObjects(monitor); includedTags = conn.DidFetchIncludeTags(); // Connection was used for object transfer. If we // do another fetch we must open a new connection. // CloseConnection(result); } else { includedTags = false; } if (tagopt == TagOpt.AUTO_FOLLOW && !additionalTags.IsEmpty()) { // There are more tags that we want to follow, but // not all were asked for on the initial request. // Sharpen.Collections.AddAll(have, askFor.Keys); askFor.Clear(); foreach (Ref r in additionalTags) { ObjectId id = r.GetPeeledObjectId(); if (id == null) { id = r.GetObjectId(); } if (transport.local.HasObject(id)) { WantTag(r); } } if (!askFor.IsEmpty() && (!includedTags || !AskForIsComplete())) { ReopenConnection(); if (!askFor.IsEmpty()) { FetchObjects(monitor); } } } } finally { CloseConnection(result); } BatchRefUpdate batch = transport.local.RefDatabase.NewBatchUpdate().SetAllowNonFastForwards (true).SetRefLogMessage("fetch", true); RevWalk walk = new RevWalk(transport.local); try { if (monitor is BatchingProgressMonitor) { ((BatchingProgressMonitor)monitor).SetDelayStart(250, TimeUnit.MILLISECONDS); } if (transport.IsRemoveDeletedRefs()) { DeleteStaleTrackingRefs(result, batch); } foreach (TrackingRefUpdate u in localUpdates) { result.Add(u); batch.AddCommand(u.AsReceiveCommand()); } foreach (ReceiveCommand cmd in batch.GetCommands()) { cmd.UpdateType(walk); if (cmd.GetType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD && cmd is TrackingRefUpdate.Command && !((TrackingRefUpdate.Command)cmd).CanForceUpdate()) { cmd.SetResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD); } } if (transport.IsDryRun()) { foreach (ReceiveCommand cmd_1 in batch.GetCommands()) { if (cmd_1.GetResult() == ReceiveCommand.Result.NOT_ATTEMPTED) { cmd_1.SetResult(ReceiveCommand.Result.OK); } } } else { batch.Execute(walk, monitor); } } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef , GetFirstFailedRefName(batch), err.Message), err); } finally { walk.Release(); } if (!fetchHeadUpdates.IsEmpty()) { try { UpdateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingFETCH_HEAD , err.Message), err); } } }