/** * Constructs a new {@code SymRef} with the given name and target reference. * * @param name the name of the symbolic reference * @param target the reference that this symbolic ref points to */ public SymRef(String name, Ref target) { super(name, target.getObjectId()); this.target = target.getName(); }
private Ref toRemote(Ref localRef) { if (localRef.namespace().equals(Ref.TAGS_PREFIX)) { return localRef; } checkArgument(!localRef.getName().startsWith(Ref.REMOTES_PREFIX), "ref is already in a remotes namespace: %s", localRef); final String remoteNamespace = Ref.REMOTES_PREFIX + remote.getName() + "/"; final String remoteRefName = remoteNamespace + localRef.localName(); Ref remoteRef; if (localRef instanceof SymRef) { SymRef sr = (SymRef) localRef; String localtarget = sr.getTarget(); Ref remoteTarget = toRemote(new Ref(localtarget, sr.getObjectId())); remoteRef = new SymRef(remoteRefName, remoteTarget); } else { remoteRef = new Ref(remoteRefName, localRef.getObjectId()); } return remoteRef; }
private String toOrigInternal(String name) { String origName = append(txOrigNamespace, name); return origName; }
private String refDisplayString(Ref ref) { String branchName = ref.getName(); if (branchName.startsWith(Ref.HEADS_PREFIX)) { branchName = ref.localName(); } else if (branchName.startsWith(Ref.REMOTES_PREFIX)) { branchName = branchName.substring(Ref.REMOTES_PREFIX.length()); } if (ref instanceof SymRef) { branchName += " -> " + Ref.localName(((SymRef) ref).getTarget()); } return branchName; } }
private Ref toLocal(Ref remoteRef) { Optional<String> localName = remote.mapToRemote(remoteRef.getName()); Preconditions.checkArgument(localName.isPresent(), "Can't map %s to local ref using %s", remoteRef.getName(), remote.getFetchSpec()); Ref localRef; if (remoteRef instanceof SymRef) { Ref target = toLocal(remoteRef.peel()); localRef = new SymRef(localName.get(), target); } else { localRef = new Ref(localName.get(), remoteRef.getObjectId()); } return localRef; }
private Iterable<RefDiff> updateLocalRemoteRefs(Remote remote, List<LocalRemoteRef> fetchSpecs, final boolean prune) { List<RefDiff> updatedLocalRemoteRefs = new ArrayList<>(); for (LocalRemoteRef expected : fetchSpecs) { final boolean isNew = expected.isNew; final boolean remoteDeleted = expected.remoteDeleted; final String localName = expected.localRemoteRef.getName(); if (remoteDeleted) { if (prune) { updatedLocalRemoteRefs.add(RefDiff.removed(expected.localRemoteRef)); command(UpdateRef.class).setName(localName) .setOldValue(expected.localRemoteRef.getObjectId()).setDelete(true) .call(); } continue; } RefDiff localRefDiff; Ref oldRef = isNew ? null : expected.localRemoteRef; Ref newRef = new Ref(localName, expected.remoteRef.getObjectId()); command(UpdateRef.class).setName(localName).setNewValue(newRef.getObjectId()).call(); localRefDiff = new RefDiff(oldRef, newRef); updatedLocalRemoteRefs.add(localRefDiff); } return updatedLocalRemoteRefs; }
@Test public void testToString() throws Exception { Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid); assertEquals("[" + testRef.getName() + " -> " + testRef.getObjectId().toString() + "]", testRef.toString()); }
@Override protected ImmutableList<RevTag> _call() { List<Ref> refs = newArrayList( command(ForEachRef.class).setPrefixFilter(Ref.TAGS_PREFIX).call()); List<ObjectId> tagIds = transform(refs, (r) -> r.getObjectId()); Iterator<RevTag> alltags; alltags = objectDatabase().getAll(tagIds, BulkOpListener.NOOP_LISTENER, RevTag.class); ImmutableList<RevTag> res = ImmutableList.copyOf(alltags); return res; }
private static Set<ObjectId> veifyRepositoryContents(Repository repo, Map<String, Ref> allRefs) { Set<ObjectId> allIds = Sets.newConcurrentHashSet(); for (Ref ref : allRefs.values()) { if (ref instanceof SymRef) { Ref target = ref.peel(); assertTrue(format("symref points to a non existent ref: %s", ref), allRefs.containsKey(target.getName())); } else { Stack<String> pathToObject = new Stack<>(); pathToObject.push(ref.getName()); verifyAllReachableContents(repo, ref.getObjectId(), pathToObject, allIds); pathToObject.pop(); } } return allIds; }
@Override public String apply(Ref ref) { return ref.getName(); } };
@Test public void testPushWithRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), null, new Ref("refs/heads/NewRemoteBranch", commit.getId())); assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); // verify that the local reference of the remote master is updated Optional<Ref> ref = localRepo.command(RefParse.class) .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); TestSupport.verifyRepositoryContents(remoteRepo); }
/** * @return the name for this ref with the prefix removed */ public String localName() { return localName(name); }
public void writeBranchCreateResponse(Ref createdBranch) throws StreamWriterException { out.writeStartElement("BranchCreated"); writeElement("name", createdBranch.localName()); writeElement("source", createdBranch.getObjectId().toString()); out.writeEndElement(); // End BranchCreated }
@Test public void testPushNewBranch() throws Exception { localRepo.command(BranchCreateOp.class).setName("newbranch").call(); localRepo.command(CheckoutOp.class).setSource("newbranch").call(); // Add a commit to the local repository insertAndAdd(localRepo, lines3); insertAndAdd(localRepo, points1_modified); localRepo.command(CommitOp.class).call(); final Ref branch1 = getRef(localRepo, "newbranch").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("newbranch"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId()))); TestSupport.verifyRepositoryContents(remoteRepo); }
public @Test void prepareAndManuallyResolveAllConflicts() { createConflicts(TestData.point1, TestData.line1, TestData.poly1); PRStatus result = prepare(); assertEquals(3, result.getNumConflicts()); final UUID transactionId = request.getTransactionId(); origin.resumeTransaction(transactionId); assertEquals(request.getTargetBranch(), origin.getRef("HEAD").peel().localName()); //@formatter:off SimpleFeature c1 = TestData.clone(TestData.point1); c1.setAttribute("sp", "manually set"); SimpleFeature c2 = TestData.clone(TestData.line1); c2.setAttribute("sp", "manually set"); SimpleFeature c3 = TestData.clone(TestData.poly1); c3.setAttribute("sp", "manually set"); //@formatter:on Context context = clone.checkout("issuerBranch").getContext(); try { PullResult pres = context.command(PullOp.class).addRefSpec("master").call(); fail("Expected MergeConflictsException , got " + pres); } catch (MergeConflictsException e) { assertEquals(3, e.getReport().getConflicts()); clone.insert(c1, c2, c3).add().commit("manual conflict fix"); } result = prepare(); assertTrue(result.getMergeCommit().isPresent()); assertTrue(result.getReport().isPresent()); GeogigTransaction prtx = getTransaction(); Optional<Ref> mergeRef = request.resolveMergeRef(prtx); assertTrue(mergeRef.isPresent()); assertEquals(result.getMergeCommit().get(), mergeRef.get().getObjectId()); }
@Test public void testLocalNameAndNamespace() { String ref = Ref.localName(Ref.HEADS_PREFIX + "branch1"); assertEquals("branch1", ref); ref = Ref.localName(Ref.REFS_PREFIX + "commit1"); assertEquals("commit1", ref); ref = Ref.localName(Ref.REMOTES_PREFIX + "origin/branch1"); assertEquals("branch1", ref); ref = Ref.localName(Ref.TAGS_PREFIX + "tag1"); assertEquals("tag1", ref); ref = Ref.localName("ref1"); assertEquals("ref1", ref); ref = Ref.namespace(Ref.HEADS_PREFIX + "branch1"); assertEquals(Ref.HEADS_PREFIX, ref); ref = Ref.namespace(Ref.REFS_PREFIX + "commit1"); assertEquals(Ref.REFS_PREFIX, ref); ref = Ref.namespace(Ref.REMOTES_PREFIX + "origin/branch1"); assertEquals(Ref.REMOTES_PREFIX + "origin/", ref); ref = Ref.namespace(Ref.TAGS_PREFIX + "tag1"); assertEquals(Ref.TAGS_PREFIX, ref); ref = Ref.namespace("ref1"); assertEquals("ref1", ref); }
/** * @return the non-symbolic {@link Ref} this symbolic reference points to. */ public @Override Ref peel() { return new Ref(target, getObjectId()); }
@Test public void testEquals() throws Exception { Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid); Ref testRef2 = new Ref(Ref.REFS_PREFIX + "commit2", oid2); assertFalse(testRef.equals(testRef2)); testRef2 = new Ref(Ref.REFS_PREFIX + "commit1", oid3); assertFalse(testRef.equals(testRef2)); assertFalse(testRef.equals("not a ref")); assertTrue(testRef.equals(testRef)); }
public Optional<String> mapToLocal(final String remoteRef) { Preconditions.checkNotNull(remoteRef); String localRef = null; if (isAllChildren()) { if (Ref.isChild(this.remoteRef, remoteRef)) { final String remoteRefName = remoteRef.substring(this.remoteRef.length()); localRef = Ref.append(this.localRef, remoteRefName); } } else { if (remoteRef.equals(this.remoteRef)) { localRef = this.localRef; } } return Optional.ofNullable(localRef); }