View Javadoc
1   /*
2    * Copyright (C) 2015, Kaloyan Raev <kaloyan.r@zend.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.api;
11  
12  import static org.junit.Assert.assertArrayEquals;
13  import static org.junit.Assert.assertEquals;
14  
15  import org.eclipse.jgit.lib.Repository;
16  import org.eclipse.jgit.transport.RemoteConfig;
17  import org.eclipse.jgit.transport.URIish;
18  import org.junit.Test;
19  
20  public class RemoteAddCommandTest extends AbstractRemoteCommandTest {
21  
22  	@Test
23  	public void testAdd() throws Exception {
24  		// create another repository
25  		Repository remoteRepository = createWorkRepository();
26  		URIish uri = new URIish(
27  				remoteRepository.getDirectory().toURI().toURL());
28  
29  		// execute the command to add a new remote
30  		RemoteAddCommand cmd = Git.wrap(db).remoteAdd();
31  		cmd.setName(REMOTE_NAME);
32  		cmd.setUri(uri);
33  		RemoteConfig remote = cmd.call();
34  
35  		// assert that the added remote represents the remote repository
36  		assertEquals(REMOTE_NAME, remote.getName());
37  		assertArrayEquals(new URIish[] { uri }, remote.getURIs().toArray());
38  		assertEquals(1, remote.getFetchRefSpecs().size());
39  		assertEquals(
40  				String.format("+refs/heads/*:refs/remotes/%s/*", REMOTE_NAME),
41  				remote.getFetchRefSpecs().get(0).toString());
42  
43  		// assert that the added remote is available in the git configuration
44  		assertRemoteConfigEquals(remote,
45  				new RemoteConfig(db.getConfig(), REMOTE_NAME));
46  	}
47  
48  }