-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: merge and merge status #38495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
927fc5d
41f5faa
f464a95
7a3406e
70ad2a1
8877a5b
1283574
2976a4c
3a72c16
9500e83
ab5e336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,6 @@ | |
| import org.eclipse.jgit.api.ResetCommand; | ||
| import org.eclipse.jgit.api.Status; | ||
| import org.eclipse.jgit.api.TransportConfigCallback; | ||
| import org.eclipse.jgit.api.errors.CheckoutConflictException; | ||
| import org.eclipse.jgit.api.errors.GitAPIException; | ||
| import org.eclipse.jgit.lib.BranchTrackingStatus; | ||
| import org.eclipse.jgit.lib.PersonIdent; | ||
|
|
@@ -846,15 +845,14 @@ public Mono<String> mergeBranch(Path repoSuffix, String sourceBranch, String des | |
| git -> Mono.fromCallable(() -> { | ||
| Stopwatch processStopwatch = StopwatchHelpers.startStopwatch( | ||
| repoSuffix, AnalyticsEvents.GIT_MERGE.getEventName()); | ||
| log.debug(Thread.currentThread().getName() + ": Merge branch " + sourceBranch | ||
| + " on " + destinationBranch); | ||
| try { | ||
| // checkout the branch on which the merge command is run | ||
| git.checkout() | ||
| .setName(destinationBranch) | ||
| .setCreateBranch(false) | ||
| .call(); | ||
|
|
||
| log.info( | ||
| "{}: Merge branch {} on {}", | ||
| Thread.currentThread().getName(), | ||
| sourceBranch, | ||
| destinationBranch); | ||
|
|
||
| try { | ||
| MergeResult mergeResult = git.merge() | ||
| .include(git.getRepository().findRef(sourceBranch)) | ||
| .setStrategy(MergeStrategy.RECURSIVE) | ||
|
|
@@ -934,7 +932,7 @@ public Mono<String> fetchRemote( | |
|
|
||
| @Override | ||
| public Mono<String> fetchRemote( | ||
| Path repoSuffix, String publicKey, String privateKey, boolean isRepoPath, String... branchNames) { | ||
| Path repoSuffix, String publicKey, String privateKey, boolean isRepoPath, String... refNames) { | ||
| Stopwatch processStopwatch = | ||
| StopwatchHelpers.startStopwatch(repoSuffix, AnalyticsEvents.GIT_FETCH.getEventName()); | ||
| Path repoPath = TRUE.equals(isRepoPath) ? repoSuffix : createRepoPath(repoSuffix); | ||
|
|
@@ -946,9 +944,9 @@ public Mono<String> fetchRemote( | |
| String fetchMessages; | ||
|
|
||
| List<RefSpec> refSpecs = new ArrayList<>(); | ||
| for (String branchName : branchNames) { | ||
| for (String refName : refNames) { | ||
| RefSpec ref = new RefSpec( | ||
| "refs/heads/" + branchName + ":refs/remotes/origin/" + branchName); | ||
| "refs/heads/" + refName + ":refs/remotes/origin/" + refName); | ||
| refSpecs.add(ref); | ||
| } | ||
|
|
||
|
|
@@ -980,30 +978,13 @@ public Mono<MergeStatusDTO> isMergeBranch(Path repoSuffix, String sourceBranch, | |
| return Mono.using( | ||
| () -> Git.open(createRepoPath(repoSuffix).toFile()), | ||
| git -> Mono.fromCallable(() -> { | ||
| log.debug( | ||
| Thread.currentThread().getName() | ||
| + ": Check mergeability for repo {} with src: {}, dest: {}", | ||
| log.info( | ||
| "{}: Check mergeability for repo {} with src: {}, dest: {}", | ||
| Thread.currentThread().getName(), | ||
| repoSuffix, | ||
| sourceBranch, | ||
| destinationBranch); | ||
|
|
||
| // checkout the branch on which the merge command is run | ||
| try { | ||
| git.checkout() | ||
| .setName(destinationBranch) | ||
| .setCreateBranch(false) | ||
| .call(); | ||
| } catch (GitAPIException e) { | ||
| if (e instanceof CheckoutConflictException) { | ||
| MergeStatusDTO mergeStatus = new MergeStatusDTO(); | ||
| mergeStatus.setMergeAble(false); | ||
| mergeStatus.setConflictingFiles( | ||
| ((CheckoutConflictException) e).getConflictingPaths()); | ||
| processStopwatch.stopAndLogTimeInMillis(); | ||
| return mergeStatus; | ||
| } | ||
| } | ||
|
|
||
| MergeResult mergeResult = git.merge() | ||
| .include(git.getRepository().findRef(sourceBranch)) | ||
| .setFastForward(MergeCommand.FastForwardMode.NO_FF) | ||
|
|
@@ -1054,6 +1035,20 @@ public Mono<MergeStatusDTO> isMergeBranch(Path repoSuffix, String sourceBranch, | |
| return Mono.error(e); | ||
| } | ||
| }) | ||
| .onErrorResume(error -> { | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a try catch here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of errors we would need to reset it to last commit, and the method reset to last commit is throwing checked exceptions which needs to be handled. |
||
| MergeStatusDTO mergeStatusDTO = new MergeStatusDTO(); | ||
| mergeStatusDTO.setMergeAble(false); | ||
| mergeStatusDTO.setMessage(error.getMessage()); | ||
| mergeStatusDTO.setReferenceDoc( | ||
| ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl()); | ||
| return resetToLastCommit(repoSuffix, destinationBranch) | ||
| .thenReturn(mergeStatusDTO); | ||
| } 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)), | ||
| Git::close) | ||
| .subscribeOn(scheduler); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format is only applicable to branches, not tags. We'll need a separate path for tags