public void testLeaf() { global::GitSharp.Core.Ref a; SymbolicRef b, c, d; a = new PeeledTag(Storage.Packed, targetName, ID_A, ID_B); b = new SymbolicRef("B", a); c = new SymbolicRef("C", b); d = new SymbolicRef("D", c); Assert.AreSame(c, d.getTarget()); Assert.AreSame(b, c.getTarget()); Assert.AreSame(a, b.getTarget()); Assert.AreSame(a, d.getLeaf()); Assert.AreSame(a, c.getLeaf()); Assert.AreSame(a, b.getLeaf()); Assert.AreSame(a, a.getLeaf()); Assert.AreSame(ID_A, d.getObjectId()); Assert.AreSame(ID_A, c.getObjectId()); Assert.AreSame(ID_A, b.getObjectId()); Assert.IsTrue(d.isPeeled()); Assert.IsTrue(c.isPeeled()); Assert.IsTrue(b.isPeeled()); Assert.AreSame(ID_B, d.getPeeledObjectId()); Assert.AreSame(ID_B, c.getPeeledObjectId()); Assert.AreSame(ID_B, b.getPeeledObjectId()); }
public void testConstructor() { global::GitSharp.Core.Ref t; SymbolicRef r; t = new Unpeeled(Storage.New, targetName, null); r = new SymbolicRef(name, t); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.IsNull(r.getObjectId(), "no id on new ref"); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(t, r.getLeaf(), "leaf is t"); Assert.AreSame(t, r.getTarget(), "target is t"); Assert.IsTrue(r.isSymbolic(), "is symbolic"); t = new Unpeeled(Storage.Packed, targetName, ID_A); r = new SymbolicRef(name, t); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.AreSame(ID_A, r.getObjectId()); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(t, r.getLeaf(), "leaf is t"); Assert.AreSame(t, r.getTarget(), "target is t"); Assert.IsTrue(r.isSymbolic(), "is symbolic"); }
public virtual void TestIntoSymbolicRefHeadPointingToMaster() { Ref a = db.GetRef("refs/heads/a"); Ref master = db.GetRef("refs/heads/master"); SymbolicRef head = new SymbolicRef("HEAD", master); string message = formatter.Format(Arrays.AsList(a), head); NUnit.Framework.Assert.AreEqual("Merge branch 'a'", message); }
public virtual void TestIntoHeadOtherThanMaster() { Ref a = db.GetRef("refs/heads/a"); Ref b = db.GetRef("refs/heads/b"); SymbolicRef head = new SymbolicRef("HEAD", b); string message = formatter.Format(Arrays.AsList(a), head); NUnit.Framework.Assert.AreEqual("Merge branch 'a' into b", message); }
/// <exception cref="NGit.Errors.TransportException"></exception> private Ref ReadRef(SortedDictionary <string, Ref> avail, string rn) { string s; string @ref = WalkRemoteObjectDatabase.ROOT_DIR + rn; try { BufferedReader br = this.OpenReader(@ref); try { s = br.ReadLine(); } finally { br.Close(); } } catch (FileNotFoundException) { return(null); } catch (IOException err) { throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionReadRef , @ref), err); } if (s == null) { throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionEmptyRef , rn)); } if (s.StartsWith("ref: ")) { string target = Sharpen.Runtime.Substring(s, "ref: ".Length); Ref r = avail.Get(target); if (r == null) { r = this.ReadRef(avail, target); } if (r == null) { r = new ObjectIdRef.Unpeeled(RefStorage.NEW, target, null); } r = new SymbolicRef(rn, r); avail.Put(r.GetName(), r); return(r); } if (ObjectId.IsId(s)) { Ref r = new ObjectIdRef.Unpeeled(this.Loose(avail.Get(rn)), rn, ObjectId.FromString (s)); avail.Put(r.GetName(), r); return(r); } throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionBadRef , rn, s)); }
/// <exception cref="NGit.Errors.TransportException"></exception> private Ref ReadRef(SortedDictionary <string, Ref> avail, string path, string name ) { string line; try { BufferedReader br = this.OpenReader(path); try { line = br.ReadLine(); } finally { br.Close(); } } catch (FileNotFoundException) { return(null); } catch (IOException err) { throw new TransportException("Cannot read " + this.objectsPath + "/" + path + ": " + err.Message, err); } if (line == null) { throw new TransportException("Empty ref: " + name); } if (line.StartsWith("ref: ")) { string target = Sharpen.Runtime.Substring(line, "ref: ".Length); Ref r = avail.Get(target); if (r == null) { r = this.ReadRef(avail, WalkRemoteObjectDatabase.ROOT_DIR + target, target); } if (r == null) { r = new ObjectIdRef.Unpeeled(RefStorage.NEW, target, null); } r = new SymbolicRef(name, r); avail.Put(r.GetName(), r); return(r); } if (ObjectId.IsId(line)) { Ref r = new ObjectIdRef.Unpeeled(this.Loose(avail.Get(name)), name, ObjectId.FromString (line)); avail.Put(r.GetName(), r); return(r); } throw new TransportException("Bad ref: " + name + ": " + line); }
private Ref ReadRef(IDictionary <string, Ref> avail, string path, string name) { string line; try { using (StreamReader br = openReader(path)) { line = br.ReadLine(); } } catch (FileNotFoundException) { return(null); } catch (IOException err) { throw new TransportException("Cannot Read " + _objectsPath + "/" + path + ": " + err.Message, err); } if (line == null) { throw new TransportException("Empty ref: " + name); } if (line.StartsWith("ref: ")) { string target = line.Substring("ref: ".Length); Ref r = avail.GetValue(target); if (r == null) { r = ReadRef(avail, ROOT_DIR + target, target); } if (r == null) { r = new Unpeeled(Storage.New, target, null); } r = new SymbolicRef(name, r); avail.put(r.getName(), r); return(r); } if (ObjectId.IsId(line)) { Ref r = new Unpeeled(Loose(avail.GetValue(name)), name, ObjectId.FromString(line)); avail.put(r.getName(), r); return(r); } throw new TransportException("Bad ref: " + name + ": " + line); }
public void testToString() { global::GitSharp.Core.Ref a; SymbolicRef b, c, d; a = new PeeledTag(Storage.Packed, targetName, ID_A, ID_B); b = new SymbolicRef("B", a); c = new SymbolicRef("C", b); d = new SymbolicRef("D", c); Assert.AreEqual("SymbolicRef[D -> C -> B -> " + targetName + "=" + ID_A.Name + "]", d.ToString()); }
private Ref ReadRef(IDictionary<string, Ref> avail, string path, string name) { string line; try { using (StreamReader br = openReader(path)) { line = br.ReadLine(); } } catch (FileNotFoundException) { return null; } catch (IOException err) { throw new TransportException("Cannot Read " + _objectsPath + "/" + path + ": " + err.Message, err); } if (line == null) throw new TransportException("Empty ref: " + name); if (line.StartsWith("ref: ")) { string target = line.Substring("ref: ".Length); Ref r = avail.GetValue(target); if (r == null) r = ReadRef(avail, ROOT_DIR + target, target); if (r == null) r = new Unpeeled(Storage.New, target, null); r = new SymbolicRef(name, r); avail.put(r.getName(), r); return r; } if (ObjectId.IsId(line)) { Ref r = new Unpeeled(Loose(avail.GetValue(name)), name, ObjectId.FromString(line)); avail.put(r.getName(), r); return r; } throw new TransportException("Bad ref: " + name + ": " + line); }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="NGit.Errors.PackProtocolException"></exception> private FetchConnection NewDumbConnection(InputStream @in) { TransportHttp.HttpObjectDB d = new TransportHttp.HttpObjectDB(this, objectsUrl); BufferedReader br = ToBufferedReader(@in); IDictionary <string, Ref> refs; try { refs = d.ReadAdvertisedImpl(br); } finally { br.Close(); } if (!refs.ContainsKey(Constants.HEAD)) { // If HEAD was not published in the info/refs file (it usually // is not there) download HEAD by itself as a loose file and do // the resolution by hand. // HttpURLConnection conn = HttpOpen(new Uri(baseUrl, Constants.HEAD)); int status = HttpSupport.Response(conn); switch (status) { case HttpURLConnection.HTTP_OK: { br = ToBufferedReader(OpenInputStream(conn)); try { string line = br.ReadLine(); if (line != null && line.StartsWith(RefDirectory.SYMREF)) { string target = Sharpen.Runtime.Substring(line, RefDirectory.SYMREF.Length); Ref r = refs.Get(target); if (r == null) { r = new ObjectIdRef.Unpeeled(RefStorage.NEW, target, null); } r = new SymbolicRef(Constants.HEAD, r); refs.Put(r.GetName(), r); } else { if (line != null && ObjectId.IsId(line)) { Ref r = new ObjectIdRef.Unpeeled(RefStorage.NETWORK, Constants.HEAD, ObjectId.FromString (line)); refs.Put(r.GetName(), r); } } } finally { br.Close(); } break; } case HttpURLConnection.HTTP_NOT_FOUND: { break; } default: { throw new TransportException(uri, MessageFormat.Format(JGitText.Get().cannotReadHEAD , status, conn.GetResponseMessage())); } } } WalkFetchConnection wfc = new WalkFetchConnection(this, d); wfc.Available(refs); return(wfc); }