|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the rebase extension interface. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtWidgets import QDialog |
|
15 |
|
16 from ..HgExtension import HgExtension |
|
17 from ..HgDialog import HgDialog |
|
18 |
|
19 |
|
20 class Rebase(HgExtension): |
|
21 """ |
|
22 Class implementing the rebase extension interface. |
|
23 """ |
|
24 def __init__(self, vcs): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param vcs reference to the Mercurial vcs object |
|
29 """ |
|
30 super(Rebase, self).__init__(vcs) |
|
31 |
|
32 def hgRebase(self, path): |
|
33 """ |
|
34 Public method to rebase changesets to a different branch. |
|
35 |
|
36 @param path directory name of the project (string) |
|
37 @return flag indicating that the project should be reread (boolean) |
|
38 """ |
|
39 # find the root of the repo |
|
40 repodir = self.vcs.splitPath(path)[0] |
|
41 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
42 repodir = os.path.dirname(repodir) |
|
43 if os.path.splitdrive(repodir)[1] == os.sep: |
|
44 return False |
|
45 |
|
46 res = False |
|
47 from .HgRebaseDialog import HgRebaseDialog |
|
48 dlg = HgRebaseDialog(self.vcs.hgGetTagsList(repodir), |
|
49 self.vcs.hgGetBranchesList(repodir), |
|
50 self.vcs.hgGetBookmarksList(repodir), |
|
51 self.vcs.version) |
|
52 if dlg.exec_() == QDialog.Accepted: |
|
53 (indicator, sourceRev, destRev, collapse, keep, keepBranches, |
|
54 detach, dryRunOnly, dryRunConfirm) = dlg.getData() |
|
55 |
|
56 args = self.vcs.initCommand("rebase") |
|
57 if indicator == "S": |
|
58 args.append("--source") |
|
59 args.append(sourceRev) |
|
60 elif indicator == "B": |
|
61 args.append("--base") |
|
62 args.append(sourceRev) |
|
63 if destRev: |
|
64 args.append("--dest") |
|
65 args.append(destRev) |
|
66 if collapse: |
|
67 args.append("--collapse") |
|
68 if keep: |
|
69 args.append("--keep") |
|
70 if keepBranches: |
|
71 args.append("--keepbranches") |
|
72 if detach: |
|
73 args.append("--detach") |
|
74 if dryRunOnly: |
|
75 args.append("--dry-run") |
|
76 elif dryRunConfirm: |
|
77 args.append("--confirm") |
|
78 args.append("--verbose") |
|
79 |
|
80 dia = HgDialog(self.tr('Rebase Changesets'), self.vcs) |
|
81 res = dia.startProcess(args, repodir) |
|
82 if res: |
|
83 dia.exec_() |
|
84 res = dia.hasAddOrDelete() |
|
85 self.vcs.checkVCSStatus() |
|
86 return res |
|
87 |
|
88 def hgRebaseContinue(self, path): |
|
89 """ |
|
90 Public method to continue rebasing changesets from another branch. |
|
91 |
|
92 @param path directory name of the project (string) |
|
93 @return flag indicating that the project should be reread (boolean) |
|
94 """ |
|
95 # find the root of the repo |
|
96 repodir = self.vcs.splitPath(path)[0] |
|
97 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
98 repodir = os.path.dirname(repodir) |
|
99 if os.path.splitdrive(repodir)[1] == os.sep: |
|
100 return False |
|
101 |
|
102 args = self.vcs.initCommand("rebase") |
|
103 args.append("--continue") |
|
104 args.append("--verbose") |
|
105 |
|
106 dia = HgDialog(self.tr('Rebase Changesets (Continue)'), self.vcs) |
|
107 res = dia.startProcess(args, repodir) |
|
108 if res: |
|
109 dia.exec_() |
|
110 res = dia.hasAddOrDelete() |
|
111 self.vcs.checkVCSStatus() |
|
112 return res |
|
113 |
|
114 def hgRebaseAbort(self, path): |
|
115 """ |
|
116 Public method to abort rebasing changesets from another branch. |
|
117 |
|
118 @param path directory name of the project (string) |
|
119 @return flag indicating that the project should be reread (boolean) |
|
120 """ |
|
121 # find the root of the repo |
|
122 repodir = self.vcs.splitPath(path)[0] |
|
123 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
124 repodir = os.path.dirname(repodir) |
|
125 if os.path.splitdrive(repodir)[1] == os.sep: |
|
126 return False |
|
127 |
|
128 args = self.vcs.initCommand("rebase") |
|
129 args.append("--abort") |
|
130 args.append("--verbose") |
|
131 |
|
132 dia = HgDialog(self.tr('Rebase Changesets (Abort)'), self.vcs) |
|
133 res = dia.startProcess(args, repodir) |
|
134 if res: |
|
135 dia.exec_() |
|
136 res = dia.hasAddOrDelete() |
|
137 self.vcs.checkVCSStatus() |
|
138 return res |