|
32 | 32 | import static java.util.concurrent.TimeUnit.SECONDS;
|
33 | 33 | import static org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME;
|
34 | 34 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 35 | +import static org.hamcrest.Matchers.equalTo; |
35 | 36 | import static org.hamcrest.Matchers.is;
|
36 | 37 | import static org.hamcrest.Matchers.not;
|
37 | 38 | import static roboguice.RoboGuice.newDefaultRoboModule;
|
|
45 | 46 | import com.madgag.agit.matchers.GitTestHelper;
|
46 | 47 | import com.madgag.agit.operation.lifecycle.OperationLifecycleSupport;
|
47 | 48 | import com.madgag.agit.operations.Clone;
|
| 49 | +import com.madgag.agit.operations.Fetch; |
48 | 50 | import com.madgag.agit.operations.GitAsyncTask;
|
49 | 51 | import com.madgag.agit.operations.GitAsyncTaskFactory;
|
50 | 52 | import com.madgag.agit.operations.GitOperation;
|
|
56 | 58 | import java.io.IOException;
|
57 | 59 | import java.util.concurrent.CountDownLatch;
|
58 | 60 |
|
| 61 | +import org.eclipse.jgit.lib.ObjectId; |
59 | 62 | import org.eclipse.jgit.lib.Repository;
|
60 | 63 | import org.eclipse.jgit.storage.file.FileRepository;
|
61 | 64 | import org.eclipse.jgit.transport.RemoteConfig;
|
@@ -113,25 +116,54 @@ public void testCloneNonBareRepoFromLocalTestServer() throws Exception {
|
113 | 116 | assertThat(readmeFile, ofLength(12));
|
114 | 117 | }
|
115 | 118 |
|
| 119 | + @MediumTest |
| 120 | + public void testFetchUpdatesOnCloneFromLocalTestServer() throws Exception { |
| 121 | + Clone cloneOp = new Clone(true, integrationGitServerURIFor("small-test-repo.early.git"), helper().newFolder()); |
| 122 | + |
| 123 | + Repository repository = executeAndWaitFor(cloneOp); |
| 124 | + |
| 125 | + String initialCommitId = "3974996807a9f596cf25ac3a714995c24bb97e2c", commit1 = "ce1e0703402e989bedf03d5df535401340f54b42"; |
| 126 | + assertThat(repository, hasGitObject(initialCommitId)); |
| 127 | + assertThat(repository.resolve("master").name(), equalTo(initialCommitId)); |
| 128 | + assertThat(repository, not(hasGitObject(commit1))); |
| 129 | + |
| 130 | + setRemoteUrl(repository, integrationGitServerURIFor("small-test-repo.later.git")); |
| 131 | + |
| 132 | + executeAndWaitFor(new Fetch(repository, DEFAULT_REMOTE_NAME)); |
| 133 | + |
| 134 | + assertThat(repository, hasGitObject(commit1)); |
| 135 | + assertThat(repository.resolve("master").name(), equalTo(commit1)); |
| 136 | + } |
| 137 | + |
| 138 | + @MediumTest |
| 139 | + public void testFetchUpdatesFromLocalTestServer() throws Exception { |
| 140 | + Repository repository = helper().unpackRepo("small-test-repo.early.bare.git.zap"); |
| 141 | + setRemoteUrl(repository, integrationGitServerURIFor("small-test-repo.later.git")); |
| 142 | + |
| 143 | + String initialCommitId = "3974996807a9f596cf25ac3a714995c24bb97e2c", commit1 = "ce1e0703402e989bedf03d5df535401340f54b42"; |
| 144 | + assertThat(repository, hasGitObject(initialCommitId)); |
| 145 | + assertThat(repository.resolve("master").name(), equalTo(initialCommitId)); |
| 146 | + assertThat(repository, not(hasGitObject(commit1))); |
| 147 | + |
| 148 | + executeAndWaitFor(new Fetch(repository, DEFAULT_REMOTE_NAME)); |
| 149 | + |
| 150 | + assertThat(repository, hasGitObject(commit1)); |
| 151 | + assertThat(repository.resolve("master").name(), equalTo(commit1)); |
| 152 | + } |
| 153 | + |
116 | 154 | @MediumTest
|
117 | 155 | public void testPullUpdatesFromLocalTestServer() throws Exception {
|
118 | 156 | Repository repository = helper().unpackRepo("small-test-repo.early.zap");
|
119 |
| - RemoteConfig remoteConfig = remoteConfigFor(repository, DEFAULT_REMOTE_NAME); |
120 |
| - for (URIish urIish : remoteConfig.getURIs()) { |
121 |
| - remoteConfig.removeURI(urIish); |
122 |
| - } |
123 |
| - remoteConfig.addURI(integrationGitServerURIFor("small-test-repo.later.git")); |
124 |
| - remoteConfig.update(repository.getConfig()); |
125 |
| - repository.getConfig().save(); |
| 157 | + setRemoteUrl(repository, integrationGitServerURIFor("small-test-repo.later.git")); |
126 | 158 | // Git.wrap(repository).branchCreate().setName("master").setStartPoint("origin/master");
|
127 | 159 |
|
128 | 160 | assertThat(repository, hasGitObject("3974996807a9f596cf25ac3a714995c24bb97e2c"));
|
129 | 161 | String commit1 = "ce1e0703402e989bedf03d5df535401340f54b42";
|
130 | 162 | assertThat(repository, not(hasGitObject(commit1)));
|
131 | 163 | assertFileLength(2, repository.getWorkTree(), "EXAMPLE");
|
132 |
| - Pull pullOp = new Pull(repository); |
133 | 164 |
|
134 |
| - executeAndWaitFor(pullOp); |
| 165 | + executeAndWaitFor(new Pull(repository)); |
| 166 | + |
135 | 167 | assertThat(repository, hasGitObject(commit1));
|
136 | 168 |
|
137 | 169 | assertFileLength(4, repository.getWorkTree(), "EXAMPLE");
|
@@ -239,4 +271,14 @@ public void completed(OpNotification completionNotification) {
|
239 | 271 | return new FileRepository(operation.getGitDir());
|
240 | 272 | }
|
241 | 273 |
|
| 274 | + private void setRemoteUrl(Repository repository, URIish uri) throws IOException { |
| 275 | + RemoteConfig remoteConfig = remoteConfigFor(repository, DEFAULT_REMOTE_NAME); |
| 276 | + for (URIish urIish : remoteConfig.getURIs()) { |
| 277 | + remoteConfig.removeURI(urIish); |
| 278 | + } |
| 279 | + remoteConfig.addURI(uri); |
| 280 | + remoteConfig.update(repository.getConfig()); |
| 281 | + repository.getConfig().save(); |
| 282 | + } |
| 283 | + |
242 | 284 | }
|
0 commit comments