Browse Source

Fetch(Process): should tolerate duplicate refspecs

Bug: 529314
Change-Id: I91eaeda8a988d4786908fba6de00478cfc47a2a2
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.9
Marc Strapetz 7 years ago committed by Thomas Wolf
parent
commit
65a0cfc82a
  1. 45
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
  2. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java

45
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java

@ -56,6 +56,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.TagOpt;
import org.eclipse.jgit.transport.TrackingRefUpdate;
@ -270,4 +271,48 @@ public class FetchCommandTest extends RepositoryTestCase {
assertEquals(RefUpdate.Result.FORCED, update.getResult());
assertEquals(tagRef2.getObjectId(), db.resolve(tagName));
}
@Test
public void fetchAddRefsWithDuplicateRefspec() throws Exception {
final String branchName = "branch";
final String remoteBranchName = "test/" + branchName;
remoteGit.commit().setMessage("commit").call();
Ref branchRef = remoteGit.branchCreate().setName(branchName).call();
final String spec1 = "+refs/heads/*:refs/remotes/test/*";
final String spec2 = "refs/heads/*:refs/remotes/test/*";
final StoredConfig config = db.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
remoteConfig.addFetchRefSpec(new RefSpec(spec1));
remoteConfig.addFetchRefSpec(new RefSpec(spec2));
remoteConfig.update(config);
git.fetch().setRemote("test").setRefSpecs(spec1).call();
assertEquals(branchRef.getObjectId(), db.resolve(remoteBranchName));
}
@Test
public void fetchPruneRefsWithDuplicateRefspec()
throws Exception {
final String branchName = "branch";
final String remoteBranchName = "test/" + branchName;
remoteGit.commit().setMessage("commit").call();
Ref branchRef = remoteGit.branchCreate().setName(branchName).call();
final String spec1 = "+refs/heads/*:refs/remotes/test/*";
final String spec2 = "refs/heads/*:refs/remotes/test/*";
final StoredConfig config = db.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
remoteConfig.addFetchRefSpec(new RefSpec(spec1));
remoteConfig.addFetchRefSpec(new RefSpec(spec2));
remoteConfig.update(config);
git.fetch().setRemote("test").setRefSpecs(spec1).call();
assertEquals(branchRef.getObjectId(), db.resolve(remoteBranchName));
remoteGit.branchDelete().setBranchNames(branchName).call();
git.fetch().setRemote("test").setRefSpecs(spec1)
.setRemoveDeletedRefs(true).call();
assertNull(db.resolve(remoteBranchName));
}
}

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java

@ -481,12 +481,14 @@ class FetchProcess {
private void deleteStaleTrackingRefs(FetchResult result,
BatchRefUpdate batch) throws IOException {
final Set<Ref> processed = new HashSet<>();
for (final Ref ref : localRefs().values()) {
final String refname = ref.getName();
for (final RefSpec spec : toFetch) {
if (spec.matchDestination(refname)) {
final RefSpec s = spec.expandFromDestination(refname);
if (result.getAdvertisedRef(s.getSource()) == null) {
if (result.getAdvertisedRef(s.getSource()) == null
&& processed.add(ref)) {
deleteTrackingRef(result, batch, s, ref);
}
}

Loading…
Cancel
Save