public void GetCommit() { Commit c = directory.GetCommit("init"); Assert.AreEqual(c.Hash, "init"); Assert.IsTrue(c.Changelog.Added.ContainsKey("file1.txt")); Assert.AreEqual(c.Version.Data.Children.Count, 2); }
/// <summary> /// Converts this object to a Commit object /// </summary> /// <param name="directory">The directory dependency for proxies</param> /// <param name="loader">The loader object which specifies which objects to load</param> /// <returns></returns> public Commit GetCommit(DirectoryStructure directory, CommitDependencyLoader loader) { Commit[] parents = new Commit[Parents.Length]; for (int i = 0; i < parents.Length; i++) { string p = Parents[i]; if (loader.LoadParents && loader.ShouldLoadParent(p)) { parents[i] = directory.GetCommit(p, loader.GetParent(p)); } else { parents[i] = new CommitProxy(p, directory); } } Changelog changelog = loader.LoadChangelog ? directory.GetChangelog(Changelog) : new ChangelogProxy(Changelog, directory); Version version = loader.LoadVersion ? directory.GetVersion(Hash, loader.LoadVersionData) : new VersionProxy(Version, directory); CommitMetadata metadata = Metadata != null?Metadata.GetMetadata() : throw new FormatException("Commit must contain metadata"); return(new Commit(parents, changelog, version, metadata, Hash)); }
public Branch GetBranch(DirectoryStructure directory) { if (TargetHash == null) { throw new FormatException("TargetHash should not be null"); } Commit target = directory.GetCommit(TargetHash); if (Metadata == null) { throw new FormatException("Metadata should not be null"); } BranchMetadata metadata = Metadata.GetMetadata(); if (Name == null) { throw new FormatException("Name should not be null"); } return(new Branch(target, metadata, Name)); }
/// <summary> /// Converts this to a Head object /// </summary> /// <param name="directory">The directory to load the dependency</param> /// <returns></returns> public Head GetHead(DirectoryStructure directory) { if (TargetType == COMMIT) { Commit commit = directory.GetCommit(TargetHash); return(new Head(commit)); } else if (TargetType == BRANCH) { Branch branch = directory.LoadBranch(TargetHash); return(new Head(branch)); } else if (TargetType == UNINITIALIZED) { return(new Head()); } else { throw new FormatException("Head must point to either a Commit or a Branch"); } }
/// <summary> /// Loads a Commit from the file directory /// </summary> /// <param name="hash">The hash of the Commit to load</param> /// <param name="loader">TODO: add CommitDependencyLoader support</param> /// <returns></returns> public Commit GetCommit(string hash) { return(directory.GetCommit(hash)); }