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