} // CreateRepositoryAndPerformInitialCommit private static void DisplayPvcsSourcesForIssue(PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail, string selectedIssueNumber) { SortedSet <string> additionalIssueNumberCollection = new SortedSet <string>(); pvcsCompleteSystemArchiveDetail.CheckDescendents(selectedIssueNumber, "System_Test", additionalIssueNumberCollection); if (additionalIssueNumberCollection.Count == 0) { Console.WriteLine(); Console.WriteLine("*** No Issue Numbers in addtion to {0} were found", selectedIssueNumber); } else { string heading = String.Format("Issue Numbers Found in Addition to {0}", selectedIssueNumber); Console.WriteLine(); ConsoleDisplay.WritelineWithUnderline(heading); foreach (string issueNumber in additionalIssueNumberCollection) { Console.WriteLine("{0}{1}", ConsoleDisplay.Indent(1), issueNumber); } } string promotionGroup = "System_Test"; Console.WriteLine(); string promotionHeading = String.Format("Promotion List for Issue Number {0} at {1}", selectedIssueNumber, promotionGroup); ConsoleDisplay.WritelineWithUnderline(promotionHeading); pvcsCompleteSystemArchiveDetail.GeneratePromotionListForIssue(selectedIssueNumber, promotionGroup); // Assume already at User_Test. Bad but good enough for now (forever?) pvcsCompleteSystemArchiveDetail.CheckBuriedPromotionGroup("System_Test"); } // DisplayPvcsSourcesForIssue
} // MigratePvcsArchiveSourcestoGit static bool MigratePvcsArchiveSourcestoGit(PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail, string singlePromotionGroupName, string rootWorkingDirectory) { bool success = false; const CommandOperation.DebugProgress debugProgress = CommandOperation.DebugProgress.None; const int highLevelIndent = 0; PvcsPromotionGroupDetailCollection pvcsPromotionGroupDetailCollection = new PvcsPromotionGroupDetailCollection(); // ============================================================================================================ // For this to work, the Repository must have the branch from which this Promotion Group is to come checked out // ============================================================================================================ success = GitOperation.ImportBranchFromPvcs(pvcsCompleteSystemArchiveDetail, singlePromotionGroupName, true, pvcsPromotionGroupDetailCollection.PromotionGroupNetworkShareName(singlePromotionGroupName), pvcsPromotionGroupDetailCollection.GitBranchName(singlePromotionGroupName), rootWorkingDirectory, String.Format("Initial PVCS {0} commit to Git {1}", singlePromotionGroupName, pvcsPromotionGroupDetailCollection.GitBranchName(singlePromotionGroupName)), highLevelIndent, debugProgress); return(success); } // MigratePvcsArchiveSourcestoGit
} // Commit /// <summary> /// Import all the sources associated with a PVCS Promotion Group into a single git branch /// </summary> /// <param name="pvcsCompleteSystemArchiveDetail">Complete set of PVCS Archive Details with Promotion Group and revision details</param> /// <param name="promotionGroup">The particular Promotion Group to be imported</param> /// <param name="performImport">Whether or not to actually perform the import (true) or just create the branch (false)</param> /// <param name="promotionGroupSourceVolume">The location of the PVCS source revisions that correspond to the Promotion Group</param> /// <param name="branchName">The name of the Git Branch into which to perform the import</param> /// <param name="rootWorkingDirectory">The full path to the directory containing the Git Repository including working tree</param> /// <param name="commitMessage">The message to be placed on the Git Branch Commit</param> /// <param name="indent">The indent value of output</param> /// <param name="debugProgress">The progress debug output details</param> /// <returns></returns> public static bool ImportBranchFromPvcs(PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail, string promotionGroup, bool performImport, string promotionGroupSourceVolume, string branchName, string rootWorkingDirectory, string commitMessage, int indent, CommandOperation.DebugProgress debugProgress) { bool success = false; Console.WriteLine(); Console.WriteLine("Importing PVCS \"{0}\" Source Revisions from \"{1}\" to Repository \"{2}\" branch \"{3}\"", promotionGroup, promotionGroupSourceVolume, rootWorkingDirectory, branchName); // Check that the working directory has/is a Git Repository success = GitOperation.GitStatus(rootWorkingDirectory, indent, debugProgress); if (success && (success = GitOperation.CreateAndSwitchToBranch(branchName, rootWorkingDirectory, indent, debugProgress)) ) { // On the appropriate Git Repository branch if (performImport) { Console.WriteLine(); Console.WriteLine("Adding Source Revisions for PVCS Promotion Group \"{0}\" to \"{1}\"", promotionGroup, branchName); if (pvcsCompleteSystemArchiveDetail.GitAdd(promotionGroup, indent, promotionGroupSourceVolume, rootWorkingDirectory) ) { success = GitOperation.Commit(commitMessage, rootWorkingDirectory, indent, debugProgress); if (success) { Console.WriteLine(); Console.WriteLine("Committed Source Revisions for PVCS Promotion Group \"{0}\" to \"{1}\"", promotionGroup, branchName); } } else { success = false; Console.WriteLine("*** Not all \"{0}\" Source Revisions were added to branch \"{1}\"", promotionGroup, branchName); } } else { Console.WriteLine(); Console.WriteLine("Skipping import of PVCS Promotion Group \"{0}\" to \"{1}\"", promotionGroup, branchName); } } // On the appropriate Git Repository branch return(success); } // ImportBranchFromPvcs
private static int Main(string[] args) { int error = _errorSuccess; string fullReportPath = null; // Mandatory string gitRepositoryDirectoryPath = null; // Optional - defaulted bool useExistingGitRepository = false; string importSinglePromotionGroupName = null; foreach (string argValue in args) { if (argValue.StartsWith("/")) { // Value is a switch switch (argValue.ToLower()[1]) { case 'e': Console.WriteLine("Use existing Git Repository selected"); useExistingGitRepository = true; break; case 'i': if (!useExistingGitRepository) { Console.WriteLine("A single Promotion Group import cannot be performed unless using an existing Git Repository"); } else { // /x:PromotionGroupName // 0123... string possiblePromotionGroupName = argValue.Substring(3); if (new PvcsPromotionGroupDetailCollection().PromotionGroupNameIsValid(possiblePromotionGroupName)) { importSinglePromotionGroupName = possiblePromotionGroupName; Console.WriteLine("PVCS Import includes only Promotion Group \"{0}\"", importSinglePromotionGroupName); } } break; case 'x': { // /x:PromotionGroupName // 0123... string possiblePromotionGroupName = argValue.Substring(3); if (new PvcsPromotionGroupDetailCollection().PromotionGroupNameIsValid(possiblePromotionGroupName)) { if (!_sortedSetPromotionGroupExclude.Contains(possiblePromotionGroupName)) { _sortedSetPromotionGroupExclude.Add(possiblePromotionGroupName); Console.WriteLine("PVCS Import excludes Promotion Group \"{0}\" and all lower Promotion Groups", possiblePromotionGroupName); } } else { Console.WriteLine("Promotion Group Name \"{0}\" is invalid)", possiblePromotionGroupName); } } break; default: Console.WriteLine("Unknown switch \"{0}\"", argValue); break; } // switch } // Value is a switch else { if (fullReportPath == null) { fullReportPath = IdentifyFullPromotionGroupReportPath(argValue); Console.WriteLine("Promotion Group Report Directory is \"{0}\"", fullReportPath); } else if (gitRepositoryDirectoryPath == null) { gitRepositoryDirectoryPath = argValue; Console.WriteLine("Importing from PVCS to a Git Repository located in \"{0}\"", gitRepositoryDirectoryPath); } else { Console.WriteLine("Unexpected argument \"{0}\"", argValue); } } } if (fullReportPath == null) { Console.WriteLine(); Console.WriteLine("The PVCS Archive Report Path is mandatory but was not supplied"); } else { // PVCS Archive Report path was supplied if (gitRepositoryDirectoryPath == null) { // Assume a Git Repository import from PVCS gitRepositoryDirectoryPath = "d:\\Repos\\Heritage"; Console.WriteLine("Defaulting to import from PVCS to a Git Repository located in \"{0}\"", gitRepositoryDirectoryPath); } Console.WriteLine(); Console.WriteLine("Promotion Group Report Directory is \"{0}\"", fullReportPath); try { PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail = new PvcsCompleteSystemArchiveDetail( fullReportPath, PvcsCompleteSystemArchiveDetail.PvcsArchiveDetailLevel.AllArchives); pvcsCompleteSystemArchiveDetail.Display(); pvcsCompleteSystemArchiveDetail.GeneratePromotionGroupLists(); if (importSinglePromotionGroupName == null) { // Git Repository import from PVCS error = PerformPVCStoGitMigration(pvcsCompleteSystemArchiveDetail, _sortedSetPromotionGroupExclude, gitRepositoryDirectoryPath, useExistingGitRepository); } else { error = PerformPVCStoGitMigration(pvcsCompleteSystemArchiveDetail, importSinglePromotionGroupName, gitRepositoryDirectoryPath); } } catch (FileNotFoundException exFileNotFound) { Console.WriteLine(); Console.WriteLine("File \"{0}\" was not found", exFileNotFound.Message); error = _errorFileNotFound; } catch (PvcsCompleteSystemArchiveDetail.UnableToOpenFileException exFileCantOpen) { Console.WriteLine(); Console.WriteLine("Unable to open file \"{0}\"", exFileCantOpen.Message); error = _errorFileUnableToBeOpened; } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("Exception : \"{0}\"", ex.ToString()); error = _errorGeneralError; } } // PVCS Archive Report path was supplied return(error); } // Main
} // PerformPVCStoGitMigration private static int PerformIssueAnalysis(PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail, string selectedIssueNumber) { DisplayPvcsSourcesForIssue(pvcsCompleteSystemArchiveDetail, selectedIssueNumber); return(_errorSuccess); }
} // PerformPVCStoGitMigration private static int PerformPVCStoGitMigration(PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail, string singlePromotionGroupName, string gitRepositoryDirectoryPath) { int error = _errorSuccess; bool migrationSuccess = false; // Start timing the migration into Git from PVCS Stopwatch stopwatchMigration = new Stopwatch(); stopwatchMigration.Start(); try { migrationSuccess = MigratePvcsArchiveSourcestoGit(pvcsCompleteSystemArchiveDetail, singlePromotionGroupName, gitRepositoryDirectoryPath); } catch (FileNotFoundException exFileNotFound) { Console.WriteLine(); Console.WriteLine("File \"{0}\" was not found", exFileNotFound.Message); error = _errorFileNotFound; } catch (PvcsCompleteSystemArchiveDetail.UnableToOpenFileException exFileCantOpen) { Console.WriteLine(); Console.WriteLine("Unable to open file \"{0}\"", exFileCantOpen.Message); error = _errorFileUnableToBeOpened; } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("Exception : \"{0}\"", ex.ToString()); error = _errorGeneralError; } // Stop timing stopwatchMigration.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan timespanMigration = stopwatchMigration.Elapsed; // Format and display the TimeSpan value. string elapsedTimeMigration = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", timespanMigration.Hours, timespanMigration.Minutes, timespanMigration.Seconds, timespanMigration.Milliseconds / 10); if (migrationSuccess) { Console.WriteLine(); Console.WriteLine("Partial migration from PVCS to Git is complete. Elapsed time {0}", elapsedTimeMigration); error = _errorSuccess; } else { Console.WriteLine(); Console.WriteLine("Partial migration from PVCS to Git failed. Elapsed time {0}", elapsedTimeMigration); error = _errorMigrationFailed; } return(error); } // PerformPVCStoGitMigration
static bool MigratePvcsArchiveSourcestoGit(PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail, SortedSet <string> sortedSetPromotionGroupExclude, string rootWorkingDirectory, bool useExistingGitRepository) { bool success = false; const CommandOperation.DebugProgress debugProgress = CommandOperation.DebugProgress.None; const int highLevelIndent = 0; PvcsPromotionGroupDetailCollection pvcsPromotionGroupDetailCollection = new PvcsPromotionGroupDetailCollection(); bool createRepositoryAndPerformInitialCommit = !useExistingGitRepository; // Assume that if using the existing Repository the user knows that the branch structure already exists bool importPvcsProduction = !sortedSetPromotionGroupExclude.Contains(PvcsPromotionGroupDetailCollection.ProductionPromotionGroupName); // It only makes sense to import this Promotion Group if all higher Promotion Groups have been imported // unless the existing Git Repository already contains those higher Promotion Groups bool importPvcsPreProduction = ((importPvcsProduction) || (useExistingGitRepository /* Higher Promotion Group must already be present */)) && (!sortedSetPromotionGroupExclude.Contains(PvcsPromotionGroupDetailCollection.PreProductionPromotionGroupName)); // It only makes sense to import this Promotion Group if all higher Promotion Groups have been imported // unless the existing Git Repository already contains those higher Promotion Groups bool importPvcsUserTest = ((importPvcsPreProduction) || (useExistingGitRepository /* Higher Promotion Group must already be present */)) && (!sortedSetPromotionGroupExclude.Contains(PvcsPromotionGroupDetailCollection.UserTestPromotionGroupName)); // It only makes sense to import this Promotion Group if all higher Promotion Groups have been imported // unless the existing Git Repository already contains those higher Promotion Groups bool importPvcsSystemTest = ((importPvcsUserTest) || (useExistingGitRepository /* Higher Promotion Group must already be present */)) && (!sortedSetPromotionGroupExclude.Contains(PvcsPromotionGroupDetailCollection.SystemTestPromotionGroupName)); Console.WriteLine(); ConsoleDisplay.WritelineWithUnderline("Importing PVCS Archive Revisions for PVCS Promotion Groups into a single Git Repository"); if (createRepositoryAndPerformInitialCommit) { success = CreateRepositoryAndPerformInitialCommit(rootWorkingDirectory, highLevelIndent, debugProgress); } else { // Indicate success so that subsequent steps execute success = true; } if (success) { string promotionGroupName = PvcsPromotionGroupDetailCollection.ProductionPromotionGroupName; bool importPromotionGroup = importPvcsProduction; success = GitOperation.ImportBranchFromPvcs( pvcsCompleteSystemArchiveDetail, promotionGroupName, importPromotionGroup, pvcsPromotionGroupDetailCollection.PromotionGroupNetworkShareName(promotionGroupName), pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName), rootWorkingDirectory, String.Format("Initial PVCS {0} commit to Git {1}", promotionGroupName, pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName)), highLevelIndent, debugProgress); } if (success) { string promotionGroupName = PvcsPromotionGroupDetailCollection.PreProductionPromotionGroupName; bool importPromotionGroup = importPvcsPreProduction; success = GitOperation.ImportBranchFromPvcs( pvcsCompleteSystemArchiveDetail, promotionGroupName, importPromotionGroup, pvcsPromotionGroupDetailCollection.PromotionGroupNetworkShareName(promotionGroupName), pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName), rootWorkingDirectory, String.Format("Initial PVCS {0} commit to Git {1}", promotionGroupName, pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName)), highLevelIndent, debugProgress); } if (success) { string promotionGroupName = PvcsPromotionGroupDetailCollection.UserTestPromotionGroupName; bool importPromotionGroup = importPvcsUserTest; success = GitOperation.ImportBranchFromPvcs( pvcsCompleteSystemArchiveDetail, promotionGroupName, importPromotionGroup, pvcsPromotionGroupDetailCollection.PromotionGroupNetworkShareName(promotionGroupName), pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName), rootWorkingDirectory, String.Format("Initial PVCS {0} commit to Git {1}", promotionGroupName, pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName)), highLevelIndent, debugProgress); } if (success) { string promotionGroupName = PvcsPromotionGroupDetailCollection.SystemTestPromotionGroupName; bool importPromotionGroup = importPvcsSystemTest; success = GitOperation.ImportBranchFromPvcs( pvcsCompleteSystemArchiveDetail, promotionGroupName, importPromotionGroup, pvcsPromotionGroupDetailCollection.PromotionGroupNetworkShareName(promotionGroupName), pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName), rootWorkingDirectory, String.Format("Initial PVCS {0} commit to Git {1}", promotionGroupName, pvcsPromotionGroupDetailCollection.GitBranchName(promotionGroupName)), highLevelIndent, debugProgress); } if (success) { for (int pvcsSystemTestIndex = PvcsPromotionGroupDetailCollection.FirstLowerSystemTestNumber; (success) && (pvcsSystemTestIndex <= PvcsPromotionGroupDetailCollection.LastLowerSystemTestNumber); ++pvcsSystemTestIndex) { string pvcsBranchName = String.Format("{0}{1}", PvcsPromotionGroupDetailCollection.SystemTestPromotionGroupName, pvcsSystemTestIndex); string pvcsShareName = pvcsPromotionGroupDetailCollection.PromotionGroupNetworkShareName(pvcsBranchName); string gitBranchName = pvcsPromotionGroupDetailCollection.GitBranchName(pvcsBranchName); string gitBranchCommitComment = String.Format("Initial PVCS {0} commit to Git {1}", pvcsBranchName, gitBranchName); // Ensure that the new Git Branch comes off Git Integration Test if (!GitOperation.CheckedOutBranchIs(pvcsPromotionGroupDetailCollection.GitBranchName(PvcsPromotionGroupDetailCollection.SystemTestPromotionGroupName), rootWorkingDirectory) ) { // Switch (back) to the Integration Test Branch success = GitOperation.CheckOutBranch(pvcsPromotionGroupDetailCollection.GitBranchName(PvcsPromotionGroupDetailCollection.SystemTestPromotionGroupName), rootWorkingDirectory, highLevelIndent, debugProgress); } if (success) { // It only makes sense to import this Promotion Group if all higher Promotion Groups have been imported // unless the existing Git Repository already contains those higher Promotion Groups bool importPvcsLowerSystemTest = ((importPvcsSystemTest) || (useExistingGitRepository /* Higher Promotion Group must already be present */)) && (!sortedSetPromotionGroupExclude.Contains(pvcsBranchName)); success = GitOperation.ImportBranchFromPvcs(pvcsCompleteSystemArchiveDetail, pvcsBranchName, importPvcsLowerSystemTest, pvcsShareName, gitBranchName, rootWorkingDirectory, gitBranchCommitComment, highLevelIndent, debugProgress); } } // for pvcsSystemTestIndex } if (success) { // Switch to the Integration Test Branch when everything is done success = GitOperation.CheckOutBranch(pvcsPromotionGroupDetailCollection.GitBranchName(PvcsPromotionGroupDetailCollection.SystemTestPromotionGroupName), rootWorkingDirectory, highLevelIndent, debugProgress); } return(success); } // MigratePvcsArchiveSourcestoGit
} // IdentifyFullPromotionGroupReportPath private static int Main(string[] args) { int error = _errorSuccess; if (args.Length >= 1) { // The first argument must be a directory path to the PVCS Archive Reports string fullReportPath = IdentifyFullPromotionGroupReportPath(args[0]); string selectedIssueNumber = null; string gitRepositoryDirectoryPath = null; if (args.Length == 1) { // Assume a Git Repository import from PVCS gitRepositoryDirectoryPath = "d:\\Repos\\Heritage"; Console.WriteLine("Defaulting to import from PVCS to a Git Repository located in \"{0}\"", gitRepositoryDirectoryPath); } else { // More than one argument try { FileAttributes fileAttributes = File.GetAttributes(args[1]); if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory) { // It's an existing directory so assume a Git Repository import from PVCS // into a Repository in that directory gitRepositoryDirectoryPath = args[1]; Console.WriteLine("Importing from PVCS to a Git Repository located in \"{0}\"", gitRepositoryDirectoryPath); } else { // Assume it's an issue number selectedIssueNumber = args[1]; Console.WriteLine("Analysing the status of Issue Number \"{0}\"", selectedIssueNumber); } } catch (FileNotFoundException) { // Assume it's an issue number selectedIssueNumber = args[1]; Console.WriteLine("Analysing the status of Issue Number \"{0}\"", selectedIssueNumber); } } // More than one argument Console.WriteLine(); Console.WriteLine("Promotion Group Report Directory is \"{0}\"", fullReportPath); try { PvcsCompleteSystemArchiveDetail pvcsCompleteSystemArchiveDetail = new PvcsCompleteSystemArchiveDetail( fullReportPath, PvcsCompleteSystemArchiveDetail.PvcsArchiveDetailLevel.AllArchives); pvcsCompleteSystemArchiveDetail.Display(); pvcsCompleteSystemArchiveDetail.GeneratePromotionGroupLists(); if (gitRepositoryDirectoryPath != null) { // Git Repository import from PVCS error = PerformPVCStoGitMigration(pvcsCompleteSystemArchiveDetail, gitRepositoryDirectoryPath); } else { // An Issue Number has been supplied error = PerformIssueAnalysis(pvcsCompleteSystemArchiveDetail, selectedIssueNumber); } } catch (FileNotFoundException exFileNotFound) { Console.WriteLine(); Console.WriteLine("File \"{0}\" was not found", exFileNotFound.Message); error = _errorFileNotFound; } catch (PvcsCompleteSystemArchiveDetail.UnableToOpenFileException exFileCantOpen) { Console.WriteLine(); Console.WriteLine("Unable to open file \"{0}\"", exFileCantOpen.Message); error = _errorFileUnableToBeOpened; } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("Exception : \"{0}\"", ex.ToString()); error = _errorGeneralError; } } // There are arguments return(error); } // Main