public GitBasedFileSystemHistoryTest()
        { 
            RepositoryInitHelper.InitializeRepository(m_TempDirectory.Location);

            m_Repository = new Repository(m_TempDirectory.Location);
            var branchName = new BranchName("", "branch1");
            m_Repository.CreateBranch(branchName, m_Repository.GetAllCommits().Single());

            m_Instance = new GitBasedFileSystemHistory(m_Repository, branchName);

        }
        /// <summary>
        /// Initializes a new bare repository at the specified location, adds a repository info file to the root directory
        /// and tags the initial commit with he value of <see cref="InitialCommitTagName"/>
        /// </summary>
        public static void InitializeRepository(string location)
        {            
            // initialize a bare repository
            Repository.Init(location, true);

            var directoryCreator = new LocalItemCreator();

            // clone the repository, add initial commit and push the changes back to the actual repository
            using (var tempDirectory = directoryCreator.CreateTemporaryDirectory())
            {
                var clonedRepoPath = Repository.Clone(location, tempDirectory.Directory.Location);

                var repositoryInfoFile = new RepositoryInfoFile(tempDirectory.Directory);

                // add a empty file to the repository
                directoryCreator.CreateFile(repositoryInfoFile, tempDirectory.Directory.Location);

                // commit and push the file to the bare repository we created
                using (var clonedRepo = new Repository(clonedRepoPath))
                {
                    var signature = SignatureHelper.NewSignature();

                    clonedRepo.Stage(repositoryInfoFile.Name);
                    clonedRepo.Commit("Initial Commit", signature, signature, new CommitOptions());                    

                    clonedRepo.Network.Push(clonedRepo.Network.Remotes["origin"], @"refs/heads/master");                    
                }
            }

            //create the configuration branch pointing to the initial commit
            using (var repository = new Repository(location))
            {
                repository.CreateBranch(ConfigurationBranchName.ToString(), repository.GetAllCommits().Single());
                repository.Tags.Add(InitialCommitTagName, repository.GetAllCommits().Single());
            }
        }
        public void CanReuseLocalRepository_returns_false_if_the_repository_contains_unpublished_branches()
        {
            var transaction1 = CreateTransaction();
            transaction1.Begin();
            using (var repository = new Repository(transaction1.LocalPath))
            {
                repository.CreateBranch("newBranch", repository.GetAllCommits().Single());
            }

            //do not commit the changes from the transaction (leaves the local directory intact (with a new commit))        

            var cachingTransaction = CreateCachingTransaction(transaction1.LocalPath);
            Assert.False(cachingTransaction.CanReuseLocalRepository());
        }
        public void Commit_pushes_changes_from_all_branches_to_the_remote_repository()
        {
            var transaction = CreateTransaction();
            transaction.Begin();

            var expectedCommitCount = m_RemoteRepository.Commits.Count();

            // make change on master branch
            AddFile(transaction, "master", "file1");            
            expectedCommitCount += 1;
            
            using (var localRepo = new Repository(transaction.LocalPath))
            {
                Assert.Equal(expectedCommitCount, localRepo.GetAllCommits().Count());
            }


            // make change on branch2
            AddFile(transaction, s_Branch2, "file2");            
            expectedCommitCount += 1;

            using (var localRepo = new Repository(transaction.LocalPath))
            {
                Assert.Equal(expectedCommitCount, localRepo.GetAllCommits().Count());
            }

            // push to remote repository
            transaction.Commit();

            // check that the commit where pushed to the remote directory
            Assert.Equal(expectedCommitCount, m_RemoteRepository.GetAllCommits().Count());            
        }
        public void Begin_gets_all_changes_from_the_remote_repository()
        {            
            var transaction1 = CreateTransaction();
            var transaction2 = CreateTransaction();

            transaction1.Begin();
            transaction2.Begin();

            // add a file to the repository in transaction1
            AddFile(transaction1, s_Branch2, "file1");
            transaction1.Commit();

            //in transaction2, add a file, too
            AddFile(transaction2, s_Branch3, "file2");
            transaction2.Commit();

            //create a new transaction using the directory of transaction1

            var transaction3 = CreateCachingTransaction(transaction1.LocalPath);
            // Begin() needs to fetch the changes made by transaction2 into the local repository
            transaction3.Begin();

            // make sure there are really all commits in the local repository
            using (var repository = new Repository(transaction3.LocalPath))
            {
                Assert.Equal(3, repository.GetAllCommits().Count());
            }
        }