public void DoNotHaveProjectDoesNotFilterOutRepo()
		{
			using (var sueRepo = new RepositoryWithFilesSetup("SueForLift", "Sue.lift", "contents"))
			{
				var fakeProjectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
				Directory.CreateDirectory(fakeProjectDir);
				using (var tempDir = TemporaryFolder.TrackExisting(fakeProjectDir))
				{
					var extantDir = Path.Combine(fakeProjectDir, "extantmatchingrepo", Utilities.OtherRepositories, Utilities.LIFT);
					Directory.CreateDirectory(extantDir);
					Directory.CreateDirectory(Path.Combine(fakeProjectDir, "norepowithoffset", Utilities.OtherRepositories, Utilities.LIFT));
					Directory.CreateDirectory(Path.Combine(fakeProjectDir, "noreposansoffset"));
					var strat = new ObtainProjectStrategyLift();
					Assert.IsTrue(strat.ProjectFilter(sueRepo.ProjectFolder.Path));
				}
			}
		}
예제 #2
0
        private void FinishCloning(Dictionary <string, string> commandLineArgs, string cloneLocation, string expectedPathToClonedRepository)
        {
            // "obtain_lift"
            //		'cloneLocation' wants to be a new folder at the $fwroot\foo\OtherRepositories\foo_LIFT folder,
            //		but Chorus may put it in $fwroot\foo\OtherRepositories\bar.
            //		So, it might need to be moved or the containing folder renamed,
            //		as we have no real control over the actual folder of 'cloneLocation' from Chorus.
            //		'expectedPathToClonedRepository' is where it is supposed to be.
            // It may not be in the right, fixed folder, so rename/move, as needed
            var actualCloneResult = new ActualCloneResult
            {
                // Be a bit pessimistic at first.
                CloneResult       = null,
                ActualCloneFolder = null,
                FinalCloneResult  = FinalCloneResult.ExistingCloneTargetFolder
            };

            // Update to the head of the desired branch, if possible.
            ObtainProjectStrategyLift.UpdateToTheCorrectBranchHeadIfPossible(cloneLocation, "LIFT" + commandLineArgs["-liftmodel"], actualCloneResult);

            switch (actualCloneResult.FinalCloneResult)
            {
            case FinalCloneResult.ExistingCloneTargetFolder:
                MessageBox.Show(CommonResources.kFlexProjectExists, CommonResources.kObtainProject, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Directory.Delete(cloneLocation, true);
                _liftFolder = null;
                return;

            case FinalCloneResult.FlexVersionIsTooOld:
                MessageBox.Show(CommonResources.kFlexUpdateRequired, CommonResources.kObtainProject, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Directory.Delete(cloneLocation, true);
                _liftFolder = null;
                return;

            case FinalCloneResult.Cloned:
                _gotClone = true;
                break;
            }

            if (cloneLocation == expectedPathToClonedRepository)
            {
                _liftFolder = cloneLocation;
                return;
            }

            if (!Directory.Exists(expectedPathToClonedRepository) || Utilities.FolderIsEmpty(expectedPathToClonedRepository))
            {
                if (Directory.Exists(expectedPathToClonedRepository))
                {
                    Directory.Delete(expectedPathToClonedRepository);
                }
                DirectoryUtilities.MoveDirectorySafely(cloneLocation, expectedPathToClonedRepository);
                actualCloneResult.ActualCloneFolder = expectedPathToClonedRepository;
                actualCloneResult.FinalCloneResult  = FinalCloneResult.Cloned;
                _liftFolder = expectedPathToClonedRepository;
            }
            else
            {
                // Not good at all.
                if (Directory.Exists(cloneLocation))
                {
                    Directory.Delete(cloneLocation, true);
                }
                if (Directory.Exists(expectedPathToClonedRepository))
                {
                    Directory.Delete(expectedPathToClonedRepository, true);
                }
                _liftFolder = null;
            }
        }
예제 #3
0
        /// <summary>
        /// Start doing whatever is needed for the supported type of action.
        /// </summary>
        public void StartWorking(Dictionary <string, string> commandLineArgs)
        {
            _baseLiftDir = Utilities.LiftOffset(Path.GetDirectoryName(commandLineArgs["-p"]));
            var fwLangProjGuid          = commandLineArgs["-g"];
            var basePathForOldLiftRepos = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                "LiftBridge");

            if (!Directory.Exists(basePathForOldLiftRepos))
            {
                return;
            }
            if (Directory.GetDirectories(basePathForOldLiftRepos).Length == 0)
            {
                Directory.Delete(basePathForOldLiftRepos, true);
                return;
            }
            var mappingDocPathname = Path.Combine(basePathForOldLiftRepos, MappingFilename);

            if (!File.Exists(mappingDocPathname))
            {
                return;
            }

            var mappingDoc = XDocument.Load(mappingDocPathname);

            if (!mappingDoc.Root.HasElements)
            {
                Directory.Delete(basePathForOldLiftRepos, true);
                return;
            }
            var removedElements = mappingDoc.Root.Elements(MappingTag)
                                  .Where(mapElement => mapElement.Attribute(ProjectguidAttrTag) == null || mapElement.Attribute(RepositoryidentifierAttrTag) == null).ToList();

            foreach (var goner in removedElements)
            {
                goner.Remove();
            }
            if (removedElements.Count > 0)
            {
                removedElements.Clear();
                mappingDoc.Save(mappingDocPathname);
            }

            string oldLiftFolder = null;

            foreach (var mapElement in mappingDoc.Root.Elements(MappingTag).ToList())
            {
                if (mapElement.Attribute(ProjectguidAttrTag).Value.ToLowerInvariant() != fwLangProjGuid.ToLowerInvariant())
                {
                    continue;
                }

                var repoId = mapElement.Attribute(RepositoryidentifierAttrTag).Value;

                foreach (var directory in Directory.GetDirectories(basePathForOldLiftRepos).Where(directory => Directory.Exists(Path.Combine(directory, Utilities.hg))))
                {
                    var repo = new HgRepository(directory, new NullProgress());
                    if (repo.Identifier != repoId)
                    {
                        continue;
                    }

                    oldLiftFolder = directory;
                    break;
                }
                if (oldLiftFolder == null)
                {
                    continue;
                }

                RemoveElementAndSaveDoc(mappingDoc, mapElement, mappingDocPathname);
                break;
            }
            if (oldLiftFolder == null)
            {
                return;
            }

            var actualCloneResult = new ActualCloneResult();

            ObtainProjectStrategyLift.MakeLocalClone(oldLiftFolder, _baseLiftDir);
            actualCloneResult.ActualCloneFolder = _baseLiftDir;
            actualCloneResult.FinalCloneResult  = FinalCloneResult.Cloned;

            // Update to the head of the desired branch, if possible.
            ObtainProjectStrategyLift.UpdateToTheCorrectBranchHeadIfPossible(_baseLiftDir, "LIFT" + commandLineArgs["-liftmodel"], actualCloneResult);
            if (actualCloneResult.FinalCloneResult != FinalCloneResult.Cloned)
            {
                MessageBox.Show(actualCloneResult.Message, LocalizationManager.GetString("LiftBridge_MoveFailed_Title",
                                                                                         "Failed to update LiftBridge project.",
                                                                                         "Title of error message shown when moving a LiftBridge repo to the FlexBridge location fails."));
                // The clone and update did not go smoothly.
                return;
            }
            var folderToZap = mappingDoc.Root.HasElements || Directory.GetDirectories(basePathForOldLiftRepos).Length > 1
                                                                  ? oldLiftFolder
                                                                  : basePathForOldLiftRepos;

            Directory.Delete(folderToZap, true);
            var otherRepoDir = Directory.GetParent(_baseLiftDir).FullName;

            if (!Directory.Exists(_baseLiftDir) && Directory.GetDirectories(_baseLiftDir).Length == 0)
            {
                Directory.Delete(otherRepoDir);
            }
        }