Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history


� Conflicts:
�	src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java

Added ;
  • Loading branch information
loghijiaha committed Feb 12, 2020
2 parents 48d46f3 + a519e1b commit 069b55a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java
Expand Up @@ -44,7 +44,6 @@
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 @@ -600,20 +599,20 @@ public void testAddRemoteUrl() throws Exception {
assertEquals(upstreamRepoURL, gitClient.getRemoteUrl("upstream"));
}

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

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

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 069b55a

Please sign in to comment.