mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
Extract methods to emphasize flow
This commit is contained in:
@@ -60,6 +60,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
|||||||
private final String toMerge;
|
private final String toMerge;
|
||||||
private final Person author;
|
private final Person author;
|
||||||
private final Git clone;
|
private final Git clone;
|
||||||
|
|
||||||
private MergeWorker(Repository clone, MergeCommandRequest request) {
|
private MergeWorker(Repository clone, MergeCommandRequest request) {
|
||||||
this.target = request.getTargetBranch();
|
this.target = request.getTargetBranch();
|
||||||
this.toMerge = request.getBranchToMerge();
|
this.toMerge = request.getBranchToMerge();
|
||||||
@@ -70,7 +71,13 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
|||||||
private MergeCommandResult merge() throws IOException {
|
private MergeCommandResult merge() throws IOException {
|
||||||
createClone();
|
createClone();
|
||||||
MergeResult result = doMergeInClone();
|
MergeResult result = doMergeInClone();
|
||||||
return analyzeResult(result);
|
if (result.getMergeStatus().isSuccessful()) {
|
||||||
|
doCommit();
|
||||||
|
push();
|
||||||
|
return MergeCommandResult.success();
|
||||||
|
} else {
|
||||||
|
return analyseFailure(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createClone() {
|
private void createClone() {
|
||||||
@@ -94,8 +101,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MergeCommandResult analyzeResult(MergeResult result) {
|
private void doCommit() {
|
||||||
if (result.getMergeStatus().isSuccessful()) {
|
|
||||||
logger.debug("merged branch {} into {}", toMerge, target);
|
logger.debug("merged branch {} into {}", toMerge, target);
|
||||||
try {
|
try {
|
||||||
clone.commit()
|
clone.commit()
|
||||||
@@ -105,18 +111,21 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
|||||||
} catch (GitAPIException e) {
|
} catch (GitAPIException e) {
|
||||||
throw new InternalRepositoryException("could not commit merge between branch " + toMerge + " and " + target, e);
|
throw new InternalRepositoryException("could not commit merge between branch " + toMerge + " and " + target, e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void push() {
|
||||||
try {
|
try {
|
||||||
clone.push().call();
|
clone.push().call();
|
||||||
} catch (GitAPIException e) {
|
} catch (GitAPIException e) {
|
||||||
throw new InternalRepositoryException("could not push merged branch " + toMerge + " to origin", e);
|
throw new InternalRepositoryException("could not push merged branch " + toMerge + " to origin", e);
|
||||||
}
|
}
|
||||||
logger.debug("pushed merged branch {}", target);
|
logger.debug("pushed merged branch {}", target);
|
||||||
return MergeCommandResult.success();
|
}
|
||||||
} else {
|
|
||||||
|
private MergeCommandResult analyseFailure(MergeResult result) {
|
||||||
logger.info("could not merged branch {} into {} due to conflict in paths {}", toMerge, target, result.getConflicts().keySet());
|
logger.info("could not merged branch {} into {} due to conflict in paths {}", toMerge, target, result.getConflicts().keySet());
|
||||||
return MergeCommandResult.failure(result.getConflicts().keySet());
|
return MergeCommandResult.failure(result.getConflicts().keySet());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private ObjectId resolveRevision(String branchToMerge) throws IOException {
|
private ObjectId resolveRevision(String branchToMerge) throws IOException {
|
||||||
ObjectId resolved = clone.getRepository().resolve(branchToMerge);
|
ObjectId resolved = clone.getRepository().resolve(branchToMerge);
|
||||||
|
|||||||
Reference in New Issue
Block a user