diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java index 27c723a70ac0..e3e20e404335 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java @@ -1414,6 +1414,18 @@ private Mono resetToLastCommit(Git git) { .subscribeOn(scheduler); } + /** + * reset to last commit on the current branch itself but doesn't checkout to any specific branch + * @param repoSuffix suffixedPath used to generate the base repo path this includes workspaceId, defaultAppId, repoName + * @return a boolean whether the operation was successfull or not + */ + public Mono resetToLastCommit(Path repoSuffix) { + return Mono.using( + () -> Git.open(createRepoPath(repoSuffix).toFile()), + git -> this.resetToLastCommit(git).thenReturn(true).onErrorReturn(false), + Git::close); + } + public Mono resetToLastCommit(Path repoSuffix, String branchName) { return Mono.using( () -> Git.open(createRepoPath(repoSuffix).toFile()), diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java index 545e9efd2be1..c58afbd54d42 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java @@ -203,6 +203,13 @@ Mono fetchRemote( */ Mono resetToLastCommit(Path repoSuffix, String branchName) throws GitAPIException, IOException; + /** + * This method will reset the repo to last commit for the current branch on which it's present + * @param repoSuffix suffixedPath used to generate the base repo path this includes workspaceId, defaultAppId, repoName + * @return success status + */ + Mono resetToLastCommit(Path repoSuffix); + /** * * @param repoSuffix suffixedPath used to generate the base repo path this includes workspaceId, defaultAppId, repoName diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java index 52a96b384316..f5ab1ee406c0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java @@ -869,7 +869,7 @@ protected Mono createReference( new AppsmithException( AppsmithError.GIT_ACTION_FAILED, "ref creation", - "either ref name is already exists or it doesn't meet naming criteria, or the artifact is not in a publishable state")); + "either ref name already exists or it doesn't meet naming criteria, or the artifact is not in a publishable state")); } Mono newArtifactFromSourceMono = generateArtifactForRefCreation( diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java index 3880a9c5920d..e6b8f95f43d7 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java @@ -275,8 +275,18 @@ public void setRepositoryDetailsInGitArtifactMetadata( @Override public Mono reconstructArtifactJsonFromGitRepository( ArtifactJsonTransformationDTO artifactJsonTransformationDTO) { - return commonGitFileUtils.constructArtifactExchangeJsonFromGitRepositoryWithAnalytics( - artifactJsonTransformationDTO); + GitArtifactHelper gitArtifactHelper = + gitArtifactHelperResolver.getArtifactHelper(artifactJsonTransformationDTO.getArtifactType()); + + Path repoSuffix = gitArtifactHelper.getRepoSuffixPath( + artifactJsonTransformationDTO.getWorkspaceId(), + artifactJsonTransformationDTO.getBaseArtifactId(), + artifactJsonTransformationDTO.getRepoName()); + + return fsGitHandler + .resetToLastCommit(repoSuffix) + .then(commonGitFileUtils.constructArtifactExchangeJsonFromGitRepositoryWithAnalytics( + artifactJsonTransformationDTO)); } @Override