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 package org.eclipse.jgit.gitrepo;
44
45 import static org.junit.Assert.assertEquals;
46 import static org.junit.Assert.assertFalse;
47 import static org.junit.Assert.assertTrue;
48
49 import java.io.File;
50
51 import org.eclipse.jgit.api.Git;
52 import org.eclipse.jgit.junit.JGitTestUtil;
53 import org.eclipse.jgit.junit.RepositoryTestCase;
54 import org.eclipse.jgit.lib.Repository;
55 import org.eclipse.jgit.util.FS;
56 import org.junit.Before;
57 import org.junit.Test;
58
59 public class RepoCommandSymlinkTest extends RepositoryTestCase {
60 @Before
61 public void beforeMethod() {
62
63
64 org.junit.Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
65 }
66
67 private Repository defaultDb;
68
69 private String rootUri;
70 private String defaultUri;
71
72 @Override
73 public void setUp() throws Exception {
74 super.setUp();
75
76 defaultDb = createWorkRepository();
77 try (Git git = new Git(defaultDb)) {
78 JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "hello world");
79 git.add().addFilepattern("hello.txt").call();
80 git.commit().setMessage("Initial commit").call();
81 addRepoToClose(defaultDb);
82 }
83
84 defaultUri = defaultDb.getDirectory().toURI().toString();
85 int root = defaultUri.lastIndexOf("/",
86 defaultUri.lastIndexOf("/.git") - 1)
87 + 1;
88 rootUri = defaultUri.substring(0, root)
89 + "manifest";
90 defaultUri = defaultUri.substring(root);
91 }
92
93 @Test
94 public void testLinkFileBare() throws Exception {
95 try (
96 Repository remoteDb = createBareRepository();
97 Repository tempDb = createWorkRepository()) {
98 StringBuilder xmlContent = new StringBuilder();
99 xmlContent
100 .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
101 .append("<manifest>")
102 .append("<remote name=\"remote1\" fetch=\".\" />")
103 .append("<default revision=\"master\" remote=\"remote1\" />")
104 .append("<project path=\"foo\" name=\"").append(defaultUri)
105 .append("\" revision=\"master\" >")
106 .append("<linkfile src=\"hello.txt\" dest=\"LinkedHello\" />")
107 .append("<linkfile src=\"hello.txt\" dest=\"foo/LinkedHello\" />")
108 .append("<linkfile src=\"hello.txt\" dest=\"subdir/LinkedHello\" />")
109 .append("</project>")
110 .append("<project path=\"bar/baz\" name=\"")
111 .append(defaultUri).append("\" revision=\"master\" >")
112 .append("<linkfile src=\"hello.txt\" dest=\"bar/foo/LinkedHello\" />")
113 .append("</project>").append("</manifest>");
114 JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
115 xmlContent.toString());
116 RepoCommand command = new RepoCommand(remoteDb);
117 command.setPath(
118 tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
119 .setURI(rootUri).call();
120
121 File directory = createTempDirectory("testCopyFileBare");
122 Repository localDb = Git.cloneRepository().setDirectory(directory)
123 .setURI(remoteDb.getDirectory().toURI().toString()).call()
124 .getRepository();
125
126
127 File linkedhello = new File(localDb.getWorkTree(), "LinkedHello");
128 assertTrue("The LinkedHello file should exist",
129 localDb.getFS().exists(linkedhello));
130 assertTrue("The LinkedHello file should be a symlink",
131 localDb.getFS().isSymLink(linkedhello));
132 assertEquals("foo/hello.txt",
133 localDb.getFS().readSymLink(linkedhello));
134
135
136 File linkedfoohello = new File(localDb.getWorkTree(), "foo/LinkedHello");
137 assertFalse("The foo/LinkedHello file should be skipped",
138 localDb.getFS().exists(linkedfoohello));
139
140
141 File linkedsubdirhello = new File(localDb.getWorkTree(),
142 "subdir/LinkedHello");
143 assertTrue("The subdir/LinkedHello file should exist",
144 localDb.getFS().exists(linkedsubdirhello));
145 assertTrue("The subdir/LinkedHello file should be a symlink",
146 localDb.getFS().isSymLink(linkedsubdirhello));
147 assertEquals("../foo/hello.txt",
148 localDb.getFS().readSymLink(linkedsubdirhello));
149
150
151 File linkedbarfoohello = new File(localDb.getWorkTree(),
152 "bar/foo/LinkedHello");
153 assertTrue("The bar/foo/LinkedHello file should exist",
154 localDb.getFS().exists(linkedbarfoohello));
155 assertTrue("The bar/foo/LinkedHello file should be a symlink",
156 localDb.getFS().isSymLink(linkedbarfoohello));
157 assertEquals("../baz/hello.txt",
158 localDb.getFS().readSymLink(linkedbarfoohello));
159
160 localDb.close();
161 }
162 }
163 }