diff --git a/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs b/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs index 128ba207b..86a525bad 100644 --- a/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs +++ b/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs @@ -52,4 +52,20 @@ public void CreateRepositoryConfig_UsesUsernameAndPasswordFromLoadedProperties() httpsGitConnection.Password.Should().Be("pwd-from-file"); httpsGitConnection.Uri.Value.Should().Be(new Uri("https://example.invalid/repo.git")); } + + [Test] + public void CreateRepositoryConfig_WhenDestinationPathIsMissing_DefaultsToEmptyString() + { + //Octopus server removes variables containing empty strings, thus a missing property should default to an empty string. + //Thus the TargetRepositorydestinationPath could validly be missing from the variable set, in such case, it should default to an empty string. + loader.Load() + .Returns(new CommitToGitCustomPropertiesDto(new UsernamePasswordGitCredentialDto("MyCred", "https://example.invalid/repo.git", "user", "pwd"))); + variables.Get(SpecialVariables.Action.Git.DestinationPath).Returns((string)null); + + var deployment = new RunningDeployment(null, variables); + + var config = factory.CreateRepositoryConfig(deployment, loader); + + config.DestinationPath.Should().Be(string.Empty); + } } diff --git a/source/Calamari/Commands/CommitToGitCommand.cs b/source/Calamari/Commands/CommitToGitCommand.cs index 53153b00f..30f7722fb 100644 --- a/source/Calamari/Commands/CommitToGitCommand.cs +++ b/source/Calamari/Commands/CommitToGitCommand.cs @@ -165,7 +165,7 @@ IEnumerable BuildSubstituteAndCopyInputFilesConventions( [ new DelegateInstallConvention(d => { - var destinationPath = repositoryConfig!.DestinationPath ?? string.Empty; + var destinationPath = repositoryConfig.DestinationPath; var destBase = Path.Combine(clonedRepository.WorkingDirectory, destinationPath); foreach (var package in metadataParser.GetPackageDependenciesForCopying(d)) diff --git a/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs b/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs index 30b3f2da9..99fe56229 100644 --- a/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs +++ b/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs @@ -43,9 +43,10 @@ public CommitToGitRepositorySettings CreateRepositoryConfig(RunningDeployment de _ => throw new NotSupportedException($"An unrecognised credential type '{properties.GitCredential.GetType().Name}' was found for '{uriAsString}'"), }; + //Note: Octopus server removes variables containing empty strings, thus a missing property should default to an empty string. return new CommitToGitRepositorySettings(connection, commitParameters, - variables.Get(SpecialVariables.Action.Git.DestinationPath)); + variables.Get(SpecialVariables.Action.Git.DestinationPath) ?? string.Empty); } string EvaluateNonsensitiveExpression(string expression)