Exemplo n.º 1
0
        public void Repository_with_single_commit_and_single_file()
        {
            using (var repo = new Repository(m_Repository.Directory.Location))
            {
                var commit = repo.Commits.Single();

                var gitDirectory = new GitDirectory(null, m_Repository.Directory.Name, commit);

                Assert.Equal(m_Repository.Directory.Name, gitDirectory.Name);
                Assert.Empty(gitDirectory.Directories);
                Assert.Single(gitDirectory.Files);
                Assert.True(gitDirectory.FileExists(RepositoryInfoFile.RepositoryInfoFileName));
            }
        }
Exemplo n.º 2
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;

        } 
Exemplo n.º 3
0
        public ISyncPoint this[int id]
        {
            get
            {
                if (!GitGroup.Repository.LocalBranchExists(BranchName))
                {
                    throw new SyncPointNotFoundException(id);
                }

                var root = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);
                var relativePath = GetRelativeSynchronizationStateFilePath(id);

                if (!root.FileExists(relativePath))
                {
                    throw new SyncPointNotFoundException(id);
                }

                return SyncPointStateFile.Load(null, (IReadableFile)root.GetFile(relativePath)).Content;
            }
        }
Exemplo n.º 4
0
        public ConflictInfo this[string filePath]
        {
            get
            {
                PathValidator.EnsureIsValidFilePath(filePath);
                PathValidator.EnsureIsRootedPath(filePath);

                if (!GitGroup.Repository.LocalBranchExists(BranchName))
                {
                    throw new ItemNotFoundException($"There is no ConflictInfo for file '{filePath}'");
                }

                var root = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);

                var relativePath = GetRelativeConflictInfoFilePath(filePath);
                if (!root.FileExists(relativePath))
                {
                    throw new ItemNotFoundException($"There is no ConflictInfo for file '{filePath}'");
                }

                var file = (IReadableFile) root.GetFile(relativePath);
                return ConflictInfoFile.Load(null, file).Content;
            }
        }
Exemplo n.º 5
0
        public bool ItemExists(int id)
        {
            if (!GitGroup.Repository.LocalBranchExists(BranchName))
            {
                return false;
            }

            var root = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);
            var relativePath = GetRelativeSynchronizationStateFilePath(id);

            return root.FileExists(relativePath);
        }
Exemplo n.º 6
0
        public void AddItems(IEnumerable<ConflictInfo> conflicts)
        {
            if (conflicts == null)
            {
                throw new ArgumentNullException(nameof(conflicts));
            }
            conflicts = conflicts.ToArray();

            if(!conflicts.Any())
            {
                return;
            }

            EnsureBranchExists();

            var exisitngRoot = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);
            var createdRoot = new Directory(null, "root");

            // verify conflicts
            foreach (var conflict in conflicts)
            {                
                var relativePath = GetRelativeConflictInfoFilePath(conflict.FilePath);
                if (exisitngRoot.FileExists(relativePath))
                {
                    throw new DuplicateItemException($"A ConflictInfo for '{conflict.FilePath}' already exists");
                }

                var directory = DirectoryHelper.GetOrAddDirectory(createdRoot, PathParser.GetDirectoryName(relativePath));
                directory.Add(f => new ConflictInfoFile(f, conflict));
            }


            using (var workingDirectory = new TemporaryWorkingDirectory(GitGroup.Repository.Info.Path, BranchName.ToString()))
            {                
                var localItemCreator = new LocalItemCreator();
                localItemCreator.CreateDirectoryInPlace(createdRoot, workingDirectory.Location);

                workingDirectory.Commit($"{nameof(GitConflictService)}: Added {conflicts.Count()} items");
                workingDirectory.Push();
            }            

        }
Exemplo n.º 7
0
        public bool ItemExists(string filePath)
        {
            PathValidator.EnsureIsValidFilePath(filePath);
            PathValidator.EnsureIsRootedPath(filePath);
            
            if (!GitGroup.Repository.LocalBranchExists(BranchName))
            {
                return false;
            }

            var root = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);
            return root.FileExists(GetRelativeConflictInfoFilePath(filePath));
        }
Exemplo n.º 8
0
        public void RemoveItems(IEnumerable<ConflictInfo> conflicts)
        {
            if (conflicts == null)
            {
                throw new ArgumentNullException(nameof(conflicts));
            }

            conflicts = conflicts.ToArray();

            if (!conflicts.Any())
            {
                return;
            }

            if (!GitGroup.Repository.LocalBranchExists(BranchName))
            {
                throw new ItemNotFoundException($"There is no ConflictInfo for file '{conflicts.First().FilePath}'");
            }


            var root = new GitDirectory(null, "root", GitGroup.Repository.GetLocalBranch(BranchName).Tip);

            // verify conflicts
            foreach (var conflict in conflicts)
            {             
                var relativePath = GetRelativeConflictInfoFilePath(conflict.FilePath);
                if (!root.FileExists(relativePath))
                {
                    throw new ItemNotFoundException($"There is no ConflictInfo for file '{conflict.FilePath}'");
                }
            }


            // delete conflict info files
            using (var workingDirectory = new TemporaryWorkingDirectory(GitGroup.Repository.Info.Path, BranchName.ToString()))
            {
                var localDirectory= new LocalDirectory(null, workingDirectory.Location);

                foreach (var conflict in conflicts)
                {
                    var relativePath = GetRelativeConflictInfoFilePath(conflict.FilePath);
                    System.IO.File.Delete(((ILocalFile)localDirectory.GetFile(relativePath)).Location);
                }

                workingDirectory.Commit($"{nameof(GitConflictService)}: Removed {conflicts.Count()} items");
                workingDirectory.Push();
            }                
        }