Update jgit to v5.11.1.202105131744-r-scm1 (#1661)

Update jgit to v5.11.1.202105131744-r-scm1

Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
This commit is contained in:
Sebastian Sdorra
2021-05-20 14:14:58 +02:00
committed by GitHub
parent 42745c9e34
commit d7d0d2375c
4 changed files with 19 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ plugins {
id 'org.scm-manager.smp' version '0.7.5' id 'org.scm-manager.smp' version '0.7.5'
} }
def jgitVersion = '5.10.0.202012080955-r-scm2' def jgitVersion = '5.11.1.202105131744-r-scm1'
dependencies { dependencies {
// required by scm-it // required by scm-it

View File

@@ -26,6 +26,8 @@ package sonia.scm.repository;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import com.google.common.base.Strings;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@@ -39,6 +41,8 @@ import javax.xml.bind.annotation.XmlTransient;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class GitConfig extends RepositoryConfig { public class GitConfig extends RepositoryConfig {
private static final String FALLBACK_BRANCH = "main";
@SuppressWarnings("WeakerAccess") // This might be needed for permission checking @SuppressWarnings("WeakerAccess") // This might be needed for permission checking
public static final String PERMISSION = "git"; public static final String PERMISSION = "git";
@@ -49,7 +53,7 @@ public class GitConfig extends RepositoryConfig {
private boolean nonFastForwardDisallowed; private boolean nonFastForwardDisallowed;
@XmlElement(name = "default-branch") @XmlElement(name = "default-branch")
private String defaultBranch = "main"; private String defaultBranch = FALLBACK_BRANCH;
public String getGcExpression() { public String getGcExpression() {
return gcExpression; return gcExpression;
@@ -68,6 +72,9 @@ public class GitConfig extends RepositoryConfig {
} }
public String getDefaultBranch() { public String getDefaultBranch() {
if (Strings.isNullOrEmpty(defaultBranch)) {
return FALLBACK_BRANCH;
}
return defaultBranch; return defaultBranch;
} }

View File

@@ -27,6 +27,7 @@ package sonia.scm.repository.spi;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@@ -75,6 +76,13 @@ class GitWorkingCopyInitializer {
} }
return new ParentAndClone<>(null, clone, target); return new ParentAndClone<>(null, clone, target);
} catch (TransportException e) {
String message = e.getMessage();
if (initialBranch != null && message.contains(initialBranch) && message.contains("not found")) {
throw notFound(entity("Branch", initialBranch).in(context.getRepository()));
} else {
throw new InternalRepositoryException(context.getRepository(), "could not clone working copy of repository", e);
}
} catch (GitAPIException | IOException e) { } catch (GitAPIException | IOException e) {
throw new InternalRepositoryException(context.getRepository(), "could not clone working copy of repository", e); throw new InternalRepositoryException(context.getRepository(), "could not clone working copy of repository", e);
} finally { } finally {

View File

@@ -60,14 +60,14 @@ public class GitModifyCommand_withEmptyRepositoryTest extends GitModifyCommandTe
} }
@Test @Test
public void shouldCreateCommitOnMasterByDefault() throws IOException, GitAPIException { public void shouldCreateCommitOnMainByDefault() throws IOException, GitAPIException {
createContext().getGlobalConfig().setDefaultBranch(""); createContext().getGlobalConfig().setDefaultBranch("");
executeModifyCommand(); executeModifyCommand();
try (Git git = new Git(createContext().open())) { try (Git git = new Git(createContext().open())) {
List<Ref> branches = git.branchList().call(); List<Ref> branches = git.branchList().call();
assertThat(branches).extracting("name").containsExactly("refs/heads/master"); assertThat(branches).extracting("name").containsExactly("refs/heads/main");
} }
} }