From bfeab838f21cc956ee5e5f86de5074f0121ba2e5 Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Thu, 30 Mar 2023 15:53:10 +0530 Subject: [PATCH] fix: do not create files for empty body of queries in the git repo (#21774) We're currently creating an empty txt file even when there is no body for an API call. For eg, in GET API calls. We should check whether there is content in a file before creating the file. Fixes #21683 --- .../main/java/com/appsmith/git/helpers/FileUtilsImpl.java | 2 +- .../main/java/com/appsmith/git/service/GitExecutorImpl.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java index 78dca2bf93..81503ebba4 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java @@ -414,7 +414,7 @@ public class FileUtilsImpl implements FileInterface { Files.createDirectories(path); // Write the user written query to .txt file to make conflict handling easier // Body will be null if the action is of type JS - if (body != null) { + if (StringUtils.hasLength(body)) { Path bodyPath = path.resolve(resourceName + CommonConstants.TEXT_FILE_EXTENSION); writeStringToFile(body, bodyPath); } diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java index 1a1bedefe9..0dacf5e2c8 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java @@ -494,8 +494,9 @@ public class GitExecutorImpl implements GitExecutor { for (String x : modifiedAssets) { if (x.contains(CommonConstants.CANVAS)) { modifiedPages++; - } else if (x.contains(GitDirectories.ACTION_DIRECTORY + "/") && !x.endsWith(".json")) { - String queryName = x.substring(x.lastIndexOf("/") + 1); + } else if (x.contains(GitDirectories.ACTION_DIRECTORY + "/")) { + String queryName = x.split(GitDirectories.ACTION_DIRECTORY + "/")[1]; + queryName = queryName.substring(0, queryName.indexOf("/")); String pageName = x.split("/")[1]; if (!queriesModified.contains(pageName + queryName)) { queriesModified.add(pageName + queryName);