File indexing completed on 2025-03-09 05:11:40

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 "commandpull.h"
0008 
0009 #ifdef GIT_GUI
0010 #include "ui_commandpullwidget.h"
0011 #include <KLocalizedString>
0012 #include <KMessageBox>
0013 #endif
0014 
0015 namespace Git
0016 {
0017 
0018 bool CommandPull::squash() const
0019 {
0020     return mSquash;
0021 }
0022 
0023 void CommandPull::setSquash(bool newSquash)
0024 {
0025     mSquash = newSquash;
0026 }
0027 
0028 bool CommandPull::noCommit() const
0029 {
0030     return mNoCommit;
0031 }
0032 
0033 void CommandPull::setNoCommit(bool newNoCommit)
0034 {
0035     mNoCommit = newNoCommit;
0036 }
0037 
0038 bool CommandPull::prune() const
0039 {
0040     return mPrune;
0041 }
0042 
0043 void CommandPull::setPrune(bool newPrune)
0044 {
0045     mPrune = newPrune;
0046 }
0047 
0048 bool CommandPull::tags() const
0049 {
0050     return mTags;
0051 }
0052 
0053 void CommandPull::setTags(bool newTags)
0054 {
0055     mTags = newTags;
0056 }
0057 
0058 void CommandPull::parseOutputSection(const QByteArray &output, const QByteArray &errorOutput)
0059 {
0060 #ifdef GIT_GUI
0061     if (output.contains("Already up to date.")) {
0062         mUi->labelStatus->setText(i18n("Already up to date."));
0063     }
0064     if (errorOutput.startsWith("fatal:")) {
0065         mUi->labelStatus->setText(errorOutput.mid(6));
0066         KMessageBox::error(mWidget, errorOutput.mid(6), i18n("Error"));
0067     }
0068 #else
0069     Q_UNUSED(output)
0070     Q_UNUSED(errorOutput)
0071 #endif
0072 }
0073 
0074 bool CommandPull::supportWidget() const
0075 {
0076     return true;
0077 }
0078 
0079 QWidget *CommandPull::createWidget()
0080 {
0081 #ifdef GIT_GUI
0082     mWidget = new QWidget;
0083     mUi = new Ui::CommandPullWidget;
0084     mUi->setupUi(mWidget);
0085     return mWidget;
0086 #else
0087     return nullptr;
0088 #endif
0089 }
0090 
0091 const QString &CommandPull::remote() const
0092 {
0093     return mRemote;
0094 }
0095 
0096 void CommandPull::setRemote(const QString &newRemote)
0097 {
0098     mRemote = newRemote;
0099 }
0100 
0101 const QString &CommandPull::branch() const
0102 {
0103     return mBranch;
0104 }
0105 
0106 void CommandPull::setBranch(const QString &newBranch)
0107 {
0108     mBranch = newBranch;
0109 }
0110 
0111 CommandPull::Rebase CommandPull::rebase() const
0112 {
0113     return mRebase;
0114 }
0115 
0116 void CommandPull::setRebase(Rebase newRebase)
0117 {
0118     mRebase = newRebase;
0119 }
0120 
0121 CommandPull::FastForward CommandPull::fastForward() const
0122 {
0123     return mFastForward;
0124 }
0125 
0126 void CommandPull::setFastForward(FastForward newFastForward)
0127 {
0128     mFastForward = newFastForward;
0129 }
0130 
0131 QStringList CommandPull::generateArgs() const
0132 {
0133     QStringList args{QStringLiteral("pull"), mRemote, mBranch};
0134     if (mSquash)
0135         args.append(QStringLiteral("--squash"));
0136     if (mNoCommit)
0137         args.append(QStringLiteral("--no-commit"));
0138     if (mPrune)
0139         args.append(QStringLiteral("--prune"));
0140     if (mTags)
0141         args.append(QStringLiteral("--tags"));
0142 
0143     switch (mFastForward) {
0144     case Unset:
0145         break;
0146     case Yes:
0147         args << QStringLiteral("--ff");
0148         break;
0149     case No:
0150         args << QStringLiteral("--no-ff");
0151         break;
0152     case OnlyFastForward:
0153         args << QStringLiteral("--ff-only");
0154         break;
0155     }
0156 
0157     switch (mRebase) {
0158     case None:
0159         break;
0160     case False:
0161         args << QStringLiteral("--rebase=false");
0162         break;
0163     case True:
0164         args << QStringLiteral("--rebase=true");
0165         break;
0166     case Preserve:
0167         args << QStringLiteral("--rebase=preserve");
0168         break;
0169     case Merge:
0170         args << QStringLiteral("--rebase=merges");
0171         break;
0172     }
0173 
0174     return args;
0175 }
0176 
0177 CommandPull::CommandPull() = default;
0178 
0179 CommandPull::~CommandPull()
0180 {
0181 #ifdef GIT_GUI
0182     if (mWidget)
0183         mWidget->deleteLater();
0184 
0185     delete mUi;
0186 #endif
0187 }
0188 
0189 } // namespace Git
0190 
0191 #include "moc_commandpull.cpp"