Example #1
0
    def create_tag(self):
        """Verifies inputs and emits a notifier tag message."""

        revision = self.revision.value()
        tag_name = self.tag_name.value()
        tag_msg = self.tag_msg.value()
        sign_tag = self.sign_tag.isChecked()

        if not revision:
            critical(N_('Missing Revision'),
                     N_('Please specify a revision to tag.'))
            return
        elif not tag_name:
            critical(N_('Missing Name'),
                     N_('Please specify a name for the new tag.'))
            return
        elif (sign_tag and not tag_msg and
              not qtutils.confirm(N_('Missing Tag Message'),
                                  N_('Tag-signing was requested but the tag '
                                     'message is empty.'),
                                  N_('An unsigned, lightweight tag will be '
                                     'created instead.\n'
                                     'Create an unsigned tag?'),
                                  N_('Create Unsigned Tag'),
                                  default=False,
                                  icon=qtutils.save_icon())):
            return

        cmds.do(cmds.Tag, tag_name, revision, sign=sign_tag, message=tag_msg)
        information(N_('Tag Created'),
                    N_('Created a new tag named "%s"') % tag_name,
                    details=tag_msg or None)
        self.accept()
Example #2
0
 def viz_revision(self):
     """Launch a gitk-like viewer on the selection revision"""
     revision = ustr(self.revision.text())
     if not revision:
         qtutils.information(N_("No Revision Specified"), N_("You must specify a revision to view."))
         return
     cmds.do(cmds.VisualizeRevision, revision)
Example #3
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out, err) in results:
            if status != 0:
                Interaction.critical(
                    N_('Error Creating Branch'),
                    (N_('"%(command)s" returned exit status "%(status)d"') %
                     dict(command='git ' + cmd, status=status)))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            if out:
                detail_lines.append(out)
            if err:
                detail_lines.append(err)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information(N_('Create Branch'),
                            N_('Branch created'),
                            details=details)
        self.accept()
Example #4
0
    def create_tag(self):
        """Verifies inputs and emits a notifier tag message."""

        revision = self.revision.value()
        tag_name = self.tag_name.value()
        tag_msg = self.tag_msg.value()
        sign_tag = self.sign_tag.isChecked()

        if not revision:
            critical('Missing Revision', 'Please specify a revision to tag.')
            return
        elif not tag_name:
            critical('Missing Name', 'Please specify a name for the new tag.')
            return
        elif (sign_tag and not tag_msg and
                not qtutils.confirm('Missing Tag Message',
                                    'Tag-signing was requested but the tag '
                                    'message is empty.',
                                    'An unsigned, lightweight tag will be '
                                    'created instead.\n'
                                    'Create an unsigned tag?',
                                    'Create Unsigned Tag',
                                    default=False,
                                    icon=qtutils.save_icon())):
            return

        cola.notifier().broadcast(signals.tag, tag_name, revision,
                                  sign=sign_tag, message=tag_msg)
        information('Tag Created', 'Created a new tag named "%s"' % tag_name,
                    details=tag_msg or None)
        self.accept()
Example #5
0
    def exec_(self):
        if self.expr:
            filenames = gitcmds.diff_filenames(*self.diff_arg)
        elif self.b is None:
            filenames = gitcmds.diff_index_filenames(self.a)
        else:
            filenames = gitcmds.diff_filenames(*self.diff_arg)

        if not filenames:
            details = ('"git diff --name-only %s" returned an empty list' %
                       ' '.join(self.diff_arg))
            self.hide()
            qtutils.information('git cola',
                                message='No changes to diff',
                                details=details)
            self.close()
            return self.Accepted

        icon = qtutils.file_icon()
        items = []
        for filename in filenames:
            item = QtGui.QTreeWidgetItem()
            item.setIcon(0, icon)
            item.setText(0, filename)
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
            items.append(item)
        self._tree.addTopLevelItems(items)

        return QtGui.QDialog.exec_(self)
Example #6
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out, err) in results:
            if status != 0:
                Interaction.critical(
                        N_('Error Creating Branch'),
                        (N_('"%(command)s" returned exit status "%(status)d"') %
                         dict(command='git '+cmd, status=status)))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            if out:
                detail_lines.append(out)
            if err:
                detail_lines.append(err)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information(N_('Create Branch'),
                            N_('Branch created'),
                            details=details)
        self.accept()
Example #7
0
def create_tarball(self):
    ref = self._clicked_item.commit.sha1
    dlg = GitArchiveDialog.create(ref, parent=self)
    if dlg is None:
        return
    self.emit(SIGNAL(archive), ref, dlg.fmt, dlg.prefix, dlg.filename)
    qtutils.information('File Saved', 'File saved to "%s"' % dlg.filename)
Example #8
0
    def _action_completed(self, task, status, output):
        # Grab the results of the action and finish up
        if task in self._tasks:
            self._tasks.remove(task)

        if not output: # git fetch --tags --verbose doesn't print anything...
            output = self.tr('Already up-to-date.')
        # Force the status to 1 so that we always display the log
        qtutils.log(1, output)

        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        if status != 0 and self.action == 'push':
            message = 'Error pushing to "%s".\n\nPull first?' % self.model.remotename
            qtutils.critical('Push Error',
                             message=message, details=output)
        else:
            title = self.view.windowTitle()
            if status == 0:
                result = 'succeeded'
            else:
                result = 'returned exit status %d' % status

            message = '"git %s" %s' % (self.action, result)
            qtutils.information(title,
                                message=message, details=output)
        self.view.accept()
Example #9
0
    def exec_(self):
        if self.expr:
            filenames = gitcmds.diff_filenames(*self.diff_arg)
        elif self.b is None:
            filenames = gitcmds.diff_index_filenames(self.a)
        else:
            filenames = gitcmds.diff_filenames(*self.diff_arg)

        if not filenames:
            details = ('"git diff --name-only %s" returned an empty list' %
                       ' '.join(self.diff_arg))
            self.hide()
            qtutils.information('git cola',
                                message='No changes to diff',
                                details=details)
            self.close()
            return self.Accepted

        icon = qtutils.file_icon()
        items = []
        for filename in filenames:
            item = QtGui.QTreeWidgetItem()
            item.setIcon(0, icon)
            item.setText(0, filename)
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
            items.append(item)
        self._tree.addTopLevelItems(items)

        return QtGui.QDialog.exec_(self)
Example #10
0
 def viz_revision(self):
     """Launch a gitk-like viewer on the selection revision"""
     revision = unicode(self.revision.text())
     if not revision:
         qtutils.information(N_('No Revision Specified'),
                             N_('You must specify a revision to view.'))
         return
     cmds.do(cmds.VisualizeRevision, revision)
Example #11
0
 def viz_revision(self):
     """Launch a gitk-like viewer on the selection revision"""
     revision = unicode(self.revision.text())
     if not revision:
         qtutils.information('No Revision Specified',
                             'You must specify a revision to view')
         return
     cmds.do(cmds.VisualizeRevision, revision)
Example #12
0
 def viz_revision(self):
     """Launch a gitk-like viewer on the selection revision"""
     revision = unicode(self.revision.text())
     if not revision:
         qtutils.information('No Revision Specified',
                             'You must specify a revision to view')
         return
     self.emit(SIGNAL(visualize_revision), revision)
Example #13
0
 def diff_files_doubleclick(self):
     """Shows the diff for a specific file
     """
     tree_widget = self.view.diff_files
     id_num, selected = qtutils.selected_treeitem(tree_widget)
     if not selected:
         qtutils.information('Oops!', 'Please select a file to compare')
         return
     filename = self.model.diff_files[id_num]
     self._compare_file(filename)
Example #14
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = ustr(self.revision.text())
        if not revision:
            qtutils.information(N_("No Revision Specified"), N_("You must specify a revision to merge."))
            return

        do_commit = self.checkbox_commit.isChecked()
        squash = self.checkbox_squash.isChecked()
        cmds.do(cmds.Merge, revision, not (do_commit), squash)
        self.accept()
Example #15
0
def save_bookmark():
    """
    Adds the current directory to the saved bookmarks

    In practice, the current directory is the git worktree.

    """
    model = settings.SettingsManager.settings()
    model.add_bookmark(os.getcwd())
    model.save()
    qtutils.information("Bookmark Saved")
Example #16
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = unicode(self.revision.text())
        if not revision:
            qtutils.information(N_('No Revision Specified'),
                                N_('You must specify a revision to merge.'))
            return

        do_commit = self.checkbox_commit.isChecked()
        squash = self.checkbox_squash.isChecked()
        cmds.do(cmds.Merge, revision, not (do_commit), squash)
        self.accept()
Example #17
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = unicode(self.revision.text())
        if not revision:
            qtutils.information('No Revision Specified',
                                'You must specify a revision to merge')
            return

        do_commit = self.checkbox_commit.isChecked()
        squash = self.checkbox_squash.isChecked()
        self.emit(SIGNAL(merge), revision, not(do_commit), squash)
        self.accept()
Example #18
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = unicode(self.revision.text())
        if not revision:
            qtutils.information('No Revision Specified',
                                'You must specify a revision to merge')
            return

        do_commit = self.checkbox_commit.isChecked()
        squash = self.checkbox_squash.isChecked()
        self.emit(SIGNAL(merge), revision, not (do_commit), squash)
        self.accept()
Example #19
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = ustr(self.revision.text())
        if not revision:
            qtutils.information(N_('No Revision Specified'),
                                N_('You must specify a revision to merge.'))
            return

        noff = self.checkbox_noff.isChecked()
        no_commit = not self.checkbox_commit.isChecked()
        squash = self.checkbox_squash.isChecked()
        sign = self.checkbox_sign.isChecked()
        cmds.do(cmds.Merge, revision, no_commit, squash, noff, sign)
        self.accept()
Example #20
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = ustr(self.revision.text())
        if not revision:
            qtutils.information(N_('No Revision Specified'),
                                N_('You must specify a revision to merge.'))
            return

        noff = self.checkbox_noff.isChecked()
        do_commit = self.checkbox_commit.isChecked()
        squash = self.checkbox_squash.isChecked()
        sign = self.checkbox_sign.isChecked()
        cmds.do(cmds.Merge, revision, not(do_commit), squash, noff, sign)
        self.accept()
Example #21
0
 def compare_selected_file(self):
     """Compares the currently selected file
     """
     # When a filename was provided in the constructor then we
     # simply compare that file
     if self.filename:
         self._compare_file(self.filename)
         return
     # Otherwise, use the selection to choose the compared file
     tree_widget = self.view.compare_files
     id_num, selected = qtutils.selected_treeitem(tree_widget)
     if not selected:
         qtutils.information('Oops!', 'Please select a file to compare')
         return
     filename = self.model.compare_files[id_num]
     self._compare_file(filename)
Example #22
0
    def create_tag(self):
        """Verifies inputs and emits a notifier tag message."""

        revision = self.revision.value()
        tag_name = self.tag_name.value()
        tag_msg = self.tag_msg.value()
        sign_tag = self.sign_tag.isChecked()

        if not revision:
            qtutils.critical(N_('Missing Revision'),
                             N_('Please specify a revision to tag.'))
            return
        elif not tag_name:
            qtutils.critical(N_('Missing Name'),
                             N_('Please specify a name for the new tag.'))
            return
        elif (sign_tag and not tag_msg and
              not qtutils.confirm(N_('Missing Tag Message'),
                                  N_('Tag-signing was requested but the tag '
                                     'message is empty.'),
                                  N_('An unsigned, lightweight tag will be '
                                     'created instead.\n'
                                     'Create an unsigned tag?'),
                                  N_('Create Unsigned Tag'),
                                  default=False,
                                  icon=icons.save())):
            return

        status, output, err = cmds.do(cmds.Tag,
                                      tag_name,
                                      revision,
                                      sign=sign_tag,
                                      message=tag_msg)

        if status == 0:
            qtutils.information(N_('Tag Created'),
                                N_('Created a new tag named "%s"') % tag_name,
                                details=tag_msg or None)
            self.close()
        else:
            qtutils.critical(
                N_('Error: could not create tag "%s"') % tag_name,
                (N_('git tag returned exit code %s') % status) +
                ((output + err) and ('\n\n' + output + err) or ''))
Example #23
0
    def merge_revision(self):
        """Merge the selected revision/branch"""
        revision = self.model.revision
        if not revision:
            qtutils.information('No Revision Specified',
                                'You must specify a revision to merge')
            return

        no_commit = not(self.view.checkbox_commit.isChecked())
        squash = self.view.checkbox_squash.isChecked()
        msg = gitcmds.merge_message()
        qtutils.log(*self.model.git.merge('-m'+msg,
                                         revision,
                                         strategy='recursive',
                                         no_commit=no_commit,
                                         squash=squash,
                                         with_stderr=True,
                                         with_status=True))
        self.view.accept()
Example #24
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out) in results:
            if status != 0:
                Interaction.critical(
                    'Create Branch Error',
                    '"git %s" returned exit status "%d"' % (cmd, status))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            detail_lines.append(out)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information('Create Branch', 'Branch created', details=details)
        self.accept()
Example #25
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out) in results:
            if status != 0:
                qtutils.critical('Create Branch Error',
                                 '"git %s" returned exit status "%d"' %
                                 (cmd, status))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            detail_lines.append(out)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information('Create Branch', 'Branch created',
                            details=details)
        self.accept()
Example #26
0
    def exec_(self):
        filenames = gitcmds.diff_filenames(self.diff_arg)
        if not filenames:
            details = '"git diff --name-only %s" returned an empty list' % self.diff_arg
            self.hide()
            qtutils.information("git cola", message="No changes to diff", details=details)
            self.close()
            return self.Accepted

        icon = qtutils.file_icon()
        items = []
        for filename in filenames:
            item = QtGui.QTreeWidgetItem()
            item.setIcon(0, icon)
            item.setText(0, filename)
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
            items.append(item)
        self._tree.addTopLevelItems(items)

        return QtGui.QDialog.exec_(self)
Example #27
0
    def create_tag(self):
        """Verifies inputs and emits a notifier tag message."""

        revision = self.revision.value()
        tag_name = self.tag_name.value()
        tag_msg = self.tag_msg.value()
        sign_tag = self.sign_tag.isChecked()

        if not revision:
            critical(N_('Missing Revision'),
                     N_('Please specify a revision to tag.'))
            return
        elif not tag_name:
            critical(N_('Missing Name'),
                     N_('Please specify a name for the new tag.'))
            return
        elif (sign_tag and not tag_msg and
                not qtutils.confirm(N_('Missing Tag Message'),
                                    N_('Tag-signing was requested but the tag '
                                       'message is empty.'),
                                    N_('An unsigned, lightweight tag will be '
                                       'created instead.\n'
                                       'Create an unsigned tag?'),
                                    N_('Create Unsigned Tag'),
                                    default=False,
                                    icon=qtutils.save_icon())):
            return

        status, output, err = cmds.do(cmds.Tag, tag_name, revision,
                                      sign=sign_tag, message=tag_msg)

        if status == 0:
            information(N_('Tag Created'),
                        N_('Created a new tag named "%s"') % tag_name,
                        details=tag_msg or None)
            self.accept()
        else:
            critical(N_('Error: could not create tag "%s"') % tag_name,
                    (N_('git tag returned exit code %s') % status) +
                    ((output+err) and ('\n\n' + output + err) or ''))
Example #28
0
    def stash_save(self):
        """Saves the worktree in a stash

        This prompts the user for a stash name and creates
        a git stash named accordingly.
        """
        if not qtutils.question(self.view,
                                'Stash Changes?',
                                'This will stash your current '
                                'changes away for later use.\n'
                                'Continue?'):
            return

        stash_name, ok = qtutils.prompt('Enter a name for this stash')
        if not ok:
            return
        while stash_name in self.model.stash_list:
            qtutils.information('Oops!',
                                'That name already exists.  '
                                'Please enter another name.')
            stash_name, ok = qtutils.prompt('Enter a name for this stash')
            if not ok:
                return

        if not stash_name:
            return

        # Sanitize the stash name
        stash_name = utils.sanitize(stash_name)
        args = []
        if self.model.keep_index:
            args.append('--keep-index')
        args.append(stash_name)

        qtutils.log(*self.model.git.stash('save',
                                          with_stderr=True,
                                          with_status=True,
                                          *args))
        self.view.accept()
Example #29
0
 def save(self):
     """Saves the bookmarks settings and exits"""
     self.model.save()
     qtutils.information("Bookmarks Saved")
     self.save_button.setEnabled(False)
Example #30
0
 def save(cls, ref, shortref, parent):
     dlg = cls.create(ref, shortref, parent)
     if dlg is None:
         return
     parent.emit(SIGNAL(archive), ref, dlg.fmt, dlg.prefix, dlg.filename)
     qtutils.information('File Saved', 'File saved to "%s"' % dlg.filename)
Example #31
0
 def archive_saved(self):
     cmds.do(cmds.Archive, self.ref, self.fmt, self.prefix, self.filename)
     qtutils.information(N_('File Saved'),
                         N_('File saved to "%s"') % self.filename)
Example #32
0
    def create_branch(self):
        """Creates a branch; called by the "Create Branch" button"""

        revision = self.model.revision
        branch = self.model.local_branch
        existing_branches = self.model.local_branches

        if not branch or not revision:
            qtutils.information('Missing Data',
                                'Please provide both a branch '
                                'name and revision expression.')
            return

        check_branch = False
        if branch in existing_branches:
            if self.view.no_update_radio.isChecked():
                msg = self.tr("Branch '%s' already exists.")
                msg = unicode(msg) % branch
                qtutils.information('warning', msg)
                return
            # Whether we should prompt the user for lost commits
            commits = gitcmds.rev_list_range(revision, branch)
            check_branch = bool(commits)

        if check_branch:
            msg = self.tr("Resetting '%s' to '%s' will "
                          "lose the following commits:")
            lines = [ unicode(msg) % (branch, revision) ]

            for idx, commit in enumerate(commits):
                subject = commit[1][0:min(len(commit[1]),16)]
                if len(subject) < len(commit[1]):
                    subject += '...'
                lines.append('\t' + commit[0][:8]
                        +'\t' + subject)
                if idx >= 5:
                    skip = len(commits) - 5
                    lines.append('\t(%d skipped)' % skip)
                    break

            lines.extend([
                unicode(self.tr('Recovering lost commits may not be easy.')),
                unicode(self.tr("Reset '%s'?")) % branch
                ])

            result = qtutils.question(self.view, 'warning', '\n'.join(lines))
            if not result:
                return

        # TODO handle fetch
        track = self.view.remote_radio.isChecked()
        fetch = self.view.fetch_checkbox.isChecked()
        ffwd = self.view.ffwd_only_radio.isChecked()
        reset = self.view.reset_radio.isChecked()
        chkout = self.view.checkout_checkbox.isChecked()

        status, output = self.model.create_branch(branch, revision, track=track)
        qtutils.log(status, output)
        if status == 0 and chkout:
            status, output = self.model.git.checkout(branch,
                                                     with_status=True,
                                                     with_stderr=True)
            qtutils.log(status, output)
        self.view.accept()
Example #33
0
 def archive_saved(self):
     self.emit(SIGNAL(archive),
               self.ref, self.fmt, self.prefix, self.filename)
     qtutils.information('File Saved', 'File saved to "%s"' %
                         self.filename)
Example #34
0
 def archive_saved(self):
     cmds.do(cmds.Archive, self.ref, self.fmt, self.prefix, self.filename)
     qtutils.information(N_('File Saved'),
                         N_('File saved to "%s"') % self.filename)
Example #35
0
 def archive_saved(self):
     self.emit(SIGNAL(archive), self.ref, self.fmt, self.prefix,
               self.filename)
     qtutils.information('File Saved', 'File saved to "%s"' % self.filename)
Example #36
0
 def save(self):
     """Saves the bookmarks settings and exits"""
     self.model.save()
     qtutils.information("Bookmarks Saved")
     self.save_button.setEnabled(False)