gitbranch.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. void rebase(git_annotated_commit* upstreamCommit);
  62. GitBranch();
  63. Q_DISABLE_COPY(GitBranch)
  64. git_annotated_commit *m_commit;
  65. BranchType m_type;
  66. QString m_name;
  67. QString m_fullName;
  68. QString m_remote;
  69. };
  70. #endif // GITBRANCH_H