aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RemoteAddCommandTest.java
blob: c40c52488e8b7011cf1b06e919af310a3d0652ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (C) 2015, Kaloyan Raev <kaloyan.r@zend.com> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.api;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.junit.Test;

public class RemoteAddCommandTest extends AbstractRemoteCommandTest {

	@Test
	public void testAdd() throws Exception {
		// create another repository
		Repository remoteRepository = createWorkRepository();
		URIish uri = new URIish(
				remoteRepository.getDirectory().toURI().toURL());

		// execute the command to add a new remote
		RemoteAddCommand cmd = Git.wrap(db).remoteAdd();
		cmd.setName(REMOTE_NAME);
		cmd.setUri(uri);
		RemoteConfig remote = cmd.call();

		// assert that the added remote represents the remote repository
		assertEquals(REMOTE_NAME, remote.getName());
		assertArrayEquals(new URIish[] { uri }, remote.getURIs().toArray());
		assertEquals(1, remote.getFetchRefSpecs().size());
		assertEquals(
				String.format("+refs/heads/*:refs/remotes/%s/*", REMOTE_NAME),
				remote.getFetchRefSpecs().get(0).toString());

		// assert that the added remote is available in the git configuration
		assertRemoteConfigEquals(remote,
				new RemoteConfig(db.getConfig(), REMOTE_NAME));
	}

}