gitbranch.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef GITBRANCH_H
  2. #define GITBRANCH_H
  3. #include <gitreference.h>
  4. #include <git2/types.h>
  5. struct git_oid;
  6. class GitBranch : public GitReference
  7. {
  8. Q_OBJECT
  9. Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
  10. Q_PROPERTY(QString fullName READ fullName NOTIFY fullNameChanged)
  11. Q_PROPERTY(QString remote READ remote NOTIFY remoteChanged)
  12. Q_PROPERTY(BranchType type READ type CONSTANT)
  13. Q_PROPERTY(GitOid oid READ oid CONSTANT)
  14. Q_ENUMS(BranchType PullStrategy)
  15. public:
  16. enum BranchType {
  17. Invalid = 0,
  18. Local = GIT_BRANCH_LOCAL,
  19. Remote = GIT_BRANCH_REMOTE
  20. };
  21. enum PullStrategy {
  22. Rebase,
  23. Merge
  24. };
  25. GitBranch(git_reference *ref, git_branch_t type, GitRepository *parent);
  26. GitBranch(GitBranch &&other);
  27. GitBranch &operator=(GitBranch &&other);
  28. virtual ~GitBranch();
  29. BranchType type() const;
  30. QString name() const {
  31. return m_name;
  32. }
  33. QString fullName() const {
  34. return m_fullName;
  35. }
  36. git_annotated_commit *annotatedCommit()
  37. {
  38. return m_commit;
  39. }
  40. QString remote() const
  41. {
  42. return m_remote;
  43. }
  44. GitBranch upstream() const;
  45. void setUpstream(const GitBranch &branch);
  46. void pull(PullStrategy strategy);
  47. public slots:
  48. void setName(QString name) {
  49. if (m_name == name)
  50. return;
  51. m_name = name;
  52. emit nameChanged(name);
  53. }
  54. signals:
  55. void nameChanged(QString name);
  56. void fullNameChanged(QString fullName);
  57. void remoteChanged(QString remote);
  58. private:
  59. void free();
  60. void fastForward();
  61. GitBranch();
  62. Q_DISABLE_COPY(GitBranch)
  63. git_annotated_commit *m_commit;
  64. BranchType m_type;
  65. QString m_name;
  66. QString m_fullName;
  67. QString m_remote;
  68. };
  69. #endif // GITBRANCH_H