From 27b83e388b78014fdf08885e59073eb6a047e977 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 27 May 2026 09:35:35 +1000 Subject: [PATCH 1/4] handle missing destination Path --- .../CommitToGit/CommitToGitConfigFactoryTests.cs | 14 ++++++++++++++ source/Calamari/Commands/CommitToGitCommand.cs | 2 +- .../CommitToGit/CommitToGitConfigFactory.cs | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs b/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs index 128ba207b..71625dffd 100644 --- a/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs +++ b/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs @@ -52,4 +52,18 @@ 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() + { + 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..434ff9a4c 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..88a1a88aa 100644 --- a/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs +++ b/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs @@ -45,7 +45,7 @@ public CommitToGitRepositorySettings CreateRepositoryConfig(RunningDeployment de return new CommitToGitRepositorySettings(connection, commitParameters, - variables.Get(SpecialVariables.Action.Git.DestinationPath)); + variables.Get(SpecialVariables.Action.Git.DestinationPath) ?? string.Empty); } string EvaluateNonsensitiveExpression(string expression) From 68ac641b5865ac9a2ff3f8038ae8185820355404 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 27 May 2026 09:56:04 +1000 Subject: [PATCH 2/4] this looks better --- source/Calamari/Commands/CommitToGitCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Calamari/Commands/CommitToGitCommand.cs b/source/Calamari/Commands/CommitToGitCommand.cs index 434ff9a4c..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; + var destinationPath = repositoryConfig.DestinationPath; var destBase = Path.Combine(clonedRepository.WorkingDirectory, destinationPath); foreach (var package in metadataParser.GetPackageDependenciesForCopying(d)) From 1ef084dc58710955b310a8738a37a0b41073d520 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 27 May 2026 10:02:18 +1000 Subject: [PATCH 3/4] add comments --- .../Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs | 2 ++ source/Calamari/CommitToGit/CommitToGitConfigFactory.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs b/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs index 71625dffd..86a525bad 100644 --- a/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs +++ b/source/Calamari.Tests/CommitToGit/CommitToGitConfigFactoryTests.cs @@ -56,6 +56,8 @@ public void CreateRepositoryConfig_UsesUsernameAndPasswordFromLoadedProperties() [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); diff --git a/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs b/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs index 88a1a88aa..99fe56229 100644 --- a/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs +++ b/source/Calamari/CommitToGit/CommitToGitConfigFactory.cs @@ -43,6 +43,7 @@ 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) ?? string.Empty); From 5fb7867a4a1d3d5bc3afdf9cf7f3550aeafe0e0e Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 27 May 2026 13:27:03 +1000 Subject: [PATCH 4/4] add verbose logging to the file copy --- source/Calamari/Commands/CommitToGitCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Calamari/Commands/CommitToGitCommand.cs b/source/Calamari/Commands/CommitToGitCommand.cs index 30f7722fb..a2fbb2ded 100644 --- a/source/Calamari/Commands/CommitToGitCommand.cs +++ b/source/Calamari/Commands/CommitToGitCommand.cs @@ -253,6 +253,7 @@ string CopyDependencyToRepository(RunningDeployment deployment, RepositoryWrappe foreach (var (sourceFile, destRelativePath) in filesToTarget) { var destFile = Path.Combine(depDestBase, destRelativePath); + log.Verbose($"Copying '{Path.GetRelativePath(deployment.CurrentDirectory, sourceFile)}' -> '{Path.GetRelativePath(clonedRepository.WorkingDirectory, destFile)}'"); fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(destFile)!); fileSystem.CopyFile(sourceFile, destFile); }