public virtual void TestPush() { // create other repository Repository db2 = CreateWorkRepository(); // setup the first repository StoredConfig config = ((FileBasedConfig)db.GetConfig()); RemoteConfig remoteConfig = new RemoteConfig(config, "test"); URIish uri = new URIish(db2.Directory.ToURI().ToURL()); remoteConfig.AddURI(uri); remoteConfig.Update(config); config.Save(); Git git1 = new Git(db); // create some refs via commits and tag RevCommit commit = git1.Commit().SetMessage("initial commit").Call(); Ref tagRef = git1.Tag().SetName("tag").Call(); try { db2.Resolve(commit.Id.GetName() + "^{commit}"); NUnit.Framework.Assert.Fail("id shouldn't exist yet"); } catch (MissingObjectException) { } // we should get here RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x"); git1.Push().SetRemote("test").SetRefSpecs(spec).Call(); NUnit.Framework.Assert.AreEqual(commit.Id, db2.Resolve(commit.Id.GetName() + "^{commit}" )); NUnit.Framework.Assert.AreEqual(tagRef.GetObjectId(), db2.Resolve(tagRef.GetObjectId ().GetName())); }
/// <summary>Add a new push RefSpec to this remote.</summary> /// <remarks>Add a new push RefSpec to this remote.</remarks> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public virtual bool AddPushRefSpec(RefSpec s) { if (push.Contains(s)) { return(false); } return(push.AddItem(s)); }
/// <summary>Add a new fetch RefSpec to this remote.</summary> /// <remarks>Add a new fetch RefSpec to this remote.</remarks> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public virtual bool AddFetchRefSpec(RefSpec s) { if (fetch.Contains(s)) { return(false); } return(fetch.AddItem(s)); }
public virtual void TestSetDestination() { RefSpec a = new RefSpec(); RefSpec b = a.SetDestination("refs/heads/master"); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.AreEqual("HEAD", a.ToString()); NUnit.Framework.Assert.AreEqual("HEAD:refs/heads/master", b.ToString()); }
/// <exception cref="NGit.Errors.TransportException"></exception> private TrackingRefUpdate CreateUpdate(RefSpec spec, ObjectId newId) { Ref @ref = LocalRefs().Get(spec.GetDestination()); ObjectId oldId = @ref != null && @ref.GetObjectId() != null? @ref.GetObjectId() : ObjectId.ZeroId; return(new TrackingRefUpdate(spec.IsForceUpdate(), spec.GetSource(), spec.GetDestination (), oldId, newId)); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ExpandWildcard(RefSpec spec, ICollection <Ref> matched) { foreach (Ref src in conn.GetRefs()) { if (spec.MatchSource(src) && matched.AddItem(src)) { Want(src, spec.ExpandFromSource(src)); } } }
public virtual void TestCreateEmpty() { RefSpec rs = new RefSpec(); NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual("HEAD", rs.GetSource()); NUnit.Framework.Assert.IsNull(rs.GetDestination()); NUnit.Framework.Assert.AreEqual("HEAD", rs.ToString()); }
/// <exception cref="Sharpen.URISyntaxException"></exception> /// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private FetchResult FetchFromBundle(Repository newRepo, byte[] bundle) { URIish uri = new URIish("in-memory://"); ByteArrayInputStream @in = new ByteArrayInputStream(bundle); RefSpec rs = new RefSpec("refs/heads/*:refs/heads/*"); ICollection <RefSpec> refs = Collections.Singleton(rs); return(new TransportBundleStream(newRepo, uri, @in).Fetch(NullProgressMonitor.INSTANCE , refs)); }
public virtual void TestSetSourceDestination() { RefSpec a = new RefSpec(); RefSpec b; b = a.SetSourceDestination("refs/heads/*", "refs/remotes/origin/*"); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.AreEqual("HEAD", a.ToString()); NUnit.Framework.Assert.AreEqual("refs/heads/*:refs/remotes/origin/*", b.ToString( )); }
public virtual void TestSplitLastColon() { string lhs = ":m:a:i:n:t"; string rhs = "refs/heads/maint"; RefSpec rs = new RefSpec(lhs + ":" + rhs); NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual(lhs, rs.GetSource()); NUnit.Framework.Assert.AreEqual(rhs, rs.GetDestination()); NUnit.Framework.Assert.AreEqual(lhs + ":" + rhs, rs.ToString()); NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString())); }
public virtual void TestExpandFromDestination_Wildcard() { string src = "refs/heads/master"; string dst = "refs/remotes/origin/master"; RefSpec a = new RefSpec("refs/heads/*:refs/remotes/origin/*"); RefSpec r = a.ExpandFromDestination(dst); NUnit.Framework.Assert.AreNotSame(a, r); NUnit.Framework.Assert.IsFalse(r.IsWildcard()); NUnit.Framework.Assert.AreEqual(src, r.GetSource()); NUnit.Framework.Assert.AreEqual(dst, r.GetDestination()); }
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()); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ExpandSingle(RefSpec spec, ICollection <Ref> matched) { Ref src = conn.GetRef(spec.GetSource()); if (src == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().remoteDoesNotHaveSpec , spec.GetSource())); } if (matched.AddItem(src)) { Want(src, spec); } }
public virtual void TestSetForceUpdate() { string s = "refs/heads/*:refs/remotes/origin/*"; RefSpec a = new RefSpec(s); NUnit.Framework.Assert.IsFalse(a.IsForceUpdate()); RefSpec b = a.SetForceUpdate(true); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.IsFalse(a.IsForceUpdate()); NUnit.Framework.Assert.IsTrue(b.IsForceUpdate()); NUnit.Framework.Assert.AreEqual(s, a.ToString()); NUnit.Framework.Assert.AreEqual("+" + s, b.ToString()); }
/// <exception cref="System.IO.IOException"></exception> private void DeleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch) { foreach (Ref @ref in LocalRefs().Values) { string refname = @ref.GetName(); foreach (RefSpec spec in toFetch) { if (spec.MatchDestination(refname)) { RefSpec s = spec.ExpandFromDestination(refname); if (result.GetAdvertisedRef(s.GetSource()) == null) { DeleteTrackingRef(result, batch, s, @ref); } } } } }
public virtual void TestMasterMaster() { string sn = "refs/heads/master"; RefSpec rs = new RefSpec(sn + ":" + sn); NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual(sn, rs.GetSource()); NUnit.Framework.Assert.AreEqual(sn, rs.GetDestination()); NUnit.Framework.Assert.AreEqual(sn + ":" + sn, rs.ToString()); NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString())); Ref r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn, null); NUnit.Framework.Assert.IsTrue(rs.MatchSource(r)); NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r)); NUnit.Framework.Assert.AreSame(rs, rs.ExpandFromSource(r)); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn + "-and-more", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void DeleteStaleTrackingRefs(FetchResult result, RevWalk walk) { Repository db = transport.local; foreach (Ref @ref in db.GetAllRefs().Values) { string refname = @ref.GetName(); foreach (RefSpec spec in toFetch) { if (spec.MatchDestination(refname)) { RefSpec s = spec.ExpandFromDestination(refname); if (result.GetAdvertisedRef(s.GetSource()) == null) { DeleteTrackingRef(result, db, walk, s, @ref); } } } } }
public virtual void TestForceMasterMaster() { string sn = "refs/heads/master"; RefSpec rs = new RefSpec("+" + sn + ":" + sn); NUnit.Framework.Assert.IsTrue(rs.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual(sn, rs.GetSource()); NUnit.Framework.Assert.AreEqual(sn, rs.GetDestination()); NUnit.Framework.Assert.AreEqual("+" + sn + ":" + sn, rs.ToString()); NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString())); Ref r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn, null); NUnit.Framework.Assert.IsTrue(rs.MatchSource(r)); NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r)); NUnit.Framework.Assert.AreSame(rs, rs.ExpandFromSource(r)); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn + "-and-more", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); }
public virtual void TestFetch() { // create other repository Repository db2 = CreateWorkRepository(); Git git2 = new Git(db2); // setup the first repository to fetch from the second repository StoredConfig config = ((FileBasedConfig)db.GetConfig()); RemoteConfig remoteConfig = new RemoteConfig(config, "test"); URIish uri = new URIish(db2.Directory.ToURI().ToURL()); remoteConfig.AddURI(uri); remoteConfig.Update(config); config.Save(); // create some refs via commits and tag RevCommit commit = git2.Commit().SetMessage("initial commit").Call(); RevTag tag = git2.Tag().SetName("tag").Call(); Git git1 = new Git(db); RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x"); git1.Fetch().SetRemote("test").SetRefSpecs(spec).Call(); NUnit.Framework.Assert.AreEqual(commit.Id, db.Resolve(commit.Id.GetName() + "^{commit}" )); NUnit.Framework.Assert.AreEqual(tag.Id, db.Resolve(tag.Id.GetName())); }
/// <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); }
public static bool fetch(this API_NGit nGit, string remote, string fromBranch, string toBranch) { if (nGit.git().notNull()) { try { nGit.Last_FetchResult = null; nGit.Last_Exception = null; var fetchCommand = nGit.git().Fetch(); fetchCommand.SetRemote(remote); var spec = new RefSpec("refs/heads/{0}:refs/heads/{1}".format(fromBranch, toBranch)); fetchCommand.SetRefSpecs(spec); nGit.Last_FetchResult = fetchCommand.Call(); return true; } catch (Exception ex) { nGit.Last_Exception = ex; ex.log("[API_NGit][fetch]"); } } return false; }
/// <exception cref="System.IO.IOException"></exception> internal TrackingRefUpdate(Repository db, RefSpec spec, AnyObjectId nv, string msg ) : this(db, spec.GetDestination(), spec.GetSource(), spec.IsForceUpdate(), nv, msg) { }
public virtual void TestSetSource() { RefSpec a = new RefSpec(); RefSpec b = a.SetSource("refs/heads/master"); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.AreEqual("HEAD", a.ToString()); NUnit.Framework.Assert.AreEqual("refs/heads/master", b.ToString()); }
public void Fetch(Git git, BusyIndicatorProgressMonitor monitor) { FetchCommand command = git.Fetch(); RefSpec spec = new RefSpec("refs/heads/master:refs/heads/FETCH_HEAD"); command.SetRefSpecs(spec); command.SetProgressMonitor(monitor); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, evt) => { monitor.StartAction(); try { command.Call(); } catch (JGitInternalException) { // TODO: } }; bw.RunWorkerCompleted += (s, evt) => { monitor.CompleteAction(); }; bw.RunWorkerAsync(); }
/// <summary> /// フェッチ /// </summary> /// <param name="git"></param> /// <param name="privateKeyData"></param> /// <param name="publicKeyData"></param> /// <param name="monitor"></param> public void Fetch(Git git, CloneEntity entity, string privateKeyData, string publicKeyData, BusyIndicatorProgressMonitor monitor) { var customConfigSessionFactory = new CustomConfigSessionFactory(); customConfigSessionFactory.PrivateKey = privateKeyData; customConfigSessionFactory.PublicKey = publicKeyData; NGit.Transport.JschConfigSessionFactory.SetInstance(customConfigSessionFactory); UsernamePasswordCredentialsProvider creds = new UsernamePasswordCredentialsProvider(entity.UserName, entity.PassWord); FetchCommand command = git.Fetch(); RefSpec spec = new RefSpec("refs/heads/master:refs/heads/FETCH_HEAD"); command.SetRemoveDeletedRefs(true); command.SetRefSpecs(spec); command.SetProgressMonitor(monitor); command.SetCredentialsProvider(creds); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, evt) => { monitor.StartAction(); try { command.Call(); } catch (JGitInternalException) { // TODO: } }; bw.RunWorkerCompleted += (s, evt) => { monitor.CompleteAction(); }; bw.RunWorkerAsync(); }
public virtual void TestTrackingUpdate() { Repository db2 = CreateBareRepository(); string remote = "origin"; string branch = "refs/heads/master"; string trackingBranch = "refs/remotes/" + remote + "/master"; Git git = new Git(db); RevCommit commit1 = git.Commit().SetMessage("Initial commit").Call(); RefUpdate branchRefUpdate = db.UpdateRef(branch); branchRefUpdate.SetNewObjectId(commit1.Id); branchRefUpdate.Update(); RefUpdate trackingBranchRefUpdate = db.UpdateRef(trackingBranch); trackingBranchRefUpdate.SetNewObjectId(commit1.Id); trackingBranchRefUpdate.Update(); StoredConfig config = ((FileBasedConfig)db.GetConfig()); RemoteConfig remoteConfig = new RemoteConfig(config, remote); URIish uri = new URIish(db2.Directory.ToURI().ToURL()); remoteConfig.AddURI(uri); remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remote + "/*")); remoteConfig.Update(config); config.Save(); RevCommit commit2 = git.Commit().SetMessage("Commit to push").Call(); RefSpec spec = new RefSpec(branch + ":" + branch); Iterable<PushResult> resultIterable = git.Push().SetRemote(remote).SetRefSpecs(spec ).Call(); PushResult result = resultIterable.Iterator().Next(); TrackingRefUpdate trackingRefUpdate = result.GetTrackingRefUpdate(trackingBranch); NUnit.Framework.Assert.IsNotNull(trackingRefUpdate); NUnit.Framework.Assert.AreEqual(trackingBranch, trackingRefUpdate.GetLocalName()); NUnit.Framework.Assert.AreEqual(branch, trackingRefUpdate.GetRemoteName()); NUnit.Framework.Assert.AreEqual(commit2.Id, trackingRefUpdate.GetNewObjectId()); NUnit.Framework.Assert.AreEqual(commit2.Id, db.Resolve(trackingBranch)); NUnit.Framework.Assert.AreEqual(commit2.Id, db2.Resolve(branch)); }
/// <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); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ExpandWildcard(RefSpec spec, ICollection<Ref> matched) { foreach (Ref src in conn.GetRefs()) { if (spec.MatchSource(src) && matched.AddItem(src)) { Want(src, spec.ExpandFromSource(src)); } } }
/// <summary>Add a new push RefSpec to this remote.</summary> /// <remarks>Add a new push RefSpec to this remote.</remarks> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public virtual bool AddPushRefSpec(RefSpec s) { if (push.Contains(s)) { return false; } return push.AddItem(s); }
/// <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.IO.IOException"></exception> private TrackingRefUpdate CreateUpdate(RefSpec spec, ObjectId newId) { return new TrackingRefUpdate(transport.local, spec, newId, "fetch"); }
/// <summary>Remove a push RefSpec from this remote.</summary> /// <remarks>Remove a push RefSpec from this remote.</remarks> /// <param name="s">the specification to remove.</param> /// <returns>true if the specification existed and was removed.</returns> public virtual bool RemovePushRefSpec(RefSpec s) { return(push.Remove(s)); }
/// <summary>Remove a fetch RefSpec from this remote.</summary> /// <remarks>Remove a fetch RefSpec from this remote.</remarks> /// <param name="s">the specification to remove.</param> /// <returns>true if the specification existed and was removed.</returns> public virtual bool RemoveFetchRefSpec(RefSpec s) { return(fetch.Remove(s)); }
/// <summary>Remove a fetch RefSpec from this remote.</summary> /// <remarks>Remove a fetch RefSpec from this remote.</remarks> /// <param name="s">the specification to remove.</param> /// <returns>true if the specification existed and was removed.</returns> public virtual bool RemoveFetchRefSpec(RefSpec s) { return fetch.Remove(s); }
/// <summary>Add a new fetch RefSpec to this remote.</summary> /// <remarks>Add a new fetch RefSpec to this remote.</remarks> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public virtual bool AddFetchRefSpec(RefSpec s) { if (fetch.Contains(s)) { return false; } return fetch.AddItem(s); }
public virtual void TestFindRemoteRefUpdatesTwoRefSpecs() { transport = NGit.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"); ICollection<RefSpec> specs = Arrays.AsList(specA, specC); ICollection<RemoteRefUpdate> result = transport.FindRemoteRefUpdatesFor(specs); NUnit.Framework.Assert.AreEqual(2, result.Count); bool foundA = false; bool foundC = false; foreach (RemoteRefUpdate rru in result) { if ("refs/heads/a".Equals(rru.GetSrcRef()) && "refs/heads/b".Equals(rru.GetRemoteName ())) { foundA = true; } if ("refs/heads/c".Equals(rru.GetSrcRef()) && "refs/heads/d".Equals(rru.GetRemoteName ())) { foundC = true; } } NUnit.Framework.Assert.IsTrue(foundA); NUnit.Framework.Assert.IsTrue(foundC); }
/// <exception cref="System.IO.IOException"></exception> private TrackingRefUpdate CreateUpdate(RefSpec spec, ObjectId newId) { return(new TrackingRefUpdate(transport.local, spec, newId, "fetch")); }
public static FileRepository Init (string targetLocalPath, string url, IProgressMonitor monitor) { InitCommand ci = new InitCommand (); ci.SetDirectory (targetLocalPath); var git = ci.Call (); FileRepository repo = (FileRepository) git.GetRepository (); string branch = Constants.R_HEADS + "master"; RefUpdate head = repo.UpdateRef (Constants.HEAD); head.DisableRefLog (); head.Link (branch); RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), "origin"); remoteConfig.AddURI (new URIish (url)); string dst = Constants.R_REMOTES + remoteConfig.Name; RefSpec wcrs = new RefSpec(); wcrs = wcrs.SetForceUpdate (true); wcrs = wcrs.SetSourceDestination (Constants.R_HEADS + "*", dst + "/*"); remoteConfig.AddFetchRefSpec (wcrs); // we're setting up for a clone with a checkout repo.GetConfig().SetBoolean ("core", null, "bare", false); remoteConfig.Update (repo.GetConfig()); repo.GetConfig().Save(); return repo; }
public virtual void TestForceRemotesOrigin() { string srcn = "refs/heads/*"; string dstn = "refs/remotes/origin/*"; RefSpec rs = new RefSpec("+" + srcn + ":" + dstn); NUnit.Framework.Assert.IsTrue(rs.IsForceUpdate()); NUnit.Framework.Assert.IsTrue(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual(srcn, rs.GetSource()); NUnit.Framework.Assert.AreEqual(dstn, rs.GetDestination()); NUnit.Framework.Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString()); NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString())); Ref r; RefSpec expanded; r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", null); NUnit.Framework.Assert.IsTrue(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); expanded = rs.ExpandFromSource(r); NUnit.Framework.Assert.AreNotSame(rs, expanded); NUnit.Framework.Assert.IsTrue(expanded.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(expanded.IsWildcard()); NUnit.Framework.Assert.AreEqual(r.GetName(), expanded.GetSource()); NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", expanded.GetDestination ()); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/remotes/origin/next", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r)); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/tags/v1.0", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); }
public virtual void TestCheckoutRemoteTrackingWithoutLocalBranch() { // create second repository Repository db2 = CreateWorkRepository(); Git git2 = new Git(db2); // setup the second repository to fetch from the first repository StoredConfig config = db2.GetConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); URIish uri = new URIish(db.Directory.ToURI().ToURL()); remoteConfig.AddURI(uri); remoteConfig.Update(config); config.Save(); // fetch from first repository RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); git2.Fetch().SetRemote("origin").SetRefSpecs(spec).Call(); // checkout remote tracking branch in second repository // (no local branches exist yet in second repository) git2.Checkout().SetName("remotes/origin/test").Call(); NUnit.Framework.Assert.AreEqual("[Test.txt, mode:100644, content:Some change]", IndexState (db2, CONTENT)); }
public virtual void TestSetDestination_SourceNull() { RefSpec a = new RefSpec(); RefSpec b; b = a.SetDestination("refs/heads/master"); b = b.SetSource(null); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.AreEqual("HEAD", a.ToString()); NUnit.Framework.Assert.AreEqual(":refs/heads/master", b.ToString()); }
public static FileRepository Clone (string targetLocalPath, string url, IProgressMonitor monitor) { // Initialize InitCommand ci = new InitCommand (); ci.SetDirectory (targetLocalPath); var git = ci.Call (); FileRepository repo = (FileRepository) git.GetRepository (); string branch = Constants.R_HEADS + "master"; string remoteName = "origin"; RefUpdate head = repo.UpdateRef (Constants.HEAD); head.DisableRefLog (); head.Link (branch); RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), remoteName); remoteConfig.AddURI (new URIish (url)); string dst = Constants.R_REMOTES + remoteConfig.Name; RefSpec wcrs = new RefSpec(); wcrs = wcrs.SetForceUpdate (true); wcrs = wcrs.SetSourceDestination (Constants.R_HEADS + "*", dst + "/*"); remoteConfig.AddFetchRefSpec (wcrs); // we're setting up for a clone with a checkout repo.GetConfig().SetBoolean ("core", null, "bare", false); remoteConfig.Update (repo.GetConfig()); repo.GetConfig().Save(); // Fetch Transport tn = Transport.Open (repo, remoteName); FetchResult r; try { r = tn.Fetch(new GitMonitor (monitor), null); } finally { tn.Close (); } // Create the master branch // branch is like 'Constants.R_HEADS + branchName', we need only // the 'branchName' part String branchName = branch.Substring (Constants.R_HEADS.Length); git.BranchCreate ().SetName (branchName).SetUpstreamMode (CreateBranchCommand.SetupUpstreamMode.TRACK).SetStartPoint ("origin/master").Call (); // Checkout DirCache dc = repo.LockDirCache (); try { RevWalk rw = new RevWalk (repo); ObjectId remCommitId = repo.Resolve (remoteName + "/" + branchName); RevCommit remCommit = rw.ParseCommit (remCommitId); DirCacheCheckout co = new DirCacheCheckout (repo, null, dc, remCommit.Tree); co.Checkout (); } catch { dc.Unlock (); throw; } return repo; }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ExpandSingle(RefSpec spec, ICollection<Ref> matched) { Ref src = conn.GetRef(spec.GetSource()); if (src == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().remoteDoesNotHaveSpec , spec.GetSource())); } if (matched.AddItem(src)) { Want(src, spec); } }
/// <summary>Remove a push RefSpec from this remote.</summary> /// <remarks>Remove a push RefSpec from this remote.</remarks> /// <param name="s">the specification to remove.</param> /// <returns>true if the specification existed and was removed.</returns> public virtual bool RemovePushRefSpec(RefSpec s) { return push.Remove(s); }