Skip to content

Commit 06ef150

Browse files
committed
Fix rtyley#92 properly- don't write malformed refspecs, but tolerate them
Use JGit library patched to tolerate the malformed refspecs generated by JGit v1.0-v2.3.1 for bare-repo clones. From JGit v2.1 onwards (commit 3da13473), these malformed refspecs were no longer tolerated and would stop fetches from updating refs. Normalising the refspecs fixes this issue and allows fetches to update refs successfully. https://bugs.eclipse.org/bugs/show_bug.cgi?id=402031
1 parent 7ffb349 commit 06ef150

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
import java.io.IOException;
5959
import java.util.concurrent.CountDownLatch;
6060

61-
import org.eclipse.jgit.lib.ObjectId;
6261
import org.eclipse.jgit.lib.Repository;
6362
import org.eclipse.jgit.storage.file.FileRepository;
63+
import org.eclipse.jgit.transport.RefSpec;
6464
import org.eclipse.jgit.transport.RemoteConfig;
6565
import org.eclipse.jgit.transport.URIish;
6666

@@ -122,6 +122,8 @@ public void testFetchUpdatesOnCloneFromLocalTestServer() throws Exception {
122122

123123
Repository repository = executeAndWaitFor(cloneOp);
124124

125+
printFetchRefSpecs(repository);
126+
125127
String initialCommitId = "3974996807a9f596cf25ac3a714995c24bb97e2c", commit1 = "ce1e0703402e989bedf03d5df535401340f54b42";
126128
assertThat(repository, hasGitObject(initialCommitId));
127129
assertThat(repository.resolve("master").name(), equalTo(initialCommitId));
@@ -135,6 +137,13 @@ public void testFetchUpdatesOnCloneFromLocalTestServer() throws Exception {
135137
assertThat(repository.resolve("master").name(), equalTo(commit1));
136138
}
137139

140+
private void printFetchRefSpecs(Repository repository) {
141+
RemoteConfig remoteConfig = remoteConfigFor(repository, DEFAULT_REMOTE_NAME);
142+
for (RefSpec refSpec : remoteConfig.getFetchRefSpecs()) {
143+
Log.i(TAG, "refSpec = " + refSpec);
144+
}
145+
}
146+
138147
@MediumTest
139148
public void testFetchUpdatesFromLocalTestServer() throws Exception {
140149
Repository repository = helper().unpackRepo("small-test-repo.early.bare.git.zap");

agit/src/main/java/com/madgag/agit/GitFetchService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030

3131
import java.util.Collection;
3232
import java.util.Collections;
33+
import java.util.Map;
3334

3435
import org.eclipse.jgit.api.Git;
3536
import org.eclipse.jgit.api.TransportConfigCallback;
3637
import org.eclipse.jgit.api.errors.GitAPIException;
38+
import org.eclipse.jgit.lib.Ref;
3739
import org.eclipse.jgit.transport.CredentialsProvider;
3840
import org.eclipse.jgit.transport.FetchResult;
3941
import org.eclipse.jgit.transport.RefSpec;
@@ -58,6 +60,9 @@ public class GitFetchService {
5860
public FetchResult fetch(String remote, Collection<RefSpec> toFetch) {
5961
Log.d(TAG, "About to run fetch : " + remote);
6062

63+
for (Map.Entry<String,Ref> entry : git.getRepository().getAllRefs().entrySet()) {
64+
Log.d(TAG, entry.getKey()+" = "+entry.getValue());
65+
}
6166
FetchResult fetchResult = null;
6267
try {
6368
fetchResult = git.fetch()
@@ -70,7 +75,10 @@ public FetchResult fetch(String remote, Collection<RefSpec> toFetch) {
7075
} catch (GitAPIException e) {
7176
throw exceptionWithFriendlyMessageFor(e);
7277
}
73-
Log.d(TAG, "Fetch complete with : " + fetchResult);
78+
Log.d(TAG, "Fetch complete with : " + fetchResult+" messages="+fetchResult.getMessages());
79+
for (Ref ref : fetchResult.getAdvertisedRefs()) {
80+
Log.d(TAG, "AdvertisedRef : " + ref.getName()+" objectId="+ref.getObjectId());
81+
}
7482
for (TrackingRefUpdate update : fetchResult.getTrackingRefUpdates()) {
7583
Log.d(TAG, "TrackingRefUpdate : " + update.getLocalName() + " old=" + update.getOldObjectId() + " new=" + update.getNewObjectId());
7684
}

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.0.0.0.1-UNOFFICIAL-ROBERTO-RELEASE</version>
65+
<version>2.3.1.1.0-UNOFFICIAL-ROBERTO-RELEASE</version>
6666
</dependency>
6767
<dependency>
6868
<groupId>com.google.android</groupId>

0 commit comments

Comments
 (0)