Merge branch 'stable-5.0'
* stable-5.0: Ensure Jsch checks all configured algorithms RawTextTest#testBinary: use array comparison to compare arrays LFS: Better SSH authentication token timeout handling Ensure DirectoryStream is closed promptly Validate branch names on branch creation Change-Id: Ic4f6a24b6ccee6730eee3fd5dcb0d1f3e291c478 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
commit
0f8f6746ed
|
@ -273,7 +273,7 @@ public static Protocol.Request toRequest(String operation,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class AuthCache {
|
private static final class AuthCache {
|
||||||
private static final long AUTH_CACHE_EAGER_TIMEOUT = 100;
|
private static final long AUTH_CACHE_EAGER_TIMEOUT = 500;
|
||||||
|
|
||||||
private static final SimpleDateFormat ISO_FORMAT = new SimpleDateFormat(
|
private static final SimpleDateFormat ISO_FORMAT = new SimpleDateFormat(
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSSX"); //$NON-NLS-1$
|
"yyyy-MM-dd'T'HH:mm:ss.SSSX"); //$NON-NLS-1$
|
||||||
|
@ -290,8 +290,9 @@ public AuthCache(Protocol.ExpiringAction action) {
|
||||||
this.cachedAction = action;
|
this.cachedAction = action;
|
||||||
try {
|
try {
|
||||||
if (action.expiresIn != null && !action.expiresIn.isEmpty()) {
|
if (action.expiresIn != null && !action.expiresIn.isEmpty()) {
|
||||||
this.validUntil = System.currentTimeMillis()
|
this.validUntil = (System.currentTimeMillis()
|
||||||
+ Long.parseLong(action.expiresIn);
|
+ Long.parseLong(action.expiresIn))
|
||||||
|
- AUTH_CACHE_EAGER_TIMEOUT;
|
||||||
} else if (action.expiresAt != null
|
} else if (action.expiresAt != null
|
||||||
&& !action.expiresAt.isEmpty()) {
|
&& !action.expiresAt.isEmpty()) {
|
||||||
this.validUntil = ISO_FORMAT.parse(action.expiresAt)
|
this.validUntil = ISO_FORMAT.parse(action.expiresAt)
|
||||||
|
|
|
@ -191,6 +191,18 @@ public void testCreateAndList() throws Exception {
|
||||||
- allBefore);
|
- allBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = InvalidRefNameException.class)
|
||||||
|
public void testInvalidBranchHEAD() throws Exception {
|
||||||
|
git.branchCreate().setName("HEAD").call();
|
||||||
|
fail("Create branch with invalid ref name should fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = InvalidRefNameException.class)
|
||||||
|
public void testInvalidBranchDash() throws Exception {
|
||||||
|
git.branchCreate().setName("-x").call();
|
||||||
|
fail("Create branch with invalid ref name should fail");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListAllBranchesShouldNotDie() throws Exception {
|
public void testListAllBranchesShouldNotDie() throws Exception {
|
||||||
setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
|
setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
package org.eclipse.jgit.diff;
|
package org.eclipse.jgit.diff;
|
||||||
|
|
||||||
import static org.eclipse.jgit.lib.Constants.CHARSET;
|
import static org.eclipse.jgit.lib.Constants.CHARSET;
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -69,7 +70,7 @@ public void testBinary() {
|
||||||
String input = "foo-a\nf\0o-b\n";
|
String input = "foo-a\nf\0o-b\n";
|
||||||
byte[] data = Constants.encodeASCII(input);
|
byte[] data = Constants.encodeASCII(input);
|
||||||
final RawText a = new RawText(data);
|
final RawText a = new RawText(data);
|
||||||
assertEquals(a.content, data);
|
assertArrayEquals(a.content, data);
|
||||||
assertEquals(a.size(), 1);
|
assertEquals(a.size(), 1);
|
||||||
assertEquals(a.getString(0, 1, false), input);
|
assertEquals(a.getString(0, 1, false), input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,9 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.api;
|
package org.eclipse.jgit.api;
|
||||||
|
|
||||||
|
import static org.eclipse.jgit.lib.Constants.HEAD;
|
||||||
|
import static org.eclipse.jgit.lib.Constants.R_HEADS;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ public class CreateBranchCommand extends GitCommand<Ref> {
|
||||||
|
|
||||||
private SetupUpstreamMode upstreamMode;
|
private SetupUpstreamMode upstreamMode;
|
||||||
|
|
||||||
private String startPoint = Constants.HEAD;
|
private String startPoint = HEAD;
|
||||||
|
|
||||||
private RevCommit startCommit;
|
private RevCommit startCommit;
|
||||||
|
|
||||||
|
@ -121,7 +124,7 @@ public Ref call() throws GitAPIException, RefAlreadyExistsException,
|
||||||
try (RevWalk revWalk = new RevWalk(repo)) {
|
try (RevWalk revWalk = new RevWalk(repo)) {
|
||||||
Ref refToCheck = repo.findRef(name);
|
Ref refToCheck = repo.findRef(name);
|
||||||
boolean exists = refToCheck != null
|
boolean exists = refToCheck != null
|
||||||
&& refToCheck.getName().startsWith(Constants.R_HEADS);
|
&& refToCheck.getName().startsWith(R_HEADS);
|
||||||
if (!force && exists)
|
if (!force && exists)
|
||||||
throw new RefAlreadyExistsException(MessageFormat.format(
|
throw new RefAlreadyExistsException(MessageFormat.format(
|
||||||
JGitText.get().refAlreadyExists1, name));
|
JGitText.get().refAlreadyExists1, name));
|
||||||
|
@ -153,7 +156,7 @@ public Ref call() throws GitAPIException, RefAlreadyExistsException,
|
||||||
else
|
else
|
||||||
refLogMessage = "branch: Created from commit " + baseCommit; //$NON-NLS-1$
|
refLogMessage = "branch: Created from commit " + baseCommit; //$NON-NLS-1$
|
||||||
|
|
||||||
} else if (startPointFullName.startsWith(Constants.R_HEADS)
|
} else if (startPointFullName.startsWith(R_HEADS)
|
||||||
|| startPointFullName.startsWith(Constants.R_REMOTES)) {
|
|| startPointFullName.startsWith(Constants.R_REMOTES)) {
|
||||||
baseBranch = startPointFullName;
|
baseBranch = startPointFullName;
|
||||||
if (exists)
|
if (exists)
|
||||||
|
@ -171,7 +174,7 @@ public Ref call() throws GitAPIException, RefAlreadyExistsException,
|
||||||
+ startPointFullName;
|
+ startPointFullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefUpdate updateRef = repo.updateRef(Constants.R_HEADS + name);
|
RefUpdate updateRef = repo.updateRef(R_HEADS + name);
|
||||||
updateRef.setNewObjectId(startAt);
|
updateRef.setNewObjectId(startAt);
|
||||||
updateRef.setRefLogMessage(refLogMessage, false);
|
updateRef.setRefLogMessage(refLogMessage, false);
|
||||||
Result updateResult;
|
Result updateResult;
|
||||||
|
@ -279,16 +282,33 @@ private ObjectId getStartPointObjectId() throws AmbiguousObjectException,
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStartPointOrHead() {
|
private String getStartPointOrHead() {
|
||||||
return startPoint != null ? startPoint : Constants.HEAD;
|
return startPoint != null ? startPoint : HEAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processOptions() throws InvalidRefNameException {
|
private void processOptions() throws InvalidRefNameException {
|
||||||
if (name == null
|
if (name == null
|
||||||
|| !Repository.isValidRefName(Constants.R_HEADS + name))
|
|| !Repository.isValidRefName(R_HEADS + name)
|
||||||
|
|| !isValidBranchName(name))
|
||||||
throw new InvalidRefNameException(MessageFormat.format(JGitText
|
throw new InvalidRefNameException(MessageFormat.format(JGitText
|
||||||
.get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$
|
.get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given branch name is valid
|
||||||
|
*
|
||||||
|
* @param branchName
|
||||||
|
* branch name to check
|
||||||
|
* @return {@code true} if the branch name is valid
|
||||||
|
*
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
public static boolean isValidBranchName(String branchName) {
|
||||||
|
if (HEAD.equals(branchName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !branchName.startsWith("-"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name of the new branch
|
* Set the name of the new branch
|
||||||
*
|
*
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.jcraft.jsch.ConfigRepository;
|
import com.jcraft.jsch.ConfigRepository;
|
||||||
|
import com.jcraft.jsch.ConfigRepository.Config;
|
||||||
import com.jcraft.jsch.JSch;
|
import com.jcraft.jsch.JSch;
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import com.jcraft.jsch.Session;
|
import com.jcraft.jsch.Session;
|
||||||
|
@ -222,10 +223,30 @@ Session createSession(CredentialsProvider credentialsProvider,
|
||||||
session.setUserInfo(new CredentialsProviderUserInfo(session,
|
session.setUserInfo(new CredentialsProviderUserInfo(session,
|
||||||
credentialsProvider));
|
credentialsProvider));
|
||||||
}
|
}
|
||||||
|
safeConfig(session, hc.getConfig());
|
||||||
configure(hc, session);
|
configure(hc, session);
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void safeConfig(Session session, Config cfg) {
|
||||||
|
// Ensure that Jsch checks all configured algorithms, not just its
|
||||||
|
// built-in ones. Otherwise it may propose an algorithm for which it
|
||||||
|
// doesn't have an implementation, and then run into an NPE if that
|
||||||
|
// algorithm ends up being chosen.
|
||||||
|
copyConfigValueToSession(session, cfg, "Ciphers", "CheckCiphers"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
copyConfigValueToSession(session, cfg, "KexAlgorithms", "CheckKexes"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
copyConfigValueToSession(session, cfg, "HostKeyAlgorithms", //$NON-NLS-1$
|
||||||
|
"CheckSignatures"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyConfigValueToSession(Session session, Config cfg,
|
||||||
|
String from, String to) {
|
||||||
|
String value = cfg.getValue(from);
|
||||||
|
if (value != null) {
|
||||||
|
session.setConfig(to, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setUserName(Session session, String userName) {
|
private void setUserName(Session session, String userName) {
|
||||||
// Jsch 0.1.54 picks up the user name from the ssh config, even if an
|
// Jsch 0.1.54 picks up the user name from the ssh config, even if an
|
||||||
// explicit user name was given! We must correct that if ~/.ssh/config
|
// explicit user name was given! We must correct that if ~/.ssh/config
|
||||||
|
|
Loading…
Reference in New Issue