Make sure we don't ignore hidden files.
[vng.git] / src / GitRunner.cpp
blobe3ab826c151e9844bc0edd4470db5b223a920e7d
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),
26 m_timeout(30000)
30 AbstractCommand::ReturnCodes GitRunner::start(WaitCondition condition, Fail fail)
32 Q_ASSERT(condition <= WaitUntilReadyForWrite);
33 if (Logger::verbosity() >= Logger::Debug) {
34 Logger::debug() << "command: git";
35 foreach(QString arg, m_arguments)
36 Logger::debug() << " " << arg;
37 Logger::debug() << endl;
38 Logger::debug().flush();
41 if (condition == WaitForStandardOutput)
42 m_process->setReadChannel(QProcess::StandardOutput);
43 else if (condition == WaitForStandardError) {
44 m_process->setReadChannel(QProcess::StandardError);
45 condition = WaitForStandardOutput;
48 QIODevice::OpenMode mode = QIODevice::ReadOnly;
49 if (condition == WaitUntilReadyForWrite)
50 mode |= QIODevice::WriteOnly;
52 m_process->start(QLatin1String("git"), m_arguments, mode);
53 if ((condition == WaitForStandardOutput && !m_process->waitForReadyRead())
54 || (condition == WaitUntilFinished && !m_process->waitForFinished())
55 || (condition == WaitUntilReadyForWrite && !m_process->waitForStarted())) {
56 if (m_process->state() != QProcess::NotRunning) { // time out
57 Logger::error() << "ERROR: the backend (git) fails to start, timing out" << endl;
58 m_process->kill();
59 return AbstractCommand::GitTimedOut;
61 if (m_process->exitStatus() == QProcess::NormalExit) {
62 if (m_process->exitCode() != 0) {
63 if (fail == WarnOnFail)
64 Logger::error() << "ERROR: Failed calling git" << endl; // we may have to change this to debug later.
65 Logger::debug() << " we got return code:" << m_process->exitCode() << endl;
66 return AbstractCommand::GitFailed;
68 return AbstractCommand::Ok;
70 Logger::error() << "ERROR: the backend (git) crashed" << endl;
71 return AbstractCommand::GitCrashed;
73 if (m_process->exitCode() != 0) {
74 Logger::debug() << " we got return code:" << m_process->exitCode() << endl;
75 return AbstractCommand::GitFailed;
77 return AbstractCommand::Ok;
80 void GitRunner::setArguments(const QStringList &arguments)
82 m_arguments = arguments;