Exemplo n.º 1
0
def diff_expression():
    """Diff using an arbitrary expression."""
    tracked = gitcmds.tracked_branch()
    current = gitcmds.current_branch()
    if tracked and current:
        ref = tracked + '..' + current
    else:
        ref = 'origin/master..'
    difftool.diff_expression(qtutils.active_window(), ref)
Exemplo n.º 2
0
def diff_expression():
    """Diff using an arbitrary expression."""
    tracked = gitcmds.tracked_branch()
    current = gitcmds.current_branch()
    if tracked and current:
        default = tracked + '..' + current
    else:
        default = 'origin/master..'
    ref = choose_ref('Enter Diff Expression', 'Diff', default=default)
    if not ref:
        return
    difftool.diff_expression(qtutils.active_window(), ref)
Exemplo n.º 3
0
def diff_expression():
    """Diff using an arbitrary expression."""
    tracked = gitcmds.tracked_branch()
    current = gitcmds.current_branch()
    if tracked and current:
        default = tracked + '..' + current
    else:
        default = 'origin/master..'
    ref = choose_ref('Enter Diff Expression', 'Diff',
                     default=default)
    if not ref:
        return
    difftool.diff_expression(qtutils.active_window(), ref)
Exemplo n.º 4
0
def select_file_from_repo():
    """Launch a dialog for selecting a filename from a branch."""
    # Clone the model to allow opening multiple browsers
    # with different sets of data
    model = browser.BrowserModel(gitcmds.current_branch())
    parent = QtGui.QApplication.instance().activeWindow()
    view = SelectCommitsView(parent, syntax=False)
    controller = RepoBrowserController(model, view,
                                       title='Select File',
                                       get_file=True)
    view.show()
    if view.exec_() == QtGui.QDialog.Accepted:
        return controller.filename
    else:
        return None
Exemplo n.º 5
0
    def remote_ref(self, branch):
        """Returns the remote ref for 'git diff [local] [remote]'
        """
        if branch == self.BRANCH_POINT:
            # Compare against the branch point so find the merge-base
            branch = gitcmds.current_branch()
            tracked_branch = gitcmds.tracked_branch()
            if tracked_branch:
                return gitcmds.merge_base(branch, tracked_branch)
            else:
                remote_branches = gitcmds.branch_list(remote=True)
                remote_branch = 'origin/%s' % branch
                if remote_branch in remote_branches:
                    return gitcmds.merge_base(branch, remote_branch)

                elif 'origin/master' in remote_branches:
                    return gitcmds.merge_base(branch, 'origin/master')
                else:
                    return 'HEAD'
        else:
            # Compare against the remote branch
            return branch
Exemplo n.º 6
0
    def remote_ref(self, branch):
        """Returns the remote ref for 'git diff [local] [remote]'
        """
        if branch == self.BRANCH_POINT:
            # Compare against the branch point so find the merge-base
            branch = gitcmds.current_branch()
            tracked_branch = gitcmds.tracked_branch()
            if tracked_branch:
                return gitcmds.merge_base(branch, tracked_branch)
            else:
                remote_branches = gitcmds.branch_list(remote=True)
                remote_branch = 'origin/%s' % branch
                if remote_branch in remote_branches:
                    return gitcmds.merge_base(branch, remote_branch)

                elif 'origin/master' in remote_branches:
                    return gitcmds.merge_base(branch, 'origin/master')
                else:
                    return 'HEAD'
        else:
            # Compare against the remote branch
            return branch
Exemplo n.º 7
0
    def update_status(self):
        # Give observers a chance to respond
        self.notify_message_observers(self.message_about_to_update)
        # This allows us to defer notification until the
        # we finish processing data
        staged_only = self.read_only()
        head = self.head
        notify_enabled = self.notification_enabled
        self.notification_enabled = False

        # Set these early since they are used to calculate 'upstream_changed'.
        self.set_trackedbranch(gitcmds.tracked_branch())
        self.set_currentbranch(gitcmds.current_branch())

        (self.staged,
         self.modified,
         self.unmerged,
         self.untracked,
         self.upstream_changed) = gitcmds.worktree_state(head=head,
                                                staged_only=staged_only)
        # NOTE: the model's unstaged list holds an aggregate of the
        # the modified, unmerged, and untracked file lists.
        self.set_unstaged(self.modified + self.unmerged + self.untracked)
        self.set_remotes(self.git.remote().splitlines())

        local_branches, remote_branches, tags = gitcmds.all_refs(split=True)
        self.set_local_branches(local_branches)
        self.set_remote_branches(remote_branches)
        self.set_tags(tags)

        self.set_revision('')
        self.set_local_branch('')
        self.set_remote_branch('')
        # Re-enable notifications and emit changes
        self.notification_enabled = notify_enabled

        self.read_font_sizes()
        self.notify_observers('staged', 'unstaged')
        self.notify_message_observers(self.message_updated)
Exemplo n.º 8
0
def browse_current():
    """Launch the 'Browse Current Branch' dialog."""
    branch = gitcmds.current_branch()
    BrowseDialog.browse(branch)
Exemplo n.º 9
0
 def test_currentbranch(self):
     """Test current_branch()."""
     self.assertEqual(gitcmds.current_branch(), 'master')
Exemplo n.º 10
0
def test_currentbranch(app_context):
    """Test current_branch()."""
    assert gitcmds.current_branch(app_context) == 'main'
Exemplo n.º 11
0
 def test_currentbranch(self):
     """Test current_branch()."""
     self.assertEqual(gitcmds.current_branch(), 'master')
Exemplo n.º 12
0
 def _update_branch_heads(self):
     # Set these early since they are used to calculate 'upstream_changed'.
     self.currentbranch = gitcmds.current_branch()
Exemplo n.º 13
0
def browse_current():
    """Launch the 'Browse Current Branch' dialog."""
    from cola.controllers.repobrowser import browse_git_branch

    browse_git_branch(gitcmds.current_branch())
Exemplo n.º 14
0
 def browse_current(self):
     """Launch the 'Browse Current Branch' dialog."""
     browse_git_branch(gitcmds.current_branch())
Exemplo n.º 15
0
    def __init__(self, model, parent=None):
        Dialog.__init__(self, parent=parent)
        self.setAttribute(Qt.WA_MacMetalStyle)
        self.setWindowTitle(N_('Create Branch'))
        if parent is not None:
            self.setWindowModality(Qt.WindowModal)

        self.model = model
        self.opts = CreateOpts(model)
        self.thread = CreateThread(self.opts, self)

        self.progress = QtGui.QProgressDialog(self)
        self.progress.setRange(0, 0)
        self.progress.setCancelButton(None)
        self.progress.setWindowTitle(N_('Create Branch'))
        self.progress.setWindowModality(Qt.WindowModal)

        self.branch_name_label = QtGui.QLabel()
        self.branch_name_label.setText(N_('Branch Name'))

        self.branch_name = QtGui.QLineEdit()

        self.rev_label = QtGui.QLabel()
        self.rev_label.setText(N_('Starting Revision'))

        self.revision = completion.GitRefLineEdit()
        current = gitcmds.current_branch()
        if current:
            self.revision.setText(current)

        self.local_radio = QtGui.QRadioButton()
        self.local_radio.setText(N_('Local branch'))
        self.local_radio.setChecked(True)

        self.remote_radio = QtGui.QRadioButton()
        self.remote_radio.setText(N_('Tracking branch'))

        self.tag_radio = QtGui.QRadioButton()
        self.tag_radio.setText(N_('Tag'))

        self.branch_list = QtGui.QListWidget()

        self.update_existing_label = QtGui.QLabel()
        self.update_existing_label.setText(N_('Update Existing Branch:'))

        self.no_update_radio = QtGui.QRadioButton()
        self.no_update_radio.setText(N_('No'))

        self.ffwd_only_radio = QtGui.QRadioButton()
        self.ffwd_only_radio.setText(N_('Fast Forward Only'))
        self.ffwd_only_radio.setChecked(True)

        self.reset_radio = QtGui.QRadioButton()
        self.reset_radio.setText(N_('Reset'))

        self.fetch_checkbox = QtGui.QCheckBox()
        self.fetch_checkbox.setText(N_('Fetch Tracking Branch'))
        self.fetch_checkbox.setChecked(True)

        self.checkout_checkbox = QtGui.QCheckBox()
        self.checkout_checkbox.setText(N_('Checkout After Creation'))
        self.checkout_checkbox.setChecked(True)

        self.create_button = qtutils.create_button(text=N_('Create Branch'),
                                                   icon=qtutils.git_icon())
        self.create_button.setDefault(True)

        self.close_button = qtutils.create_button(text=N_('Close'))

        self.rev_start_group = QtGui.QGroupBox()
        self.rev_start_group.setTitle(N_('Starting Revision'))

        self.option_group = QtGui.QGroupBox()
        self.option_group.setTitle(N_('Options'))

        self.options_checkbox_layout = qtutils.vbox(defs.margin, defs.spacing,
                                                    self.fetch_checkbox,
                                                    self.checkout_checkbox)

        self.options_bottom_layout = qtutils.hbox(defs.margin, defs.spacing,
                                                  self.options_checkbox_layout,
                                                  qtutils.STRETCH)

        self.branch_name_layout = qtutils.hbox(defs.margin, defs.spacing,
                                               self.branch_name_label,
                                               self.branch_name)

        self.rev_start_radiobtn_layout = qtutils.hbox(defs.margin, defs.spacing,
                                                      self.local_radio,
                                                      self.remote_radio,
                                                      self.tag_radio,
                                                      qtutils.STRETCH)

        self.rev_start_textinput_layout = qtutils.hbox(defs.no_margin, defs.spacing,
                                                       self.rev_label,
                                                       self.revision)

        self.rev_start_layout = qtutils.vbox(defs.no_margin, defs.spacing,
                                             self.rev_start_radiobtn_layout,
                                             self.branch_list,
                                             self.rev_start_textinput_layout)
        self.rev_start_group.setLayout(self.rev_start_layout)

        self.options_radio_layout = qtutils.hbox(defs.no_margin, defs.spacing,
                                                 self.update_existing_label,
                                                 self.no_update_radio,
                                                 self.ffwd_only_radio,
                                                 self.reset_radio)

        self.options_grp_layout = qtutils.vbox(defs.no_margin, defs.spacing,
                                               self.options_radio_layout,
                                               self.options_bottom_layout)
        self.option_group.setLayout(self.options_grp_layout)

        self.buttons_layout = qtutils.hbox(defs.margin, defs.spacing,
                                           self.create_button,
                                           self.close_button)

        self.options_section_layout = qtutils.hbox(defs.no_margin, defs.spacing,
                                                   self.option_group,
                                                   self.buttons_layout)

        self.main_layout = qtutils.vbox(defs.margin, defs.spacing,
                                        self.branch_name_layout,
                                        self.rev_start_group,
                                        self.options_section_layout)
        self.setLayout(self.main_layout)

        qtutils.connect_button(self.close_button, self.reject)
        qtutils.connect_button(self.create_button, self.create_branch)
        qtutils.connect_button(self.local_radio, self.display_model)
        qtutils.connect_button(self.remote_radio, self.display_model)
        qtutils.connect_button(self.tag_radio, self.display_model)

        self.connect(self.branch_list, SIGNAL('itemSelectionChanged()'),
                     self.branch_item_changed)

        self.connect(self.thread, SIGNAL(COMMAND_SIGNAL),
                     self.thread_command, Qt.QueuedConnection)

        self.connect(self.thread, SIGNAL('done(PyQt_PyObject)'),
                     self.thread_done, Qt.QueuedConnection)

        self.resize(555, 333)
        self.display_model()
Exemplo n.º 16
0
 def _update_branch_heads(self):
     # Set these early since they are used to calculate 'upstream_changed'.
     self.currentbranch = gitcmds.current_branch()
Exemplo n.º 17
0
 def test_currentbranch(self):
     """Test current_branch()."""
     self.assertEqual(gitcmds.current_branch(self.context), 'main')