예제 #1
0
        public static int Promote(string pvcsArchivePathAndFilename, string fromPromotionGroup)
        {
            int error = WindowsErrorDefinition.Success;

            List <string> stdout = new List <string>();
            List <string> stderr = new List <string>();

            // Use the "-q" option to suppress questions
            string command = "vpromote -q -g" + fromPromotionGroup + " \"" + pvcsArchivePathAndFilename + "\"";
            bool   success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(),
                                                                command,
                                                                1,
                                                                CommandOperation.DebugProgress.Enabled,
                                                                CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError,
                                                                stdout,
                                                                stderr);

            if (!success)
            {
                Console.WriteLine("PvcsCommandOperation.Promote : Failed to Promote from Promotion Group \"{0}\" in PVCS Archive \"{1}\"",
                                  fromPromotionGroup, pvcsArchivePathAndFilename);
                error = WindowsErrorDefinition.InvalidFunction;
            }

            return(error);
        } // Promote
예제 #2
0
        }                 // GetArchivePromotionGroupNames

        public static int AssignPromotionGroup(string pvcsArchivePathAndFilename, string promotionGroup)
        {
            int error = WindowsErrorDefinition.Success;

            List <string> stdout = new List <string>();
            List <string> stderr = new List <string>();

            // Assign the Promotion Group to the tip revision
            string command = "vcs -q -g" + promotionGroup + " -r \"" + pvcsArchivePathAndFilename + "\"";
            bool   success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(),
                                                                command,
                                                                1,
                                                                CommandOperation.DebugProgress.Enabled,
                                                                CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError,
                                                                stdout,
                                                                stderr);

            if (!success)
            {
                Console.WriteLine("PvcsCommandOperation.AssignPromotionGroup : Failed to assign Promotion Group \"{0}\" to the tip of PVCS Archive \"{1}\"",
                                  promotionGroup, pvcsArchivePathAndFilename);
                error = WindowsErrorDefinition.InvalidFunction;
            }

            return(error);
        }
예제 #3
0
        public static int GetArchivePromotionGroupNames(string pvcsArchivePathAndFilename, ref SortedSet <string> promotionGroupList)
        {
            int error = WindowsErrorDefinition.Success;

            promotionGroupList.Clear();

            List <string> stdout = new List <string>();
            List <string> stderr = new List <string>();

            string command = "vlog -q -bg \"" + pvcsArchivePathAndFilename + "\"";
            bool   success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(),
                                                                command,
                                                                1,
                                                                CommandOperation.DebugProgress.Enabled,
                                                                CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError,
                                                                stdout,
                                                                stderr);

            if (!success)
            {
                Console.WriteLine("PvcsCommandOperation.GetArchivePromotionGroupNames : Failed to get Promotions Groups from PVCS Archive \"{0}\"",
                                  pvcsArchivePathAndFilename);
                error = WindowsErrorDefinition.InvalidFunction;
            }
            else
            {
                // Look for the Promotion Groups in the output from the command

                foreach (string line in stdout)
                {
                    Console.WriteLine("{0}", line);
                    if (line.StartsWith(pvcsArchivePathAndFilename))
                    {
                        // Output line begins with the Archive Name

                        string   promotionGroup = null;
                        string[] words          = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int wordIndex = 0;
                             (promotionGroup == null) &&
                             (wordIndex < words.Count());
                             ++wordIndex
                             )
                        {
                            if (words[wordIndex] == ":")
                            {
                                // The word prior to the colon is the Promotion Group
                                promotionGroup = words[wordIndex - 1];
                                promotionGroupList.Add(promotionGroup);
                            }
                        } // for
                    }     // Output line begins with the Archive Name
                }         // foreach
            }             // Look for the Promotion Groups in the output from the command
            return(error);
        }                 // GetArchivePromotionGroupNames
예제 #4
0
        private static int CheckIn(string pvcsUserId,
                                   string changeDescription,
                                   string promotionGroup,
                                   string pvcsArchivePathAndFilename,
                                   string workfilePathAndName)
        {
            int error = WindowsErrorDefinition.Success;

            string changeDescriptionPathAndFilename = null;

            error = WriteChangeDescriptionFile(changeDescription, out changeDescriptionPathAndFilename);
            if (error == WindowsErrorDefinition.Success)
            {
                // Change description filename exists

                List <string> stdout = new List <string>();
                List <string> stderr = new List <string>();

                string command = "put -y \"-m@"
                                 + changeDescriptionPathAndFilename + "\"";
                if (promotionGroup != null)
                {
                    // Assign a Promotion Group upon CheckIn which will only work for an empty Archive
                    command += " -g" + promotionGroup;
                }
                command += " \""
                           + pvcsArchivePathAndFilename
                           + "(" + workfilePathAndName + ")"
                           + "\"";
                bool success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(),
                                                                  command,
                                                                  1,
                                                                  CommandOperation.DebugProgress.Enabled,
                                                                  CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError,
                                                                  stdout,
                                                                  stderr);
                if (!success)
                {
                    Console.WriteLine("PvcsCommandOperation.CheckIn : Failed to CheckIn revision from \"{0}\" to PVCS Archive \"{1}\"",
                                      workfilePathAndName, pvcsArchivePathAndFilename);
                    error = WindowsErrorDefinition.InvalidFunction;
                }

                // Tidy up the change description file
                File.Delete(changeDescriptionPathAndFilename);
            } // Change description filename exists

            return(error);
        }
예제 #5
0
        static bool RunOverFileList(string command, string streamName, StreamReader fileListStream)
        {
            bool success = true;

            Console.WriteLine();
            Console.WriteLine("Executing command \"{0}\" over files contained in \"{1}\"", command, streamName);
            Console.WriteLine();

            int    lineNumber = 0;
            string filename   = null;

            while ((filename = fileListStream.ReadLine()) != null)
            {
                lineNumber += 1;
                if (!filename.StartsWith("#"))
                {
                    // Not a comment line

                    filename = filename.Trim(new char[] { ' ', '\"' });

                    if (!File.Exists(filename))
                    {
                        Console.WriteLine("File \"{0}\" does not exist", filename);
                    }
                    else
                    {
                        string fullCommand = String.Format("{0} \"{1}\"", command, Path.GetFullPath(filename));

                        string currentDirectory = Directory.GetCurrentDirectory();

                        bool commandSuccess = CommandOperation.RunVisibleCommand(currentDirectory,
                                                                                 fullCommand,
                                                                                 1,
                                                                                 CommandOperation.DebugProgress.Enabled,
                                                                                 CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                        if (!commandSuccess)
                        {
                            Console.WriteLine("Command \"{0}\" failed", fullCommand);
                        }
                        success = commandSuccess && success;
                    }
                } // Not a comment line
            }     // while

            return(success);
        } // RunOverListOfFiles
예제 #6
0
        } // Promote

        public static int ArchiveIsEmpty(string pvcsArchivePathAndFilename, out bool isEmpty)
        {
            int error = WindowsErrorDefinition.Success;

            // Initialise to the Archive being empty
            isEmpty = true;

            List <string> stdout = new List <string>();
            List <string> stderr = new List <string>();

            // Generate just a brief report of the newest revision
            string command = "vlog -q -bn \"" + pvcsArchivePathAndFilename + "\"";
            bool   success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(),
                                                                command, 1,
                                                                CommandOperation.DebugProgress.Enabled,
                                                                CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError,
                                                                stdout,
                                                                stderr);

            if (!success)
            {
                Console.WriteLine("PvcsCommandOperation.ArchiveIsEmpty : Failed to determine empty status of PVCS Archive \"{0}\"",
                                  pvcsArchivePathAndFilename);
                error = WindowsErrorDefinition.GeneralFailure;
            }
            else
            {
                // Look for details about any revision

                for (int lineIndex = 0; (isEmpty) && (lineIndex < stdout.Count); ++lineIndex)
                {
                    string line = stdout[lineIndex];
                    Console.WriteLine("{0}", line);
                    if (line.StartsWith(pvcsArchivePathAndFilename))
                    {
                        // Found a revision so the Archive is not empty
                        isEmpty = false;
                    }
                }
            } // Look for details about any revision

            return(error);
        } // ArchiveIsEmpty
예제 #7
0
        public int CreateFeatureBranch(string gitRepositoryRootPath, string pvcsSharePath)
        {
            int error = WindowsErrorDefinition.Success;

            if (!_commitAttempted)
            {
                // A commit has not yet been attempted

                _commitAttempted = true;

                bool success = false;

                // Git Checkout the Main Branch
                string command = "git checkout " + GitMainBranchName;
                success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                             command,
                                                             1,
                                                             CommandOperation.DebugProgress.Enabled,
                                                             CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                if (!success)
                {
                    Console.WriteLine("CreateFeatureBranch : Unable to checkout main branch \"{0}\"", GitMainBranchName);
                    error = WindowsErrorDefinition.InvalidFunction;
                }
                else
                {
                    if (GitFeatureBranchName != null)
                    {
                        // Create the feature branch
                        command = "git branch " + GitFeatureBranchName;
                        success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                                     command,
                                                                     1,
                                                                     CommandOperation.DebugProgress.Enabled,
                                                                     CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                        if (!success)
                        {
                            Console.WriteLine("CreateFeatureBranch : Unable to create feature branch \"{0}\"", GitFeatureBranchName);
                            error = WindowsErrorDefinition.InvalidData;
                        }
                    }
                }

                if (error == WindowsErrorDefinition.Success)
                {
                    // Checkout the feature branch
                    if (GitFeatureBranchName != null)
                    {
                        command = "git checkout " + GitFeatureBranchName;
                        success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                                     command,
                                                                     1,
                                                                     CommandOperation.DebugProgress.Enabled,
                                                                     CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                        if (!success)
                        {
                            Console.WriteLine("CreateFeatureBranch : Unable to checkout feature branch \"{0}\"", GitFeatureBranchName);
                            error = WindowsErrorDefinition.InvalidFunction;
                        }
                    }
                } // Checkout the feature branch

                if (error == WindowsErrorDefinition.Success)
                {
                    // Copy each new revision into the right place in the repository directory
                    for (int revisionIndex = 0;
                         (error == WindowsErrorDefinition.Success) &&
                         (revisionIndex < PvcsRevisionDetailsLineSortedSet.Count);
                         ++revisionIndex
                         )
                    {
                        string pvcsRevisionDetailsLine = PvcsRevisionDetailsLineSortedSet.ElementAt(revisionIndex);
                        string archiveFilename         = null;
                        if (pvcsRevisionDetailsLine.StartsWith("\""))
                        {
                            // Parse for double quote at the end of the filename
                            int doubleQuoteCharPos = pvcsRevisionDetailsLine.Substring(1).IndexOf("\"");
                            archiveFilename = pvcsRevisionDetailsLine.Substring(1, doubleQuoteCharPos);
                        }
                        else
                        {
                            // Parse for the next space which delimits the filename
                            string[] lineElement = pvcsRevisionDetailsLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            archiveFilename = lineElement[0];
                        }

                        // Get the relative path filename skipping the drive letter, the colon and the first slash
                        string relativePathFilename = archiveFilename.Substring(archiveFilename.IndexOf(":") + 2);

                        string sourcePathAndFilename      = Path.Combine(pvcsSharePath + "\\", relativePathFilename);
                        string destinationPathAndFilename = Path.Combine(gitRepositoryRootPath + "\\", relativePathFilename);
                        try
                        {
                            // Ensure there is a directory in which to put the file i.e. it might be a file that is not usually copied by the utilities e.g. a DLL
                            error = CreateFullDirectoryPathForFile(destinationPathAndFilename);
                            if (error == WindowsErrorDefinition.Success)
                            {
                                // Attempt to copy the file
                                File.Copy(sourcePathAndFilename, destinationPathAndFilename, /*overwrite*/ true);
                                // Ensure the file is not read only
                                FileAttributes fileAttributes = File.GetAttributes(destinationPathAndFilename);
                                if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                                {
                                    fileAttributes = fileAttributes & ~FileAttributes.ReadOnly;
                                    File.SetAttributes(destinationPathAndFilename, fileAttributes);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("CreateFeatureBranch : Exception during copy and attribute management of \"{0}\" to \"{1}\" generated exception {2}",
                                              sourcePathAndFilename,
                                              destinationPathAndFilename,
                                              ex.ToString());
                            error = WindowsErrorDefinition.GeneralFailure;
                        }
                    } // for revisionIndex

                    if (error == WindowsErrorDefinition.Success)
                    {
                        // Display a git status before adding the files
                        command = "git status";
                        success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                                     command,
                                                                     1,
                                                                     CommandOperation.DebugProgress.Enabled,
                                                                     CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                        if (!success)
                        {
                            Console.WriteLine("CreateFeatureBranch : Unable to perform a \"git status\" on repository \"{0}\"", gitRepositoryRootPath);
                            // Only change the error is there isn't already an error
                            if (error == WindowsErrorDefinition.Success)
                            {
                                error = WindowsErrorDefinition.InvalidFunction;
                            }
                        }
                    }
                } // Copy each new revision into the right place in the repository directory

                if (error == WindowsErrorDefinition.Success)
                {
                    // Stage all the changes
                    command = "git add .";
                    success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                                 command,
                                                                 1,
                                                                 CommandOperation.DebugProgress.Enabled,
                                                                 CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                    if (!success)
                    {
                        if (GitFeatureBranchName != null)
                        {
                            Console.WriteLine("CreateFeatureBranch : Unable to stage changes to feature branch \"{0}\"", GitFeatureBranchName);
                        }
                        else
                        {
                            Console.WriteLine("CreateFeatureBranch : Unable to stage changes to main branch \"{0}\"", GitMainBranchName);
                        }
                        error = WindowsErrorDefinition.InvalidFunction;
                    }
                } // Stage all the changes

                if (error == WindowsErrorDefinition.Success)
                {
                    // Commit the changes
                    List <string> stdout   = new List <string>();
                    List <string> stderror = new List <string>();
                    command = "git commit -m \"" + GitFeatureTidyBranchDescription + "\"";
                    success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                                 command,
                                                                 1,
                                                                 CommandOperation.DebugProgress.Enabled,
                                                                 CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError,
                                                                 stdout,
                                                                 stderror);
                    if (!success)
                    {
                        // Check whether there really was anything to commit
                        bool sourcesToCommit = true;
                        for (int lineIndex = 0; (sourcesToCommit) && (lineIndex < stdout.Count); ++lineIndex)
                        {
                            sourcesToCommit = !(stdout[lineIndex].IndexOf("nothing to commit") >= 0);
                        }
                        if (sourcesToCommit)
                        {
                            Console.WriteLine("CreateFeatureBranch : Unable to stage changes to feature branch \"{0}\"", GitCurrentBranchName);
                            error = WindowsErrorDefinition.InvalidFunction;
                        }
                        else
                        {
                            Console.WriteLine("CreateFeatureBranch : No source differences were detected for branch \"{0}\" - commit abandoned", GitCurrentBranchName);
                            error = WindowsErrorDefinition.Success;
                        }
                    }
                } // Commit the changes

                // Display a final git status
                command = "git status";
                success = CommandOperation.RunVisibleCommand(gitRepositoryRootPath,
                                                             command,
                                                             1,
                                                             CommandOperation.DebugProgress.Enabled,
                                                             CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError);
                if (!success)
                {
                    Console.WriteLine("CreateFeatureBranch : Unable to perform a final \"git status\" on repository \"{0}\"", gitRepositoryRootPath);
                    // Only change the error is there isn't already an error
                    if (error == WindowsErrorDefinition.Success)
                    {
                        error = WindowsErrorDefinition.InvalidFunction;
                    }
                }
            } // A commit has not yet been attempted

            return(error);
        } // CreateFeatureBranch