Examples of JGitFlow


Examples of com.atlassian.jgitflow.core.JGitFlow

    @Test
    public void finishFeatureConflictRestore() throws Exception
    {
        Git git = RepoUtil.createRepositoryWithMasterAndDevelop(newDir());
        JGitFlowInitCommand initCommand = new JGitFlowInitCommand();
        JGitFlow flow = initCommand.setDirectory(git.getRepository().getWorkTree()).call();

        flow.featureStart("my-feature").call();

        //go back to develop and do a commit
        git.checkout().setName(flow.getDevelopBranchName()).call();
        File junkFile = new File(git.getRepository().getWorkTree(), "junk.txt");
        FileUtils.writeStringToFile(junkFile, "A");
        git.add().addFilepattern(junkFile.getName()).call();
        git.commit().setMessage("committing junk file").call();

        //commit the same file in feature to create a conflict
        git.checkout().setName(flow.getFeatureBranchPrefix() + "my-feature").call();
        FileUtils.writeStringToFile(junkFile, "B");
        git.add().addFilepattern(junkFile.getName()).call();
        git.commit().setMessage("committing junk file").call();

        boolean gotException = false;
        //try to finish
        try
        {
            flow.featureFinish("my-feature").call();
        }
        catch (Exception e)
        {
            gotException = true;
            File gitFlowDir = new File(git.getRepository().getDirectory(), JGitFlowConstants.GITFLOW_DIR);
            File mergeBase = new File(gitFlowDir, JGitFlowConstants.MERGE_BASE);
            assertTrue(mergeBase.exists());
            assertEquals(flow.getDevelopBranchName(), FileHelper.readFirstLine(mergeBase));
        }
       
        if(!gotException)
        {
            fail("Merge Conflict not detected!!");
        }
       
        assertEquals(flow.getDevelopBranchName(),git.getRepository().getBranch());

        FileUtils.writeStringToFile(junkFile, "A");
        git.add().addFilepattern(junkFile.getName()).setUpdate(true).call();
        git.commit().setMessage("merging").call();

        //try to finish again
        git.checkout().setName(flow.getFeatureBranchPrefix() + "my-feature").call();
        flow.featureFinish("my-feature").call();

        //we should be on develop branch
        assertEquals(flow.getDevelopBranchName(), git.getRepository().getBranch());

        //feature branch should be gone
        Ref ref2check = git.getRepository().getRef(flow.getFeatureBranchPrefix() + "my-feature");
        assertNull(ref2check);

        File gitFlowDir2 = new File(git.getRepository().getDirectory(), JGitFlowConstants.GITFLOW_DIR);
        File mergeBase2 = new File(gitFlowDir2, JGitFlowConstants.MERGE_BASE);
        assertFalse(mergeBase2.exists());
View Full Code Here
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.