diff --git a/move2kube/m2k-func/src/main/java/dev/parodos/SaveTransformationFunction.java b/move2kube/m2k-func/src/main/java/dev/parodos/SaveTransformationFunction.java index 2e76cdad..3853f5df 100644 --- a/move2kube/m2k-func/src/main/java/dev/parodos/SaveTransformationFunction.java +++ b/move2kube/m2k-func/src/main/java/dev/parodos/SaveTransformationFunction.java @@ -60,6 +60,15 @@ public CloudEvent saveTransformation(FunInput input) { input.transformId, input.workspaceId, input.projectId, input.gitRepo, e), SOURCE); } + try { + cleanTransformationOutputFolder(transformationOutputPath); + } catch (IOException e) { + log.error("Error while cleaning extracted transformation output", e); + return EventGenerator.createErrorEvent(input.workflowCallerId, String.format("Cannot clean extracted transformation output of transformation %s" + + " in workspace %s for project %s for repo %s; error: %s", + input.transformId, input.workspaceId, input.projectId, input.gitRepo, e), SOURCE); + } + return pushTransformationToGitRepo(input, transformationOutputPath); } @@ -114,6 +123,20 @@ public void moveTransformationOutputToBranchDirectory(Path transformationOutput, gitDirectory.resolve("Readme.md").toFile()); } + private static void cleanTransformationOutputFolder(Path transformationOutput) throws IOException { + try (var files = Files.walk(transformationOutput)) { + files.forEach(path -> { + if (path.toAbsolutePath().toString().contains(".git") && path.toFile().isDirectory()) { + try { + FileUtils.deleteDirectory(path.toFile()); + } catch (IOException e) { + log.error("Error while deleting .git directory {} of transformation output", path, e); + } + } + }); + } + } + private static void cleanCurrentGitFolder(Path gitDirectory) throws IOException { try (var files = Files.walk(gitDirectory, 1)) { files.forEach(path -> { diff --git a/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/expected_output.zip b/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/expected_output.zip index 70002623..08c77e3f 100644 Binary files a/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/expected_output.zip and b/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/expected_output.zip differ diff --git a/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/transformation_output.zip b/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/transformation_output.zip index be45603a..91c8ba92 100644 Binary files a/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/transformation_output.zip and b/move2kube/m2k-func/src/test/resources/SaveTransformationFunctionTest/references/transformation_output.zip differ