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 "commandswitchbranch.h" 0008 0009 #include "libkommit_debug.h" 0010 0011 #include <KLocalizedString> 0012 0013 namespace Git 0014 { 0015 0016 CommandSwitchBranch::CommandSwitchBranch(Manager *git) 0017 : AbstractCommand(git) 0018 { 0019 } 0020 0021 void CommandSwitchBranch::parseOutputSection(const QByteArray &output, const QByteArray &errorOutput) 0022 { 0023 if (errorOutput.contains("error: Your local changes to the following files would be overwritten by checkout")) { 0024 setStatus(Error); 0025 setErrorMessage( 0026 i18n("Your local changes to the following files would be overwritten by checkout. " 0027 "Please commit your changes or stash them before you switch branches.")); 0028 } 0029 qCDebug(KOMMITLIB_LOG) << "Error" << errorOutput; 0030 qCDebug(KOMMITLIB_LOG) << "out" << output; 0031 } 0032 0033 const QString &CommandSwitchBranch::target() const 0034 { 0035 return mTarget; 0036 } 0037 0038 void CommandSwitchBranch::setTarget(const QString &newTarget) 0039 { 0040 mTarget = newTarget; 0041 } 0042 0043 CommandSwitchBranch::Mode CommandSwitchBranch::mode() const 0044 { 0045 return mMode; 0046 } 0047 0048 void CommandSwitchBranch::setMode(Mode newMode) 0049 { 0050 mMode = newMode; 0051 } 0052 0053 QStringList CommandSwitchBranch::generateArgs() const 0054 { 0055 QStringList cmd; 0056 0057 if (mMode == NewBranch) 0058 cmd << QStringLiteral("checkout") << QStringLiteral("-b") << mTarget; 0059 else if (mMode == RemoteBranch) 0060 cmd << QStringLiteral("checkout") << QStringLiteral("-b") << mTarget << mRemoteBranch; 0061 else 0062 cmd << QStringLiteral("switch") << mTarget; 0063 0064 if (mForce) 0065 cmd.append(QStringLiteral("--force")); 0066 return cmd; 0067 } 0068 0069 bool CommandSwitchBranch::force() const 0070 { 0071 return mForce; 0072 } 0073 0074 void CommandSwitchBranch::setForce(bool newForce) 0075 { 0076 mForce = newForce; 0077 } 0078 0079 QString CommandSwitchBranch::remoteBranch() const 0080 { 0081 return mRemoteBranch; 0082 } 0083 0084 void CommandSwitchBranch::setRemoteBranch(const QString &newRemoteBranch) 0085 { 0086 mRemoteBranch = newRemoteBranch; 0087 } 0088 0089 } // namespace Git 0090 0091 #include "moc_commandswitchbranch.cpp"