Merged in bugfix/merge_with_unrelated_histories (pull request #318)

Check for unrelated histories
This commit is contained in:
Sebastian Sdorra
2019-10-02 06:22:22 +00:00
5 changed files with 45 additions and 19 deletions

View File

@@ -0,0 +1,22 @@
package sonia.scm.repository;
import sonia.scm.BadRequestException;
import static java.util.Collections.emptyList;
@SuppressWarnings("squid:MaximumInheritanceDepth")
public class NoCommonHistoryException extends BadRequestException {
public NoCommonHistoryException() {
this("no common history");
}
public NoCommonHistoryException(String message) {
super(emptyList(), message);
}
@Override
public String getCode() {
return "4iRct4avG1";
}
}

View File

@@ -62,7 +62,6 @@ import org.eclipse.jgit.util.LfsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ContextEntry;
import sonia.scm.ScmConstraintViolationException;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.Util;
import sonia.scm.web.GitUserAgentProvider;
@@ -77,7 +76,6 @@ import java.util.concurrent.TimeUnit;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static sonia.scm.ScmConstraintViolationException.Builder.doThrow;
//~--- JDK imports ------------------------------------------------------------
@@ -87,7 +85,7 @@ import static sonia.scm.ScmConstraintViolationException.Builder.doThrow;
*/
public final class GitUtil
{
private static final GitUserAgentProvider GIT_USER_AGENT_PROVIDER = new GitUserAgentProvider();
/** Field description */
@@ -333,14 +331,14 @@ public final class GitUtil
return branch;
}
/**
* Returns {@code true} if the provided reference name is a branch name.
*
*
* @param refName reference name
*
*
* @return {@code true} if the name is a branch name
*
*
* @since 1.50
*/
public static boolean isBranch(String refName)
@@ -619,11 +617,11 @@ public final class GitUtil
/**
* Returns the name of the tag or {@code null} if the the ref is not a tag.
*
*
* @param refName ref name
*
*
* @return name of tag or {@link null}
*
*
* @since 1.50
*/
public static String getTagName(String refName)
@@ -696,7 +694,7 @@ public final class GitUtil
{
//J-
return fs.resolve(dir, DIRECTORY_OBJETCS).exists()
&& fs.resolve(dir, DIRECTORY_REFS).exists()
&& fs.resolve(dir, DIRECTORY_REFS).exists()
&&!fs.resolve(dir, DIRECTORY_DOTGIT).exists();
//J+
}
@@ -736,9 +734,10 @@ public final class GitUtil
mergeBaseWalk.markStart(mergeBaseWalk.lookupCommit(revision1));
mergeBaseWalk.markStart(mergeBaseWalk.parseCommit(revision2));
RevCommit ancestor = mergeBaseWalk.next();
doThrow()
.violation("revisions " + revision1.name() + " and " + revision2.name() + " are not related and therefore do not have a common ancestor", "revisions")
.when(ancestor == null);
if (ancestor == null) {
String msg = "revisions %s and %s are not related and therefore do not have a common ancestor";
throw new NoCommonHistoryException(String.format(msg, revision1.name(), revision2.name()));
}
return ancestor.getId();
}
}

View File

@@ -55,7 +55,7 @@ final class Differ implements AutoCloseable {
if (!Strings.isNullOrEmpty(request.getAncestorChangeset()))
{
ObjectId otherRevision = repository.resolve(request.getAncestorChangeset());
ObjectId ancestorId = computeCommonAncestor(repository, revision, otherRevision);
ObjectId ancestorId = GitUtil.computeCommonAncestor(repository, revision, otherRevision);
RevTree tree = walk.parseCommit(ancestorId).getTree();
treeWalk.addTree(tree);
}
@@ -82,10 +82,6 @@ final class Differ implements AutoCloseable {
return new Differ(commit, walk, treeWalk);
}
private static ObjectId computeCommonAncestor(org.eclipse.jgit.lib.Repository repository, ObjectId revision1, ObjectId revision2) throws IOException {
return GitUtil.computeCommonAncestor(repository, revision1, revision2);
}
private Diff diff() throws IOException {
List<DiffEntry> entries = DiffEntry.scan(treeWalk);
return new Diff(commit, entries);
@@ -115,4 +111,5 @@ final class Differ implements AutoCloseable {
return entries;
}
}
}

View File

@@ -176,6 +176,10 @@
"displayName": "Es wurden keine Änderungen durchgeführt",
"description": "Das Repository wurde nicht verändert. Daher konnte kein neuer Commit erzeugt werden."
},
"4iRct4avG1": {
"displayName": "Die Revisionen haben keinen gemeinsamen Ursprung",
"description": "Die Historie der Revisionen hat keinen gemeinsamen Urspung und kann somit auch nicht gegen einen solchen verglichen werden."
},
"65RdZ5atX1": {
"displayName": "Fehler beim Löschen von Plugin-Dateien",
"description": "Einige Dateien für die Plugin-Deinstallation konnten nicht gelöscht werden. Dieses kann zu Inkonsistenzen führen, so dass der SCM-Manager nicht mehr korrekt starten kann. Bitte prüfen Sie die Logs und bereinigen Sie das Plugin-Verzeichnis des SCM-Managers manuell. Um die Installation eines Plugins abzubrechen, löschen Sie die zugehörige smp Datei aus dem Plugin-Verzeichnis. Um ein Entfernen eines Plugins zu verhindern, entfernen Sie die Datei namens 'uninstall' aus dem entsprechenden Verzeichnis des Plugins."

View File

@@ -176,6 +176,10 @@
"displayName": "No changes were made",
"description": "No changes were made to the files of the repository. Therefor no new commit could be created."
},
"4iRct4avG1": {
"displayName": "The revisions have unrelated histories",
"description": "The revisions have unrelated histories. Therefor there is no common commit to compare with."
},
"65RdZ5atX1": {
"displayName": "Error removing plugin files",
"description": "Some files to cancel the plugin (un)installation could not be deleted. This can lead to inconsistencies so that the SCM-Manager cannot restart properly. Please check the logs and clean up the plugin folder manually. To cancel the installation of a plugin, remove the corresponding smp file. To cancel the uninstallation, remove the file named 'uninstall' inside the directory for this plugin."