Package com.aragost.javahg.commands

Source Code of com.aragost.javahg.commands.GraftCommandTest

package com.aragost.javahg.commands;

import java.io.IOException;
import java.util.List;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;

import com.aragost.javahg.BaseRepository;
import com.aragost.javahg.Changeset;
import com.aragost.javahg.UnknownCommandException;
import com.aragost.javahg.internals.Utils;
import com.aragost.javahg.merge.ConflictResolvingContext;
import com.aragost.javahg.merge.GraftContext;
import com.aragost.javahg.merge.KeepDeleteConflict;
import com.aragost.javahg.merge.MergeConflict;
import com.aragost.javahg.test.AbstractTestCase;

public class GraftCommandTest extends AbstractTestCase {

    private boolean isGraftSupported() {
        BaseRepository repo = getTestRepository();
        try {
            PhaseCommand.on(repo).rev(Changeset.NULL_ID).execute();
            return true;
        } catch (UnknownCommandException e) {
            return false;
        }
    }

    @Test
    public void testGraftSelf() throws IOException {
        Assume.assumeTrue(isGraftSupported());
        BaseRepository repo = getTestRepository();
        Changeset cs = createChangeset();
        GraftCommand.on(repo).execute(cs);
        List<Changeset> heads = repo.heads();
        assertSingleton(cs, heads);
    }

    @Test
    public void test() throws IOException {
        Assume.assumeTrue(isGraftSupported());
        BaseRepository repo = getTestRepository();
        Changeset base = createChangeset();
        writeFile("a");
        Changeset cs = commit();
        update(base);
        writeFile("b");
        commit();
        ConflictResolvingContext r = GraftCommand.on(repo).execute(cs);
        Assert.assertNull(r);
        Changeset tip = repo.tip();
        String source = tip.getExtra().getString("source");
        Assert.assertEquals(cs.getNode(), source);
    }

    @Test
    public void testKeepDeleteConflict() throws IOException {
        Assume.assumeTrue(isGraftSupported());
        BaseRepository repo = getTestRepository();
        writeFile("file", "");
        Changeset base = commit();
        writeFile("file", "X");
        Changeset changed = commit();
        update(base);
        RemoveCommand.on(repo).execute("file");
        Changeset removed = commit();

        GraftContext ctx = GraftCommand.on(repo).execute(changed);
        Assert.assertNotNull(ctx);
        Assert.assertTrue(ctx.getFlagConflicts().isEmpty());
        Assert.assertTrue(ctx.getMergeConflicts().isEmpty());
        KeepDeleteConflict kdc = Utils.single(ctx.getKeepDeleteConflicts());
        Assert.assertNotNull(kdc);
        Assert.assertSame(removed, repo.tip());
        Assert.assertEquals("file", kdc.getFilename());
        Assert.assertSame(changed, ctx.getSource());
        kdc.delete();
        // TODO commiting results in an error, see issue 3261
        // Changeset cs = ctx.commit();
        // Assert.assertNotNull(cs);
    }

    @Test
    public void testMergeConflict() throws IOException {
        Assume.assumeTrue(isGraftSupported());
        BaseRepository repo = getTestRepository();
        writeFile("file", "");
        Changeset base = commit();
        writeFile("file", "X");
        Changeset changed1 = commit();
        update(base);
        writeFile("file", "Y");
        commit();

        GraftContext ctx = GraftCommand.on(repo).execute(changed1);
        Assert.assertNotNull(ctx);
        Assert.assertTrue(ctx.getFlagConflicts().isEmpty());
        Assert.assertTrue(ctx.getKeepDeleteConflicts().isEmpty());
        MergeConflict mergeConflict = Utils.single(ctx.getMergeConflicts());
        Assert.assertNotNull(mergeConflict);
        // Mercurial 2.2 will skip empty commits, so we must resolve
        // with new content.
        writeFile("file", "XY");
        mergeConflict.markResolved();
        Changeset cs = ctx.commit();
        Assert.assertNotNull(cs);
        Assert.assertEquals(changed1.getNode(), cs.getExtra().getString("source"));
    }

}
TOP

Related Classes of com.aragost.javahg.commands.GraftCommandTest

TOP
Copyright © 2018 www.massapi.com. 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.