public void BothDeleted()
        {
            var resolver = new ExceptionResolver<ConfigitPackageReference>();
              var merger = new PackagesConfigMerger( CurrentOperation.Merge, resolver );

              var result = merger.Merge( "TestFilePath", _packageV1, _packageEmpty, _packageEmpty ).ToList();

              Assert.That( result, Is.Empty );
        }
        public void BothAddedUserResolved()
        {
            var resolver = new TestConflictResolver<ConfigitPackageReference>( ConflictItemType.Local );
              var merger = new PackagesConfigMerger( CurrentOperation.Merge, resolver );

              var result = merger.Merge( "TestFilePath", _packageEmpty, _packageV1, _packageV2Net46 ).ToList();

              Assert.That( resolver.Called, Is.EqualTo( true ) );
              Assert.That( result, Is.EquivalentTo( _packageV1 ) );
        }
示例#3
0
        private static void ProcessPackagesConfig(
      CurrentOperation operation,
      string[] conflictPaths,
      DirectoryInfo folder,
      Logger logger,
      string rootFolder )
        {
            var packagesConfigMerger = new PackagesConfigMerger(
            operation,
            new UserConflictResolver<ConfigitPackageReference>( operation, repositoryRootDirectory: rootFolder ) );

              foreach ( var conflict in conflictPaths.Where( p => Path.GetFileName( p ) == "packages.config" ) ) {

            var fullConflictPath = Path.Combine( folder.FullName, conflict );
            logger.Info( $"{LogHelper.Header}{Environment.NewLine}Examining concurrent modification for {fullConflictPath}" );

            var baseContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Ancestor, conflict );
            var localContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Ours, conflict );
            var incomingContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Theirs, conflict );

            // TODO: Is this correct? if base is not null then we have a deletion of the packages config file
            if ( string.IsNullOrEmpty( localContent ) || string.IsNullOrEmpty( incomingContent ) ) {
              logger.Log( LogLevel.Info, $"Skipping '{conflict}' - no content on one side" );
              continue;
            }

            bool resolved = false;

            try {
              var result = packagesConfigMerger.Merge( conflict,
              baseContent == null ? new ConfigitPackageReference[0]:
                                   NuGetExtensions.ReadPackageReferences( baseContent ),
              NuGetExtensions.ReadPackageReferences( localContent ),
              NuGetExtensions.ReadPackageReferences( incomingContent ) ).ToArray();

              result.Write( fullConflictPath );

              using ( var repository = new Repository( rootFolder ) ) {
            repository.Stage( conflict );
            resolved = true;
              }

            } catch ( MergeAbortException ) {
              logger.Log( LogLevel.Info, $"Package merge aborted for {conflict}" );
              continue;
            }
            catch ( UserQuitException ) {
              throw;
            } catch ( Exception exception ) {
              logger.Log( LogLevel.Error, exception, $"Package merge failed for {conflict}{Environment.NewLine}{exception}" );
            }

            if ( resolved ) {
              continue;
            }

              string userQuestionText = $"Could not resolve conflict: {conflict}{Environment.NewLine}Would you like to resolve the conflict with the mergetool?";
              var userQuestion = new UserQuestion<bool>( userQuestionText, UserQuestion<bool>.YesNoOptions() );

            if ( !userQuestion.Resolve() ) {
              continue;
            }

            XDocument localDocument = XDocument.Parse( localContent );
            XDocument theirDocument = XDocument.Parse( incomingContent );
            XDocument baseDocument = baseContent == null ? new XDocument() : XDocument.Parse( baseContent );

            using ( var repository = new Repository( rootFolder ) ) {
              GitHelper.ResolveWithStandardMergetool(
                repository,
                fullConflictPath,
                baseDocument,
                localDocument,
                theirDocument,
                logger,
                conflict );
            }
              }
        }
        public void MineDeletedTheirsUpdated_ResolveMine()
        {
            var resolver = new TestConflictResolver<ConfigitPackageReference>( ConflictItemType.Local );
              var merger = new PackagesConfigMerger( CurrentOperation.Merge, resolver );

              var result = merger.Merge( "TestFilePath", _packageV0, _packageEmpty, _packageV1 ).ToList();

              Assert.That( resolver.Called, Is.EqualTo( true ) );
              Assert.That( result, Is.Empty );
        }
        public void BothUpdatedAutoResolved()
        {
            var resolver = new TestConflictResolver<ConfigitPackageReference>( ConflictItemType.Local );
              var merger = new PackagesConfigMerger( CurrentOperation.Merge, resolver );

              // CurrentOperation.Merge causes local to be set to mine
              var result = merger.Merge( "TestFilePath", _packageV0, _packageV1, _packageV2 ).ToList();

              Assert.That( resolver.Called, Is.EqualTo( false ) );
              Assert.That( result, Is.EquivalentTo( _packageV2 ) );
        }
        public void TheirsUpdated()
        {
            var resolver = new ExceptionResolver<ConfigitPackageReference>();
              var merger = new PackagesConfigMerger( CurrentOperation.Merge, resolver );

              var result = merger.Merge( "TestFilePath", _packageV0, _packageV0, _packageV1 ).ToList();

              Assert.That( result, Is.EquivalentTo( _packageV1 ) );
        }