internal static IncomingChangeInfo FromFileConflict(
                FileConflict fileConflict,
                UnityIncomingChangesTree tree)
            {
                foreach (IncomingChangesCategory category in tree.GetNodes())
                {
                    foreach (IncomingChangeInfo changeInfo in category.GetChanges())
                    {
                        if (changeInfo.CategoryType != IncomingChangesCategory.Type.FileConflicts &&
                            changeInfo.CategoryType != IncomingChangesCategory.Type.Changed)
                        {
                            continue;
                        }

                        if (changeInfo.GetPath() != fileConflict.SrcDiff.Path)
                        {
                            continue;
                        }

                        return(changeInfo);
                    }
                }

                return(null);
            }
        public void TestChangedNoMeta()
        {
            MergeTreeResult conflicts = new MergeTreeResult();

            MountPointWithPath rootMountPointWithPath = BuildRootMountPointWithPath();

            FileConflict fileConflict =
                BuildMergeTreeResult.CreateModifiedDifference("/foo/bar.c");

            conflicts.FilesModifiedOnSource.Add(fileConflict);

            UnityIncomingChangesTree tree = UnityIncomingChangesTree.BuildIncomingChangeCategories(
                IncomingChangesTree.BuildIncomingChangeCategories(
                    conflicts,
                    new GetConflictResolutionMock(),
                    rootMountPointWithPath));

            IncomingChangeInfo changeInfo = FindChangeInfo.FromFileConflict(
                fileConflict, tree);

            Assert.IsNotNull(
                changeInfo,
                "ChangeInfo not found");

            Assert.IsNull(
                tree.GetMetaChange(changeInfo),
                "Meta change should be null");
        }
        public void TestOnlyMeta()
        {
            MergeTreeResult conflicts = new MergeTreeResult();

            MountPointWithPath rootMountPointWithPath = BuildRootMountPointWithPath();

            FileConflict fileConflictMeta =
                BuildMergeTreeResult.CreateFileConflict("/foo/bar.c.meta");

            conflicts.FileConflicts.Add(fileConflictMeta);

            UnityIncomingChangesTree tree = UnityIncomingChangesTree.BuildIncomingChangeCategories(
                IncomingChangesTree.BuildIncomingChangeCategories(
                    conflicts,
                    new GetConflictResolutionMock(),
                    rootMountPointWithPath));

            IncomingChangeInfo conflictMetaChangeInfo = FindChangeInfo.FromFileConflict(
                fileConflictMeta, tree);

            Assert.IsNotNull(
                conflictMetaChangeInfo,
                "ChangeInfo not found");

            Assert.IsNull(
                tree.GetMetaChange(conflictMetaChangeInfo),
                "Meta change should be null");
        }
        public async Task <Result> AddConflict(FileConflict fileConflict)
        {
            var db = _databaseFactory.Get();

            using (db)
                return(await db.Execute(_insertStatementAddConflict, new { fileConflict.FileId, fileConflict.Type }));
        }
        public void TestChangedMovedWithMeta()
        {
            MergeTreeResult conflicts = new MergeTreeResult();

            MountPointWithPath rootMountPointWithPath = BuildRootMountPointWithPath();

            FileConflict fileConflict =
                BuildMergeTreeResult.CreateFileConflict("/foo/var.c");

            FileConflict fileConflictMeta =
                BuildMergeTreeResult.CreateFileConflict("/foo/var.c.meta");

            Difference difference =
                BuildMergeTreeResult.CreateMovedDifference("/foo/bar.c", "/foo/var.c");
            Difference differenceMeta =
                BuildMergeTreeResult.CreateMovedDifference("/foo/bar.c.meta", "/foo/var.c.meta");

            conflicts.FilesModifiedOnSource.Add(fileConflict);
            conflicts.FilesModifiedOnSource.Add(fileConflictMeta);
            conflicts.MovesToApply.Add(difference);
            conflicts.MovesToApply.Add(differenceMeta);

            UnityIncomingChangesTree tree = UnityIncomingChangesTree.BuildIncomingChangeCategories(
                IncomingChangesTree.BuildIncomingChangeCategories(
                    conflicts,
                    new GetConflictResolutionMock(),
                    rootMountPointWithPath));

            IncomingChangeInfo fileChangeInfo = FindChangeInfo.FromFileConflict(
                fileConflict, tree);
            IncomingChangeInfo differenceChangeInfo = FindChangeInfo.FromDifference(
                difference, tree);

            Assert.IsNotNull(
                fileChangeInfo,
                "FileConflict not found");

            Assert.IsNotNull(
                differenceChangeInfo,
                "Difference not found");

            Assert.IsNotNull(
                tree.GetMetaChange(fileChangeInfo),
                "Meta change for file conflict not should be null");

            Assert.IsNotNull(
                tree.GetMetaChange(differenceChangeInfo),
                "Meta change for difference not should be null");
        }
示例#6
0
        public void TestChangedWithDeletedMeta()
        {
            MergeTreeResult conflicts = new MergeTreeResult();

            MountPointWithPath rootMountPointWithPath = BuildRootMountPointWithPath();

            FileConflict modified =
                BuildMergeTreeResult.CreateModifiedDifference("/foo/bar.c");

            Difference deletedMeta =
                BuildMergeTreeResult.CreateDeletedDifference("/foo/bar.c.meta");

            conflicts.FilesModifiedOnSource.Add(modified);
            conflicts.DeletesToApply.Add(deletedMeta);

            UnityIncomingChangesTree tree = UnityIncomingChangesTree.BuildIncomingChangeCategories(
                MergeChangesTree.BuildForIncomingChangesView(
                    conflicts,
                    new GetConflictResolutionMock(),
                    rootMountPointWithPath));

            MergeChangeInfo changeInfo = FindChangeInfo.FromFileConflict(
                modified, tree);

            MergeChangeInfo deleteInfo = FindChangeInfo.FromDifference(
                deletedMeta, tree);

            Assert.IsNotNull(
                changeInfo,
                "ChangeInfo not found");

            Assert.IsNotNull(
                deleteInfo,
                "DeleteInfo not found");

            Assert.IsNull(
                tree.GetMetaChange(changeInfo),
                "Meta change should be null");
        }
        public async Task <bool> Check(File currentFile, ICollection <File> otherVersions)
        {
            if (currentFile is null || otherVersions is null || !otherVersions.Any())
            {
                return(false);
            }

            var hasConflicts  = false;
            var maxVersion    = otherVersions.Max(x => x.Version);
            var sumOfVersions = otherVersions.Sum(x => x.Version);

            if (otherVersions.Count(x => x.Version == currentFile.Version) > 1)
            {
                WorkerLog.Instance.Information($"Conflict found while assembling file '{currentFile.Path}': There is already version {currentFile.Version} for this file.");
                var conflict = new FileConflict(currentFile.Id, FileConflictType.SameVersion);
                await _conflictRepository.AddConflict(conflict);

                hasConflicts = true;
            }
            //disable other checks for the moment. No decent way yet to resolve them

            //else if (currentFile.Version < maxVersion)
            //{
            //	WorkerLog.Instance.Information($"Conflict found while assembling file '{currentFile.Path}': There is a higher version than {currentFile.Version} for this file.");
            //	var conflict = FileConflict.Create(currentFile.Id, FileConflictType.HigherVersion);
            //	await _conflictRepository.AddConflict(conflict);
            //	hasConflicts = true;
            //}
            //else if (maxVersion * (maxVersion + 1) / 2 != sumOfVersions)
            //{
            //	WorkerLog.Instance.Information($"Conflict found while assembling file '{currentFile.Path}': The file seems to be missing a version.");
            //	var conflict = FileConflict.Create(currentFile.Id, FileConflictType.MissingVersion);
            //	await _conflictRepository.AddConflict(conflict);
            //	hasConflicts = true;
            //}

            return(hasConflicts);
        }