public void testCreateEmpty() { RefSpec rs = new RefSpec(); Assert.IsFalse(rs.Force); Assert.IsFalse(rs.Wildcard); Assert.AreEqual("HEAD", rs.Source); Assert.IsNull(rs.Destination); Assert.AreEqual("HEAD", rs.ToString()); }
private void expandWildcard(RefSpec spec, HashSet <Ref> matched) { foreach (Ref src in _connection.Refs) { if (spec.MatchSource(src) && matched.Add(src)) { want(src, spec.ExpandFromSource((src))); } } }
public bool AddPushRefSpec(RefSpec s) { if (Push.Contains(s)) { return(false); } Push.Add(s); return(true); }
public bool AddFetchRefSpec(RefSpec s) { if (Fetch.Contains(s)) { return(false); } Fetch.Add(s); return(true); }
public void testSplitLastColon() { string lhs = ":m:a:i:n:t"; string rhs = "refs/heads/maint"; RefSpec rs = new RefSpec(lhs + ":" + rhs); Assert.IsFalse(rs.Force); Assert.IsFalse(rs.Wildcard); Assert.AreEqual(lhs, rs.Source); Assert.AreEqual(rhs, rs.Destination); Assert.AreEqual(lhs + ":" + rhs, rs.ToString()); Assert.AreEqual(rs, new RefSpec(rs.ToString())); }
private void expandSingle(RefSpec spec, HashSet <Ref> matched) { Ref src = _connection.Refs.Find(x => x.Name == spec.Source); if (src == null) { throw new TransportException("Remote does not have " + spec.Source + " available for fetch."); } if (matched.Add(src)) { want(src, spec); } }
/// <summary> /// Create a new RefSpec with a different source name setting. /// </summary> /// <param name="source">new value for source in the returned instance.</param> /// <returns>a new RefSpec with source as specified.</returns> public RefSpec SetSource(string source) { var r = new RefSpec(this); r.Source = source; if (IsWildcard(r.Source) && r.Destination == null) { throw new InvalidOperationException("Destination is not a wildcard."); } if (IsWildcard(r.Source) != IsWildcard(r.Destination)) { throw new InvalidOperationException("Source/Destination must match."); } return(r); }
/// <summary> /// Create a new RefSpec with a different destination name setting. /// </summary> /// <param name="destination">new value for destination in the returned instance.</param> /// <returns>a new RefSpec with destination as specified.</returns> public RefSpec SetDestination(string destination) { RefSpec r = new RefSpec(this); r.Destination = destination; if (IsWildcard(r.Destination) && r.Source == null) { throw new InvalidOperationException("Source is not a wildcard."); } if (IsWildcard(r.Source) != IsWildcard(r.Destination)) { throw new InvalidOperationException("Source/Destination must match."); } return(r); }
private void deleteStaleTrackingRefs(FetchResult result, RevWalk.RevWalk walk) { Repository db = _transport.Local; foreach (Ref @ref in db.getAllRefs().Values) { string refname = @ref.Name; foreach (RefSpec spec in _toFetch) { if (spec.MatchDestination(refname)) { RefSpec s = spec.ExpandFromDestination(refname); if (result.GetAdvertisedRef(s.Source) == null) { deleteTrackingRef(result, db, walk, s, @ref); } } } } }
public void testDeleteMaster() { string sn = "refs/heads/master"; RefSpec rs = new RefSpec(":" + sn); Assert.IsFalse(rs.Force); Assert.IsFalse(rs.Wildcard); Assert.AreEqual(sn, rs.Destination); Assert.IsNull(rs.Source); Assert.AreEqual(":" + sn, rs.ToString()); Assert.AreEqual(rs, new RefSpec(rs.ToString())); Core.Ref r = new Core.Ref(Core.Ref.Storage.Loose, sn, null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsTrue(rs.MatchDestination(r)); Assert.AreSame(rs, rs.ExpandFromSource(r)); r = new Core.Ref(Core.Ref.Storage.Loose, sn + "-and-more", null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsFalse(rs.MatchDestination(r)); }
public void testSetForceUpdate() { string s = "refs/heads/*:refs/remotes/origin/*"; RefSpec a = new RefSpec(s); Assert.IsFalse(a.Force); RefSpec b = a.SetForce(true); Assert.AreNotSame(a, b); Assert.IsFalse(a.Force); Assert.IsTrue(b.Force); Assert.AreEqual(s, a.ToString()); Assert.AreEqual("+" + s, b.ToString()); }
public void testForceRemotesOrigin() { string srcn = "refs/heads/*"; string dstn = "refs/remotes/origin/*"; RefSpec rs = new RefSpec("+" + srcn + ":" + dstn); Assert.IsTrue(rs.Force); Assert.IsTrue(rs.Wildcard); Assert.AreEqual(srcn, rs.Source); Assert.AreEqual(dstn, rs.Destination); Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString()); Assert.AreEqual(rs, new RefSpec(rs.ToString())); Core.Ref r; RefSpec expanded; r = new Core.Ref(Core.Ref.Storage.Loose, "refs/heads/master", null); Assert.IsTrue(rs.MatchSource(r)); Assert.IsFalse(rs.MatchDestination(r)); expanded = rs.ExpandFromSource(r); Assert.AreNotSame(rs, expanded); Assert.IsTrue(expanded.Force); Assert.IsFalse(expanded.Wildcard); Assert.AreEqual(r.Name, expanded.Source); Assert.AreEqual("refs/remotes/origin/master", expanded.Destination); r = new Core.Ref(Core.Ref.Storage.Loose, "refs/remotes/origin/next", null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsTrue(rs.MatchDestination(r)); r = new Core.Ref(Core.Ref.Storage.Loose, "refs/tags/v1.0", null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsFalse(rs.MatchDestination(r)); }
public void testSetDestination_SourceNull() { RefSpec a = new RefSpec(); RefSpec b; b = a.SetDestination("refs/heads/master"); b = b.SetSource(null); Assert.AreNotSame(a, b); Assert.AreEqual("HEAD", a.ToString()); Assert.AreEqual(":refs/heads/master", b.ToString()); }
private void want(Ref src, RefSpec spec) { ObjectId newId = src.ObjectId; if (spec.Destination != null) { try { TrackingRefUpdate tru = createUpdate(spec, newId); if (newId.Equals(tru.OldObjectId)) { return; } _localUpdates.Add(tru); } catch (System.IO.IOException err) { // Bad symbolic ref? That is the most likely cause. throw new TransportException("Cannot resolve" + " local tracking ref " + spec.Destination + " for updating.", err); } } _askFor.Add(newId, src); FetchHeadRecord fhr = new FetchHeadRecord(newId, spec.Destination != null, src.Name, _transport.Uri); _fetchHeadUpdates.Add(fhr); }
public void testFindRemoteRefUpdatesTwoRefSpecs() { transport = GitSharp.Core.Transport.Transport.open(db, remoteConfig); RefSpec specA = new RefSpec("+refs/heads/a:refs/heads/b"); RefSpec specC = new RefSpec("+refs/heads/c:refs/heads/d"); List<RefSpec> specs = new List<RefSpec>{specA, specC}; ICollection<RemoteRefUpdate> result = transport.findRemoteRefUpdatesFor(specs); Assert.AreEqual(2, result.Count); bool foundA = false; bool foundC = false; foreach (RemoteRefUpdate rru in result) { if ("refs/heads/a".Equals(rru.SourceRef) && "refs/heads/b".Equals(rru.RemoteName)) foundA = true; if ("refs/heads/c".Equals(rru.SourceRef) && "refs/heads/d".Equals(rru.RemoteName)) foundC = true; } Assert.IsTrue(foundA); Assert.IsTrue(foundC); }
/// <summary> /// Add a new push RefSpec to this remote. /// </summary> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public bool AddPushRefSpec(RefSpec s) { if (Push.Contains(s)) return false; Push.Add(s); return true; }
private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId) { return(new TrackingRefUpdate(_transport.Local, spec, newId, "fetch")); }
/// <summary> /// Create a new RefSpec with a different source name setting. /// </summary> /// <param name="source">new value for source in the returned instance.</param> /// <returns>a new RefSpec with source as specified.</returns> public RefSpec SetSource(string source) { var r = new RefSpec(this); r.Source = source; if (IsWildcard(r.Source) && r.Destination == null) throw new InvalidOperationException("Destination is not a wildcard."); if (IsWildcard(r.Source) != IsWildcard(r.Destination)) throw new InvalidOperationException("Source/Destination must match."); return r; }
/// <summary> /// Add a new fetch RefSpec to this remote. /// </summary> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public bool AddFetchRefSpec(RefSpec s) { if (Fetch.Contains(s)) { return false; } Fetch.Add(s); return true; }
public void testExpandFromDestination_NonWildcard() { string src = "refs/heads/master"; string dst = "refs/remotes/origin/master"; RefSpec a = new RefSpec(src + ":" + dst); RefSpec r = a.ExpandFromDestination(dst); Assert.AreSame(a, r); Assert.IsFalse(r.Wildcard); Assert.AreEqual(src, r.Source); Assert.AreEqual(dst, r.Destination); }
private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef) { string name = localRef.Name; try { TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted"); result.Add(u); if (_transport.DryRun) { return; } u.Delete(walk); switch (u.Result) { case RefUpdate.RefUpdateResult.New: case RefUpdate.RefUpdateResult.NoChange: case RefUpdate.RefUpdateResult.FastForward: case RefUpdate.RefUpdateResult.Forced: break; default: throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + u.Result.ToString()); } } catch (System.IO.IOException e) { throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e); } }
public void testSetSource() { RefSpec a = new RefSpec(); RefSpec b = a.SetSource("refs/heads/master"); Assert.AreNotSame(a, b); Assert.AreEqual("HEAD", a.ToString()); Assert.AreEqual("refs/heads/master", b.ToString()); }
public bool RemoveFetchRefSpec(RefSpec s) { return(Fetch.Remove(s)); }
private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef) { string name = localRef.Name; try { TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted"); result.Add(u); if (_transport.DryRun) { return; } u.Delete(walk); switch (u.Result) { case RefUpdate.RefUpdateResult.NEW: case RefUpdate.RefUpdateResult.NO_CHANGE: case RefUpdate.RefUpdateResult.FAST_FORWARD: case RefUpdate.RefUpdateResult.FORCED: break; default: throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + Enum.GetName(typeof(RefUpdate.RefUpdateResult), u.Result)); } } catch (IOException e) { throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e); } }
public void testSetSourceDestination() { RefSpec a = new RefSpec(); RefSpec b; b = a.SetSourceDestination("refs/heads/*", "refs/remotes/origin/*"); Assert.AreNotSame(a, b); Assert.AreEqual("HEAD", a.ToString()); Assert.AreEqual("refs/heads/*:refs/remotes/origin/*", b.ToString()); }
public bool RemovePushRefSpec(RefSpec s) { return(Push.Remove(s)); }
private FetchResult fetchFromBundle(Core.Repository newRepo, byte[] bundle) { var uri = new URIish("in-memory://"); var @in = new MemoryStream(bundle); var rs = new RefSpec("refs/heads/*:refs/heads/*"); var refs = new List<RefSpec>{rs}; var transportBundleStream = new TransportBundleStream(newRepo, uri, @in); _transportBundleStreams.Add(transportBundleStream); return transportBundleStream.fetch(NullProgressMonitor.Instance, refs); }
private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId) { return new TrackingRefUpdate(_transport.Local, spec, newId, "fetch"); }
private RefSpec(RefSpec p) { Force = p.Force; Wildcard = p.Wildcard; Source = p.Source; Destination = p.Destination; }
/// <summary> /// Create a new RefSpec with a different destination name setting. /// </summary> /// <param name="destination">new value for destination in the returned instance.</param> /// <returns>a new RefSpec with destination as specified.</returns> public RefSpec SetDestination(string destination) { RefSpec r = new RefSpec(this); r.Destination = destination; if (IsWildcard(r.Destination) && r.Source == null) { throw new InvalidOperationException("Source is not a wildcard."); } if (IsWildcard(r.Source) != IsWildcard(r.Destination)) { throw new InvalidOperationException("Source/Destination must match."); } return r; }
private void expandSingle(RefSpec spec, HashSet<Ref> matched) { Ref src = _connection.Refs.Find(x => x.Name == spec.Source); if (src == null) { throw new TransportException("Remote does not have " + spec.Source + " available for fetch."); } if (matched.Add(src)) { want(src, spec); } }
/// <summary> /// Remove a fetch RefSpec from this remote. /// </summary> /// <param name="s">the specification to remove.</param> /// <returns>true if the specification existed and was removed.</returns> public bool RemoveFetchRefSpec(RefSpec s) { return Fetch.Remove(s); }
private void expandWildcard(RefSpec spec, HashSet<Ref> matched) { foreach (Ref src in _connection.Refs) { if (spec.MatchSource(src) && matched.Add(src)) want(src, spec.ExpandFromSource((src))); } }
/// <summary> /// Remove a push RefSpec from this remote. /// </summary> /// <param name="s">the specification to remove.</param> /// <returns>true if the specification existed and was removed.</returns> public bool RemovePushRefSpec(RefSpec s) { return Push.Remove(s); }