Skip to content

Commit

Permalink
[JENKINS-40834] Fix tests to apply for correct versions of the git cl…
Browse files Browse the repository at this point in the history
…ients
  • Loading branch information
stephenc committed Mar 22, 2017
1 parent c5edec5 commit f5e2296
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/jenkinsci/plugins/gitclient/JGitAPIImplTest.java
Expand Up @@ -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>
Expand All @@ -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.
*/
Expand Down
Expand Up @@ -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>
Expand All @@ -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.
*/
Expand Down

0 comments on commit f5e2296

Please sign in to comment.