Line data Source code
1 : /*! 2 : * \file esys/repo/git/branch_git.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2020 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/git/branch.h" 20 : 21 : namespace esys::repo::git 22 : { 23 : 24 162 : Branch::Branch() = default; 25 : 26 4 : Branch::Branch(const std::string &name, bool is_head) 27 4 : : m_name(name) 28 4 : , m_is_head(is_head) 29 : { 30 4 : } 31 : 32 0 : Branch::Branch(const std::string &name, BranchType type, bool is_head) 33 0 : : m_name(name) 34 0 : , m_type(type) 35 0 : , m_is_head(is_head) 36 : { 37 0 : } 38 : 39 174 : Branch::~Branch() = default; 40 : 41 162 : void Branch::set_name(const std::string &name) 42 : { 43 162 : m_name = name; 44 162 : } 45 : 46 110 : const std::string &Branch::get_name() const 47 : { 48 110 : return m_name; 49 : } 50 : 51 162 : void Branch::set_ref_name(const std::string &ref_name) 52 : { 53 162 : m_ref_name = ref_name; 54 162 : } 55 : 56 0 : const std::string &Branch::get_ref_name() const 57 : { 58 0 : return m_ref_name; 59 : } 60 : 61 162 : void Branch::set_type(BranchType type) 62 : { 63 162 : m_type = type; 64 162 : } 65 : 66 0 : BranchType Branch::get_type() const 67 : { 68 0 : return m_type; 69 : } 70 : 71 149 : void Branch::set_is_head(bool is_head) 72 : { 73 149 : m_is_head = is_head; 74 149 : } 75 : 76 210 : bool Branch::get_is_head() const 77 : { 78 210 : return m_is_head; 79 : } 80 : 81 162 : void Branch::set_remote_branch(const std::string &remote_tracking) 82 : { 83 162 : m_remote_branch = remote_tracking; 84 162 : } 85 : 86 53 : const std::string &Branch::get_remote_branch() const 87 : { 88 53 : return m_remote_branch; 89 : } 90 : 91 18 : void Branch::set_remote_branch_name(const std::string &remote_branch_name) 92 : { 93 18 : m_remote_branch_name = remote_branch_name; 94 18 : } 95 : 96 0 : const std::string &Branch::get_remote_branch_name() const 97 : { 98 0 : return m_remote_branch_name; 99 : } 100 : 101 162 : void Branch::set_remote_name(const std::string &remote_name) 102 : { 103 162 : m_remote_name = remote_name; 104 162 : } 105 : 106 37 : const std::string &Branch::get_remote_name() const 107 : { 108 37 : return m_remote_name; 109 : } 110 : 111 18 : void Branch::set_detached(bool detached) 112 : { 113 18 : m_detached = detached; 114 18 : } 115 : 116 1 : bool Branch::get_detached() const 117 : { 118 1 : return m_detached; 119 : } 120 : 121 0 : bool Branch::operator==(const Branch &other) const 122 : { 123 0 : if (get_name() != other.get_name()) return false; 124 0 : if (get_ref_name() != other.get_ref_name()) return false; 125 0 : if (get_type() != other.get_type()) return false; 126 0 : if (get_is_head() != other.get_is_head()) return false; 127 : 128 : //!\TODO should other parameter be added? 129 : return true; 130 : } 131 : 132 0 : bool Branch::operator!=(const Branch &other) const 133 : { 134 0 : return !operator==(other); 135 : } 136 : 137 : } // namespace esys::repo::git 138 : 139 : namespace std 140 : { 141 : 142 0 : ESYSREPO_API ostream &operator<<(ostream &os, const esys::repo::git::Branch &branch) 143 : { 144 0 : os << "name : " << branch.get_name(); 145 0 : if (branch.get_is_head()) os << " [HEAD]"; 146 0 : if (branch.get_is_head()) os << " [detached]"; 147 0 : os << std::endl; 148 0 : os << "ref : " << branch.get_ref_name() << std::endl; 149 : 150 0 : return os; 151 : } 152 : 153 : } // namespace std