| 1 | #pragma once |
| 2 | |
| 3 | /**************************************************************************************** |
| 4 | ** GitQlient is an application to manage and operate one or several Git repositories. With |
| 5 | ** GitQlient you will be able to add commits, branches and manage all the options Git provides. |
| 6 | ** Copyright (C) 2021 Francesc Martinez |
| 7 | ** |
| 8 | ** LinkedIn: www.linkedin.com/in/cescmm/ |
| 9 | ** Web: www.francescmm.com |
| 10 | ** |
| 11 | ** This program is free software; you can redistribute it and/or |
| 12 | ** modify it under the terms of the GNU Lesser General Public |
| 13 | ** License as published by the Free Software Foundation; either |
| 14 | ** version 2 of the License, or (at your option) any later version. |
| 15 | ** |
| 16 | ** This program is distributed in the hope that it will be useful, |
| 17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | ** Lesser General Public License for more details. |
| 20 | ** |
| 21 | ** You should have received a copy of the GNU Lesser General Public |
| 22 | ** License along with this library; if not, write to the Free Software |
| 23 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | ***************************************************************************************/ |
| 25 | |
| 26 | #include <QDialog> |
| 27 | |
| 28 | namespace Ui |
| 29 | { |
| 30 | class BranchDlg; |
| 31 | } |
| 32 | |
| 33 | class GitCache; |
| 34 | class GitBase; |
| 35 | |
| 36 | /** |
| 37 | * @brief The mode indicates what operation will perform the dialog |
| 38 | * |
| 39 | * @enum BranchDlgMode |
| 40 | */ |
| 41 | enum class BranchDlgMode |
| 42 | { |
| 43 | CREATE, |
| 44 | CREATE_CHECKOUT, |
| 45 | CREATE_FROM_COMMIT, |
| 46 | CREATE_CHECKOUT_FROM_COMMIT, |
| 47 | RENAME, |
| 48 | STASH_BRANCH, |
| 49 | PUSH_UPSTREAM |
| 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * @brief The configuration indicates the dialog which is the base branch and in which mode the dialog has to be |
| 54 | * executed. |
| 55 | * |
| 56 | * @class BranchDlgConfig BranchDlg.h "BranchDlg.h" |
| 57 | */ |
| 58 | struct BranchDlgConfig |
| 59 | { |
| 60 | /** |
| 61 | * @brief mCurrentBranchName The current working branch. |
| 62 | */ |
| 63 | QString mCurrentBranchName; |
| 64 | /** |
| 65 | * @brief mDialogMode The dialog mode configuration. |
| 66 | */ |
| 67 | BranchDlgMode mDialogMode; |
| 68 | QSharedPointer<GitCache> mCache; |
| 69 | /** |
| 70 | * @brief mGit The GitBase object to perform the git branch operations. |
| 71 | */ |
| 72 | QSharedPointer<GitBase> mGit; |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * @brief The BranchDlg class creates a small dialog where the user can apply branch operations as: create (with |
| 77 | * different newonces), rename, stash a branch and push a local branch. |
| 78 | * |
| 79 | * For the creation of a branch the user can configure the dialog in different ways: |
| 80 | * - Normal create: creates a new branch in the same commit that the branch selected |
| 81 | * - Create and checkout: in addition to create a branch, GitQlient will checkout the new branch to continue the work in |
| 82 | * there. |
| 83 | * - Create from commit: instead of taking a branch as reference, the dialog takes a commit SHA to create a new branch |
| 84 | * in there. |
| 85 | * |
| 86 | * The operations over Git are done once the user accepts the dialog and all the validations pass. |
| 87 | * |
| 88 | * @class BranchDlg BranchDlg.h "BranchDlg.h" |
| 89 | */ |
| 90 | class BranchDlg : public QDialog |
| 91 | { |
| 92 | Q_OBJECT |
| 93 | |
| 94 | public: |
| 95 | /** |
| 96 | * @brief Constructor that takes the configuration as parameter. Builds the UI layout and configures some widgets |
| 97 | * based on the configuration. |
| 98 | * |
| 99 | * @param config The configuration for the dialog |
| 100 | * @param parent The parent widget if needed |
| 101 | */ |
| 102 | explicit BranchDlg(BranchDlgConfig config, QWidget *parent = nullptr); |
| 103 | /** |
| 104 | * @brief Destructor that deallocates the Ui::BranchDlg class. |
| 105 | */ |
| 106 | ~BranchDlg() override; |
| 107 | |
| 108 | private: |
| 109 | Ui::BranchDlg *ui = nullptr; |
| 110 | BranchDlgConfig mConfig; |
| 111 | |
| 112 | /** |
| 113 | * @brief Validates that the new branch name is not the same for the creation and renaming cases. If the user is |
| 114 | * trying to push the branch it won't validate it's name. |
| 115 | */ |
| 116 | void checkNewBranchName(); |
| 117 | /** |
| 118 | * @brief Executes the Git actions based on the configuration once the validation as taken place. |
| 119 | */ |
| 120 | void accept() override; |
| 121 | |
| 122 | /** |
| 123 | * @brief copyBranchName Copies the current remote branch name into the line edit so the user doesn't have to type |
| 124 | * it. |
| 125 | */ |
| 126 | void copyBranchName(); |
| 127 | }; |
| 128 | |