Skip to content
Permalink
Browse files

[JENKINS-40834] Fix tests to apply for correct versions of the git cl…

…ients
  • Loading branch information...
stephenc committed Mar 22, 2017
1 parent c5edec5 commit f5e22966ba11c5e5f309d5e9a0de7adcd99dd6c7
@@ -17,6 +17,11 @@ protected GitClient setupGitAPI(File ws) throws Exception {
return Git.with(listener, env).in(ws).using("git").getClient();
}

@Override
protected boolean hasWorkingGetRemoteSymbolicReferences() {
return ((CliGitAPIImpl)(w.git)).isAtLeastVersion(2,8,0,0);
}

private static boolean cliGitDefaultsSet = false;

private void setCliGitDefaults() throws Exception {
@@ -6,6 +6,8 @@
import static org.hamcrest.Matchers.*;
import static org.jenkinsci.plugins.gitclient.StringSharesPrefix.sharesPrefix;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assume.assumeThat;

import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
@@ -3376,14 +3378,18 @@ public void test_getRemoteReferences_withMatchingPattern() throws Exception {
* Test getRemoteSymbolicReferences with listing all references
*/
public void test_getRemoteSymbolicReferences() throws Exception {
assumeThat(hasWorkingGetRemoteSymbolicReferences(), is(true));
Map<String, String> references = w.git.getRemoteSymbolicReferences(remoteMirrorURL, null);
assertThat(references, hasEntry(is(Constants.HEAD), is(Constants.R_HEADS + Constants.MASTER)));
}

protected abstract boolean hasWorkingGetRemoteSymbolicReferences();

/**
* Test getRemoteSymbolicReferences with listing all references
*/
public void test_getRemoteSymbolicReferences_withMatchingPattern() throws Exception {
assumeThat(hasWorkingGetRemoteSymbolicReferences(), is(true));
Map<String, String> references = w.git.getRemoteSymbolicReferences(remoteMirrorURL, Constants.HEAD);
assertThat(references, hasEntry(is(Constants.HEAD), is(Constants.R_HEADS + Constants.MASTER)));
assertThat(references.size(), is(1));
@@ -3,6 +3,7 @@
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.eclipse.jgit.transport.BasePackFetchConnection;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
@@ -13,6 +14,17 @@ protected GitClient setupGitAPI(File ws) throws Exception {
return Git.with(listener, env).in(ws).using("jgit").getClient();
}

@Override
protected boolean hasWorkingGetRemoteSymbolicReferences() {
try {
// TODO if JGit implement https://bugs.eclipse.org/bugs/show_bug.cgi?id=514052 we should switch to that
BasePackFetchConnection.class.getSuperclass().getDeclaredField("remoteCapablities");
return true;
} catch (NoSuchFieldException e) {
return false;
}
}

/**
* timeout is not implemented in JGitAPIImpl.
*/
@@ -3,6 +3,7 @@
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.eclipse.jgit.transport.BasePackFetchConnection;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
@@ -13,6 +14,17 @@ protected GitClient setupGitAPI(File ws) throws Exception {
return Git.with(listener, env).in(ws).using("jgitapache").getClient();
}

@Override
protected boolean hasWorkingGetRemoteSymbolicReferences() {
try {
// TODO if JGit implement https://bugs.eclipse.org/bugs/show_bug.cgi?id=514052 we should switch to that
BasePackFetchConnection.class.getSuperclass().getDeclaredField("remoteCapablities");
return true;
} catch (NoSuchFieldException e) {
return false;
}
}

/**
* timeout is not implemented in JGitAPIImpl.
*/

0 comments on commit f5e2296

Please sign in to comment.
You can’t perform that action at this time.