mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
Handle unexpected merge results
It is possible that a git work tree is dirty directly after the clone of a repository, eg. when files are not changed correctly due to bogous .gitattribute files (though this is just a guess). In these cases a merge might fail due to these dirty files and not due to merge conflicts. Without this change such results lead to null pointer exceptions, because result.getConflicts() is null.
This commit is contained in:
@@ -88,7 +88,14 @@ abstract class GitMergeStrategy extends AbstractGitCommand.GitCloneWorker<MergeC
|
||||
}
|
||||
|
||||
MergeCommandResult analyseFailure(MergeResult result) {
|
||||
logger.info("could not merge branch {} into {} due to conflict in paths {}", branchToMerge, targetBranch, result.getConflicts().keySet());
|
||||
logger.info("could not merge branch {} into {} with merge status '{}' due to ...", branchToMerge, targetBranch, result.getMergeStatus());
|
||||
logger.info("... conflicts: {}", result.getConflicts());
|
||||
logger.info("... checkout conflicts: {}", result.getCheckoutConflicts());
|
||||
logger.info("... failing paths: {}", result.getFailingPaths());
|
||||
logger.info("... message: {}", result);
|
||||
if (result.getConflicts() == null) {
|
||||
throw new UnexpectedMergeResultException(getRepository(), result);
|
||||
}
|
||||
return MergeCommandResult.failure(targetRevision.name(), revisionToMerge.name(), result.getConflicts().keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.api.MergeResult;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.ExceptionWithContext;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
class UnexpectedMergeResultException extends ExceptionWithContext {
|
||||
|
||||
public static final String CODE = "4GRrgkSC01";
|
||||
|
||||
public UnexpectedMergeResultException(Repository repository, MergeResult result) {
|
||||
super(ContextEntry.ContextBuilder.entity(repository).build(), createMessage(result));
|
||||
}
|
||||
|
||||
private static String createMessage(MergeResult result) {
|
||||
return "unexpected merge result: " + result
|
||||
+ "\nconflicts: " + result.getConflicts()
|
||||
+ "\ncheckout conflicts: " + result.getCheckoutConflicts()
|
||||
+ "\nfailing paths: " + result.getFailingPaths();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return CODE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user