diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-02-20 18:11:49 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-03-06 17:30:01 +0100 |
commit | 8a2c76941729629dce06e2238464e114f2ccc79a (patch) | |
tree | d8b66eb5d0527f34bb7c56b509f5cf65fd8fb9e2 /org.eclipse.jgit.test/tst/org/eclipse/jgit/api | |
parent | 90df7c123ecac9ae75a189b761a2599d5fba3565 (diff) | |
download | jgit-8a2c76941729629dce06e2238464e114f2ccc79a.tar.gz jgit-8a2c76941729629dce06e2238464e114f2ccc79a.zip |
[push] support the "matching" RefSpecs ":" and "+:"
The implementation of push.default=matching was not correct.
It used the RefSpec "refs/heads/*:refs/heads/*", which would push
_all_ local branches. But "matching" must push only those local
branches for which a remote branch with the same name already exists
at the remote.
This RefSpec can be expanded only once the advertisement from the
remote has been received.
Enhance RefSpec so that ":" and "+:" can be represented. Introduce a
special RemoteRefUpdate for such a RefSpec; it must carry through the
fetch RefSpecs to be able to fill in the remote tracking updates as
needed. Implement the expansion in PushProcess.
Bug: 353405
Change-Id: I54a4bfbb0a6a7d77b9128bf4a9c951d6586c3df4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java index 1a1f5b487e..6f7aa63edc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java @@ -10,6 +10,7 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -392,28 +393,64 @@ public class PushCommandTest extends RepositoryTestCase { git.add().addFilepattern("f").call(); RevCommit commit = git.commit().setMessage("adding f").call(); - git.checkout().setName("also-pushed").setCreateBranch(true).call(); + git.checkout().setName("not-pushed").setCreateBranch(true).call(); git.checkout().setName("branchtopush").setCreateBranch(true).call(); assertEquals(null, git2.getRepository().resolve("refs/heads/branchtopush")); assertEquals(null, - git2.getRepository().resolve("refs/heads/also-pushed")); + git2.getRepository().resolve("refs/heads/not-pushed")); assertEquals(null, git2.getRepository().resolve("refs/heads/master")); - git.push().setRemote("test").setPushDefault(PushDefault.MATCHING) + // push master and branchtopush + git.push().setRemote("test").setRefSpecs( + new RefSpec("refs/heads/master:refs/heads/master"), + new RefSpec( + "refs/heads/branchtopush:refs/heads/branchtopush")) .call(); assertEquals(commit.getId(), - git2.getRepository().resolve("refs/heads/branchtopush")); - assertEquals(commit.getId(), - git2.getRepository().resolve("refs/heads/also-pushed")); + git2.getRepository().resolve("refs/heads/master")); assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + // Create two different commits on these two branches + writeTrashFile("b", "on branchtopush"); + git.add().addFilepattern("b").call(); + RevCommit bCommit = git.commit().setMessage("on branchtopush") + .call(); + git.checkout().setName("master").call(); + writeTrashFile("m", "on master"); + git.add().addFilepattern("m").call(); + RevCommit mCommit = git.commit().setMessage("on master").call(); + // Now push with mode "matching": should push both branches. + Iterable<PushResult> result = git.push().setRemote("test") + .setPushDefault(PushDefault.MATCHING) + .call(); + int n = 0; + for (PushResult r : result) { + n++; + assertEquals(1, n); + assertEquals(2, r.getRemoteUpdates().size()); + for (RemoteRefUpdate update : r.getRemoteUpdates()) { + assertFalse(update.isMatching()); + assertTrue(update.getSrcRef() + .equals("refs/heads/branchtopush") + || update.getSrcRef().equals("refs/heads/master")); + assertEquals(RemoteRefUpdate.Status.OK, update.getStatus()); + } + } + assertEquals(bCommit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(mCommit.getId(), git2.getRepository().resolve("refs/heads/master")); - assertEquals(commit.getId(), git.getRepository() + assertEquals(bCommit.getId(), git.getRepository() .resolve("refs/remotes/origin/branchtopush")); - assertEquals(commit.getId(), git.getRepository() - .resolve("refs/remotes/origin/also-pushed")); - assertEquals(commit.getId(), + assertEquals(null, git.getRepository() + .resolve("refs/remotes/origin/not-pushed")); + assertEquals(mCommit.getId(), git.getRepository().resolve("refs/remotes/origin/master")); } } |