/// <summary> /// Adds an unparented blob to the "repo" /// </summary> public void AddBlob(string sha, string name, string contents) { MockGitObject newObj = new MockGitObject(sha, name, true); newObj.Content = contents; this.objects.Add(sha, newObj); }
/// <summary> /// Adds an unparented tree to the "repo" /// </summary> public void AddTree(string sha, string name, params string[] childShas) { MockGitObject newObj = new MockGitObject(sha, name, false); newObj.ChildShas.AddRange(childShas); this.objects.Add(sha, newObj); }
private MockGitObject GetTree(string treeSha) { this.objects.ContainsKey(treeSha).ShouldEqual(true); MockGitObject obj = this.objects[treeSha]; obj.IsBlob.ShouldEqual(false); return(obj); }
public override bool TryCopyBlobContentStream_CanTimeout(string blobSha, Action <StreamReader, long> writeAction) { if (this.objects.ContainsKey(blobSha)) { MockGitObject obj = this.objects[blobSha]; obj.IsBlob.ShouldEqual(true); using (Stream contentStream = new ReusableMemoryStream(obj.Content)) using (StreamReader reader = new StreamReader(contentStream)) { writeAction(reader, contentStream.Length); return(true); } } return(false); }
public override int ReadPrefix(byte[] shortOid, out byte[] oid, out Stream data, out GitObjectType objectType) { oid = null; data = null; objectType = GitObjectType.Bad; MockGitObject gitObjectAlreadyFound = null; foreach (MockGitObject gitObject in m_objectIdToContent.Values) { bool match = true; for (int i = 0; i < shortOid.Length; i++) { if (gitObject.ObjectId[i] != shortOid[i]) { match = false; break; } } if (!match) { continue; } if (null != gitObjectAlreadyFound) { return(GIT_EAMBIGUOUS); } gitObjectAlreadyFound = gitObject; } if (null != gitObjectAlreadyFound) { oid = gitObjectAlreadyFound.ObjectId; objectType = gitObjectAlreadyFound.ObjectType; data = Allocate(gitObjectAlreadyFound.Data.LongLength); data.Write(gitObjectAlreadyFound.Data, 0, gitObjectAlreadyFound.Data.Length); return(GIT_OK); } return(GIT_ENOTFOUND); }
/// <summary> /// Adds a child sha to an existing tree /// </summary> public void AddChildBySha(string treeSha, string childSha) { MockGitObject treeObj = this.GetTree(treeSha); treeObj.ChildShas.Add(childSha); }