gitbranch.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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)
  15. public:
  16. enum BranchType {
  17. Invalid = 0,
  18. Local = GIT_BRANCH_LOCAL,
  19. Remote = GIT_BRANCH_REMOTE
  20. };
  21. GitBranch(git_reference *ref, git_branch_t type, GitRepository *parent);
  22. GitBranch(GitBranch &&other);
  23. GitBranch &operator=(GitBranch &&other);
  24. virtual ~GitBranch();
  25. BranchType type() const;
  26. QString name() const {
  27. return m_name;
  28. }
  29. QString fullName() const {
  30. return m_fullName;
  31. }
  32. git_annotated_commit *annotatedCommit()
  33. {
  34. return m_commit;
  35. }
  36. QString remote() const
  37. {
  38. return m_remote;
  39. }
  40. GitBranch upstream() const;
  41. void setUpstream(const GitBranch &branch);
  42. public slots:
  43. void setName(QString name) {
  44. if (m_name == name)
  45. return;
  46. m_name = name;
  47. emit nameChanged(name);
  48. }
  49. signals:
  50. void nameChanged(QString name);
  51. void fullNameChanged(QString fullName);
  52. void remoteChanged(QString remote);
  53. private:
  54. void free();
  55. GitBranch();
  56. Q_DISABLE_COPY(GitBranch)
  57. git_annotated_commit *m_commit;
  58. BranchType m_type;
  59. QString m_name;
  60. QString m_fullName;
  61. QString m_remote;
  62. };
  63. #endif // GITBRANCH_H