Exemplo n.º 1
0
        } // 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
Exemplo n.º 2
0
        private static string CreateGitArguments(
            this GitOperation operation,
            string argument = null)
        {
            switch (operation)
            {
            case GitOperation.CHECKOUT_BRANCH:
                if (string.IsNullOrWhiteSpace(argument))
                {
                    throw new InvalidOperationException(
                              "Cannot checkout a branch without specifying a branch name.");
                }

                return($"checkout {argument}");

            case GitOperation.CHECKOUT_FILES:
                return("checkout .");

            case GitOperation.CLEAN:
                return("clean -fd");

            case GitOperation.FETCH:
                return("fetch");

            case GitOperation.PULL:
                return("pull");

            default:
                throw new NotImplementedException();
            }
        }
 private static IList <CommandStart> GenerateGitCommandList(Config config, GitOperation operation, string argument = null)
 {
     return(new List <CommandStart>()
     {
         config.CreateGitCommandStart(operation, argument)
     });
 }
Exemplo n.º 4
0
        public static CommandStart CreateGitCommandStart(
            this Config config,
            GitOperation operation,
            string argument = null)
        {
            var arguments = operation.CreateGitArguments(argument);
            var command   = new Command()
            {
                CommandName = "git",
                Arguments   = arguments
            };

            var startInfo = new ProcessStartInfo()
            {
                FileName         = config.GitPath,
                Arguments        = arguments,
                WorkingDirectory = config.RepoDir
            };

            return(new CommandStart(command, startInfo));
        }
Exemplo n.º 5
0
        } // MigratePvcsArchiveSourcestoGit

        static bool CreateRepositoryAndPerformInitialCommit(string rootWorkingDirectory,
                                                            int indent,
                                                            CommandOperation.DebugProgress debugProgress)
        {
            bool success = false;

            DirectoryInfo directoryInfo = new DirectoryInfo(rootWorkingDirectory);

            if (!directoryInfo.Exists)
            {
                Console.WriteLine();
                Console.WriteLine("{0}Local Git Repository Directory \"{1}\" does not exist",
                                  ConsoleDisplay.Indent(indent), rootWorkingDirectory);
                success = false;
            }
            else
            {
                // Root working directory exists

                Console.WriteLine();
                Console.WriteLine("{0}Local Git Repository Directory is \"{1}\"",
                                  ConsoleDisplay.Indent(indent), rootWorkingDirectory);

                // Create the Git Repository
                success = GitOperation.Init(rootWorkingDirectory, indent, debugProgress);
                if (success)
                {
                    // Repository was initialised successfully

                    const string readMeFilename       = "readme.txt";
                    const string initialCommitMessage = "Initial commit to create Branch master";

                    string readMeFileFullPathAndFilename = Path.Combine(rootWorkingDirectory, readMeFilename);

                    try
                    {
                        using (System.IO.StreamWriter readMeFile = new System.IO.StreamWriter(readMeFileFullPathAndFilename, true))
                        {
                            string[] readMeLines = { "Heritage Source Git Repository",
                                                     "Contains all the sources imported from the PVCS Change Control System" };
                            foreach (string readMeLine in readMeLines)
                            {
                                readMeFile.WriteLine(readMeLine);
                            }

                            DateTime datetimeNow = DateTime.Now;
                            readMeFile.WriteLine("Git Repository created {0} {1}", datetimeNow.ToString("D"), datetimeNow.ToString("T"));
                        }
                        success = true;
                    }
                    catch (Exception eek)
                    {
                        success = false;
                        Console.WriteLine("Exception writing file \"{0}\" = {1}", readMeFileFullPathAndFilename, eek.ToString());
                    }

                    if (success)
                    {
                        // Add the file to the Repo
                        success = GitOperation.Add(rootWorkingDirectory, readMeFilename, indent, debugProgress);
                        if (success)
                        {
                            success = GitOperation.Commit(initialCommitMessage, rootWorkingDirectory, indent, debugProgress);
                            if (success)
                            {
                                Console.WriteLine();
                                Console.WriteLine("Committed initial file \"{0}\"", readMeFileFullPathAndFilename);
                            }
                        }
                    }
                } // Repository was initialised successfully
            }     // Root working directory exists

            return(success);
        } // CreateRepositoryAndPerformInitialCommit
Exemplo n.º 6
0
        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
Exemplo n.º 7
0
        public bool GitAdd(string sourceRootDirectory, string rootWorkingDirectory, int indent, CommandOperation.DebugProgress debugProgress)
        {
            bool success = false;

            // PVCS Archive Names start with the Archive Drive which ends at the first slash
            int firstSlashIndex = Name.IndexOf('\\');

            if (firstSlashIndex >= 0)
            {
                // Found start of relative path
                string relativePathAndFilename = Name.Substring(firstSlashIndex + 1);

                string sourceFileFullPath = Path.Combine(sourceRootDirectory, relativePathAndFilename);

                if (!File.Exists(sourceFileFullPath))
                {
                    Console.WriteLine("{0}*** Source File \"{1}\" does not exist", ConsoleDisplay.Indent(indent), sourceFileFullPath);
                }
                else
                {
                    // Source File exists

                    string workfileFullPath = Path.Combine(rootWorkingDirectory, relativePathAndFilename);

                    if (debugProgress == CommandOperation.DebugProgress.Enabled)
                    {
                        Console.WriteLine("{0}Archive Path \"{1}\" working path resolves to \"{2}\"",
                                          ConsoleDisplay.Indent(indent),
                                          Name,
                                          workfileFullPath);
                    }

                    // Find the last slash to pass to xcopy so that it works with a destination directory
                    int    lastSlashIndex    = workfileFullPath.LastIndexOf('\\');
                    string workfileDirectory = workfileFullPath.Substring(0, lastSlashIndex + 1);

                    string fullWorkfilePathAndFilename = Path.Combine(workfileDirectory, this.FileName);
                    // Determine the length of the filename without the drive specifier
                    firstSlashIndex = fullWorkfilePathAndFilename.IndexOf('\\');
                    string    fullRootRelativeWorkfilePathAndFilename = fullWorkfilePathAndFilename.Substring(firstSlashIndex + 1);
                    const int longPathAndFilenameLength = 240;
                    if (fullRootRelativeWorkfilePathAndFilename.Length > longPathAndFilenameLength)
                    {
                        Console.WriteLine("{0}+++ Warning: \"{1}\" workfile name is {2} characters long which is longer than {3} characters",
                                          ConsoleDisplay.Indent(indent),
                                          fullWorkfilePathAndFilename,
                                          fullWorkfilePathAndFilename.Length,
                                          longPathAndFilenameLength);
                    }

                    string command = String.Format("xcopy \"{0}\" \"{1}\" /v/f/y", sourceFileFullPath, workfileDirectory);

                    // Copy the file into the working directorBy which will cause the file to be "Staged"
                    if (CommandOperation.RunCommand(rootWorkingDirectory, command, debugProgress, CommandOperation.CommandOutputDisplayType.None))
                    {
                        DateTime dateTimeNow = DateTime.Now;
                        Console.WriteLine("{0}{1} \"{2}\" -> \"{3}\"",
                                          ConsoleDisplay.Indent(indent),
                                          dateTimeNow.ToString("yyyy-MM-dd-HH:mm:ss"),
                                          sourceFileFullPath,
                                          workfileDirectory);

                        // Add the file to the Repo
                        success = GitOperation.Add(rootWorkingDirectory, WorkfileRelativePath(rootWorkingDirectory), indent, debugProgress);
                    }
                    else
                    {
                        DateTime dateTimeNow = DateTime.Now;
                        Console.WriteLine("{0} *** {1} Failed \"{2}\" -> \"{3}\"",
                                          ConsoleDisplay.Indent(indent),
                                          dateTimeNow.ToString("yyyy-MM-dd-HH:mm:ss"),
                                          sourceFileFullPath,
                                          workfileDirectory);
                    }
                } // Source File exists
            }     // Found start of relative path

            return(success);
        } // GitAdd