| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import os |
| 21 |
|
| 22 |
from PyQt5 import QtCore |
| 23 |
|
| 24 |
from breezy import ( |
| 25 |
errors, |
| 26 |
osutils, |
| 27 |
urlutils, |
| 28 |
) |
| 29 |
from breezy.commands import get_cmd_object |
| 30 |
|
| 31 |
from breezy.plugins.qbrz.lib.i18n import gettext |
| 32 |
from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog |
| 33 |
from breezy.plugins.qbrz.lib.ui_pull import Ui_PullForm |
| 34 |
from breezy.plugins.qbrz.lib.ui_push import Ui_PushForm |
| 35 |
from breezy.plugins.qbrz.lib.ui_merge import Ui_MergeForm |
| 36 |
from breezy.plugins.qbrz.lib.util import ( |
| 37 |
iter_branch_related_locations, |
| 38 |
save_pull_location, |
| 39 |
fill_pull_combo, |
| 40 |
fill_combo_with, |
| 41 |
hookup_directory_picker, |
| 42 |
DIRECTORYPICKER_SOURCE, |
| 43 |
DIRECTORYPICKER_TARGET, |
| 44 |
url_for_display, |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
class QBzrPullWindow(SubProcessDialog): |
| 49 |
|
| 50 |
NAME = "pull" |
| 51 |
|
| 52 |
def __init__(self, branch, tree=None, location=None, revision=None, remember=None, |
| 53 |
overwrite=None, ui_mode=True, parent=None): |
| 54 |
self.branch = branch |
| 55 |
self.tree = tree |
| 56 |
super(QBzrPullWindow, self).__init__(name = self.NAME, |
| 57 |
ui_mode = ui_mode, |
| 58 |
parent = parent) |
| 59 |
self.ui = Ui_PullForm() |
| 60 |
self.setupUi(self.ui) |
| 61 |
|
| 62 |
for w in self.make_default_layout_widgets(): |
| 63 |
self.layout().addWidget(w) |
| 64 |
|
| 65 |
self.default_location = fill_pull_combo(self.ui.location, self.branch) |
| 66 |
if location: |
| 67 |
self.ui.location.setEditText(location) |
| 68 |
else: |
| 69 |
self.ui.location.setFocus() |
| 70 |
|
| 71 |
if remember: |
| 72 |
self.ui.remember.setCheckState(QtCore.Qt.Checked) |
| 73 |
if overwrite: |
| 74 |
self.ui.overwrite.setCheckState(QtCore.Qt.Checked) |
| 75 |
if revision: |
| 76 |
self.ui.revision.setText(revision) |
| 77 |
|
| 78 |
|
| 79 |
hookup_directory_picker(self, |
| 80 |
self.ui.location_picker, |
| 81 |
self.ui.location, |
| 82 |
DIRECTORYPICKER_SOURCE) |
| 83 |
|
| 84 |
def do_start(self): |
| 85 |
if self.tree: |
| 86 |
dest = self.tree.basedir |
| 87 |
else: |
| 88 |
dest = self.branch.base |
| 89 |
args = [] |
| 90 |
if dest != osutils.getcwd(): |
| 91 |
args.extend(('--directory', dest)) |
| 92 |
if self.ui.overwrite.isChecked(): |
| 93 |
args.append('--overwrite') |
| 94 |
if self.ui.remember.isChecked(): |
| 95 |
args.append('--remember') |
| 96 |
revision = str(self.ui.revision.text()) |
| 97 |
if revision: |
| 98 |
args.append('--revision') |
| 99 |
args.append(revision) |
| 100 |
location = str(self.ui.location.currentText()) |
| 101 |
if location and location != self.default_location: |
| 102 |
args.insert(0, location) |
| 103 |
self.process_widget.do_start(None, 'pull', *args) |
| 104 |
save_pull_location(self.branch, location) |
| 105 |
|
| 106 |
|
| 107 |
class QBzrPushWindow(SubProcessDialog): |
| 108 |
|
| 109 |
NAME = "push" |
| 110 |
|
| 111 |
def __init__(self, branch, tree=None, location=None, |
| 112 |
create_prefix=None, use_existing_dir=None, |
| 113 |
remember=None, overwrite=None, ui_mode=True, parent=None): |
| 114 |
|
| 115 |
self.branch = branch |
| 116 |
self.tree = tree |
| 117 |
self._no_strict = None |
| 118 |
super(QBzrPushWindow, self).__init__(name = self.NAME, |
| 119 |
ui_mode = ui_mode, |
| 120 |
parent = parent) |
| 121 |
|
| 122 |
self.ui = Ui_PushForm() |
| 123 |
self.setupUi(self.ui) |
| 124 |
|
| 125 |
for w in self.make_default_layout_widgets(): |
| 126 |
self.layout().addWidget(w) |
| 127 |
|
| 128 |
self.default_location = self.branch.get_push_location() |
| 129 |
df = url_for_display(self.default_location or |
| 130 |
self._suggested_push_location()) |
| 131 |
fill_combo_with(self.ui.location, df, |
| 132 |
iter_branch_related_locations(self.branch)) |
| 133 |
if location: |
| 134 |
self.ui.location.setEditText(location) |
| 135 |
else: |
| 136 |
self.ui.location.setFocus() |
| 137 |
|
| 138 |
if remember: |
| 139 |
self.ui.remember.setCheckState(QtCore.Qt.Checked) |
| 140 |
if overwrite: |
| 141 |
self.ui.overwrite.setCheckState(QtCore.Qt.Checked) |
| 142 |
if create_prefix: |
| 143 |
self.ui.create_prefix.setCheckState(QtCore.Qt.Checked) |
| 144 |
if use_existing_dir: |
| 145 |
self.ui.use_existing_dir.setCheckState(QtCore.Qt.Checked) |
| 146 |
|
| 147 |
|
| 148 |
hookup_directory_picker(self, |
| 149 |
self.ui.location_picker, |
| 150 |
self.ui.location, |
| 151 |
DIRECTORYPICKER_TARGET) |
| 152 |
|
| 153 |
def _suggested_push_location(self): |
| 154 |
"""Suggest a push location when one is not already defined. |
| 155 |
|
| 156 |
@return: a sensible location as a string or '' if none. |
| 157 |
""" |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
parent_url = self.branch.get_parent() |
| 162 |
if parent_url and parent_url.startswith("file://"): |
| 163 |
from breezy.branch import Branch |
| 164 |
try: |
| 165 |
parent_branch = Branch.open(parent_url) |
| 166 |
except errors.NotBranchError: |
| 167 |
return '' |
| 168 |
master_url = (parent_branch.get_parent() or |
| 169 |
parent_branch.get_bound_location()) |
| 170 |
if master_url and not master_url.startswith("file://"): |
| 171 |
if master_url.find("launchpad") >= 0: |
| 172 |
suggest_url = self._build_lp_push_suggestion(master_url) |
| 173 |
if suggest_url: |
| 174 |
return suggest_url |
| 175 |
|
| 176 |
|
| 177 |
suggest_url = self._build_generic_push_suggestion(master_url) |
| 178 |
if suggest_url: |
| 179 |
return suggest_url |
| 180 |
return '' |
| 181 |
|
| 182 |
def _build_lp_push_suggestion(self, master_url): |
| 183 |
try: |
| 184 |
from breezy.plugins.launchpad import account |
| 185 |
except ImportError: |
| 186 |
|
| 187 |
|
| 188 |
return '' |
| 189 |
from breezy.plugins.qbrz.lib.util import launchpad_project_from_url |
| 190 |
user_name = account.get_lp_login() |
| 191 |
project_name = launchpad_project_from_url(master_url) |
| 192 |
branch_name = urlutils.basename(self.branch.base) |
| 193 |
if user_name and project_name and branch_name: |
| 194 |
return "lp:~%s/%s/%s" % (user_name, project_name, branch_name) |
| 195 |
else: |
| 196 |
return '' |
| 197 |
|
| 198 |
def _build_generic_push_suggestion(self, master_url): |
| 199 |
master_parent = urlutils.dirname(master_url) |
| 200 |
branch_name = urlutils.basename(self.branch.base) |
| 201 |
return urlutils.join(master_parent, branch_name) |
| 202 |
|
| 203 |
def do_start(self): |
| 204 |
if self.tree: |
| 205 |
dest = self.tree.basedir |
| 206 |
else: |
| 207 |
dest = self.branch.base |
| 208 |
args = [] |
| 209 |
if dest != osutils.getcwd(): |
| 210 |
args.extend(('--directory', dest)) |
| 211 |
if self.ui.overwrite.isChecked(): |
| 212 |
args.append('--overwrite') |
| 213 |
if self.ui.remember.isChecked(): |
| 214 |
args.append('--remember') |
| 215 |
if self.ui.create_prefix.isChecked(): |
| 216 |
args.append('--create-prefix') |
| 217 |
if self.ui.use_existing_dir.isChecked(): |
| 218 |
args.append('--use-existing-dir') |
| 219 |
if 'strict' in get_cmd_object('push').options() and self._no_strict: |
| 220 |
|
| 221 |
|
| 222 |
args.append('--no-strict') |
| 223 |
location = str(self.ui.location.currentText()) |
| 224 |
if location and location != self.default_location: |
| 225 |
args.insert(0, location) |
| 226 |
self.process_widget.do_start(None, 'push', *args) |
| 227 |
|
| 228 |
def validate(self): |
| 229 |
"""Check working tree for blocking conditions (such as uncommitted |
| 230 |
changes or out of date) and return True if we can push anyway |
| 231 |
or False if push operation should be aborted. |
| 232 |
""" |
| 233 |
if self._no_strict: |
| 234 |
return True |
| 235 |
|
| 236 |
if self.tree is None: |
| 237 |
return True |
| 238 |
cfg = self.branch.get_config() |
| 239 |
strict = cfg.get_user_option('push_strict') |
| 240 |
if strict is not None: |
| 241 |
bools = dict(yes=True, no=False, on=True, off=False, true=True, false=False) |
| 242 |
strict = bools.get(strict.lower(), None) |
| 243 |
if strict == False: |
| 244 |
return True |
| 245 |
|
| 246 |
tree = self.tree |
| 247 |
blocker = None |
| 248 |
if (tree.has_changes(tree.basis_tree()) or len(tree.get_parent_ids()) > 1): |
| 249 |
blocker = gettext('Working tree has uncommitted changes.') |
| 250 |
if tree.last_revision() != tree.branch.last_revision(): |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
blocker = gettext("Working tree is out of date, please run 'brz update'.") |
| 255 |
|
| 256 |
if blocker is None: |
| 257 |
return True |
| 258 |
if self.ask_confirmation(blocker + "\n\n" + |
| 259 |
gettext("Do you want to continue anyway?"), |
| 260 |
type='warning'): |
| 261 |
self._no_strict = True |
| 262 |
return True |
| 263 |
return False |
| 264 |
|
| 265 |
|
| 266 |
class QBzrMergeWindow(SubProcessDialog): |
| 267 |
|
| 268 |
NAME = "merge" |
| 269 |
|
| 270 |
def __init__(self, branch, tree=None, location=None, revision=None, remember=None, |
| 271 |
force=None, uncommitted=None, ui_mode=True, parent=None): |
| 272 |
super(QBzrMergeWindow, self).__init__(name = self.NAME, |
| 273 |
ui_mode = ui_mode, |
| 274 |
parent = parent) |
| 275 |
self.branch = branch |
| 276 |
self.tree = tree |
| 277 |
self.ui = Ui_MergeForm() |
| 278 |
self.setupUi(self.ui) |
| 279 |
|
| 280 |
for w in self.make_default_layout_widgets(): |
| 281 |
self.layout().addWidget(w) |
| 282 |
|
| 283 |
fill_pull_combo(self.ui.location, self.branch) |
| 284 |
if location: |
| 285 |
self.ui.location.setEditText(location) |
| 286 |
else: |
| 287 |
self.ui.location.setFocus() |
| 288 |
|
| 289 |
if remember: |
| 290 |
self.ui.remember.setCheckState(QtCore.Qt.Checked) |
| 291 |
if force: |
| 292 |
self.ui.force.setCheckState(QtCore.Qt.Checked) |
| 293 |
if uncommitted: |
| 294 |
self.ui.uncommitted.setCheckState(QtCore.Qt.Checked) |
| 295 |
if revision: |
| 296 |
self.ui.revision.setText(revision) |
| 297 |
|
| 298 |
|
| 299 |
hookup_directory_picker(self, |
| 300 |
self.ui.location_picker, |
| 301 |
self.ui.location, |
| 302 |
DIRECTORYPICKER_SOURCE) |
| 303 |
|
| 304 |
def do_start(self): |
| 305 |
if self.tree: |
| 306 |
dest = self.tree.basedir |
| 307 |
else: |
| 308 |
dest = self.branch.base |
| 309 |
if dest == os.getcwd(): |
| 310 |
args = [] |
| 311 |
else: |
| 312 |
args = ['--directory', dest] |
| 313 |
if self.ui.remember.isChecked(): |
| 314 |
args.append('--remember') |
| 315 |
if self.ui.force.isChecked(): |
| 316 |
args.append('--force') |
| 317 |
if self.ui.uncommitted.isChecked(): |
| 318 |
args.append('--uncommitted') |
| 319 |
rev = str(self.ui.revision.text()).strip() |
| 320 |
if rev: |
| 321 |
args.extend(['--revision', rev]) |
| 322 |
location = str(self.ui.location.currentText()) |
| 323 |
self.process_widget.do_start(None, 'merge', location, *args) |
| 324 |
save_pull_location(None, location) |