15
15
"""GTK+ frontends to Bazaar commands """
19
__version__ = '0.15.0'
20
version_info = tuple(int(n) for n in __version__.split('.'))
23
def check_bzrlib_version(desired):
24
"""Check that bzrlib is compatible.
26
If version is < bzr-gtk version, assume incompatible.
27
If version == bzr-gtk version, assume completely compatible
28
If version == bzr-gtk version + 1, assume compatible, with deprecations
29
Otherwise, assume incompatible.
31
desired_plus = (desired[0], desired[1]+1)
32
bzrlib_version = bzrlib.version_info[:2]
33
if bzrlib_version == desired:
36
from bzrlib.trace import warning
38
# get the message out any way we can
39
from warnings import warn as warning
40
if bzrlib_version < desired:
41
warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
' %s.' % (bzrlib.__version__, __version__))
43
# Not using BzrNewError, because it may not exist.
44
raise Exception, ('Version mismatch', version_info)
46
warning('bzr-gtk is not up to date with installed bzr version %s.'
47
' \nThere should be a newer version available, e.g. %i.%i.'
48
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
if bzrlib_version != desired_plus:
50
raise Exception, 'Version mismatch'
53
check_bzrlib_version(version_info[:2])
55
from bzrlib.trace import warning
56
if __name__ != 'bzrlib.plugins.gtk':
57
warning("Not running as bzrlib.plugins.gtk, things may break.")
59
from bzrlib import errors
60
17
from bzrlib.commands import Command, register_command, display_command
61
18
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
62
19
from bzrlib.commands import Command, register_command
65
22
from bzrlib.workingtree import WorkingTree
66
23
from bzrlib.bzrdir import BzrDir
74
raise errors.BzrCommandError("PyGTK not installed.")
80
pygtk = import_pygtk()
81
from ui import GtkUIFactory
83
bzrlib.ui.ui_factory = GtkUIFactory()
25
__version__ = '0.11.0'
86
27
class cmd_gbranch(Command):
92
pygtk = import_pygtk()
95
37
except RuntimeError, e:
96
38
if str(e) == "could not open display":
97
39
raise NoDisplayError
99
from bzrlib.plugins.gtk.branch import BranchDialog
41
from clone import CloneDialog
102
dialog = BranchDialog(os.path.abspath('.'))
43
window = CloneDialog()
44
if window.run() == gtk.RESPONSE_OK:
45
bzrdir = BzrDir.open(window.url)
46
bzrdir.sprout(window.dest_path)
105
48
register_command(cmd_gbranch)
107
class cmd_gcheckout(Command):
113
pygtk = import_pygtk()
116
except RuntimeError, e:
117
if str(e) == "could not open display":
120
from bzrlib.plugins.gtk.checkout import CheckoutDialog
123
dialog = CheckoutDialog(os.path.abspath('.'))
126
register_command(cmd_gcheckout)
128
class cmd_gpush(Command):
132
takes_args = [ "location?" ]
134
def run(self, location="."):
135
(branch, path) = Branch.open_containing(location)
137
pygtk = import_pygtk()
140
except RuntimeError, e:
141
if str(e) == "could not open display":
144
from push import PushDialog
147
dialog = PushDialog(branch)
150
register_command(cmd_gpush)
152
50
class cmd_gdiff(Command):
153
51
"""Show differences in working tree in a GTK+ Window.
177
74
tree2 = tree1.basis_tree()
179
from viz.diff import DiffWindow
76
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
181
78
window = DiffWindow()
182
79
window.connect("destroy", lambda w: gtk.main_quit())
183
80
window.set_diff("Working Tree", tree1, tree2)
184
81
if filename is not None:
185
tree_filename = wt.relpath(filename)
82
tree_filename = tree1.relpath(filename)
187
84
window.set_file(tree_filename)
188
85
except NoSuchFile:
214
111
aliases = [ "visualize", "vis", "viz" ]
216
113
def run(self, location=".", revision=None, limit=None):
218
114
(branch, path) = Branch.open_containing(location)
219
115
branch.lock_read()
220
116
branch.repository.lock_read()
249
145
Option("all", help="show annotations on all lines"),
250
146
Option("plain", help="don't highlight annotation lines"),
251
147
Option("line", type=int, argname="lineno",
252
help="jump to specified line number"),
148
help="jump to specified line number")
255
150
aliases = ["gblame", "gpraise"]
257
def run(self, filename, all=False, plain=False, line='1', revision=None):
258
pygtk = import_pygtk()
152
def run(self, filename, all=False, plain=False, line='1'):
262
158
except RuntimeError, e:
263
159
if str(e) == "could not open display":
264
160
raise NoDisplayError
273
168
from annotate.gannotate import GAnnotateWindow
274
169
from annotate.config import GAnnotateConfig
277
(tree, path) = WorkingTree.open_containing(filename)
279
except errors.NoWorkingTree:
280
(branch, path) = Branch.open_containing(filename)
281
tree = branch.basis_tree()
171
(wt, path) = WorkingTree.open_containing(filename)
283
file_id = tree.path2id(path)
174
file_id = wt.path2id(path)
285
176
if file_id is None:
286
177
raise NotVersionedError(filename)
287
if revision is not None:
288
if len(revision) != 1:
289
raise BzrCommandError("Only 1 revion may be specified.")
290
revision_id = revision[0].in_history(branch).rev_id
291
tree = branch.repository.revision_tree(revision_id)
293
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
295
179
window = GAnnotateWindow(all, plain)
296
180
window.connect("destroy", lambda w: gtk.main_quit())
327
210
if str(e) == "could not open display":
328
211
raise NoDisplayError
331
from commit import CommitDialog
213
from commit import GCommitDialog
332
214
from bzrlib.commit import Commit
333
from bzrlib.errors import (BzrCommandError,
343
(wt, path) = WorkingTree.open_containing(filename)
345
except NotBranchError, e:
347
except NoWorkingTree, e:
350
(branch, path) = Branch.open_containing(path)
351
except NotBranchError, e:
355
commit = CommitDialog(wt, path, not branch)
215
from bzrlib.errors import (BzrCommandError, PointlessCommit, ConflictsInTree,
218
(wt, path) = WorkingTree.open_containing(filename)
221
file_id = wt.path2id(path)
224
raise NotVersionedError(filename)
226
dialog = GCommitDialog(wt)
227
dialog.set_title(path + " - Commit")
228
if dialog.run() != gtk.RESPONSE_CANCEL:
229
Commit().commit(working_tree=wt,message=dialog.message,
230
specific_files=dialog.specific_files)
358
232
register_command(cmd_gcommit)
361
235
"""gtk could not find a proper display"""
363
237
def __str__(self):
364
return "No DISPLAY. Unable to run GTK+ application."
367
from unittest import TestSuite
370
result.addTest(tests.test_suite())
238
return "No DISPLAY. gannotate is disabled."