示例#1
0
    def test_cd_dir_and_back_home(self):
        self.assertEqual(self.test_dir, osutils.getcwd())
        self.run_script("""
$ mkdir dir
$ cd dir
""")
        self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
                         osutils.getcwd())

        self.run_script('$ cd')
        self.assertEqual(self.test_dir, osutils.getcwd())
示例#2
0
    def test_pull(self):
        # Make sure we can pull from paths that can't be encoded
        dirname1 = self.info['directory']
        dirname2 = self.info['directory'] + '2'
        url1 = urlutils.local_path_to_url(dirname1)
        url2 = urlutils.local_path_to_url(dirname2)
        out_bzrdir = self.wt.controldir.sprout(url1)
        out_bzrdir.sprout(url2)

        self.build_tree_contents([(osutils.pathjoin(dirname1, "a"),
                                   b'different text\n')])
        self.wt.commit('mod a')

        txt = self.run_bzr_decode('pull', working_dir=dirname2)

        expected = osutils.pathjoin(osutils.getcwd(), dirname1)
        self.assertEqual(
            u'Using saved parent location: %s/\n'
            'No revisions or tags to pull.\n' % (expected, ), txt)

        self.build_tree_contents([(osutils.pathjoin(dirname1,
                                                    'a'), b'and yet more\n')])
        self.wt.commit(u'modifying a by ' + self.info['committer'])

        # We should be able to pull, even if our encoding is bad
        self.run_bzr_decode('pull --verbose',
                            encoding='ascii',
                            working_dir=dirname2)
示例#3
0
    def open_containing(location=None,
                        require_tree=False,
                        ui_mode=False,
                        _critical_dialog=QtWidgets.QMessageBox.critical):
        """Open the branch and tree at location (or in current directory).

        @return: initialized TreeBranch if opened successfully,
            None if branch or tree not found.

        @param location: URL or local path, if None then current working
            directory will be used.
        @param require_tree: if True then NoWorkingTree error will be
            raised if there is no working tree found. Otherwise it's
            acceptable to open only branch object.
        @param ui_mode: if True show errors in the GUI error dialogs;
            otherwise propagate the error up the stack.
        @param _critical_dialog: hook for testing.
        """
        if location is None:
            location = osutils.getcwd()
        try:
            (tree, branch, relpath
             ) = controldir.ControlDir.open_containing_tree_or_branch(location)

            if require_tree and tree is None:
                raise errors.NoWorkingTree(location)
        except (errors.NotBranchError, errors.NoWorkingTree) as e:
            if not ui_mode:
                raise
            TreeBranch._report_error(location, e, _critical_dialog)
            return None
        return TreeBranch(location, tree, branch, relpath)
示例#4
0
    def test_get_invalid_parent(self):
        b = self.make_branch('.')

        cwd = getcwd()
        n_dirs = len(cwd.split('/'))

        # Force the relative path to be something invalid
        # This should attempt to go outside the filesystem
        path = ('../' * (n_dirs + 5)) + 'foo'
        b.lock_write()
        b._set_parent_location(path)
        b.unlock()

        # With an invalid branch parent, just return None
        self.assertRaises(breezy.errors.InaccessibleParent, b.get_parent)
示例#5
0
    def test_init_at_repository_root(self):
        # brz init at the root of a repository should create a branch
        # and working tree even when creation of working trees is disabled.
        t = self.get_transport()
        t.mkdir('repo')
        format = BzrDirMetaFormat1()
        newdir = format.initialize(t.abspath('repo'))
        repo = newdir.create_repository(shared=True)
        repo.set_make_working_trees(False)
        out, err = self.run_bzr('init repo')
        self.assertEqual(
            """Created a repository tree (format: %s)
Using shared repository: %s
""" % (self._default_label,
        urlutils.local_path_from_url(
           repo.controldir.root_transport.external_url())), out)
        cwd = osutils.getcwd()
        self.assertEndsWith(out, cwd + '/repo/\n')
        self.assertEqual('', err)
        newdir.open_branch()
        newdir.open_workingtree()
示例#6
0
 def do_start(self):
     if self.tree:
         dest = self.tree.basedir
     else:
         dest = self.branch.base
     args = []
     if dest != osutils.getcwd():
         args.extend(('--directory', dest))
     if self.ui.overwrite.isChecked():
         args.append('--overwrite')
     if self.ui.remember.isChecked():
         args.append('--remember')
     revision = str(self.ui.revision.text())
     if revision:
         args.append('--revision')
         args.append(revision)
     location = str(self.ui.location.currentText())
     if location and location != self.default_location:
         args.insert(0, location)
     self.process_widget.do_start(None, 'pull', *args)
     save_pull_location(self.branch, location)
示例#7
0
    def test_missing_check_last_location(self):
        # check that last location shown as filepath not file URL

        # create a source branch
        wt = self.make_branch_and_tree('a')
        b = wt.branch
        self.build_tree(['a/foo'])
        wt.add('foo')
        wt.commit('initial')

        location = osutils.getcwd() + '/a/'

        # clone
        b.controldir.sprout('b')

        # check last location
        lines, err = self.run_bzr('missing', working_dir='b')
        self.assertEqual(
            'Using saved parent location: %s\n'
            'Branches are up to date.\n' % location, lines)
        self.assertEqual('', err)
示例#8
0
 def do_start(self):
     if self.tree:
         dest = self.tree.basedir
     else:
         dest = self.branch.base
     args = []
     if dest != osutils.getcwd():
         args.extend(('--directory', dest))
     if self.ui.overwrite.isChecked():
         args.append('--overwrite')
     if self.ui.remember.isChecked():
         args.append('--remember')
     if self.ui.create_prefix.isChecked():
         args.append('--create-prefix')
     if self.ui.use_existing_dir.isChecked():
         args.append('--use-existing-dir')
     if 'strict' in get_cmd_object('push').options() and self._no_strict:
         # force --no-strict because we checking blocking conditions
         # in validate method (see below).
         args.append('--no-strict')
     location = str(self.ui.location.currentText())
     if location and location != self.default_location:
         args.insert(0, location)
     self.process_widget.do_start(None, 'push', *args)
示例#9
0
 def friendly_location(url):
     path = urlutils.unescape_for_display(url, 'ascii')
     try:
         return osutils.relpath(osutils.getcwd(), path)
     except errors.PathNotChild:
         return path
示例#10
0
    def __init__(self,
                 command=None,
                 parameters=None,
                 workdir=None,
                 category=None,
                 ui_mode=False,
                 parent=None,
                 execute=False):
        """Build dialog.

        @param command: initial command selection.
        @param parameters: initial options and arguments (string) for command.
        @param workdir: working directory to run command.
        @param category: initial category selection.
        @param ui_mode: wait after the operation is complete.
        @param parent:  parent window.
        @param execute: True => run command immediately
        """
        super(QBzrRunDialog, self).__init__(name="run",
                                            ui_mode=ui_mode,
                                            dialog=True,
                                            parent=parent)
        self.ui = Ui_RunDialog()
        self.ui.setupUi(self)
        if workdir is None:
            workdir = osutils.getcwd()
        self.ui.wd_edit.setText(workdir)
        # set help_browser with some default text
        self.set_default_help()
        # cmd_combobox should fill all available space
        self.ui.cmd_layout.setColumnStretch(1, 1)
        self.ui.cmd_layout.setColumnStretch(2, 1)
        # fill cmd_combobox with available commands
        self.collect_command_names()
        # RJL in python 2 we could do this quite happily, even if a key were None
        #
        #   categories = sorted(self.all_cmds.keys())
        #
        # Python3 spits a TypeError at you, though, so convert None to ''
        categories = sorted(self.all_cmds,
                            key=lambda k: '' if k is None else k)
        self.ui.cat_combobox.insertItems(0, categories)
        self.set_cmd_combobox(cmd_name=command)
        # add the parameters, if any
        if parameters:
            self.ui.opt_arg_edit.setText(parameters)

        # and add the subprocess widgets
        for w in self.make_default_layout_widgets():
            self.ui.subprocess_container_layout.addWidget(w)
        self.process_widget.hide_progress()

        # restore the sizes
        self.restoreSize("run", None)
        self.splitter = self.ui.splitter
        self.restoreSplitterSizes()
        # setup signals
        self.ui.hidden_checkbox.stateChanged[int].connect(self.set_show_hidden)
        self.ui.cmd_combobox.currentIndexChanged['QString'].connect(
            self.set_cmd_help)
        self.ui.cmd_combobox.editTextChanged['QString'].connect(
            self.set_cmd_help)
        self.ui.cat_combobox.currentIndexChanged['QString'].connect(
            self.set_category)
        hookup_directory_picker(self, self.ui.browse_button, self.ui.wd_edit,
                                gettext("Select working directory"))
        self.ui.directory_button.clicked.connect(self.insert_directory)
        self.ui.filenames_button.clicked.connect(self.insert_filenames)
        # Init the category if set.
        # (This needs to be done after the signals are hooked up)
        if category:
            cb = self.ui.cat_combobox
            index = cb.findText(category)
            if index >= 0:
                cb.setCurrentIndex(index)
        # ready to go
        if execute:
            # hide user edit fields
            self.ui.run_container.hide()
            self.ui.help_browser.hide()

            # create edit button
            self.editButton = QtWidgets.QPushButton(gettext('&Edit'))
            self.editButton.clicked.connect(self.enable_command_edit)

            # cause edit button to be shown if command fails
            self.subprocessFailed[bool].connect(self.editButton.setHidden)

            # add edit button to dialog buttons
            self.buttonbox.addButton(self.editButton,
                                     QtWidgets.QDialogButtonBox.ResetRole)

            # setup initial dialog button status
            self.closeButton.setHidden(True)
            self.okButton.setHidden(True)
            self.editButton.setHidden(True)

            # cancel button gets hidden when finished.
            self.subprocessFinished[bool].connect(self.cancelButton.setHidden)

            # run command
            self.do_start()
        else:
            if command:
                self.ui.opt_arg_edit.setFocus()
            else:
                self.ui.cmd_combobox.setFocus()