1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.pgm;
11
12 import static org.junit.Assert.assertEquals;
13
14 import org.eclipse.jgit.api.Git;
15 import org.eclipse.jgit.lib.CLIRepositoryTestCase;
16 import org.eclipse.jgit.lib.Repository;
17 import org.eclipse.jgit.lib.StoredConfig;
18 import org.eclipse.jgit.transport.RemoteConfig;
19 import org.eclipse.jgit.transport.URIish;
20 import org.junit.Before;
21 import org.junit.Test;
22
23 public class FetchTest extends CLIRepositoryTestCase {
24 private Git git;
25
26 private Git remoteGit;
27
28 @Override
29 @Before
30 public void setUp() throws Exception {
31 super.setUp();
32 git = new Git(db);
33 git.commit().setMessage("initial commit").call();
34
35 Repository remoteRepository = createWorkRepository();
36 remoteGit = new Git(remoteRepository);
37
38
39 final StoredConfig config = db.getConfig();
40 RemoteConfig remoteConfig = new RemoteConfig(config, "test");
41 URIish uri = new URIish(remoteRepository.getDirectory().toURI().toURL());
42 remoteConfig.addURI(uri);
43 remoteConfig.update(config);
44 config.save();
45
46 remoteGit.commit().setMessage("initial commit").call();
47 remoteGit.tag().setName("tag").call();
48 remoteGit.checkout().setName("other").setCreateBranch(true).call();
49 remoteGit.commit().setMessage("commit2").call();
50 remoteGit.tag().setName("foo").call();
51 }
52
53 @Test
54 public void testFetchDefault() throws Exception {
55 String[] result = execute("git fetch test refs/heads/master:refs/remotes/origin/master");
56 assertEquals(" * [new branch] master -> origin/master",
57 result[1]);
58 assertEquals(" * [new tag] tag -> tag", result[2]);
59 }
60
61 @Test
62 public void testFetchForceUpdate() throws Exception {
63 String[] result = execute(
64 "git fetch test refs/heads/master:refs/remotes/origin/master");
65 assertEquals(" * [new branch] master -> origin/master",
66 result[1]);
67 assertEquals(" * [new tag] tag -> tag", result[2]);
68 remoteGit.commit().setAmend(true).setMessage("amended").call();
69 result = execute(
70 "git fetch -f test refs/heads/master:refs/remotes/origin/master");
71 assertEquals("", result[0]);
72 }
73
74 @Test
75 public void testFetchNoTags() throws Exception {
76 String[] result = execute("git fetch --no-tags test refs/heads/master:refs/remotes/origin/master");
77 assertEquals(" * [new branch] master -> origin/master",
78 result[1]);
79 assertEquals("", result[2]);
80 }
81
82 @Test
83 public void testFetchAllTags() throws Exception {
84 String[] result = execute("git fetch --tags test refs/heads/master:refs/remotes/origin/master");
85 assertEquals(" * [new branch] master -> origin/master",
86 result[1]);
87 assertEquals(" * [new tag] foo -> foo", result[2]);
88 assertEquals(" * [new tag] tag -> tag", result[3]);
89 }
90 }