Пример #1
0
 def test_get_root(self):
     mf = mock.MockFunction()
     self.make_branch('a')
     tb = tree_branch.TreeBranch.open_containing('a',
                                                 require_tree=False,
                                                 ui_mode=False,
                                                 _critical_dialog=mf)
     self.assertEqual(osutils.abspath('a') + '/', tb.get_root())
     #
     self.make_branch_and_tree('b')
     root = osutils.abspath('b')
     tb = tree_branch.TreeBranch.open_containing('b',
                                                 require_tree=True,
                                                 ui_mode=False,
                                                 _critical_dialog=mf)
     self.assertEqual(root, tb.get_root())
     #
     self.build_tree(['b/dir/'])
     tb = tree_branch.TreeBranch.open_containing('b/dir',
                                                 require_tree=True,
                                                 ui_mode=False,
                                                 _critical_dialog=mf)
     self.assertEqual(root, tb.get_root())
     #
     self.run_bzr('checkout --lightweight b c')
     tb = tree_branch.TreeBranch.open_containing('c',
                                                 require_tree=True,
                                                 ui_mode=False,
                                                 _critical_dialog=mf)
     self.assertEqual(osutils.abspath('c'), tb.get_root())
Пример #2
0
    def __init__(self, branch, location=None, ui_mode = None):
        self.branch = branch
        super(QBzrBindDialog, self).__init__(
                                  gettext("Bind branch"),
                                  name = "bind",
                                  default_size = (400, 400),
                                  ui_mode = ui_mode,
                                  dialog = True,
                                  parent = None,
                                  hide_progress=False,
                                  )

        # Display information fields
        gbBind = QtWidgets.QGroupBox(gettext("Bind"), self)
        bind_box = QtWidgets.QFormLayout(gbBind)
        bind_box.addRow(gettext("Branch location:"),
            QtWidgets.QLabel(url_for_display(branch.base)))
        self.currbound = branch.get_bound_location()
        if self.currbound != None:
            bind_box.addRow(gettext("Currently bound to:"),
                QtWidgets.QLabel(url_for_display(self.currbound)))

        # Build the "Bind to" widgets
        branch_label = QtWidgets.QLabel(gettext("Bind to:"))
        branch_combo = QtWidgets.QComboBox()   
        branch_combo.setEditable(True)
        self.branch_combo = branch_combo
        browse_button = QtWidgets.QPushButton(gettext("Browse"))
        browse_button.clicked[bool].connect(self.browse_clicked)

        # Add some useful values into the combo box. If a location was given,
        # default to it. If an old bound location exists, suggest it.
        # Otherwise suggest the parent branch, if any.
        suggestions = []
        if location:
            suggestions.append(osutils.abspath(location))
        self._maybe_add_suggestion(suggestions, branch.get_old_bound_location())
        self._maybe_add_suggestion(suggestions, branch.get_parent())
        self._maybe_add_suggestion(suggestions, branch.get_push_location())
        if suggestions:
            branch_combo.addItems(suggestions)

        # Build the "Bind to" row/panel
        bind_hbox = QtWidgets.QHBoxLayout()
        bind_hbox.addWidget(branch_label)
        bind_hbox.addWidget(branch_combo)
        bind_hbox.addWidget(browse_button)
        bind_hbox.setStretchFactor(branch_label,0)
        bind_hbox.setStretchFactor(branch_combo,1)
        bind_hbox.setStretchFactor(browse_button,0)
        bind_box.addRow(bind_hbox)

        # Put the form together
        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(gbBind)
        layout.addWidget(self.make_default_status_box())
        layout.addWidget(self.buttonbox)

        branch_combo.setFocus()
Пример #3
0
 def _set_location(self, location):
     if not location:
         self.ui.local_location.setText('-')
         return
     if location != '.':
         self.ui.local_location.setText(url_for_display(location))
         return
     self.ui.local_location.setText(osutils.abspath(location))
Пример #4
0
def make_pristine_tar_delta(dest, tarball_path):
    """Create a pristine-tar delta for a tarball.

    :param dest: Directory to generate pristine tar delta for
    :param tarball_path: Path to the tarball
    :return: pristine-tarball
    """
    def subprocess_setup():
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    # If tarball_path is relative, the cwd=dest parameter to Popen will make
    # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we
    # assume local paths.
    tarball_path = osutils.abspath(tarball_path)
    command = ["pristine-tar", "gendelta", tarball_path, "-"]
    proc = subprocess.Popen(
        command, stdout=subprocess.PIPE,
        cwd=dest, preexec_fn=subprocess_setup,
        stderr=subprocess.PIPE)
    (stdout, stderr) = proc.communicate()
    if proc.returncode != 0:
        raise Exception("Generating delta from tar failed: %s" % stderr)
    return stdout
Пример #5
0
    def test_push_remember(self):
        """Push changes from one branch to another and test push location."""
        transport = self.get_transport()
        tree_a = self.make_branch_and_tree('branch_a')
        branch_a = tree_a.branch
        self.build_tree(['branch_a/a'])
        tree_a.add('a')
        tree_a.commit('commit a')
        tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
        branch_b = tree_b.branch
        tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
        branch_c = tree_c.branch
        self.build_tree(['branch_a/b'])
        tree_a.add('b')
        tree_a.commit('commit b')
        self.build_tree(['branch_b/c'])
        tree_b.add('c')
        tree_b.commit('commit c')
        # initial push location must be empty
        self.assertEqual(None, branch_b.get_push_location())

        # test push for failure without push location set
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
        self.assertEqual(out,
                         ('', 'brz: ERROR: No push location known or specified.\n'))

        # test not remembered if cannot actually push
        self.run_bzr('push path/which/doesnt/exist',
                     working_dir='branch_a', retcode=3)
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
        self.assertEqual(
            ('', 'brz: ERROR: No push location known or specified.\n'),
            out)

        # test implicit --remember when no push location set, push fails
        out = self.run_bzr('push ../branch_b',
                           working_dir='branch_a', retcode=3)
        self.assertEqual(out,
                         ('', 'brz: ERROR: These branches have diverged.  '
                          'See "brz help diverged-branches" for more information.\n'))
        # Refresh the branch as 'push' modified it
        branch_a = branch_a.controldir.open_branch()
        self.assertEqual(osutils.abspath(branch_a.get_push_location()),
                         osutils.abspath(branch_b.controldir.root_transport.base))

        # test implicit --remember after resolving previous failure
        uncommit.uncommit(branch=branch_b, tree=tree_b)
        transport.delete('branch_b/c')
        out, err = self.run_bzr('push', working_dir='branch_a')
        # Refresh the branch as 'push' modified it
        branch_a = branch_a.controldir.open_branch()
        path = branch_a.get_push_location()
        self.assertEqual(err,
                         'Using saved push location: %s\n'
                         'All changes applied successfully.\n'
                         'Pushed up to revision 2.\n'
                         % urlutils.local_path_from_url(path))
        self.assertEqual(path,
                         branch_b.controldir.root_transport.base)
        # test explicit --remember
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
        # Refresh the branch as 'push' modified it
        branch_a = branch_a.controldir.open_branch()
        self.assertEqual(branch_a.get_push_location(),
                         branch_c.controldir.root_transport.base)
Пример #6
0
    def test_merge_remember(self):
        """Merge changes from one branch to another, test submit location."""
        tree_a = self.make_branch_and_tree('branch_a')
        branch_a = tree_a.branch
        self.build_tree(['branch_a/a'])
        tree_a.add('a')
        tree_a.commit('commit a')
        branch_b = branch_a.controldir.sprout('branch_b').open_branch()
        tree_b = branch_b.controldir.open_workingtree()
        branch_c = branch_a.controldir.sprout('branch_c').open_branch()
        tree_c = branch_c.controldir.open_workingtree()
        self.build_tree(['branch_a/b'])
        tree_a.add('b')
        tree_a.commit('commit b')
        self.build_tree(['branch_c/c'])
        tree_c.add('c')
        tree_c.commit('commit c')
        # reset parent
        parent = branch_b.get_parent()
        branch_b.set_parent(None)
        self.assertEqual(None, branch_b.get_parent())
        # test merge for failure without parent set
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
        self.assertEqual(
            out, ('', 'brz: ERROR: No location specified or remembered\n'))

        # test uncommitted changes
        self.build_tree(['branch_b/d'])
        tree_b.add('d')
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
                           'merge',
                           working_dir='branch_b')

        # merge should now pass and implicitly remember merge location
        tree_b.commit('commit d')
        out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')

        base = urlutils.local_path_from_url(branch_a.base)
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
        # re-open branch as external run_brz modified it
        branch_b = branch_b.controldir.open_branch()
        self.assertEqual(osutils.abspath(branch_b.get_submit_branch()),
                         osutils.abspath(parent))
        # test implicit --remember when committing new file
        self.build_tree(['branch_b/e'])
        tree_b.add('e')
        tree_b.commit('commit e')
        out, err = self.run_bzr('merge', working_dir='branch_b')
        self.assertStartsWith(
            err, 'Merging from remembered submit location %s\n' % (base, ))
        # re-open tree as external run_brz modified it
        tree_b = branch_b.controldir.open_workingtree()
        tree_b.commit('merge branch_a')
        # test explicit --remember
        out, err = self.run_bzr('merge ../branch_c --remember',
                                working_dir='branch_b')
        self.assertEqual(out, '')
        self.assertEqual(err, '+N  c\nAll changes applied successfully.\n')
        # re-open branch as external run_brz modified it
        branch_b = branch_b.controldir.open_branch()
        self.assertEqual(
            osutils.abspath(branch_b.get_submit_branch()),
            osutils.abspath(branch_c.controldir.root_transport.base))
        # re-open tree as external run_brz modified it
        tree_b = branch_b.controldir.open_workingtree()
        tree_b.commit('merge branch_c')
Пример #7
0
 def test_add_symlink_to_abspath(self):
     self.requireFeature(features.SymlinkFeature(self.test_dir))
     self.make_branch_and_tree('tree')
     os.symlink(osutils.abspath('target'), 'tree/link')
     out = self.run_bzr(['add', 'tree/link'])[0]
     self.assertEqual(out, 'adding link\n')
Пример #8
0
    def __init__(self, branch, controldir, location, ui_mode = None):

        super(QBzrSwitchWindow, self).__init__(
                                  gettext("Switch"),
                                  name = "switch",
                                  default_size = (400, 400),
                                  ui_mode = ui_mode,
                                  dialog = True,
                                  parent = None,
                                  hide_progress=False,
                                  )

        self.branch = branch

        gbSwitch = QtWidgets.QGroupBox(gettext("Switch checkout"), self)

        switch_box = QtWidgets.QFormLayout(gbSwitch)

        branchbase = None

        boundloc = branch.get_bound_location()
        if boundloc is not None:
            label = gettext("Heavyweight checkout:")
            branchbase = branch.base
        else:
            if controldir.root_transport.base != branch.controldir.root_transport.base:
                label = gettext("Lightweight checkout:")
                boundloc = branch.controldir.root_transport.base
                branchbase = controldir.root_transport.base
            else:
                raise errors.BzrError("This branch is not checkout.")

        switch_box.addRow(label, QtWidgets.QLabel(url_for_display(branchbase)))
        switch_box.addRow(gettext("Checkout of branch:"),
                          QtWidgets.QLabel(url_for_display(boundloc)))
        self.boundloc = url_for_display(boundloc)

        throb_hbox = QtWidgets.QHBoxLayout()

        self.throbber = ThrobberWidget(self)
        throb_hbox.addWidget(self.throbber)
        self.throbber.hide()
        switch_box.addRow(throb_hbox)

        switch_hbox = QtWidgets.QHBoxLayout()

        branch_label = QtWidgets.QLabel(gettext("Switch to branch:"))
        branch_combo = QtWidgets.QComboBox()   
        branch_combo.setEditable(True)

        self.branch_combo = branch_combo

        if location is not None:
            branch_combo.addItem(osutils.abspath(location))
        elif boundloc is not None:
            branch_combo.addItem(url_for_display(boundloc))

        browse_button = QtWidgets.QPushButton(gettext("Browse"))
        browse_button.clicked[bool].connect(self.browse_clicked)

        switch_hbox.addWidget(branch_label)
        switch_hbox.addWidget(branch_combo)
        switch_hbox.addWidget(browse_button)

        switch_hbox.setStretchFactor(branch_label,0)
        switch_hbox.setStretchFactor(branch_combo,1)
        switch_hbox.setStretchFactor(browse_button,0)

        switch_box.addRow(switch_hbox)

        create_branch_box = QtWidgets.QCheckBox(gettext("Create Branch before switching"))
        create_branch_box.setChecked(False)
        switch_box.addRow(create_branch_box)
        self.create_branch_box = create_branch_box

        layout = QtWidgets.QVBoxLayout(self)

        layout.addWidget(gbSwitch)

        layout.addWidget(self.make_default_status_box())
        layout.addWidget(self.buttonbox)
        self.branch_combo.setFocus()