public void testSimple() { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" + "fetch = +refs/heads/*:refs/remotes/spearce/*\n"); RemoteConfig rc = new RemoteConfig(config, "spearce"); System.Collections.Generic.List<URIish> allURIs = rc.URIs; Assert.AreEqual("spearce", rc.Name); Assert.IsNotNull(allURIs); Assert.IsNotNull(rc.Fetch); Assert.IsNotNull(rc.Push); Assert.IsNotNull(rc.TagOpt); Assert.AreEqual(0, rc.Timeout); Assert.AreSame(TagOpt.AUTO_FOLLOW, rc.TagOpt); Assert.AreEqual(1, allURIs.Count); Assert.AreEqual("http://www.spearce.org/egit.git", allURIs[0].ToString()); Assert.AreEqual(1, rc.Fetch.Count); RefSpec spec = rc.Fetch[0]; Assert.IsTrue(spec.Force); Assert.IsTrue(spec.Wildcard); Assert.AreEqual("refs/heads/*", spec.Source); Assert.AreEqual("refs/remotes/spearce/*", spec.Destination); Assert.AreEqual(0, rc.Push.Count); }
public void ApplyConfig(RemoteConfig cfg) { OptionUploadPack = cfg.UploadPack; _fetchSpecs = cfg.Fetch; TagOpt = cfg.TagOpt; OptionReceivePack = cfg.ReceivePack; _pushSpecs = cfg.Push; }
public override void setUp() { base.setUp(); RepositoryConfig config = db.Config; remoteConfig = new RemoteConfig(config, "test"); remoteConfig.AddURI(new URIish("http://everyones.loves.git/u/2")); transport = null; }
/// <summary> /// Open a new transport instance to connect two repositories. /// </summary> /// <param name="local">existing local repository.</param> /// <param name="remote">location of the remote repository - may be URI or remote configuration name.</param> /// <param name="op"> /// planned use of the returned Transport; the URI may differ /// based on the type of connection desired. /// </param> /// <returns> /// the new transport instance. Never null. In case of multiple URIs /// in remote configuration, only the first is chosen. /// </returns> public static Transport open(Repository local, string remote, Operation op) { var cfg = new RemoteConfig(local.Config, remote); if (doesNotExist(cfg)) { return(open(local, new URIish(remote))); } return(open(local, cfg, op)); }
public static Transport Open(Repository local, string remote) { var cfg = new RemoteConfig(local.Config, remote); List <URIish> uris = cfg.URIs; if (uris.Count == 0) { return(Open(local, new URIish(remote))); } return(Open(local, cfg)); }
/// <summary> /// Support for Transport over HTTP and Git (Anon+SSH) /// </summary> /// <param name="local"></param> /// <param name="cfg"></param> /// <returns></returns> public static Transport Open(Repository local, RemoteConfig cfg) { if (cfg.URIs.Count == 0) { throw new ArgumentException("Remote config \"" + cfg.Name + "\" has no URIs associated"); } Transport tn = Open(local, cfg.URIs[0]); tn.ApplyConfig(cfg); return(tn); }
/// <summary> /// Apply provided remote configuration on this transport. /// </summary> /// <param name="cfg">configuration to apply on this transport.</param> public void ApplyConfig(RemoteConfig cfg) { if (cfg == null) { throw new ArgumentNullException("cfg"); } OptionUploadPack = cfg.UploadPack; OptionReceivePack = cfg.ReceivePack; TagOpt = cfg.TagOpt; _fetch = cfg.Fetch; _push = cfg.Push; _timeout = cfg.Timeout; }
public static List <Transport> openAll(Repository local, RemoteConfig cfg) { List <URIish> uris = cfg.URIs; var tranports = new List <Transport>(uris.Count); foreach (URIish uri in uris) { Transport tn = Open(local, uri); tn.ApplyConfig(cfg); tranports.Add(tn); } return(tranports); }
/// <summary> /// Open new transport instances to connect two repositories. /// </summary> /// <param name="local">existing local repository.</param> /// <param name="remote"> /// location of the remote repository - may be URI or remote /// configuration name. /// </param> /// <param name="op"> /// planned use of the returned Transport; the URI may differ /// based on the type of connection desired. /// </param> /// <returns> /// the list of new transport instances for every URI in remote /// configuration. /// </returns> public static List <Transport> openAll(Repository local, string remote, Operation op) { var cfg = new RemoteConfig(local.Config, remote); if (doesNotExist(cfg)) { var transports = new List <Transport>(1); transports.Add(open(local, new URIish(remote))); return(transports); } return(openAll(local, cfg, op)); }
public void testAddURI() { readConfig(string.Empty); URIish uri = new URIish("/some/dir"); RemoteConfig rc = new RemoteConfig(config, "backup"); Assert.AreEqual(0, rc.URIs.Count); Assert.IsTrue(rc.AddURI(uri)); Assert.AreEqual(1, rc.URIs.Count); Assert.AreSame(uri, rc.URIs[0]); Assert.IsFalse(rc.AddURI(new URIish(uri.ToString()))); Assert.AreEqual(1, rc.URIs.Count); }
/// <summary> /// Open a new transport instance to connect two repositories. /// </summary> /// <param name="local">existing local repository.</param> /// <param name="cfg"> /// configuration describing how to connect to the remote /// repository. /// </param> /// <param name="op"> /// planned use of the returned Transport; the URI may differ /// based on the type of connection desired. /// </param> /// <returns></returns> public static Transport open(Repository local, RemoteConfig cfg, Operation op) { List <URIish> uris = getURIs(cfg, op); if (uris.isEmpty()) { throw new ArgumentException( "Remote config \"" + cfg.Name + "\" has no URIs associated"); } Transport tn = open(local, uris[0]); tn.ApplyConfig(cfg); return(tn); }
public static List <Transport> openAll(Repository local, string remote) { var cfg = new RemoteConfig(local.Config, remote); List <URIish> uris = cfg.URIs; if (uris.isEmpty()) { var transports = new List <Transport>(1) { Open(local, new URIish(remote)) }; return(transports); } return(openAll(local, cfg)); }
private static List <URIish> getURIs(RemoteConfig cfg, Operation op) { switch (op) { case Operation.FETCH: return(cfg.URIs); case Operation.PUSH: List <URIish> uris = cfg.PushURIs; if (uris.Count == 0) { uris = cfg.URIs; } return(uris); default: throw new ArgumentException(op.ToString()); } }
public void testRemoveOnlyURI() { readConfig(string.Empty); URIish a = new URIish("/some/dir"); RemoteConfig rc = new RemoteConfig(config, "backup"); Assert.IsTrue(rc.AddURI(a)); Assert.AreEqual(1, rc.URIs.Count); Assert.AreSame(a, rc.URIs[0]); Assert.IsTrue(rc.RemoveURI(a)); Assert.AreEqual(0, rc.URIs.Count); }
public void testRemoveMiddleURI() { readConfig(string.Empty); URIish a = new URIish("/some/dir"); URIish b = new URIish("/another/dir"); URIish c = new URIish("/more/dirs"); RemoteConfig rc = new RemoteConfig(config, "backup"); Assert.IsTrue(rc.AddURI(a)); Assert.IsTrue(rc.AddURI(b)); Assert.IsTrue(rc.AddURI(c)); Assert.AreEqual(3, rc.URIs.Count); Assert.AreSame(a, rc.URIs[0]); Assert.AreSame(b, rc.URIs[1]); Assert.AreEqual(c, rc.URIs[2]); Assert.IsTrue(rc.RemoveURI(b)); Assert.AreEqual(2, rc.URIs.Count); Assert.AreSame(a, rc.URIs[0]); Assert.AreSame(c, rc.URIs[1]); }
/// <summary> /// Open a new transport instance to connect two repositories. /// <para/> /// This method assumes <see cref="Operation.FETCH"/>. /// </summary> /// <param name="local">existing local repository.</param> /// <param name="cfg"> /// configuration describing how to connect to the remote /// repository. /// </param> /// <returns> /// the new transport instance. Never null. In case of multiple URIs /// in remote configuration, only the first is chosen. /// </returns> public static Transport open(Repository local, RemoteConfig cfg) { return(open(local, cfg, Operation.FETCH)); }
public static Transport Open(Repository local, string remote) { var cfg = new RemoteConfig(local.Config, remote); List<URIish> uris = cfg.URIs; if (uris.Count == 0) { return Open(local, new URIish(remote)); } return Open(local, cfg); }
public void testUploadPack() { readConfig("[remote \"example\"]\n" + "url = [email protected]:egit.git\n" + "fetch = +refs/heads/*:refs/remotes/example/*\n" + "uploadpack = /path/to/git/git-upload-pack\n" + "receivepack = /path/to/git/git-receive-pack\n"); RemoteConfig rc = new RemoteConfig(config, "example"); System.Collections.Generic.List<URIish> allURIs = rc.URIs; Assert.AreEqual("example", rc.Name); Assert.IsNotNull(allURIs); Assert.IsNotNull(rc.Fetch); Assert.IsNotNull(rc.Push); Assert.AreEqual(1, allURIs.Count); Assert.AreEqual("[email protected]:egit.git", allURIs[0].ToString()); Assert.AreEqual(1, rc.Fetch.Count); RefSpec spec = rc.Fetch[0]; Assert.IsTrue(spec.Force); Assert.IsTrue(spec.Wildcard); Assert.AreEqual("refs/heads/*", spec.Source); Assert.AreEqual("refs/remotes/example/*", spec.Destination); Assert.AreEqual(0, rc.Push.Count); Assert.AreEqual("/path/to/git/git-upload-pack", rc.UploadPack); Assert.AreEqual("/path/to/git/git-receive-pack", rc.ReceivePack); }
public void testSimpleTimeout() { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" + "fetch = +refs/heads/*:refs/remotes/spearce/*\n" + "timeout = 12\n"); RemoteConfig rc = new RemoteConfig(config, "spearce"); Assert.AreEqual(12, rc.Timeout); }
public void testSaveTimeout() { RemoteConfig rc = new RemoteConfig(config, "origin"); rc.AddURI(new URIish("/some/dir")); rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*")); rc.Timeout = 60; rc.Update(config); checkConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n" + "\ttimeout = 60\n"); }
public static List<Transport> openAll(Repository local, RemoteConfig cfg) { if (cfg == null) throw new ArgumentNullException ("cfg"); List<URIish> uris = cfg.URIs; var tranports = new List<Transport>(uris.Count); foreach (URIish uri in uris) { Transport tn = Open(local, uri); tn.ApplyConfig(cfg); tranports.Add(tn); } return tranports; }
/// <summary> /// Support for Transport over HTTP and Git (Anon+SSH) /// </summary> /// <param name="local"></param> /// <param name="cfg"></param> /// <returns></returns> public static Transport Open(Repository local, RemoteConfig cfg) { if (cfg == null) throw new ArgumentNullException ("cfg"); if (cfg.URIs.Count == 0) { throw new ArgumentException("Remote config \"" + cfg.Name + "\" has no URIs associated"); } Transport tn = Open(local, cfg.URIs[0]); tn.ApplyConfig(cfg); return tn; }
public void testBackup() { readConfig("[remote \"backup\"]\n" + "url = http://www.spearce.org/egit.git\n" + "url = [email protected]:/srv/git/egit.git\n" + "push = +refs/heads/*:refs/heads/*\n" + "push = refs/tags/*:refs/tags/*\n"); RemoteConfig rc = new RemoteConfig(config, "backup"); System.Collections.Generic.List<URIish> allURIs = rc.URIs; Assert.AreEqual("backup", rc.Name); Assert.IsNotNull(allURIs); Assert.IsNotNull(rc.Fetch); Assert.IsNotNull(rc.Push); Assert.AreEqual(2, allURIs.Count); Assert.AreEqual("http://www.spearce.org/egit.git", allURIs[0].ToString()); Assert.AreEqual("[email protected]:/srv/git/egit.git", allURIs[1].ToString()); Assert.AreEqual(0, rc.Fetch.Count); Assert.AreEqual(2, rc.Push.Count); RefSpec spec = rc.Push[0]; Assert.IsTrue(spec.Force); Assert.IsTrue(spec.Wildcard); Assert.AreEqual("refs/heads/*", spec.Source); Assert.AreEqual("refs/heads/*", spec.Destination); spec = rc.Push[1]; Assert.IsFalse(spec.Force); Assert.IsTrue(spec.Wildcard); Assert.AreEqual("refs/tags/*", spec.Source); Assert.AreEqual("refs/tags/*", spec.Destination); }
/// <summary> /// Open a new transport instance to connect two repositories. /// <para/> /// This method assumes <see cref="Operation.FETCH"/>. /// </summary> /// <param name="local">existing local repository.</param> /// <param name="cfg"> /// configuration describing how to connect to the remote /// repository. /// </param> /// <returns> /// the list of new transport instances for every URI in remote /// configuration. /// </returns> public static List <Transport> openAll(Repository local, RemoteConfig cfg) { return(openAll(local, cfg, Operation.FETCH)); }
private static bool doesNotExist(RemoteConfig cfg) { return(cfg.URIs.Count == 0 && cfg.PushURIs.Count == 0); }
private static bool doesNotExist(RemoteConfig cfg) { return(cfg.URIs.isEmpty() && cfg.PushURIs.isEmpty()); }
public void testSaveNoTags() { RemoteConfig rc = new RemoteConfig(config, "origin"); rc.AddURI(new URIish("/some/dir")); rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*")); rc.SetTagOpt(TagOpt.NO_TAGS); rc.Update(config); checkConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n" + "\ttagopt = --no-tags\n"); }
private static bool doesNotExist(RemoteConfig cfg) { return cfg.URIs.Count == 0 && cfg.PushURIs.Count == 0; }
public void testSaveRemoveLastURI() { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" + "url = /some/dir\n" + "fetch = +refs/heads/*:refs/remotes/spearce/*\n"); RemoteConfig rc = new RemoteConfig(config, "spearce"); Assert.AreEqual(2, rc.URIs.Count); rc.RemoveURI(new URIish("/some/dir")); Assert.AreEqual(1, rc.URIs.Count); rc.Update(config); checkConfig("[remote \"spearce\"]\n" + "\turl = http://www.spearce.org/egit.git\n" + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n"); }
private static bool doesNotExist(RemoteConfig cfg) { return cfg.URIs.isEmpty() && cfg.PushURIs.isEmpty(); }
public void testSimpleNoTags() { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" + "fetch = +refs/heads/*:refs/remotes/spearce/*\n" + "tagopt = --no-tags\n"); RemoteConfig rc = new RemoteConfig(config, "spearce"); Assert.AreSame(TagOpt.NO_TAGS, rc.TagOpt); }
public static List<Transport> openAll(Repository local, RemoteConfig cfg) { List<URIish> uris = cfg.URIs; var tranports = new List<Transport>(uris.Count); foreach (URIish uri in uris) { Transport tn = Open(local, uri); tn.ApplyConfig(cfg); tranports.Add(tn); } return tranports; }
public void testUnknown() { readConfig(string.Empty); RemoteConfig rc = new RemoteConfig(config, "backup"); Assert.AreEqual(0, rc.URIs.Count); Assert.AreEqual(0, rc.Fetch.Count); Assert.AreEqual(0, rc.Push.Count); Assert.AreEqual("git-upload-pack", rc.UploadPack); Assert.AreEqual("git-receive-pack", rc.ReceivePack); }
private void saveRemote(URIish uri) { var repo = Repository._internal_repo; RemoteConfig rc = new RemoteConfig(repo.Config, OriginName); rc.AddURI(uri); rc.AddFetchRefSpec(new RefSpec().SetForce(true).SetSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + OriginName + "/*")); rc.Update(repo.Config); repo.Config.save(); }
public static List<Transport> openAll(Repository local, string remote) { var cfg = new RemoteConfig(local.Config, remote); List<URIish> uris = cfg.URIs; if (uris.isEmpty()) { var transports = new List<Transport>(1) { Open(local, new URIish(remote)) }; return transports; } return openAll(local, cfg); }
public void ApplyConfig(RemoteConfig cfg) { OptionUploadPack = cfg.UploadPack; _fetchSpecs = cfg.Fetch; TagOpt = cfg.TagOpt; OptionReceivePack = cfg.ReceivePack; _pushSpecs = cfg.Push; }
public static Transport Open(Repository local, string remote) { if (local == null) throw new ArgumentNullException ("local"); var cfg = new RemoteConfig(local.Config, remote); List<URIish> uris = cfg.URIs; if (uris.Count == 0) { return Open(local, new URIish(remote)); } return Open(local, cfg); }
protected override void Run () { var cloneDialog = new CloneRepositoryDialog (); cloneDialog.Run (); cloneDialog.Destroy (); var repositoryPath = cloneDialog.RepositoryPath; URIish source = new URIish (repositoryPath); var originName = cloneDialog.OriginName; var destination = cloneDialog.WorkingDirectory; var workingDirectory = Path.Combine (destination, Constants.DOT_GIT); if (string.IsNullOrEmpty (originName)) originName = Constants.DEFAULT_REMOTE_NAME; var rep = new GitSharp.Core.Repository (new DirectoryInfo (workingDirectory)); rep.Create (); rep.Config.setBoolean ("core", null, "bare", false); rep.Config.save (); var rc = new RemoteConfig (rep.Config, originName); rc.AddURI (source); rc.AddFetchRefSpec (new RefSpec ().SetForce (true).SetSourceDestination ( Constants.R_HEADS + "*", Constants.R_REMOTES + originName + "/*")); rc.Update (rep.Config); rep.Config.save (); Transport tn = Transport.open (rep, originName); FetchResult fetchResult = null; try { fetchResult = tn.fetch (new NullProgressMonitor (), null); } catch { tn.Dispose (); } GitSharp.Core.Ref branch = null; if (fetchResult != null) { var headId = fetchResult.GetAdvertisedRef (Constants.HEAD); var availableRefs = new List<GitSharp.Core.Ref> (); foreach (GitSharp.Core.Ref r in fetchResult.AdvertisedRefs) { var n = r.Name; if (!n.StartsWith (Constants.R_HEADS)) continue; availableRefs.Add (r); if (headId == null || branch != null) continue; if (r.ObjectId.Equals (headId.ObjectId)) branch = r; } availableRefs.Sort (RefComparator.INSTANCE); if (headId != null && branch == null) branch = headId; } if (branch != null) { if (!Constants.HEAD.Equals (branch.Name)) { //rep. (Constants.HEAD, branch.Name); GitSharp.Core.Commit commit = rep.MapCommit (branch.ObjectId); RefUpdate update = rep.UpdateRef (Constants.HEAD); update.NewObjectId = commit.CommitId; update.forceUpdate (); var index = new GitIndex (rep); var tree = commit.TreeEntry; WorkDirCheckout co = new WorkDirCheckout (rep, rep.WorkingDirectory, index, tree); co.checkout (); index.write (); } } else { MessageService.ShowError ("Cannot clone: no HEAD advertised by remote."); } MessageService.ShowMessage(string.Format("Finished cloning {0} to {1}", repositoryPath, destination)); }
public static List<Transport> openAll(Repository local, string remote) { if (local == null) throw new ArgumentNullException ("local"); var cfg = new RemoteConfig(local.Config, remote); List<URIish> uris = cfg.URIs; if (uris.isEmpty()) { var transports = new List<Transport>(1) { Open(local, new URIish(remote)) }; return transports; } return openAll(local, cfg); }
public void testCreateOrigin() { RemoteConfig rc = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); rc.AddURI(new URIish("/some/dir")); rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*")); rc.Update(config); checkConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"); }
public void ApplyConfig(RemoteConfig cfg) { if (cfg == null) throw new ArgumentNullException ("cfg"); OptionUploadPack = cfg.UploadPack; _fetchSpecs = cfg.Fetch; TagOpt = cfg.TagOpt; OptionReceivePack = cfg.ReceivePack; _pushSpecs = cfg.Push; }
public void testSaveAllTags() { RemoteConfig rc = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); rc.AddURI(new URIish("/some/dir")); rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*")); rc.SetTagOpt(TagOpt.FETCH_TAGS); rc.Update(config); checkConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n" + "\ttagopt = --tags\n"); }
private static List<URIish> getURIs(RemoteConfig cfg, Operation op) { switch (op) { case Operation.FETCH: return cfg.URIs; case Operation.PUSH: List<URIish> uris = cfg.PushURIs; if (uris.Count == 0) { uris = cfg.URIs; } return uris; default: throw new ArgumentException(op.ToString()); } }
/// <summary> /// Open a new transport instance to connect two repositories. /// <para/> /// This method assumes <see cref="Operation.FETCH"/>. /// </summary> /// <param name="local">existing local repository.</param> /// <param name="cfg"> /// configuration describing how to connect to the remote /// repository. /// </param> /// <returns> /// the list of new transport instances for every URI in remote /// configuration. /// </returns> public static List<Transport> openAll(Repository local, RemoteConfig cfg) { return openAll(local, cfg, Operation.FETCH); }