mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-01 13:19:53 +01:00
Detect proper merge and prevent empty commits
This commit is contained in:
@@ -38,6 +38,7 @@ import com.google.common.base.Strings;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.Status;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.api.errors.RefNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -214,10 +215,11 @@ class AbstractGitCommand
|
||||
}
|
||||
}
|
||||
|
||||
Optional<RevCommit> doCommit(String message, Person author, boolean isMergeCommit) {
|
||||
Optional<RevCommit> doCommit(String message, Person author) {
|
||||
Person authorToUse = determineAuthor(author);
|
||||
try {
|
||||
if (isMergeCommit || !clone.status().call().isClean()) {
|
||||
Status status = clone.status().call();
|
||||
if (!status.isClean() || isInMerge()) {
|
||||
return of(clone.commit()
|
||||
.setAuthor(authorToUse.getName(), authorToUse.getMail())
|
||||
.setMessage(message)
|
||||
@@ -225,11 +227,15 @@ class AbstractGitCommand
|
||||
} else {
|
||||
return empty();
|
||||
}
|
||||
} catch (GitAPIException e) {
|
||||
} catch (GitAPIException | IOException e) {
|
||||
throw new InternalRepositoryException(context.getRepository(), "could not commit changes", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInMerge() throws IOException {
|
||||
return clone.getRepository().readMergeHeads() != null && !clone.getRepository().readMergeHeads().isEmpty();
|
||||
}
|
||||
|
||||
void push() {
|
||||
try {
|
||||
clone.push().call();
|
||||
|
||||
@@ -99,7 +99,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
||||
|
||||
private void doCommit() {
|
||||
logger.debug("merged branch {} into {}", toMerge, target);
|
||||
doCommit(MessageFormat.format(determineMessageTemplate(), toMerge, target), author, true);
|
||||
doCommit(MessageFormat.format(determineMessageTemplate(), toMerge, target), author);
|
||||
}
|
||||
|
||||
private String determineMessageTemplate() {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
r.execute(this);
|
||||
}
|
||||
failIfNotChanged(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch()));
|
||||
Optional<RevCommit> revCommit = doCommit(request.getCommitMessage(), request.getAuthor(), false);
|
||||
Optional<RevCommit> revCommit = doCommit(request.getCommitMessage(), request.getAuthor());
|
||||
push();
|
||||
return revCommit.orElseThrow(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch())).name();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user