Skip to content

Commit

Permalink
Made changes as requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
loghijiaha committed Feb 12, 2020
1 parent 069b55a commit 7033fdb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.lib.Constants;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import org.junit.AfterClass;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -599,7 +600,7 @@ public void testAddRemoteUrl() throws Exception {
assertEquals(upstreamRepoURL, gitClient.getRemoteUrl("upstream"));
}

@Test
@Test (expected = GitException.class)
public void testAutocreateFailsOnMultipleMatchingOrigins() throws Exception {
File repoRootTemp = tempFolder.newFolder();
GitClient gitClientTemp = Git.with(TaskListener.NULL, new EnvVars()).in(repoRootTemp).using(gitImplName).getClient();
Expand All @@ -608,11 +609,11 @@ public void testAutocreateFailsOnMultipleMatchingOrigins() throws Exception {
FilePath gitClientTempFile = gitClientFilePath.createTextTempFile("aPre", ".txt", "file contents");
gitClientTemp.add(".");
gitClientTemp.commit("Added " + gitClientTempFile.toURI().toString());
gitClientTemp.clone_().url("file://" + repoRootTemp.getPath()).execute();
gitClient.clone_().url("file://" + repoRootTemp.getPath()).execute();
final URIish remote = new URIish(Constants.DEFAULT_REMOTE_NAME);

try ( // add second remote
FileRepository repo = new FileRepository(repoRootTemp)) {
FileRepository repo = new FileRepository(new File(repoRoot, ".git"))) {
StoredConfig config = repo.getConfig();
config.setString("remote", "upstream", "url", "file://" + repoRootTemp.getPath());
config.setString("remote", "upstream", "fetch", "+refs/heads/*:refs/remotes/upstream/*");
Expand All @@ -622,17 +623,16 @@ public void testAutocreateFailsOnMultipleMatchingOrigins() throws Exception {
// fill both remote branches
List<RefSpec> refspecs = Collections.singletonList(new RefSpec(
"refs/heads/*:refs/remotes/origin/*"));
gitClientTemp.fetch_().from(remote, refspecs).execute();
gitClient.fetch_().from(remote, refspecs).execute();
refspecs = Collections.singletonList(new RefSpec(
"refs/heads/*:refs/remotes/upstream/*"));
gitClientTemp.fetch_().from(remote, refspecs).execute();
gitClient.fetch_().from(remote, refspecs).execute();

// checkout will fail
gitClient.checkout().ref(Constants.MASTER).execute();
Set<String> refNames = gitClient.getRefNames("refs/heads/");
assertFalse("RefNames will not contain master", refNames.contains("refs/heads/master"));

try {
gitClientTemp.checkout().ref(Constants.MASTER).execute();
fail("GitException expected");
} catch (GitException e) {
// expected
}
}

private void assertFileInWorkingDir(GitClient client, String fileName) {
Expand Down

0 comments on commit 7033fdb

Please sign in to comment.