File indexing completed on 2025-01-19 04:22:43

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "commandcommit.h"
0008 
0009 #include <QDebug>
0010 
0011 namespace Git
0012 {
0013 
0014 CommandCommit::CommandCommit() = default;
0015 
0016 QStringList CommandCommit::generateArgs() const
0017 {
0018     QStringList args{QStringLiteral("commit"), QStringLiteral("--message"), mMessage};
0019 
0020     if (mAmend)
0021         args.append(QStringLiteral("--amend"));
0022 
0023     switch (mIncludeStatus) {
0024     case OptionalBool::True:
0025         args.append(QStringLiteral("--status"));
0026         break;
0027     case OptionalBool::False:
0028         args.append(QStringLiteral("--no-status"));
0029         break;
0030     case OptionalBool::Unset:
0031         break;
0032     }
0033     return args;
0034 }
0035 
0036 const QString &CommandCommit::message() const
0037 {
0038     return mMessage;
0039 }
0040 
0041 void CommandCommit::setMessage(const QString &newMessage)
0042 {
0043     mMessage = newMessage;
0044 }
0045 
0046 bool CommandCommit::amend() const
0047 {
0048     return mAmend;
0049 }
0050 
0051 void CommandCommit::setAmend(bool newAmend)
0052 {
0053     mAmend = newAmend;
0054 }
0055 
0056 OptionalBool CommandCommit::includeStatus() const
0057 {
0058     return mIncludeStatus;
0059 }
0060 
0061 void CommandCommit::setIncludeStatus(OptionalBool newIncludeStatus)
0062 {
0063     mIncludeStatus = newIncludeStatus;
0064 }
0065 
0066 bool CommandCommit::parseOutput(const QByteArray &output, const QByteArray &errorOutput)
0067 {
0068     Q_UNUSED(errorOutput);
0069     auto lines = output.split('\n');
0070     QString error;
0071     bool errorFound = false;
0072     for (const auto &line : lines) {
0073         if (errorFound)
0074             error.append("\n" + line);
0075         if (line.startsWith("ERROR: ")) {
0076             errorFound = true;
0077             error = line.mid(7);
0078         }
0079     }
0080     if (errorFound)
0081         setErrorMessage(error);
0082     return !errorFound;
0083 }
0084 
0085 } // namespace Git