示例#1
0
        public override void Process()
        {
            if (!ProcessOptions(_args))
            {
                PrintHelp();
                return;
            }

            List <string> stagedFiles = Index.GetStagedFiles();

            if (stagedFiles.Count == 0)
            {
                PrintNoStagedFilesError();
                return;
            }

            TreeBuilder treeBuilder = TreeBuilder.CreateRootTreeBuilder();

            AddAllStagedFilesToTree(treeBuilder, stagedFiles);
            AddRestOfTrackedFilesToTree(treeBuilder, stagedFiles);

            Commit commit = CreateCommit(treeBuilder);

            StoreCommitAndAdvanceHeadBranch(commit, treeBuilder);
        }
示例#2
0
        public void SimpleStoreTest()
        {
            CreateFile("a.txt", "some content");
            CreateFile("b.txt", "other content");

            Blob blobA = CreateBlob("a.txt");
            Blob blobB = CreateBlob("b.txt");

            HashKey keyBlobA = ObjectDatabase.Store(blobA);
            HashKey keyBlobB = ObjectDatabase.Store(blobB);

            TreeBuilder treeBuilder = TreeBuilder.CreateRootTreeBuilder();

            treeBuilder.AddBlobToTreeHierarchy(blobA);
            treeBuilder.AddBlobToTreeHierarchy(blobB);

            HashKey keyTreeBuilder = ObjectDatabase.Store(treeBuilder);

            Tree retrievedTree = ObjectDatabase.RetrieveTree(keyTreeBuilder);

            Assert.Equal(treeBuilder.GetChecksum(), retrievedTree.GetChecksum());
        }
示例#3
0
        public void SkipDirTest()
        {
            CreateFile("a.txt", "some content");
            Directory.CreateDirectory("dir/subdir");
            CreateFile("dir/subdir/b.txt", "other content");

            Blob blobA = CreateBlob("a.txt");
            Blob blobB = CreateBlob("dir/subdir/b.txt");

            TreeBuilder treeBuilder = TreeBuilder.CreateRootTreeBuilder();

            treeBuilder.AddBlobToTreeHierarchy(blobA);
            treeBuilder.AddBlobToTreeHierarchy(blobB);

            List <Blob>        allBlobs = new List <Blob>();
            List <TreeBuilder> allTrees = new List <TreeBuilder>();

            treeBuilder.GetAllBlobsAndSubTrees(allBlobs, allTrees);

            Assert.Equal(allBlobs.Count, 2);
            Assert.Equal(allTrees.Count, 3);
        }
示例#4
0
        private HashKey CreateAndStoreSimpleCommit(Blob[] blobs)
        {
            HashKey[] blobKeys = new HashKey[blobs.Length];

            // blobs are normaly stored in AddCommand
            for (int i = 0; i < blobKeys.Length; i++)
            {
                blobKeys[i] = ObjectDatabase.Store(blobs[i]);
            }

            // this is done in CommitCommand
            TreeBuilder treeBuilder = TreeBuilder.CreateRootTreeBuilder();

            foreach (Blob blob in blobs)
            {
                treeBuilder.AddBlobToTreeHierarchy(blob);
            }

            Commit commit = new Commit(null, treeBuilder.GetChecksum(), "Some commit message");

            return(ObjectDatabase.StoreCommitWithTreeHierarchy(commit, treeBuilder));
        }