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();
  }

}

package org.jetbrains.plugins.github;

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

import static com.intellij.dvcs.test.Executor.cd;
import static git4idea.test.GitExecutor.git;

/**
 * @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();

    cd(myProjectRoot.getPath());
    git("init");
    git("add file.txt");
    git("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();
  }

}

Fix git commands execution params