1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.pgm;
11
12 import static org.junit.Assert.assertArrayEquals;
13
14 import java.util.List;
15
16 import org.eclipse.jgit.api.Git;
17 import org.eclipse.jgit.lib.CLIRepositoryTestCase;
18 import org.eclipse.jgit.lib.Constants;
19 import org.eclipse.jgit.lib.RefUpdate;
20 import org.junit.Before;
21 import org.junit.Test;
22
23 public class LsRemoteTest extends CLIRepositoryTestCase {
24 private Git git;
25
26 @Override
27 @Before
28 public void setUp() throws Exception {
29 super.setUp();
30 git = new Git(db);
31
32 writeTrashFile("Test.txt", "Hello world");
33 git.add().addFilepattern("Test.txt").call();
34 git.commit().setMessage("Initial commit").call();
35
36
37 git.branchCreate().setName("test").call();
38 RefUpdate rup = db.updateRef(Constants.HEAD);
39 rup.link("refs/heads/test");
40
41
42 git.tag().setName("tag1").call();
43 git.tag().setName("tag2").call();
44 git.tag().setName("tag3").call();
45 }
46
47 @Test
48 public void testLsRemote() throws Exception {
49 final List<String> result = CLIGitCommand.execute(
50 "git ls-remote " + shellQuote(db.getDirectory()), db);
51 assertArrayEquals(new String[] {
52 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c HEAD",
53 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
54 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
55 "efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1",
56 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}",
57 "4e4b837e0fd4ba83c003678b03592dc1509a4115 refs/tags/tag2",
58 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag2^{}",
59 "489384bf8ace47522fe32093d2ceb85b65a6cbb1 refs/tags/tag3",
60 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag3^{}",
61 "" }, result.toArray());
62 }
63
64 @Test
65 public void testLsRemoteHeads() throws Exception {
66 final List<String> result = CLIGitCommand.execute(
67 "git ls-remote --heads "
68 + shellQuote(db.getDirectory()),
69 db);
70 assertArrayEquals(new String[] {
71 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
72 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
73 "" }, result.toArray());
74 }
75
76 @Test
77 public void testLsRemoteTags() throws Exception {
78 final List<String> result = CLIGitCommand.execute(
79 "git ls-remote --tags " + shellQuote(db.getDirectory()), db);
80 assertArrayEquals(new String[] {
81 "efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1",
82 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}",
83 "4e4b837e0fd4ba83c003678b03592dc1509a4115 refs/tags/tag2",
84 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag2^{}",
85 "489384bf8ace47522fe32093d2ceb85b65a6cbb1 refs/tags/tag3",
86 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag3^{}",
87 "" }, result.toArray());
88 }
89
90 @Test
91 public void testLsRemoteHeadsTags() throws Exception {
92 final List<String> result = CLIGitCommand.execute(
93 "git ls-remote --heads --tags " + shellQuote(db.getDirectory()),
94 db);
95 assertArrayEquals(new String[] {
96 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
97 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
98 "efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1",
99 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}",
100 "4e4b837e0fd4ba83c003678b03592dc1509a4115 refs/tags/tag2",
101 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag2^{}",
102 "489384bf8ace47522fe32093d2ceb85b65a6cbb1 refs/tags/tag3",
103 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag3^{}",
104 "" }, result.toArray());
105 }
106
107 @Test
108 public void testLsRemoteSymRefs() throws Exception {
109 final List<String> result = CLIGitCommand.execute(
110 "git ls-remote --symref " + shellQuote(db.getDirectory()), db);
111 assertArrayEquals(new String[] {
112 "ref: refs/heads/test HEAD",
113 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c HEAD",
114 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
115 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
116 "efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1",
117 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}",
118 "4e4b837e0fd4ba83c003678b03592dc1509a4115 refs/tags/tag2",
119 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag2^{}",
120 "489384bf8ace47522fe32093d2ceb85b65a6cbb1 refs/tags/tag3",
121 "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag3^{}",
122 "" }, result.toArray());
123 }
124
125 }