Index: E:/Source/OpenSource/ccnet-svn-trunk/project/core/sourcecontrol/Cvs.cs =================================================================== --- E:/Source/OpenSource/ccnet-svn-trunk/project/core/sourcecontrol/Cvs.cs (revision 3607) +++ E:/Source/OpenSource/ccnet-svn-trunk/project/core/sourcecontrol/Cvs.cs (working copy) @@ -98,8 +98,18 @@ private bool DoesCvsDirectoryExist(IIntegrationResult result) { - string cvsDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), "CVS"); - return fileSystem.DirectoryExists(cvsDirectory); + string workingDirectory = result.BaseFromWorkingDirectory(WorkingDirectory); + + bool exists = fileSystem.DirectoryExists(workingDirectory); + + if (exists) + { + string cvsDirectory = Path.Combine(workingDirectory, "CVS"); + + exists = fileSystem.DirectoryExists(cvsDirectory); + } + + return exists; } private void CheckoutSource(IIntegrationResult result) @@ -120,7 +130,7 @@ builder.AddArgument("-r", Branch); builder.AddArgument("-d", result.BaseFromWorkingDirectory(WorkingDirectory)); builder.AddArgument(Module); - return NewProcessInfoWithArgs(result, builder.ToString()); + return NewProcessInfoWithArgs(result, builder.ToString(), true); } private void UpdateSource(IIntegrationResult result) @@ -136,12 +146,12 @@ builder.AppendIf(CleanCopy, "-C"); builder.AddArgument("-r", Branch); - return NewProcessInfoWithArgs(result, builder.ToString()); + return NewProcessInfoWithArgs(result, builder.ToString(), false); } private ProcessInfo CreateLogProcessInfo(IIntegrationResult from) { - return NewProcessInfoWithArgs(from, BuildLogProcessInfoArgs(from.StartTime)); + return NewProcessInfoWithArgs(from, BuildLogProcessInfoArgs(from.StartTime), false); } private ProcessInfo NewLabelProcessInfo(IIntegrationResult result) @@ -149,7 +159,7 @@ ProcessArgumentBuilder buffer = new ProcessArgumentBuilder(); AppendCvsRoot(buffer); buffer.AppendArgument(string.Format("tag {0}{1}", TagPrefix, ConvertIllegalCharactersInLabel(result))); - return NewProcessInfoWithArgs(result, buffer.ToString()); + return NewProcessInfoWithArgs(result, buffer.ToString(), false); } private string ConvertIllegalCharactersInLabel(IIntegrationResult result) @@ -157,9 +167,16 @@ return Regex.Replace(result.Label, @"\.", "_"); } - private ProcessInfo NewProcessInfoWithArgs(IIntegrationResult result, string args) + private ProcessInfo NewProcessInfoWithArgs(IIntegrationResult result, string args, bool allowCreateWorkingDirectory) { - return new ProcessInfo(Executable, args, result.BaseFromWorkingDirectory(WorkingDirectory)); + string workingDirectory = result.BaseFromWorkingDirectory(WorkingDirectory); + + if (allowCreateWorkingDirectory && !fileSystem.DirectoryExists(workingDirectory)) + { + fileSystem.CreateDirectory(workingDirectory); + } + + return new ProcessInfo(Executable, args, workingDirectory); } // cvs [-d :ext:mycvsserver:/cvsroot/myrepo] -q log -N "-d>2004-12-24 12:00:00 GMT" -rmy_branch (with branch) Index: E:/Source/OpenSource/ccnet-svn-trunk/project/UnitTests/Core/SourceControl/CvsTest.cs =================================================================== --- E:/Source/OpenSource/ccnet-svn-trunk/project/UnitTests/Core/SourceControl/CvsTest.cs (revision 3607) +++ E:/Source/OpenSource/ccnet-svn-trunk/project/UnitTests/Core/SourceControl/CvsTest.cs (working copy) @@ -149,7 +149,7 @@ public void VerifyProcessInfoForGetSource() { ExpectToExecuteArguments(@"-q update -d -P -C"); - ExpectCvsDirectoryExists(true); + ExpectCvsDirectoryExists(true, true); cvs.AutoGetSource = true; cvs.CleanCopy = true; // set as default @@ -161,7 +161,7 @@ public void VerifyProcessInfoForGetSourceOnBranch() { ExpectToExecuteArguments(@"-q update -d -P -C -r branch"); - ExpectCvsDirectoryExists(true); + ExpectCvsDirectoryExists(true, true); cvs.AutoGetSource = true; cvs.Branch = "branch"; @@ -174,7 +174,8 @@ public void ShouldCheckoutInsteadOfUpdateIfCVSFoldersDoNotExist() { ExpectToExecuteArguments(@"-d :pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet -q checkout -R -P -d c:\source\ ccnet"); - ExpectCvsDirectoryExists(false); + ExpectCvsDirectoryExists(true, false); + CreateWorkingDirectoryIfDoesntExist(true); cvs.CvsRoot = ":pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet"; cvs.Module = "ccnet"; @@ -184,10 +185,24 @@ } [Test] + public void ShouldCheckoutInsteadOfUpdateIfWorkingDirectoryDoesNotExist() + { + ExpectToExecuteArguments(@"-d :pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet -q checkout -R -P -d c:\source\ ccnet"); + ExpectCvsDirectoryExists(false, false); + CreateWorkingDirectoryIfDoesntExist(false); + + cvs.CvsRoot = ":pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet"; + cvs.Module = "ccnet"; + cvs.AutoGetSource = true; + cvs.WorkingDirectory = DefaultWorkingDirectory; + cvs.GetSource(IntegrationResult()); + } + [Test] public void ShouldCheckoutFromBranchInsteadOfUpdateIfCVSFoldersDoNotExist() { ExpectToExecuteArguments(@"-d :pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet -q checkout -R -P -r branch -d c:\source\ ccnet"); - ExpectCvsDirectoryExists(false); + ExpectCvsDirectoryExists(true, false); + CreateWorkingDirectoryIfDoesntExist(true); cvs.CvsRoot = ":pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet"; cvs.Module = "ccnet"; @@ -197,20 +212,45 @@ cvs.GetSource(IntegrationResult()); } + [Test] + public void ShouldCheckoutFromBranchInsteadOfUpdateIfWorkingDirectoryDoesNotExist() + { + ExpectToExecuteArguments(@"-d :pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet -q checkout -R -P -r branch -d c:\source\ ccnet"); + ExpectCvsDirectoryExists(false, false); + CreateWorkingDirectoryIfDoesntExist(false); + + cvs.CvsRoot = ":pserver:anonymous@ccnet.cvs.sourceforge.net:/cvsroot/ccnet"; + cvs.Module = "ccnet"; + cvs.AutoGetSource = true; + cvs.Branch = "branch"; + cvs.WorkingDirectory = DefaultWorkingDirectory; + cvs.GetSource(IntegrationResult()); + } + [Test, ExpectedException(typeof(ConfigurationException))] public void ShouldThrowExceptionIfCVSRootIsNotSpecifiedAndCVSFoldersDoNotExist() { - ExpectCvsDirectoryExists(false); + ExpectCvsDirectoryExists(true, false); cvs.AutoGetSource = true; cvs.GetSource(IntegrationResult()); } + [Test, ExpectedException(typeof(ConfigurationException))] + public void ShouldThrowExceptionIfCVSRootIsNotSpecifiedAndWorkingDirectoryDoesNotExist() + { + ExpectCvsDirectoryExists(false, false); + + cvs.AutoGetSource = true; + cvs.GetSource(IntegrationResult()); + } + + [Test] public void ShouldUseCvsRootWithGetSource() { ExpectToExecuteArguments(@"-d myCvsRoot -q update -d -P -C"); - ExpectCvsDirectoryExists(true); + ExpectCvsDirectoryExists(true, true); cvs.AutoGetSource = true; cvs.CvsRoot = "myCvsRoot"; @@ -231,7 +271,7 @@ { DefaultWorkingDirectory = @"c:\devl\myproject"; ExpectToExecuteArguments(@"-q update -d -P -C"); - ExpectCvsDirectoryExists(true); + ExpectCvsDirectoryExists(true, true); cvs.AutoGetSource = true; cvs.CleanCopy = true; // set as default @@ -319,9 +359,24 @@ mockHistoryParser.ExpectAndReturn("Parse", modifications, new IsAnything(), from, to); } - private void ExpectCvsDirectoryExists(bool doesCvsDirectoryExist) + private void ExpectCvsDirectoryExists(bool doesWorkingDirectoryExist, bool doesCvsDirectoryExist) { - mockFileSystem.ExpectAndReturn("DirectoryExists", doesCvsDirectoryExist, Path.Combine(DefaultWorkingDirectory, "CVS")); + mockFileSystem.ExpectAndReturn("DirectoryExists", doesWorkingDirectoryExist, DefaultWorkingDirectory); + + if (doesWorkingDirectoryExist) + { + mockFileSystem.ExpectAndReturn("DirectoryExists", doesCvsDirectoryExist, Path.Combine(DefaultWorkingDirectory, "CVS")); + } } + + private void CreateWorkingDirectoryIfDoesntExist(bool doesWorkingDirectoryExist) + { + mockFileSystem.ExpectAndReturn("DirectoryExists", doesWorkingDirectoryExist, DefaultWorkingDirectory); + + if (!doesWorkingDirectoryExist) + { + mockFileSystem.Expect("CreateDirectory", DefaultWorkingDirectory); + } + } } } \ No newline at end of file