package org.jetbrains.plugins.github;

import com.intellij.notification.NotificationType;
import com.intellij.openapi.components.ServiceManager;
import git4idea.commands.Git;
import git4idea.test.GitExecutor;

/**
 * @author Aleksey Pivovarov
 */
public class GithubShareProjectTest extends GithubShareProjectTestBase {

  public void testSimple() throws Throwable {
    registerDefaultShareDialogHandler();
    registerDefaultUntrackedFilesDialogHandler();

    createProjectFiles();

    GithubShareAction.shareProjectOnGithub(myProject);

    checkNotification(NotificationType.INFORMATION, "Successfully created project on GitHub", null);
    checkGitExists();
    checkGithubExists();
    checkRemoteConfigured();
    checkLastCommitPushed();
  }

  public void testGithubAlreadyExists() throws Throwable {
    registerDefaultShareDialogHandler();
    registerDefaultUntrackedFilesDialogHandler();

    createProjectFiles();
    GithubShareAction.shareProjectOnGithub(myProject);
    GithubShareAction.shareProjectOnGithub(myProject);

    checkNotification(NotificationType.INFORMATION, "Project is already on GitHub", null);
  }

  public void testExistingGit() throws Throwable {
    registerDefaultShareDialogHandler();
    registerDefaultUntrackedFilesDialogHandler();

    createProjectFiles();

    GitExecutor.cd(myProjectRoot.getPath());
    GitExecutor.git(myProjectRoot.getPath(), "init");
    GitExecutor.git(myProjectRoot.getPath(), "add file.txt");
    GitExecutor.git(myProjectRoot.getPath(), "commit -m init");

    GithubShareAction.shareProjectOnGithub(myProject);

    checkNotification(NotificationType.INFORMATION, "Successfully created project on GitHub", null);
    checkGitExists();
    checkGithubExists();
    checkRemoteConfigured();
    checkLastCommitPushed();
  }

  public void testExistingFreshGit() throws Throwable {
    registerDefaultShareDialogHandler();
    registerDefaultUntrackedFilesDialogHandler();

    createProjectFiles();

    Git git = ServiceManager.getService(Git.class);
    git.init(myProject, myProjectRoot);

    GithubShareAction.shareProjectOnGithub(myProject);

    checkNotification(NotificationType.INFORMATION, "Successfully created project on GitHub", null);
    checkGitExists();
    checkGithubExists();
    checkRemoteConfigured();
    checkLastCommitPushed();
  }

  public void testEmptyProject() throws Throwable {
    registerDefaultUntrackedFilesDialogHandler();
    registerDefaultShareDialogHandler();

    GithubShareAction.shareProjectOnGithub(myProject);

    checkNotification(NotificationType.WARNING, "Failed to commit file during post activities", "No files to commit");
    checkGitExists();
    checkGithubExists();
    checkRemoteConfigured();
  }

}

@@ -168,23 +168,81 @@
 ds.Git;%0A
+%0A
 import 
+static com.intellij.dvcs.test.Executor.cd;%0Aimport static 
 git4idea
@@ -258,16 +258,20 @@
 Executor
+.git
 ;%0A%0A/**%0A 
@@ -1366,28 +1366,16 @@
 );%0A%0A    
-GitExecutor.
 cd(myPro
@@ -1403,165 +1403,54 @@
     
-GitExecutor.git(myProjectRoot.getPath(), %22init%22);%0A    GitExecutor.git(myProjectRoot.getPath(), %22add file.txt%22);%0A    GitExecutor.git(myProjectRoot.getPath(), 
+git(%22init%22);%0A    git(%22add file.txt%22);%0A    git(
 %22com

Fix git commands execution params