QString ConsoleCommand::description() const { return commandDescription( m_command ); }
AbstractCommand::ReturnCodes Push::run() { if (! checkInRepository()) return NotInRepo; CommandLineParser *args = CommandLineParser::instance(); QProcess git; QStringList arguments; arguments << "config" << "-l"; GitRunner runner(git, arguments); AbstractCommand::ReturnCodes rc = runner.start(GitRunner::WaitForStandardOutput); if (rc != Ok) { Logger::error() << "Vng failed; could not read configuration\n"; return rc; } QRegExp re("remote\\.(.*)url=(.*)\n"); QHash<QString, QString> repoNames; char buf[1024]; while (true) { //read relevant lines into repoNames hash qint64 length = Vng::readLine(&git, buf, sizeof(buf)); if (length < 0) break; QString line(buf); if (re.exactMatch(line)) { QString context = re.cap(1); if (context.endsWith(".")) context = context.left(context.length()-1); repoNames.insert(context, re.cap(2)); } } QString repo; if (args->arguments().count() > 1) repo = args->arguments()[1]; QString url = repo; if (repo.isEmpty()) repo = "default"; // the name we store the default as. if (repoNames.contains(repo)) url = repoNames[repo]; if (url.isEmpty()) { // print help Logger::standardOut() << "Vng failed: Missing argument [REPOSITORY]\n"; Logger::standardOut().flush(); args->usage(name(), argumentDescription()); Logger::standardOut() << endl << commandDescription(); return Ok; } Logger::warn() << "Pushing to `" << url << "'\n"; Logger::warn().flush(); // make sure its printed before git asks for an ssh pwd. if (dryRun()) return Ok; // TODO when not using --all ask the remote for all the refs it has and detect which ones we still have to push // TODO use interview to ask which refs to push instead of all below arguments.clear(); arguments << "push" << url; runner.setArguments(arguments); rc = runner.start(GitRunner::WaitForStandardOutput); if (rc != Ok) { Logger::error() << "Git push failed\n"; return rc; } /* TODO for some reason qprocess doesn't give me any output if the child process already finished :( while (true) { qint64 length = Vng::readLine(&git, buf, sizeof(buf)); if (length < 0) break; Logger::info() << QString(buf); } */ git.waitForFinished(-1); if ( !(args->contains("no-set-default") || (m_config.contains("no-set-default") && ! args->contains("set-default"))) && repo == url) { // lets set as default arguments.clear(); arguments << "config" << "--add" << "remote.default.url" << repo; runner.setArguments(arguments); rc = runner.start(GitRunner::WaitUntilFinished); if (rc != Ok) { Logger::warn() << "Could not store the default value for future reuse\n"; return rc; } } return Ok; }