示例#1
0
        /// <summary>
        /// Verifies that the specified path points to a valid repository usable by SyncTool
        /// (a repository with the expected tags and default branches as created by RepositoryInitHelper)
        /// </summary>
        public static bool IsValid(string path)
        {
            // check if the directory exists and is a valid git repository
            if (!Directory.Exists(path) || !Repository.IsValid(path))
            {
                return false;
            }

            using (var repository = new Repository(path))
            {
                // the repository needs to be a bare repository
                if (!repository.Info.IsBare)
                {
                    return false;
                }

                // ensure there is a configuration branch
                if (!repository.LocalBranchExists(RepositoryInitHelper.ConfigurationBranchName))
                {
                    return false;
                }

                // ensure there is a tag for the initial commit
                if (repository.Tags[RepositoryInitHelper.InitialCommitTagName] == null)
                {
                    return false;
                }

                // check if there is a repository info file in the root (on all branches)
                foreach (var localBranch in repository.GetLocalBranches())
                {
                    var gitDirectory = new GitDirectory(null, "Irrelevant", localBranch.Tip);

                    if (!gitDirectory.FileExists(RepositoryInfoFile.RepositoryInfoFileName))
                    {
                        return false;
                    }

                    //TODO: verify content of repository info file
                }                
            }

            return true;

        } 
        public void CreateGroup_Creates_a_repository_and_pushes_it_to_the_remote_repository()
        {
            // create a mock for the settings provider
            var settingsProvider = GetGroupSettingsProviderMock().WithEmptyGroupSettings();

            // set up local working directory
            var localDir = Path.Combine(m_TempDirectory.Location, "Local");
            Directory.CreateDirectory(localDir);

            // set up the "remote" repository
            var remoteDir = Path.Combine(m_TempDirectory.Location, "Remote");
            Directory.CreateDirectory(remoteDir);
            Repository.Init(remoteDir, true);

            
            var groupManager = new GitBasedGroupManager(new SingleDirectoryRepositoryPathProvider(localDir), settingsProvider.Object);

            // create a new group
            groupManager.CreateGroup("Group1", remoteDir);

            // creation of groups should not leave behind anything
            Assert.Empty(Directory.GetFileSystemEntries(localDir));

            // assert that the group was actually created in the remote repository
            using (var repository = new Repository(remoteDir))
            {
                Assert.Equal(2, repository.Branches.Count());
                Assert.True(repository.LocalBranchExists(RepositoryInitHelper.ConfigurationBranchName));
                Assert.NotNull(repository.Tags[RepositoryInitHelper.InitialCommitTagName]);
            }

            settingsProvider.Verify(m => m.SaveGroupSettings(It.IsAny<IEnumerable<GroupSettings>>()), Times.AtLeastOnce);
        }
        public void Begin_deletes_local_branches_if_the_tracked_brach_was_deleted_in_the_remote_repository()
        {

            var transaction1 = CreateTransaction();            
            transaction1.Begin();

            m_RemoteRepository.Branches.Remove(s_Branch3);
            
            var transaction2 = CreateCachingTransaction(transaction1.LocalPath);
            transaction2.Begin();

            // assert that the branch has been removed in the local repository and that other branches are still there
            using (var repository = new Repository(transaction2.LocalPath))
            {
                Assert.False(repository.LocalBranchExists(s_Branch3));
                Assert.True(repository.LocalBranchExists(s_Branch2));
                Assert.True(repository.LocalBranchExists("master"));
                
            }
        }