public void OneCommitWithSubTreeTest() { Init(); CreateFile("a.txt", "a content"); Directory.CreateDirectory("dir"); CreateFile("dir/b.txt", "b content"); Program.Main(new string[] { "add", "a.txt", "dir/b.txt" }); Program.Main(new string[] { "commit", "First commit" }); RelativePath bFilePath = new RelativePath("dir/b.txt"); Assert.True(Index.IsCommited(bFilePath)); Branch headBranch = ReferenceDatabase.GetHead(); Commit commit = headBranch.LoadCommit(); Tree tree = commit.LoadTree(); Blob blobA = tree.FindAndLoadBlob("a.txt"); Blob blobB = tree.FindAndLoadBlob("dir/b.txt"); Assert.Equal(blobA.FileName, "a.txt"); Assert.Equal(blobA.FileContent, "a content"); Assert.Equal(blobB.FileName, "b.txt"); Assert.Equal(blobB.FilePath, "dir/b.txt"); Assert.Equal(blobB.FileContent, "b content"); }
private void StoreCommitAndAdvanceHeadBranch(Commit commit, TreeBuilder treeBuilder) { Branch currentBranch = ReferenceDatabase.GetHead(); HashKey newCommitKey = ObjectDatabase.StoreCommitWithTreeHierarchy(commit, treeBuilder); currentBranch.SetCommitKey(newCommitKey); }
public void CommitInNewBranch() { Init(); CreateFile("z.txt", ""); Program.Main(new string[] { "add", "z.txt" }); Program.Main(new string[] { "commit", "Initial commit" }); Program.Main(new string[] { "branch", "branch-1" }); Program.Main(new string[] { "checkout", "branch-1" }); // Create a commit in branch-1 CreateFile("a.txt", "branch-1 content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "branch-1 commit" }); Assert.Equal( ReferenceDatabase.GetHead().GetCommitKey(), ReferenceDatabase.GetBranch("branch-1").GetCommitKey() ); Assert.Equal( ReferenceDatabase.GetBranch("branch-1").LoadCommit().Message.Trim(), "branch-1 commit" ); }
public void TreeContainsAllBlobsTest() { Init(); CreateFile("a.txt", "a content"); CreateFile("b.txt", "b content"); Program.Main(new string[] { "add", "a.txt", "b.txt" }); Program.Main(new string[] { "commit", "First commit" }); CreateFile("b.txt", "b modified content"); Program.Main(new string[] { "add", "b.txt" }); Program.Main(new string[] { "commit", "Second commit" }); RelativePath aFilePath = new RelativePath("a.txt"); Assert.True(Index.IsCommited(aFilePath)); Branch headBranch = ReferenceDatabase.GetHead(); Commit commit = headBranch.LoadCommit(); Tree tree = commit.LoadTree(); Blob blobA = tree.FindAndLoadBlob("a.txt"); Blob blobB = tree.FindAndLoadBlob("b.txt"); Assert.Equal(blobA.FileName, "a.txt"); Assert.Equal(blobA.FileContent, "a content"); Assert.Equal(blobB.FileName, "b.txt"); Assert.Equal(blobB.FileContent, "b modified content"); }
public void SecondCommitSubTreePointsToFirstCommitSubTree() { Init(); CreateFile("a.txt", "a content"); Directory.CreateDirectory("dir"); CreateFile("dir/b.txt", "b content"); Program.Main(new string[] { "add", "a.txt", "dir/b.txt" }); Program.Main(new string[] { "commit", "First commit" }); CreateFile("a.txt", "a modified content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "Second commit" }); RelativePath aFilePath = new RelativePath("a.txt"); Assert.True(Index.IsCommited(aFilePath)); Branch headBranch = ReferenceDatabase.GetHead(); Commit secondCommit = headBranch.LoadCommit(); Tree secondTree = secondCommit.LoadTree(); Blob secondBlobB = secondTree.FindAndLoadBlob("dir/b.txt"); Commit firstCommit = secondCommit.LoadParent(); Tree firstTree = firstCommit.LoadTree(); Blob firstBlobB = firstTree.FindAndLoadBlob("dir/b.txt"); Assert.Equal(firstBlobB, secondBlobB); }
public override void Process() { Branch headBranch = ReferenceDatabase.GetHead(); for (Commit commit = headBranch.LoadCommit(); commit != null; commit = commit.LoadParent()) { PrintCommit(commit); } }
private Commit CreateCommit(TreeBuilder treeBuilder) { Commit commit = new Commit( parentKey: ReferenceDatabase.GetHead().GetCommitKey(), treeKey: treeBuilder.GetChecksum(), message: _message ); return(commit); }
public override void Process() { if (!ProcessArgs()) { return; } HashKey currentCommitKey = ReferenceDatabase.GetHead().GetCommitKey(); ReferenceDatabase.CreateBranch(_branchName, currentCommitKey); PrintSuccess(); }
public void CreateOneBranchAfterCommitTest() { Init(); CreateFile("a.txt", "a content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "First commit" }); Program.Main(new string[] { "branch", "new-branch" }); Branch headBranch = ReferenceDatabase.GetHead(); Assert.Equal(headBranch.Name, "master"); Branch newBranch = ReferenceDatabase.GetBranch("new-branch"); Assert.Equal(headBranch.GetCommitKey(), newBranch.GetCommitKey()); }
public void DoCommitCommandAndIntrospectFromBranch() { Init(); CreateFile("a.txt", "a content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "Commit message" }); RelativePath aFilePath = new RelativePath("a.txt"); Assert.True(Index.IsCommited(aFilePath)); Branch headBranch = ReferenceDatabase.GetHead(); Commit commit = headBranch.LoadCommit(); Tree tree = commit.LoadTree(); Blob blobA = tree.FindAndLoadBlob("a.txt"); Assert.Equal(blobA.FileName, "a.txt"); Assert.Equal(blobA.FileContent, "a content"); }
public void TwoCommitsCheckoutToLastBranchTest() { Init(); CreateFile("a.txt", "a content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "First commit" }); Program.Main(new string[] { "branch", "branch-1" }); CreateFile("a.txt", "modified content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "Second commit" }); Program.Main(new string[] { "branch", "branch-2" }); Program.Main(new string[] { "checkout", "branch-2" }); Tree headTree = ReferenceDatabase.GetHead().LoadCommit().LoadTree(); Blob aFileBlob = headTree.FindAndLoadBlob("a.txt"); Assert.Equal(aFileBlob.FileContent, "modified content"); }
public void CommitRemovedFile() { Init(); CreateFile("a.txt", "a content"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "First commit" }); System.IO.File.Delete("a.txt"); Program.Main(new string[] { "add", "a.txt" }); Program.Main(new string[] { "commit", "Second commit" }); RelativePath aFilePath = new RelativePath("a.txt"); Assert.False(Index.ContainsFile(aFilePath)); Branch headBranch = ReferenceDatabase.GetHead(); Commit commit = headBranch.LoadCommit(); Tree tree = commit.LoadTree(); Assert.Null(tree.FindAndLoadBlob("a.txt")); }
private void PrintCurrentBranch() { Console.WriteLine($"On branch {ReferenceDatabase.GetHead().Name}"); }
/// Returns true if this Commit is in the HEAD. private bool IsHeadCommit() { HashKey headCommitKey = ReferenceDatabase.GetHead().GetCommitKey(); return(headCommitKey.Equals(_checksum)); }