Package com.aragost.javahg

Examples of com.aragost.javahg.Repository


    /**
     *
     * @return all bookmarks
     */
    public List<Bookmark> list() {
        Repository repo = getRepository();
        HgInputStream stream = launchStream();
        try {
            if (stream.match(NO_BOOKMARKS)) {
                return Collections.emptyList();
            }
            List<Bookmark> result = Lists.newArrayList();
            while (stream.peek() != -1) {
                stream.mustMatch(' ');
                boolean active = stream.read() == '*';
                stream.mustMatch(' ');
                String name = stream.textUpTo(' ');
                stream.upTo(':');
                String node = stream.textUpTo('\n');
                Bookmark bookmark = new Bookmark(repo.changeset(node), name, active);
                result.add(bookmark);
            }
            return result;
        } catch (IOException e) {
            throw new RuntimeIOException(e);
View Full Code Here


    private static final byte[] LINE_BEGIN = "add changeset ".getBytes();
    private static final byte[] REMOTE_ERROR = "remote: error: ".getBytes();

    public static List<Changeset> parseStream(AbstractCommand command,
            HgInputStream stream) throws IOException {
      Repository repo = command.getRepository();
        List<Changeset> result;

        // Pulling locally the full nodes are written after
        // "list of changesets:"
        // Over HTTP this isn't written.
        // In either case 12 character node prefixes are printed after
        // "adding changesets".
        // If possible use first case, otherwise fall back to node prefixes.

        // Make a copy
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ByteStreams.copy(stream, bos);
        stream.consumeAll();
        stream = new HgInputStream(new ByteArrayInputStream(bos.toByteArray()), repo.newDecoder());

        if (stream.find(BEGIN)) {
            result = Lists.newArrayList();
            while (!stream.isEof() && !stream.match(BEGIN_FALLBACK)) {
                result.add(repo.changeset(stream.textUpTo('\n')));
            }
        } else {
            stream = new HgInputStream(new ByteArrayInputStream(bos.toByteArray()), repo.newDecoder());

            List<String> nodePrefixes = Lists.newArrayList();

            if (stream.find(BEGIN_FALLBACK)) {
                while (stream.find(LINE_BEGIN)) {
                    // 12 Character node prefix
                    nodePrefixes.add(stream.textUpTo('\n'));
                }
            }
            if (nodePrefixes.isEmpty()) {
                result = Collections.emptyList();
            } else {
                result = LogCommand
                        .on(repo)
                        .rev(nodePrefixes.toArray(new String[nodePrefixes
                                .size()])).execute();
            }
        }

        stream = new HgInputStream(new ByteArrayInputStream(bos.toByteArray()), repo.newDecoder());

        if (stream.find(REMOTE_ERROR)) {
            throw new ExecutionException(command, stream.textUpTo('\n'));
        }
View Full Code Here

public class CommitCommandTest extends AbstractTestCase {

    @Test
    public void test() throws IOException {
        Repository repo = getTestRepository();
        writeFile("x", "abc");

        CommitCommand commit = CommitCommand.on(repo);
        StatusCommand status = StatusCommand.on(repo);
View Full Code Here

    }

    @Test(expected = IllegalStateException.class)
    public void testNoMessage() throws IOException {
        Repository repo = getTestRepository();
        CommitCommand.on(repo).execute();
    }
View Full Code Here

        CommitCommand.on(repo).execute();
    }

    @Test(expected = NullPointerException.class)
    public void testSetNullMessage() throws IOException {
        Repository repo = getTestRepository();
        CommitCommand.on(repo).message(null);
    }
View Full Code Here

        CommitCommand.on(repo).message(null);
    }

    @Test(expected = NullPointerException.class)
    public void testSetNullDate() throws IOException {
        Repository repo = getTestRepository();
        CommitCommand.on(repo).date(null);
    }
View Full Code Here

        CommitCommand.on(repo).date(null);
    }

    @Test
    public void testAmend() throws IOException {
        Repository repo = getTestRepository();
        Assume.assumeTrue(HgVersion.fromString("2.2").isBefore(repo.getHgVersion()));

        writeFile("x", "abc");

        CommitCommand commit = CommitCommand.on(repo);
        StatusCommand status = StatusCommand.on(repo);
View Full Code Here

public class HeadsCommandTest extends AbstractTestCase {

    @Test
    public void testNoFlags() throws IOException {
        Repository repo = getTestRepository();
        writeFile("a");
        Changeset csA = commit();
        writeFile("b");
        Changeset csB = commit();
        update(csA);
View Full Code Here

public class RemoveCommandTest extends AbstractTestCase {

    @Test
    public void test() throws IOException {
        Repository repo = getTestRepository();
        writeFile("a", "");
        new File(repo.getDirectory(), "dir").mkdir();
        writeFile("dir/a", "");
        writeFile("dir/b", "");
        commit();

        List<File> removed = RemoveCommand.on(repo).execute(new File("dir"));
View Full Code Here

        Assert.assertEquals(repoFile(repo, "dir", "b"), removed.get(1));
    }

    @Test
    public void testWithNoFiles() throws IOException {
        Repository repo = getTestRepository();
        RemoveCommand cmd = RemoveCommand.on(repo);
        try {
            cmd.execute();
            assertFailedExecution(cmd);
        } catch (ExecutionException e) {
View Full Code Here

TOP

Related Classes of com.aragost.javahg.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.