/** * Executes the squash command using the provided options. */ @Override public void runInternal(GeogigCLI cli) { checkParameter(commits.size() == 2, "2 commit references must be supplied"); final GeoGIG geogig = cli.getGeogig(); Optional<ObjectId> sinceId = geogig.command(RevParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(sinceId.isPresent(), "'since' reference cannot be found"); checkParameter(geogig.getRepository().commitExists(sinceId.get()), "'since' reference does not resolve to a commit"); RevCommit sinceCommit = geogig.getRepository().getCommit(sinceId.get()); Optional<ObjectId> untilId = geogig.command(RevParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(untilId.isPresent(), "'until' reference cannot be found"); checkParameter(geogig.getRepository().commitExists(untilId.get()), "'until' reference does not resolve to a commit"); RevCommit untilCommit = geogig.getRepository().getCommit(untilId.get()); geogig.command(SquashOp.class).setSince(sinceCommit).setUntil(untilCommit) .setMessage(message).call(); }
private ObjectId addCommits(List<RevCommit> commits, String currentBranch, final ObjectId squashedId) { final Platform platform = platform(); final Map<ObjectId, ObjectId> replacedCommits = Maps.newHashMap(); replacedCommits.put(until.getId(), squashedId); objectDatabase().put(newCommit); head = newCommit.getId(); ObjectId newTreeId = newCommit.getTreeId(); command(UpdateRef.class).setName(currentBranch).setNewValue(head).call(); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call(); workingTree().updateWorkHead(newTreeId); stagingArea().updateStageHead(newTreeId);
private String resolveCommitter() { final String namekey = "user.name"; String name = getClientData(namekey, String.class) .or(command(ConfigGet.class).setName(namekey).call()).orNull(); checkState(name != null, "%s not found in config. Use geogig config [--global] %s <your name> to configure it.", namekey, namekey); return name; }
@Test public void testSquashAtHistoryOrigin() throws Exception { List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3); List<RevCommit> commits = Lists.newArrayList(); for (Feature f : features) { insertAndAdd(f); final RevCommit commit = geogig.command(CommitOp.class).call(); commits.add(commit); } try { geogig.command(SquashOp.class).setSince(commits.get(0)).setUntil(commits.get(4)).call(); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("no parents")); } }
GraphDatabase graphDb = graphDatabase(); Repository repository = repository(); Platform platform = platform(); final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't squash."); Preconditions.checkState(currHead.get() instanceof SymRef, Preconditions.checkState(stagingArea().isClean() && workingTree().isClean(), "You must have a clean working tree and index to perform a squash."); Optional<ObjectId> ancestor = command(FindCommonAncestor.class).setLeft(since) .setRight(until).call(); Preconditions.checkArgument(ancestor.isPresent(), List<RevCommit> commits = getCommitsAfterUntil(); ImmutableSet<Ref> refs = command(ForEachRef.class).setPrefixFilter(Ref.HEADS_PREFIX).call(); Iterator<RevCommit> toSquash = command(LogOp.class).setSince(since.getParentIds().get(0)) .setUntil(until.getId()).setFirstParentOnly(true).call(); List<ObjectId> firstParents = Lists.newArrayList(); command(ResetOp.class).setCommit(Suppliers.ofInstance(newHead)).setMode(ResetMode.HARD) .call(); builder.committer(resolveCommitter()); builder.committerEmail(resolveCommitterEmail()); builder.committerTimestamp(timestamp);
private String resolveCommitterEmail() { final String key = "user.email"; Optional<String> email = command(ConfigGet.class).setName(key).call(); checkState(email.isPresent(), "%s not found in config. Use geogig config [--global] %s <your email> to configure it.", key, key); return email.get(); }
@Test public void testSquashAtHistoryOrigin() throws Exception { List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3); List<RevCommit> commits = Lists.newArrayList(); for (Feature f : features) { insertAndAdd(f); final RevCommit commit = geogig.command(CommitOp.class).call(); commits.add(commit); } try { geogig.command(SquashOp.class).setSince(commits.get(0)).setUntil(commits.get(4)).call(); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("no parents")); } }
GraphDatabase graphDb = graphDatabase(); Repository repository = repository(); Platform platform = platform(); final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't squash."); Preconditions.checkState(currHead.get() instanceof SymRef, Preconditions.checkState(stagingArea().isClean() && workingTree().isClean(), "You must have a clean working tree and index to perform a squash."); Optional<ObjectId> ancestor = command(FindCommonAncestor.class).setLeft(since) .setRight(until).call(); Preconditions.checkArgument(ancestor.isPresent(), List<RevCommit> commits = getCommitsAfterUntil(); ImmutableSet<Ref> refs = command(ForEachRef.class).setPrefixFilter(Ref.HEADS_PREFIX).call(); Iterator<RevCommit> toSquash = command(LogOp.class).setSince(since.getParentIds().get(0)) .setUntil(until.getId()).setFirstParentOnly(true).call(); List<ObjectId> firstParents = Lists.newArrayList(); command(ResetOp.class).setCommit(Suppliers.ofInstance(newHead)).setMode(ResetMode.HARD) .call(); builder.setCommitter(resolveCommitter()); builder.setCommitterEmail(resolveCommitterEmail()); builder.setCommitterTimestamp(timestamp);
private String resolveCommitter() { final String key = "user.name"; Optional<String> name = command(ConfigGet.class).setName(key).call(); checkState(name.isPresent(), "%s not found in config. Use geogig config [--global] %s <your name> to configure it.", key, key); return name.get(); }
/** * Executes the squash command using the provided options. */ @Override public void runInternal(GeogigCLI cli) { checkParameter(commits.size() == 2, "2 commit references must be supplied"); final GeoGIG geogig = cli.getGeogig(); Optional<ObjectId> sinceId = geogig.command(RevParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(sinceId.isPresent(), "'since' reference cannot be found"); checkParameter(geogig.getRepository().commitExists(sinceId.get()), "'since' reference does not resolve to a commit"); RevCommit sinceCommit = geogig.getRepository().getCommit(sinceId.get()); Optional<ObjectId> untilId = geogig.command(RevParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(untilId.isPresent(), "'until' reference cannot be found"); checkParameter(geogig.getRepository().commitExists(untilId.get()), "'until' reference does not resolve to a commit"); RevCommit untilCommit = geogig.getRepository().getCommit(untilId.get()); geogig.command(SquashOp.class).setSince(sinceCommit).setUntil(untilCommit) .setMessage(message).call(); }
@Test public void testUncleanIndex() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); insertAndAdd(points2); exception.expect(IllegalStateException.class); geogig.command(SquashOp.class).setSince(c1).setUntil(c1).call(); }
private ObjectId addCommits(List<RevCommit> commits, String currentBranch, final ObjectId squashedId) { final Platform platform = platform(); final Map<ObjectId, ObjectId> replacedCommits = Maps.newHashMap(); replacedCommits.put(until.getId(), squashedId); objectDatabase().put(newCommit); head = newCommit.getId(); ObjectId newTreeId = newCommit.getTreeId(); command(UpdateRef.class).setName(currentBranch).setNewValue(head).call(); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call(); workingTree().updateWorkHead(newTreeId); stagingArea().updateStageHead(newTreeId);
private String resolveCommitterEmail() { final String emailkey = "user.email"; String email = getClientData(emailkey, String.class) .or(command(ConfigGet.class).setName(emailkey).call()).orNull(); checkState(email != null, "%s not found in config. Use geogig config [--global] %s <your email> to configure it.", emailkey, emailkey); return email; }
private List<RevCommit> getCommitsAfterUntil() { Iterator<RevCommit> commitIterator = command(LogOp.class).setSince(until.getId()).call(); List<RevCommit> commits = Lists.newArrayList(commitIterator); Collections.reverse(commits); return commits; }
/** * Executes the squash command using the provided options. */ @Override public void runInternal(GeogigCLI cli) { checkParameter(commits.size() == 2, "2 commit references must be supplied"); final GeoGIG geogig = cli.getGeogig(); Optional<ObjectId> sinceId = geogig.command(RevParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(sinceId.isPresent(), "'since' reference cannot be found"); checkParameter(geogig.getRepository().commitExists(sinceId.get()), "'since' reference does not resolve to a commit"); RevCommit sinceCommit = geogig.getRepository().getCommit(sinceId.get()); Optional<ObjectId> untilId = geogig.command(RevParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(untilId.isPresent(), "'until' reference cannot be found"); checkParameter(geogig.getRepository().commitExists(untilId.get()), "'until' reference does not resolve to a commit"); RevCommit untilCommit = geogig.getRepository().getCommit(untilId.get()); geogig.command(SquashOp.class).setSince(sinceCommit).setUntil(untilCommit) .setMessage(message).call(); }
@Test public void testUncleanWorkingTree() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); insert(points2); exception.expect(IllegalStateException.class); geogig.command(SquashOp.class).setSince(c1).setUntil(c1).call(); }
private List<RevCommit> getCommitsAfterUntil() { Iterator<RevCommit> commitIterator = command(LogOp.class).setSince(until.getId()).call(); List<RevCommit> commits = Lists.newArrayList(commitIterator); Collections.reverse(commits); return commits; }
@Test public void testSquash2() throws Exception { List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3); List<RevCommit> commits = Lists.newArrayList(); for (Feature f : features) { insertAndAdd(f); final RevCommit commit = geogig.command(CommitOp.class) .setMessage(f.getIdentifier().getID()).call(); commits.add(commit); } geogig.command(SquashOp.class).setSince(commits.get(1)).setUntil(commits.get(2)) .setMessage("squashed").call(); Iterator<RevCommit> log = geogig.command(LogOp.class).call(); ArrayList<RevCommit> logentries = Lists.newArrayList(log); assertEquals(5, logentries.size()); RevCommit squashedCommit = logentries.get(3); assertEquals(commits.get(2).getTreeId(), squashedCommit.getTreeId()); assertEquals("squashed", squashedCommit.getMessage()); }
@Test public void testUncleanWorkingTree() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); insert(points2); exception.expect(IllegalStateException.class); geogig.command(SquashOp.class).setSince(c1).setUntil(c1).call(); }
@Test public void testSquashwithSameSinceAndUntilCommit() throws Exception { List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3); List<RevCommit> commits = Lists.newArrayList(); for (Feature f : features) { insertAndAdd(f); final RevCommit commit = geogig.command(CommitOp.class) .setMessage(f.getIdentifier().getID()).call(); commits.add(commit); } geogig.command(SquashOp.class).setSince(commits.get(1)).setUntil(commits.get(1)) .setMessage("squashed").call(); Iterator<RevCommit> log = geogig.command(LogOp.class).call(); ArrayList<RevCommit> logentries = Lists.newArrayList(log); assertEquals(6, logentries.size()); RevCommit squashedCommit = logentries.get(4); assertEquals(commits.get(1).getTreeId(), squashedCommit.getTreeId()); assertEquals("squashed", squashedCommit.getMessage()); }