blob: 27c7674e9c8d7a59ba47b4d87ac6729aebd9f7e0 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package org.eclipse.jgit.transport;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.UploadPack.RequestPolicy;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for server upload-pack utilities.
*/
public class UploadPackTest {
private URIish uri;
private TestProtocol<Object> testProtocol;
private Object ctx = new Object();
private InMemoryRepository server;
private InMemoryRepository client;
private RevCommit commit0;
private RevCommit commit1;
private RevCommit tip;
@Before
public void setUp() throws Exception {
server = newRepo("server");
client = newRepo("client");
TestRepository<InMemoryRepository> remote =
new TestRepository<>(server);
commit0 = remote.commit().message("0").create();
commit1 = remote.commit().message("1").parent(commit0).create();
tip = remote.commit().message("2").parent(commit1).create();
remote.update("master", tip);
}
@After
public void tearDown() {
Transport.unregister(testProtocol);
}
private static InMemoryRepository newRepo(String name) {
return new InMemoryRepository(new DfsRepositoryDescription(name));
}
@Test
public void testFetchParentOfShallowCommit() throws Exception {
testProtocol = new TestProtocol<>(
new UploadPackFactory<Object>() {
@Override
public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException,
ServiceNotAuthorizedException {
UploadPack up = new UploadPack(db);
up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);
// assume client has a shallow commit
up.getRevWalk().assumeShallow(
Collections.singleton(commit1.getId()));
return up;
}
}, null);
uri = testProtocol.register(ctx, server);
assertFalse(client.hasObject(commit0.toObjectId()));
// Fetch of the parent of the shallow commit
try (Transport tn = testProtocol.open(uri, client, "server")) {
tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit0.name())));
assertTrue(client.hasObject(commit0.toObjectId()));
}
}
}
|