public void Configure(string id, User user)
{
var repositoryUrl = string.Format("https://{0}@appharbor.com/{1}.git", user.Username, id);
try
{
_gitCommand.Execute("--version");
}
catch (GitCommandException)
{
throw new RepositoryConfigurationException(string.Format("Git is not installed."));
}
try
{
_gitCommand.Execute("status");
}
catch (GitCommandException)
{
_writer.Write("Git repository is not initialized in this folder. Do you want to initialize it (type \"y\")?");
if (_reader.ReadLine() != "y")
{
throw new RepositoryConfigurationException("Git repository was not initialized.");
}
_gitCommand.Execute("init");
using (var stream = _fileSystem.OpenWrite(Path.Combine(Directory.GetCurrentDirectory(), ".gitignore")))
{
using (var writer = new StreamWriter(stream))
{
writer.Write(DefaultGitIgnore);
}
}
_writer.WriteLine("Git repository was initialized with default .gitignore file.");
}
try
{
_gitCommand.Execute(string.Format("remote add appharbor {0}", repositoryUrl));
_writer.WriteLine("Added \"appharbor\" as a remote repository. Push to AppHarbor with git push appharbor master.");
}
catch (GitCommandException)
{
throw new RepositoryConfigurationException(
string.Format("Couldn't add appharbor repository as a git remote. Repository URL is: {0}.", repositoryUrl));
}
}