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 "commandchangedfiles.h"
0008 #include "gitmanager.h"
0009 
0010 namespace Git
0011 {
0012 
0013 CommandChangedFiles::CommandChangedFiles(Manager *git)
0014     : AbstractCommand(git)
0015 {
0016 }
0017 
0018 const QList<FileStatus> &CommandChangedFiles::files() const
0019 {
0020     return mFiles;
0021 }
0022 
0023 bool CommandChangedFiles::ignored() const
0024 {
0025     return mIgnored;
0026 }
0027 
0028 void CommandChangedFiles::setIgnored(bool newIgnored)
0029 {
0030     mIgnored = newIgnored;
0031 }
0032 
0033 bool CommandChangedFiles::untracked() const
0034 {
0035     return mUntracked;
0036 }
0037 
0038 void CommandChangedFiles::setUntracked(bool newUntracked)
0039 {
0040     mUntracked = newUntracked;
0041 }
0042 
0043 bool CommandChangedFiles::ignoreSubmodules() const
0044 {
0045     return mIgnoreSubmodules;
0046 }
0047 
0048 void CommandChangedFiles::setIgnoreSubmodules(bool newIgnoreSubmodules)
0049 {
0050     mIgnoreSubmodules = newIgnoreSubmodules;
0051 }
0052 
0053 QStringList CommandChangedFiles::generateArgs() const
0054 {
0055     QStringList args{QStringLiteral("status"), QStringLiteral("--short"), QStringLiteral("--porcelain")};
0056     if (mUntracked)
0057         args.append(QStringLiteral("--untracked-files=all"));
0058 
0059     if (mIgnoreSubmodules)
0060         args.append(QStringLiteral("--ignore-submodules"));
0061 
0062     if (mIgnored)
0063         args.append(QStringLiteral("--ignored"));
0064 
0065     return args;
0066 }
0067 
0068 void CommandChangedFiles::parseOutputSection(const QByteArray &output, const QByteArray &errorOutput)
0069 {
0070     Q_UNUSED(errorOutput)
0071     const auto buffer = QString(output).split(QLatin1Char('\n'));
0072 
0073     for (const auto &item : buffer) {
0074         if (!item.trimmed().size())
0075             continue;
0076         FileStatus fs;
0077         fs.parseStatusLine(item);
0078         fs.setFullPath(mGit->path() + fs.name());
0079         mFiles.append(fs);
0080     }
0081 }
0082 
0083 } // namespace Git