class GitCloneTask implements Task {

    @Override
    public void run(TaskQueue tasks) throws Throwable {
        if (git.exists()) {
            LOG.info("git clone already performed, issuing pull instead.");
            tasks.insertAtHead(new GitPullRemoteTask(git));
            return;
        }

        git.clone(remoteUrl);
    }

}

class GitCloneTaskTest {

    @Rule
    public TestingDir testdir;

    @Test
    public void testCloneAndBranchLauncher() throws Throwable {

        testdir.ensureEmpty();

        GitMirrors mirrors = GitMirrors.load();
        GitFactory.setMirrors(mirrors);

        WorkDir workdir = new WorkDir(testdir.getFile("work"));

        Repo repo = new Repo();
        repo.setUrl("git://android.git.kernel.org/platform/packages/apps/Launcher.git");
        String branchName = "android-sdk-2.0.1_r1";

        IGit git = workdir.getGitRepo(repo.getUrl());

        GitCloneTask gitclone = new GitCloneTask(git, repo.getUrl());
        GitSwitchBranchTask gitbranch = new GitSwitchBranchTask(git, branchName);

        TaskQueue tasks = new TaskQueue();

        gitclone.run(tasks);
        gitbranch.run(tasks);

        Assert.assertThat("Branch name", git.getCurrentBranch(), is("refs/tags/" + branchName));
    }

}