Пример #1
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
Пример #2
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