Skip to content

Commit 6fd4b1c

Browse files
committed
Revert back to JGit 2.0, as JGit 2.1 introduced rtyley#92
Agit v1.36 updated JGit from v2.0 to v2.2. It looks like some change was introduced with JGit 2.1 (and all subsequent versions I've checked) that makes the ref update fail... perhaps addressing the ref with the wrong name (or made it sensitive to using the wrong name), as we see debug like this: TrackingRefUpdate : refs/heads//master old=AnyObjectId[0000000000000000000000000000000000000000] new=AnyObjectId[ce1e0703402e989bedf03d5df535401340f54b42] The ref had a proper value before the ref update, so should not have been 00000000... and the correct new value we see is lost, not stored to any place I can see. Not sure what's going on with the double slash, JGit 2.0 has it too. Weirdly, I've only been able to reproduce this issue with repos cloned by Agit - so 'testFetchUpdatesFromLocalTestServer()' always passes, but 'testFetchUpdatesOnCloneFromLocalTestServer()' fails with JGit 2.1 and above.
1 parent ab3d211 commit 6fd4b1c

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

agit-integration-tests/src/main/java/com/madgag/agit/GitAsyncTaskTest.java

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static java.util.concurrent.TimeUnit.SECONDS;
3333
import static org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME;
3434
import static org.hamcrest.MatcherAssert.assertThat;
35+
import static org.hamcrest.Matchers.equalTo;
3536
import static org.hamcrest.Matchers.is;
3637
import static org.hamcrest.Matchers.not;
3738
import static roboguice.RoboGuice.newDefaultRoboModule;
@@ -45,6 +46,7 @@
4546
import com.madgag.agit.matchers.GitTestHelper;
4647
import com.madgag.agit.operation.lifecycle.OperationLifecycleSupport;
4748
import com.madgag.agit.operations.Clone;
49+
import com.madgag.agit.operations.Fetch;
4850
import com.madgag.agit.operations.GitAsyncTask;
4951
import com.madgag.agit.operations.GitAsyncTaskFactory;
5052
import com.madgag.agit.operations.GitOperation;
@@ -56,6 +58,7 @@
5658
import java.io.IOException;
5759
import java.util.concurrent.CountDownLatch;
5860

61+
import org.eclipse.jgit.lib.ObjectId;
5962
import org.eclipse.jgit.lib.Repository;
6063
import org.eclipse.jgit.storage.file.FileRepository;
6164
import org.eclipse.jgit.transport.RemoteConfig;
@@ -113,25 +116,54 @@ public void testCloneNonBareRepoFromLocalTestServer() throws Exception {
113116
assertThat(readmeFile, ofLength(12));
114117
}
115118

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+
116154
@MediumTest
117155
public void testPullUpdatesFromLocalTestServer() throws Exception {
118156
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"));
126158
// Git.wrap(repository).branchCreate().setName("master").setStartPoint("origin/master");
127159

128160
assertThat(repository, hasGitObject("3974996807a9f596cf25ac3a714995c24bb97e2c"));
129161
String commit1 = "ce1e0703402e989bedf03d5df535401340f54b42";
130162
assertThat(repository, not(hasGitObject(commit1)));
131163
assertFileLength(2, repository.getWorkTree(), "EXAMPLE");
132-
Pull pullOp = new Pull(repository);
133164

134-
executeAndWaitFor(pullOp);
165+
executeAndWaitFor(new Pull(repository));
166+
135167
assertThat(repository, hasGitObject(commit1));
136168

137169
assertFileLength(4, repository.getWorkTree(), "EXAMPLE");
@@ -239,4 +271,14 @@ public void completed(OpNotification completionNotification) {
239271
return new FileRepository(operation.getGitDir());
240272
}
241273

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+
242284
}
Binary file not shown.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<dependency>
6363
<groupId>com.madgag</groupId>
6464
<artifactId>org.eclipse.jgit</artifactId>
65-
<version>2.2.0.0.2-UNOFFICIAL-ROBERTO-RELEASE</version>
65+
<version>2.0.0.0.1-UNOFFICIAL-ROBERTO-RELEASE</version>
6666
</dependency>
6767
<dependency>
6868
<groupId>com.google.android</groupId>

0 commit comments

Comments
 (0)