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