| 1 | #include "GitStashes.h" | 
| 2 |  | 
| 3 | #include <GitBase.h> | 
| 4 |  | 
| 5 | #include <QLogger.h> | 
| 6 |  | 
| 7 | using namespace QLogger; | 
| 8 |  | 
| 9 | GitStashes::GitStashes(const QSharedPointer<GitBase> &gitBase) | 
| 10 |    : mGitBase(gitBase) | 
| 11 | { | 
| 12 | } | 
| 13 |  | 
| 14 | QVector<QString> GitStashes::getStashes() | 
| 15 | { | 
| 16 |    QLog_Debug("Git" , QString("Getting stashes" )); | 
| 17 |  | 
| 18 |    const auto cmd = QString("git stash list" ); | 
| 19 |  | 
| 20 |    QLog_Trace("Git" , QString("Getting stashes: {%1}" ).arg(cmd)); | 
| 21 |  | 
| 22 |    const auto ret = mGitBase->run(cmd); | 
| 23 |  | 
| 24 |    QVector<QString> stashes; | 
| 25 |  | 
| 26 |    if (ret.success) | 
| 27 |    { | 
| 28 |       const auto tagsTmp = ret.output.split("\n" ); | 
| 29 |  | 
| 30 |       for (const auto &tag : tagsTmp) | 
| 31 |          if (tag != "\n"  && !tag.isEmpty()) | 
| 32 |             stashes.append(tag); | 
| 33 |    } | 
| 34 |  | 
| 35 |    return stashes; | 
| 36 | } | 
| 37 |  | 
| 38 | GitExecResult GitStashes::pop() const | 
| 39 | { | 
| 40 |    QLog_Debug("Git" , QString("Poping the stash" )); | 
| 41 |  | 
| 42 |    const auto cmd = QString("git stash pop" ); | 
| 43 |  | 
| 44 |    QLog_Trace("Git" , QString("Poping the stash: {%1}" ).arg(cmd)); | 
| 45 |  | 
| 46 |    const auto ret = mGitBase->run(cmd); | 
| 47 |  | 
| 48 |    return ret; | 
| 49 | } | 
| 50 |  | 
| 51 | GitExecResult GitStashes::stash() | 
| 52 | { | 
| 53 |    QLog_Debug("Git" , QString("Stashing changes" )); | 
| 54 |  | 
| 55 |    const auto cmd = QString("git stash" ); | 
| 56 |  | 
| 57 |    QLog_Trace("Git" , QString("Stashing changes: {%1}" ).arg(cmd)); | 
| 58 |  | 
| 59 |    const auto ret = mGitBase->run(cmd); | 
| 60 |  | 
| 61 |    return ret; | 
| 62 | } | 
| 63 |  | 
| 64 | GitExecResult GitStashes::stashBranch(const QString &stashId, const QString &branchName) | 
| 65 | { | 
| 66 |    QLog_Debug("Git" , QString("Creating a branch from stash: {%1} in branch {%2}" ).arg(stashId, branchName)); | 
| 67 |  | 
| 68 |    const auto cmd = QString("git stash branch %1 %2" ).arg(branchName, stashId); | 
| 69 |  | 
| 70 |    QLog_Trace("Git" , QString("Creating a branch from stash: {%1}" ).arg(cmd)); | 
| 71 |  | 
| 72 |    const auto ret = mGitBase->run(cmd); | 
| 73 |  | 
| 74 |    return ret; | 
| 75 | } | 
| 76 |  | 
| 77 | GitExecResult GitStashes::stashDrop(const QString &stashId) | 
| 78 | { | 
| 79 |    QLog_Debug("Git" , QString("Droping stash: {%1}" ).arg(stashId)); | 
| 80 |  | 
| 81 |    const auto cmd = QString("git stash drop -q %1" ).arg(stashId); | 
| 82 |  | 
| 83 |    QLog_Trace("Git" , QString("Droping stash: {%1}" ).arg(cmd)); | 
| 84 |  | 
| 85 |    const auto ret = mGitBase->run(cmd); | 
| 86 |  | 
| 87 |    return ret; | 
| 88 | } | 
| 89 |  | 
| 90 | GitExecResult GitStashes::stashClear() | 
| 91 | { | 
| 92 |    QLog_Debug("Git" , QString("Clearing stash" )); | 
| 93 |  | 
| 94 |    const auto cmd = QString("git stash clear" ); | 
| 95 |  | 
| 96 |    QLog_Trace("Git" , QString("Clearing stash: {%1}" ).arg(cmd)); | 
| 97 |  | 
| 98 |    const auto ret = mGitBase->run(cmd); | 
| 99 |  | 
| 100 |    return ret; | 
| 101 | } | 
| 102 |  |