Esempio n. 1
0
        /// <summary>
        /// Create the command object that will be used to act on the repository.
        /// </summary>
        /// <returns>The command object that will be used to act on the
        ///     repository.</returns>
        /// <exception cref="Exception">TODO: Make a more specific exception</exception>
        /// <exception cref="NotImplementedException">If the command argument
        ///     is not implemented currently.  TODO: Implement the argument.</exception>
        public override ICommand CreateCommand()
        {
            ICSharpCode.SharpCvsLib.Commands.CommitCommand2 commitCommand;
            try {
                this.ParseOptions(this.unparsedOptions);
                string cvsFolder = Path.Combine(Environment.CurrentDirectory, "CVS");
                // set properties before creation of CommitCommand2
                // Open the Repository file in the CVS directory
                Manager    manager    = new Manager(cvsFolder);
                Repository repository = null;
                Root       root       = null;
                try {
                    repository = manager.FetchRepository(cvsFolder);
                } catch (CvsFileNotFoundException e) {
                    ConsoleMain.ExitProgram("Not a valid cvs repository.", e);
                }
                try {
                    root = manager.FetchRoot(cvsFolder);
                    if (null == this.cvsRoot)
                    {
                        this.cvsRoot = new CvsRoot(root.FileContents);
                    }
                } catch (CvsFileNotFoundException e) {
                    ConsoleMain.ExitProgram("Not a valid cvs repository.", e);
                }
                // If this fails error out and the user
                //    is not in a CVS repository directory tree.
                CurrentWorkingDirectory = new WorkingDirectory(this.cvsRoot,
                                                               cvsFolder, repository.FileContents);
                if (revision != null)
                {
                    this.CurrentWorkingDirectory.Revision = revision;
                }

                ArrayList files = new ArrayList();
                if (fileNames == null || fileNames == string.Empty)
                {
                    this.GetFilesRecursive((new DirectoryInfo(cvsFolder)).Parent, files);
                }
                else
                {
                    DirectoryInfo cvsFolderInfo = new DirectoryInfo(cvsFolder);
                    files = new ArrayList(cvsFolderInfo.GetFiles(fileNames));
                }

                CurrentWorkingDirectory.Folders = GetFoldersToCommit(files);
                // Create new CommitCommand2 object
                commitCommand = new ICSharpCode.SharpCvsLib.Commands.CommitCommand2(
                    this.CurrentWorkingDirectory);

                // set public properties on the commit command
                if (message != null)
                {
                    commitCommand.LogMessage = message;
                }

                return(commitCommand);
            } catch (CvsFileNotFoundException e) {
                ConsoleMain.ExitProgram(string.Format("No CVS folder found in path {0}",
                                                      Environment.CurrentDirectory), e);
                return(null);
            } catch (Exception e) {
                LOGGER.Error(e);
                throw e;
            }
        }
Esempio n. 2
0
        public void AddFilesTest()
        {
            this.CheckoutTestModule();

            String modulePath = Path.Combine(this.GetTempPath(),
                                             this.Settings.Config.Module);

            String[] files = Directory.GetFiles(modulePath, "*.txt");

            Assert.IsTrue(files.Length > 0);
            ArrayList copiedFiles = new ArrayList();

            foreach (String file in files)
            {
                LOGGER.Debug("file=[" + file + "]");
                // Remove the .txt when everything works, giving me bugs...
                String newFileName = Guid.NewGuid().ToString() + ".txt";
                String fullPath    = Path.Combine(modulePath, newFileName);
                File.Copy(file, fullPath);
                copiedFiles.Add(fullPath);
            }

            CvsRoot          root    = new CvsRoot(this.Settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.Settings.Config.LocalPath,
                                     this.Settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection);

            AddCommand command = new AddCommand(working);

            //command.Folders = this.GetFolders(modulePath);
            command.Folders = this.GetFoldersToAdd(copiedFiles);

            Assert.IsTrue(command.Folders.Count > 0);
            LOGGER.Debug("folders count=[" + command.Folders.Count + "]");
            foreach (DictionaryEntry folderDic in command.Folders)
            {
                Folder folder = (Folder)folderDic.Value;
                LOGGER.Debug("folder=[" + folder.ToString() + "]");
                LOGGER.Debug("entries count=[" + folder.Entries.Count + "]");
            }
            Assert.IsNotNull(command);

            try {
                connection.Connect(working, this.Settings.Config.ValidPassword);
            } catch (AuthenticationException) {
                // should not get here.
                Assert.IsTrue(true);
            }

            command.Execute(connection);
            connection.Close();

            try {
                connection.Connect(working, this.Settings.Config.ValidPassword);
            } catch (AuthenticationException) {
                Assert.IsTrue(true);
            }
            CommitCommand2 commitCommand = new CommitCommand2(working);

            working.Folders          = command.Folders;
            commitCommand.LogMessage = "AddCommandTest";
            commitCommand.Execute(connection);
            connection.Close();

            Manager manager = new Manager(working.WorkingPath);
            Entries entries = manager.FetchEntries(Path.Combine(modulePath, "Entries"));

            foreach (String addedFile in copiedFiles)
            {
                Assert.IsTrue(entries.Contains(Path.Combine(modulePath, addedFile)));
            }
        }
        /// <summary>
        /// Create the command object that will be used to act on the repository.
        /// </summary>
        /// <returns>The command object that will be used to act on the
        ///     repository.</returns>
        /// <exception cref="Exception">TODO: Make a more specific exception</exception>
        /// <exception cref="NotImplementedException">If the command argument
        ///     is not implemented currently.  TODO: Implement the argument.</exception>
        public override ICommand CreateCommand () {
            ICSharpCode.SharpCvsLib.Commands.CommitCommand2 commitCommand;
            try {
                this.ParseOptions(this.unparsedOptions);
                string cvsFolder = Path.Combine(Environment.CurrentDirectory, "CVS");
                // set properties before creation of CommitCommand2
                // Open the Repository file in the CVS directory
                Manager manager = new Manager(cvsFolder);
                Repository repository = null;
                Root root = null;
                try {
                    repository = manager.FetchRepository(cvsFolder); 
                } catch (CvsFileNotFoundException e) {
                    ConsoleMain.ExitProgram("Not a valid cvs repository.", e);
                }
                try {
                    root = manager.FetchRoot(cvsFolder);
                    if (null == this.cvsRoot) {
                        this.cvsRoot = new CvsRoot(root.FileContents);
                    }
                } catch (CvsFileNotFoundException e) {
                    ConsoleMain.ExitProgram("Not a valid cvs repository.", e);
                }
                // If this fails error out and the user
                //    is not in a CVS repository directory tree.
                CurrentWorkingDirectory = new WorkingDirectory( this.cvsRoot,
                    cvsFolder, repository.FileContents);
                if (revision != null) {
                    this.CurrentWorkingDirectory.Revision = revision;
                }

                ArrayList files = new ArrayList();
                if (fileNames == null || fileNames == string.Empty) {
                    this.GetFilesRecursive((new DirectoryInfo(cvsFolder)).Parent, files);
                } else {
                    DirectoryInfo cvsFolderInfo = new DirectoryInfo(cvsFolder);
                    files = new ArrayList(cvsFolderInfo.GetFiles(fileNames));
                }

                CurrentWorkingDirectory.Folders = GetFoldersToCommit(files);
                // Create new CommitCommand2 object
                commitCommand = new ICSharpCode.SharpCvsLib.Commands.CommitCommand2(
                    this.CurrentWorkingDirectory );

                // set public properties on the commit command
                if (message != null) {
                    commitCommand.LogMessage = message;
                }
         
                return commitCommand;
            } catch (CvsFileNotFoundException e) {
                ConsoleMain.ExitProgram(string.Format("No CVS folder found in path {0}",
                    Environment.CurrentDirectory), e);
                return null;
            } catch (Exception e) {
                LOGGER.Error (e);
                throw e;
            }
        }