From 3212d738caf2aabd2267d6f0fa3e5c7a722c9da4 Mon Sep 17 00:00:00 2001 From: Diljit Date: Mon, 5 May 2025 09:40:45 +0530 Subject: [PATCH] chore: remove extra reset in auto-commit (#40405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.All" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 9c004ca65ac0842a24dea725dde539c176a6dba6 > Cypress dashboard. > Tags: `@tag.All` > Spec: >
Wed, 30 Apr 2025 05:08:47 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **New Features** - Introduced a new feature flag to control the enablement of updated Git API contracts. - **Enhancements** - Improved the logic for reconstructing pages from Git repositories, allowing for more granular control based on feature flags. - Enhanced compatibility with future Git-related optimizations by adding support for additional parameters in page reconstruction operations. --- .../com/appsmith/git/files/FileUtilsCEImpl.java | 14 ++++++++++++-- .../appsmith/external/enums/FeatureFlagEnum.java | 1 + .../com/appsmith/external/git/FileInterface.java | 7 ++++++- .../server/helpers/ce/CommonGitFileUtilsCE.java | 13 +++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java index e36eea10f8..2aa964d5c4 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java @@ -1268,7 +1268,12 @@ public class FileUtilsCEImpl implements FileInterface { @Override public Mono reconstructPageFromGitRepo( - String pageName, String branchName, Path baseRepoSuffixPath, Boolean resetToLastCommitRequired) { + String pageName, + String branchName, + Path baseRepoSuffixPath, + Boolean resetToLastCommitRequired, + Boolean useFSGitHandler, + Boolean keepWorkingDirChanges) { Mono pageObjectMono; try { Mono resetToLastCommit = Mono.just(Boolean.TRUE); @@ -1276,7 +1281,12 @@ public class FileUtilsCEImpl implements FileInterface { if (Boolean.TRUE.equals(resetToLastCommitRequired)) { // instead of checking out to last branch we are first cleaning the git repo, // then checking out to the desired branch - resetToLastCommit = gitExecutor.resetToLastCommit(baseRepoSuffixPath, branchName, false); + if (Boolean.TRUE.equals(useFSGitHandler)) { + resetToLastCommit = + fsGitHandler.resetToLastCommit(baseRepoSuffixPath, branchName, keepWorkingDirChanges); + } else { + resetToLastCommit = gitExecutor.resetToLastCommit(baseRepoSuffixPath, branchName, true); + } } pageObjectMono = resetToLastCommit.map(isSwitched -> { diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/enums/FeatureFlagEnum.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/enums/FeatureFlagEnum.java index fcb8ab2c15..5aa764d353 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/enums/FeatureFlagEnum.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/enums/FeatureFlagEnum.java @@ -24,6 +24,7 @@ public enum FeatureFlagEnum { * Feature flag to detect if the RTS git reset is enabled */ ab_rts_git_reset_enabled, + release_git_api_contracts_enabled, // Deprecated CE flags over here release_git_autocommit_feature_enabled, diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java index 7d4443f9a2..9203832403 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java @@ -80,7 +80,12 @@ public interface FileInterface { Mono reconstructPackageJsonFromGitRepository(Path repoSuffix); Mono reconstructPageFromGitRepo( - String pageName, String branchName, Path repoSuffixPath, Boolean checkoutRequired); + String pageName, + String branchName, + Path repoSuffixPath, + Boolean checkoutRequired, + Boolean useFSGitHandler, + Boolean keepWorkingDirChanges); /** * Once the user connects the existing application to a remote repo, we will initialize the repo with Readme.md - diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java index fdeae3e1ba..3d52dd1239 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java @@ -933,6 +933,9 @@ public class CommonGitFileUtilsCE { String defaultArtifactId = gitArtifactMetadata.getDefaultArtifactId(); String refName = gitArtifactMetadata.getRefName(); String repoName = gitArtifactMetadata.getRepoName(); + Mono useFSGitHandlerMono = featureFlagService.check(FeatureFlagEnum.release_git_api_contracts_enabled); + Mono keepWorkingDirChangesMono = + featureFlagService.check(FeatureFlagEnum.release_git_reset_optimization_enabled); if (!hasText(workspaceId)) { return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.WORKSPACE_ID)); @@ -957,8 +960,14 @@ public class CommonGitFileUtilsCE { ArtifactGitFileUtils artifactGitFileUtils = getArtifactBasedFileHelper(artifactType); Path baseRepoSuffix = artifactGitFileUtils.getRepoSuffixPath(workspaceId, defaultArtifactId, repoName); - Mono jsonObjectMono = fileUtils - .reconstructPageFromGitRepo(pageDTO.getName(), refName, baseRepoSuffix, isResetToLastCommitRequired) + Mono jsonObjectMono = Mono.zip(useFSGitHandlerMono, keepWorkingDirChangesMono) + .flatMap(tuple -> fileUtils.reconstructPageFromGitRepo( + pageDTO.getName(), + refName, + baseRepoSuffix, + isResetToLastCommitRequired, + tuple.getT1(), + tuple.getT2())) .onErrorResume(error -> Mono.error( new AppsmithException(AppsmithError.GIT_ACTION_FAILED, RECONSTRUCT_PAGE, error.getMessage()))) .map(pageJson -> {