summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-05-28 08:56:27 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-05-28 08:56:27 +0900
commit2ab42b74d9803d8239ff4f9eda1cf153666a4079 (patch)
treec80eed44bac15145e3062855d6de1fe9888e5ab8
parent2f1b4ffcd297d9dffd8f69ee4c7e2976a714224a (diff)
parentde21c58d03d9f54e0a80d358948517d3ea518312 (diff)
downloadjgit-2ab42b74d9803d8239ff4f9eda1cf153666a4079.tar.gz
jgit-2ab42b74d9803d8239ff4f9eda1cf153666a4079.zip
Merge branch 'stable-5.0'
* stable-5.0: Don't prune symbolic refs when fetch.prune = true Prepare 5.0.0-SNAPSHOT builds JGit v5.0.0.201805221745-rc1 Prepare 5.0.0-SNAPSHOT builds JGit v5.0.0.201805151920-m7 Change-Id: I9a9a4a3ab36a2bd83e4eaed90151740d59af171b
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java44
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java3
2 files changed, 47 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index cf1afceae6..4c2c0e8d1f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -43,10 +43,15 @@
package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.util.Collection;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -204,4 +209,43 @@ public class FetchCommandTest extends RepositoryTestCase {
assertEquals(RefUpdate.Result.FORCED, update.getResult());
assertEquals(tagRef2.getObjectId(), db.resolve(tagName));
}
+
+ @Test
+ public void testFetchWithPruneShouldKeepOriginHead() throws Exception {
+ // Create a commit in the test repo.
+ commitFile("foo", "foo", "master");
+ // Produce a real clone of the git repo
+ Git cloned = Git.cloneRepository()
+ .setDirectory(createTempDirectory("testCloneRepository"))
+ .setURI("file://"
+ + git.getRepository().getWorkTree().getAbsolutePath())
+ .call();
+ assertNotNull(cloned);
+ Repository clonedRepo = cloned.getRepository();
+ addRepoToClose(clonedRepo);
+ ObjectId originMasterId = clonedRepo
+ .resolve("refs/remotes/origin/master");
+ assertNotNull("Should have origin/master", originMasterId);
+ assertNotEquals("origin/master should not be zero ID",
+ ObjectId.zeroId(), originMasterId);
+ // Canonical git creates origin/HEAD; JGit (for now) doesn't. Let's
+ // pretend we did the clone via command-line git.
+ ObjectId originHeadId = clonedRepo.resolve("refs/remotes/origin/HEAD");
+ if (originHeadId == null) {
+ JGitTestUtil.write(
+ new File(clonedRepo.getDirectory(),
+ "refs/remotes/origin/HEAD"),
+ "ref: refs/remotes/origin/master\n");
+ originHeadId = clonedRepo.resolve("refs/remotes/origin/HEAD");
+ }
+ assertEquals("Should have origin/HEAD", originMasterId, originHeadId);
+ FetchResult result = cloned.fetch().setRemote("origin")
+ .setRemoveDeletedRefs(true).call();
+ assertTrue("Fetch after clone should be up-to-date",
+ result.getTrackingRefUpdates().isEmpty());
+ assertEquals("origin/master should still exist", originMasterId,
+ clonedRepo.resolve("refs/remotes/origin/master"));
+ assertEquals("origin/HEAD should be unchanged", originHeadId,
+ clonedRepo.resolve("refs/remotes/origin/HEAD"));
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java
index 51f900b246..ff183c8974 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java
@@ -480,6 +480,9 @@ class FetchProcess {
private void deleteStaleTrackingRefs(FetchResult result,
BatchRefUpdate batch) throws IOException {
for (Ref ref : localRefs().values()) {
+ if (ref.isSymbolic()) {
+ continue;
+ }
final String refname = ref.getName();
for (RefSpec spec : toFetch) {
if (spec.matchDestination(refname)) {