We don't want vng executable to be placed inside Vng.app/Contents/MacOS on Mac OS X.
[vng.git] / GitRunner.cpp
blobe51f545d673c7b989a3721bcdb1ef8ef3d7046c3
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "GitRunner.h"
19 #include "Logger.h"
21 #include <QDebug>
23 GitRunner::GitRunner(QProcess &process, const QStringList &arguments)
24 : m_process(&process),
25 m_arguments(arguments)
29 AbstractCommand::ReturnCodes GitRunner::start(WaitCondition condition)
31 Q_ASSERT(condition <= WaitUntilReadyForWrite);
32 if (Logger::verbosity() >= Logger::Debug) {
33 Logger::debug() << "command: git";
34 foreach(QString arg, m_arguments)
35 Logger::debug() << " " << arg;
36 Logger::debug() << endl;
37 Logger::debug().flush();
40 if (condition == WaitForStandardOutput)
41 m_process->setReadChannel(QProcess::StandardOutput);
42 else if (condition == WaitForStandardError) {
43 m_process->setReadChannel(QProcess::StandardError);
44 condition = WaitForStandardOutput;
47 QIODevice::OpenMode mode = QIODevice::ReadOnly;
48 if (condition == WaitUntilReadyForWrite)
49 mode |= QIODevice::WriteOnly;
51 m_process->start("git", m_arguments, mode);
52 if (condition == WaitForStandardOutput && !m_process->waitForReadyRead()
53 || condition == WaitUntilFinished && !m_process->waitForFinished()
54 || condition == WaitUntilReadyForWrite && !m_process->waitForStarted()) {
55 if (m_process->state() != QProcess::NotRunning) { // time out
56 Logger::error() << "ERROR: the backend (git) fails to start, timing out" << endl;
57 m_process->kill();
58 return AbstractCommand::GitTimedOut;
60 if (m_process->exitStatus() == QProcess::NormalExit) {
61 if (m_process->exitCode() != 0) {
62 Logger::error() << "ERROR: Failed calling git" << endl; // we may have to change this to debug later.
63 Logger::debug() << " we got return code:" << m_process->exitCode() << endl;
64 return AbstractCommand::GitFailed;
66 return AbstractCommand::Ok;
68 Logger::error() << "ERROR: the backend (git) crashed" << endl;
69 return AbstractCommand::GitCrashed;
71 if (m_process->exitCode() != 0) {
72 Logger::debug() << " we got return code:" << m_process->exitCode() << endl;
73 return AbstractCommand::GitFailed;
75 return AbstractCommand::Ok;
78 void GitRunner::setArguments(const QStringList &arguments)
80 m_arguments = arguments;