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 "commandmerge.h"
0008 
0009 #include <QMetaEnum>
0010 
0011 namespace Git
0012 {
0013 
0014 CommandMerge::CommandMerge(Manager *git)
0015     : AbstractCommand{git}
0016 {
0017 }
0018 
0019 QStringList CommandMerge::generateArgs() const
0020 {
0021     QStringList cmd{QStringLiteral("merge")};
0022     switch (mFf) {
0023     case FastForwardType::Unset:
0024         break;
0025     case FastForwardType::Yes:
0026         cmd.append(QStringLiteral("--ff"));
0027         break;
0028     case FastForwardType::No:
0029         cmd.append(QStringLiteral("--no-ff"));
0030         break;
0031     case FastForwardType::OnlyFastForward:
0032         cmd.append(QStringLiteral("--ff-only"));
0033         break;
0034     }
0035 
0036     appendBool(mCommit, cmd, QStringLiteral("commit"));
0037     appendBool(mSquash, cmd, QStringLiteral("squash"));
0038     appendBool(mAllowUnrelatedHistories, cmd, QStringLiteral("allow-unrelated-histories"));
0039 
0040     switch (mStrategy) {
0041     case Ort:
0042         cmd << QStringLiteral("--strategy=ort");
0043         if (mIgnoreSpaceChange)
0044             cmd << QStringLiteral("--ignore-space-change");
0045         if (mIgnoreAllSpace)
0046             cmd << QStringLiteral("--ignore-all-space");
0047         if (mIgnoreSpaceAtEol)
0048             cmd << QStringLiteral("--ignore-space-at-eol");
0049         if (mIgnoreCrAtEol)
0050             cmd << QStringLiteral("--ignore-cr-at-eol");
0051         if (mRenormalize)
0052             cmd << QStringLiteral("--renormalize");
0053         if (mOurs)
0054             cmd << QStringLiteral("--ours");
0055         if (mTheirs)
0056             cmd << QStringLiteral("--theirs");
0057         break;
0058     case Recursive: {
0059         const auto e = QMetaEnum::fromType<DiffAlgorithm>();
0060         cmd << QStringLiteral("diff-algorithm=") + QString(e.valueToKey(mDiffAlgorithm)).toLower();
0061         if (mNoRenames)
0062             cmd << QStringLiteral("--no-renames");
0063         cmd << QStringLiteral("--strategy=recursive");
0064         break;
0065     }
0066     case Resolve:
0067         cmd << QStringLiteral("--strategy=resolve");
0068         break;
0069     case Octopus:
0070         cmd << QStringLiteral("--strategy=octopus");
0071         break;
0072     case Ours:
0073         cmd << QStringLiteral("--strategy=ours");
0074         break;
0075     case Subtree:
0076         cmd << QStringLiteral("--strategy=subtree");
0077         break;
0078     case Default:
0079         // Just to avoid compiler warning
0080         break;
0081     }
0082 
0083     cmd << mFromBranch;
0084 
0085     return cmd;
0086 }
0087 
0088 OptionalBool CommandMerge::commit() const
0089 {
0090     return mCommit;
0091 }
0092 
0093 void CommandMerge::setCommit(OptionalBool newCommit)
0094 {
0095     mCommit = newCommit;
0096 }
0097 
0098 OptionalBool CommandMerge::allowUnrelatedHistories() const
0099 {
0100     return mAllowUnrelatedHistories;
0101 }
0102 
0103 void CommandMerge::setAllowUnrelatedHistories(OptionalBool newAllowUnrelatedHistories)
0104 {
0105     mAllowUnrelatedHistories = newAllowUnrelatedHistories;
0106 }
0107 
0108 FastForwardType CommandMerge::ff() const
0109 {
0110     return mFf;
0111 }
0112 
0113 void CommandMerge::setFf(FastForwardType newFf)
0114 {
0115     mFf = newFf;
0116 }
0117 
0118 OptionalBool CommandMerge::squash() const
0119 {
0120     return mSquash;
0121 }
0122 
0123 void CommandMerge::setSquash(OptionalBool newSquash)
0124 {
0125     mSquash = newSquash;
0126 }
0127 
0128 const QString &CommandMerge::fromBranch() const
0129 {
0130     return mFromBranch;
0131 }
0132 
0133 void CommandMerge::setFromBranch(const QString &newFromBranch)
0134 {
0135     mFromBranch = newFromBranch;
0136 }
0137 
0138 const CommandMerge::Strategy &CommandMerge::strategy() const
0139 {
0140     return mStrategy;
0141 }
0142 
0143 void CommandMerge::setStrategy(Git::CommandMerge::Strategy newStrategy)
0144 {
0145     mStrategy = newStrategy;
0146 }
0147 
0148 bool CommandMerge::ignoreSpaceChange() const
0149 {
0150     return mIgnoreSpaceChange;
0151 }
0152 
0153 void CommandMerge::setIgnoreSpaceChange(bool newIgnoreSpaceChange)
0154 {
0155     mIgnoreSpaceChange = newIgnoreSpaceChange;
0156 }
0157 
0158 bool CommandMerge::ignoreAllSpace() const
0159 {
0160     return mIgnoreAllSpace;
0161 }
0162 
0163 void CommandMerge::setIgnoreAllSpace(bool newIgnoreAllSpace)
0164 {
0165     mIgnoreAllSpace = newIgnoreAllSpace;
0166 }
0167 
0168 bool CommandMerge::ignoreSpaceAtEol() const
0169 {
0170     return mIgnoreSpaceAtEol;
0171 }
0172 
0173 void CommandMerge::setIgnoreSpaceAtEol(bool newIgnoreSpaceAtEol)
0174 {
0175     mIgnoreSpaceAtEol = newIgnoreSpaceAtEol;
0176 }
0177 
0178 bool CommandMerge::ignoreCrAtEol() const
0179 {
0180     return mIgnoreCrAtEol;
0181 }
0182 
0183 void CommandMerge::setIgnoreCrAtEol(bool newIgnoreCrAtEol)
0184 {
0185     mIgnoreCrAtEol = newIgnoreCrAtEol;
0186 }
0187 
0188 bool CommandMerge::renormalize() const
0189 {
0190     return mRenormalize;
0191 }
0192 
0193 void CommandMerge::setRenormalize(bool newRenormalize)
0194 {
0195     mRenormalize = newRenormalize;
0196 }
0197 
0198 bool CommandMerge::noRenames() const
0199 {
0200     return mNoRenames;
0201 }
0202 
0203 void CommandMerge::setNoRenames(bool newNoRenames)
0204 {
0205     mNoRenames = newNoRenames;
0206 }
0207 
0208 CommandMerge::DiffAlgorithm CommandMerge::diffAlgorithm() const
0209 {
0210     return mDiffAlgorithm;
0211 }
0212 
0213 void CommandMerge::setDiffAlgorithm(DiffAlgorithm newDiffAlgorithm)
0214 {
0215     mDiffAlgorithm = newDiffAlgorithm;
0216 }
0217 
0218 bool CommandMerge::ours() const
0219 {
0220     return mOurs;
0221 }
0222 
0223 void CommandMerge::setOurs(bool newOurs)
0224 {
0225     mOurs = newOurs;
0226 }
0227 
0228 bool CommandMerge::theirs() const
0229 {
0230     return mTheirs;
0231 }
0232 
0233 void CommandMerge::setTheirs(bool newTheirs)
0234 {
0235     mTheirs = newTheirs;
0236 }
0237 
0238 } // namespace Git