fix: reverted git executor layer (#39949)
## Description > > _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 #39934 _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.Git" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/14103475195> > Commit: 288e4cfb7e5a38f28e50164b90e29f4eb7c21c58 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=14103475195&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Git` > Spec: > <hr>Thu, 27 Mar 2025 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Enhanced error recovery in update operations, ensuring that any pending changes are safely reverted when issues occur. - Improved conflict resolution during updates to maintain a stable and reliable system state for end-users. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
f7664d1edc
commit
30f998302c
|
|
@ -499,7 +499,7 @@ public class GitExecutorCEImpl implements GitExecutor {
|
|||
}
|
||||
}
|
||||
})
|
||||
.onErrorResume(error -> Mono.error(error))
|
||||
.onErrorResume(error -> resetToLastCommit(git).flatMap(ignore -> Mono.error(error)))
|
||||
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
|
||||
.name(GitSpan.FS_PULL)
|
||||
.tap(Micrometer.observation(observationRegistry)),
|
||||
|
|
@ -626,6 +626,15 @@ public class GitExecutorCEImpl implements GitExecutor {
|
|||
response.setRemoteBranch("untracked");
|
||||
}
|
||||
|
||||
// Remove modified changes from current branch so that checkout to other branches
|
||||
// will be possible
|
||||
if (!status.isClean()) {
|
||||
return resetToLastCommit(git).map(ref -> {
|
||||
processStopwatch.stopAndLogTimeInMillis();
|
||||
jgitStatusSpan.end();
|
||||
return response;
|
||||
});
|
||||
}
|
||||
processStopwatch.stopAndLogTimeInMillis();
|
||||
jgitStatusSpan.end();
|
||||
return Mono.just(response);
|
||||
|
|
@ -844,7 +853,13 @@ public class GitExecutorCEImpl implements GitExecutor {
|
|||
}
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
return Mono.error(error);
|
||||
try {
|
||||
return resetToLastCommit(repoSuffix, destinationBranch)
|
||||
.thenReturn(error.getMessage());
|
||||
} catch (GitAPIException | IOException e) {
|
||||
log.error("Error while hard resetting to latest commit {0}", e);
|
||||
return Mono.error(e);
|
||||
}
|
||||
})
|
||||
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
|
||||
.name(GitSpan.FS_MERGE)
|
||||
|
|
@ -1013,6 +1028,19 @@ public class GitExecutorCEImpl implements GitExecutor {
|
|||
mergeResult.getMergeStatus().name());
|
||||
return mergeStatus;
|
||||
})
|
||||
.flatMap(status -> {
|
||||
try {
|
||||
// Revert uncommitted changes if any
|
||||
return resetToLastCommit(repoSuffix, destinationBranch)
|
||||
.map(ignore -> {
|
||||
processStopwatch.stopAndLogTimeInMillis();
|
||||
return status;
|
||||
});
|
||||
} catch (GitAPIException | IOException e) {
|
||||
log.error("Error for hard resetting to latest commit {0}", e);
|
||||
return Mono.error(e);
|
||||
}
|
||||
})
|
||||
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)),
|
||||
Git::close)
|
||||
.subscribeOn(scheduler);
|
||||
|
|
@ -1093,12 +1121,12 @@ public class GitExecutorCEImpl implements GitExecutor {
|
|||
.subscribeOn(scheduler);
|
||||
}
|
||||
|
||||
public Mono<Boolean> resetToLastCommit(Path repoSuffix, String branchName) {
|
||||
public Mono<Boolean> resetToLastCommit(Path repoSuffix, String branchName) throws GitAPIException, IOException {
|
||||
return Mono.using(
|
||||
() -> Git.open(createRepoPath(repoSuffix).toFile()),
|
||||
git -> this.resetToLastCommit(git)
|
||||
.flatMap(ref -> checkoutToBranch(repoSuffix, branchName))
|
||||
.thenReturn(true),
|
||||
.flatMap(checkedOut -> resetToLastCommit(git).thenReturn(true)),
|
||||
Git::close);
|
||||
}
|
||||
|
||||
|
|
@ -1128,7 +1156,7 @@ public class GitExecutorCEImpl implements GitExecutor {
|
|||
}
|
||||
|
||||
public Mono<Boolean> rebaseBranch(Path repoSuffix, String branchName) {
|
||||
return this.resetToLastCommit(repoSuffix, branchName).flatMap(isCheckedOut -> Mono.using(
|
||||
return this.checkoutToBranch(repoSuffix, branchName).flatMap(isCheckedOut -> Mono.using(
|
||||
() -> Git.open(createRepoPath(repoSuffix).toFile()),
|
||||
git -> Mono.fromCallable(() -> {
|
||||
Span jgitRebaseSpan = observationHelper.createSpan(GitSpan.JGIT_REBASE);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user