/** * @return the name for this ref with the prefix removed */ public String localName() { return localName(name); }
/** * @return the name for this ref with the prefix removed */ public String localName() { return localName(name); }
@Override public boolean apply(String name) { return Ref.localName(name).equals(mappedBranchName); }};
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 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 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; } }
public List<BranchConfig> getAll() { List<BranchConfig> configs = new ArrayList<>(); final Map<String, String> all = configDatabase().getAll(); for (Ref branch : command(BranchListOp.class).call()) { final String section = String.format("branches.%s", branch.localName()); final String remoteKey = String.format("%s.%s", section, "remote"); final String remoteBranchKey = String.format("%s.%s", section, "merge"); final String descriptionKey = String.format("%s.%s", section, "description"); String remoteName = all.get(remoteKey); String remoteBranch = all.get(remoteBranchKey); String description = all.get(descriptionKey); BranchConfig config = BranchConfig.builder()// .branch(branch)// .remoteName(Optional.ofNullable(remoteName))// .remoteBranch(Optional.ofNullable(remoteBranch))// .description(Optional.ofNullable(description))// .build(); configs.add(config); } return configs; }
private Ref toLocal(Ref localRemoteRef) { final Remote remote = this.remote; if (localRemoteRef.namespace().equals(Ref.TAGS_PREFIX)) { return localRemoteRef; } final String localName = localRemoteRef.localName(); final String remoteNamespace = localRemoteRef.namespace(); final String expectedRemotePrefix = Ref.REMOTES_PREFIX + remote.getName() + "/"; Preconditions.checkArgument(remoteNamespace.equals(expectedRemotePrefix)); final String localPrefix = Ref.HEAD.equals(localName) ? "" : Ref.HEADS_PREFIX; final String localRefName = localPrefix + localName; Ref ref = null; if (localRemoteRef instanceof SymRef) { SymRef sr = (SymRef) localRemoteRef; Ref localTarget = toLocal(new Ref(sr.getTarget(), sr.getObjectId())); ref = new SymRef(localRefName, localTarget); } else { ref = new Ref(localRefName, localRemoteRef.getObjectId()); } return ref; }
public TestData branch(String newBranch) { Ref ref = getContext().command(BranchCreateOp.class).setName(newBranch).call(); checkState(newBranch.equals(ref.localName())); return this; }
public TestData branch(String newBranch) { Ref ref = getContext().command(BranchCreateOp.class).setName(newBranch).call(); checkState(newBranch.equals(ref.localName())); return this; }
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; }
public void writeBranchCreateResponse(Ref createdBranch) throws StreamWriterException { out.writeStartElement("BranchCreated"); writeElement("name", createdBranch.localName()); writeElement("source", createdBranch.getObjectId().toString()); out.writeEndElement(); // End BranchCreated }
private void verifyBranchConfig(Repository remote, Repository clone) { ImmutableList<Ref> remoteBranches = remote.command(BranchListOp.class).call(); for (Ref remoteBranch : remoteBranches) { BranchConfig config = clone.command(BranchConfigOp.class) .setName(remoteBranch.localName()).get(); assertEquals(remoteBranch.localName(), config.getBranch().localName()); assertEquals("origin", config.getRemoteName().get()); assertEquals(remoteBranch.getName(), config.getRemoteBranch().get()); } }
@Override public void write(ResponseWriter writer) throws Exception { writer.start(); if (!currHead.isPresent()) { writer.writeErrors("Repository has no HEAD."); } else { if (currHead.get() instanceof SymRef) { final SymRef headRef = (SymRef) currHead.get(); writer.writeHeaderElements("branch", Ref.localName(headRef.getTarget())); } } writer.writeStaged(geogig.command(DiffIndex.class).addFilter(pathFilter), offset, limit); writer.writeUnstaged(geogig.command(DiffWorkTree.class).setFilter(pathFilter), offset, limit); writer.writeUnmerged(geogig.command(ConflictsQueryOp.class).call(), offset, limit); writer.finish(); } });
/** * Executes the status command using the provided options. */ @Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(limit >= 0, "Limit must be 0 or greater."); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); StatusOp op = geogig.command(StatusOp.class).setReportLimit(limit); StatusSummary summary = op.call(); final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call(); checkParameter(currHead.isPresent(), "Repository has no HEAD."); if (currHead.get() instanceof SymRef) { final SymRef headRef = (SymRef) currHead.get(); console.println("# On branch " + Ref.localName(headRef.getTarget())); } else { console.println("# Not currently on any branch."); } print(console, summary); }
/** * Executes the status command using the provided options. */ @Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(limit >= 0, "Limit must be 0 or greater."); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); StatusOp op = geogig.command(StatusOp.class).setReportLimit(limit); StatusSummary summary = op.call(); final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call(); checkParameter(currHead.isPresent(), "Repository has no HEAD."); if (currHead.get() instanceof SymRef) { final SymRef headRef = (SymRef) currHead.get(); console.println("# On branch " + Ref.localName(headRef.getTarget())); } else { console.println("# Not currently on any branch."); } print(console, summary); }
/** * Executes the status command using the provided options. */ @Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(limit >= 0, "Limit must be 0 or greater."); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); StatusOp op = geogig.command(StatusOp.class).setReportLimit(limit); StatusSummary summary = op.call(); final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call(); checkParameter(currHead.isPresent(), "Repository has no HEAD."); if (currHead.get() instanceof SymRef) { final SymRef headRef = (SymRef) currHead.get(); console.println("# On branch " + Ref.localName(headRef.getTarget())); } else { console.println("# Not currently on any branch."); } print(console, summary); }
public TestData checkout(String branch) { getContext().command(CheckoutOp.class).setSource(branch).call(); Ref head = getContext().command(RefParse.class).setName(Ref.HEAD).call().get(); if (head instanceof SymRef) { String target = ((SymRef) head).getTarget(); head = getContext().command(RefParse.class).setName(target).call().get(); } String headBranch = head.localName(); checkState(branch.equals(headBranch), "expected %s, got %s", branch, headBranch); return this; }
public TestData checkout(String branch) { getContext().command(CheckoutOp.class).setSource(branch).call(); Ref head = getContext().command(RefParse.class).setName(Ref.HEAD).call().get(); if (head instanceof SymRef) { String target = ((SymRef) head).getTarget(); head = getContext().command(RefParse.class).setName(target).call().get(); } String headBranch = head.localName(); checkState(branch.equals(headBranch), "expected %s, got %s", branch, headBranch); return this; }
@Test public void testConstructor() throws Exception { Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid); assertEquals(Ref.REFS_PREFIX + "commit1", testRef.getName()); assertEquals(Ref.REFS_PREFIX, testRef.namespace()); assertEquals("commit1", testRef.localName()); assertEquals(oid, testRef.getObjectId()); }