1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.junit.ssh;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
15
16 import java.io.File;
17
18 import org.eclipse.jgit.api.Git;
19 import org.junit.Test;
20
21
22
23
24
25
26 public abstract class SshBasicTestBase extends SshTestHarness {
27
28 protected File defaultCloneDir;
29
30 @Override
31 public void setUp() throws Exception {
32 super.setUp();
33 defaultCloneDir = new File(getTemporaryDirectory(), "cloned");
34 }
35
36 @Test
37 public void testSshCloneWithConfig() throws Exception {
38 cloneWith("ssh://localhost/doesntmatter", defaultCloneDir, null, //
39 "Host localhost",
40 "HostName localhost",
41 "Port " + testPort,
42 "User " + TEST_USER,
43 "IdentityFile " + privateKey1.getAbsolutePath());
44 }
45
46 @Test
47 public void testSshFetchWithConfig() throws Exception {
48 File localClone = cloneWith("ssh://localhost/doesntmatter",
49 defaultCloneDir, null,
50 "Host localhost",
51 "HostName localhost",
52 "Port " + testPort,
53 "User " + TEST_USER,
54 "IdentityFile " + privateKey1.getAbsolutePath());
55
56 try (Giti/Git.html#Git">Git git = new Git(db)) {
57 writeTrashFile("SomeOtherFile.txt", "Other commit");
58 git.add().addFilepattern("SomeOtherFile.txt").call();
59 git.commit().setMessage("New commit").call();
60 }
61
62 try (Git git = Git.open(localClone)) {
63 File f = new File(git.getRepository().getWorkTree(),
64 "SomeOtherFile.txt");
65 assertFalse(f.exists());
66 git.pull().setRemote("origin").call();
67 assertTrue(f.exists());
68 assertEquals("Other commit", read(f));
69 }
70 }
71 }