Esempio n. 1
0
    def set_test_values(cls):
        """
            This will set the global branches, wallace_branch_name,
            wallace_branch_commits, TEST_wallace_branch_model,
            TEST_master_branch_model.
        """
        dummy_model = QGitModel(cls.TEST_dir)

        branches = dummy_model.get_branches()
        cls.TEST_master_branch = [branch for branch in branches
                                   if branch.name == 'master'][0]
        master_model = cls.TEST_master_branch_model = QGitModel(cls.TEST_dir)
        master_model.set_current_branch(cls.TEST_master_branch)
        master_model.populate()

        cls.TEST_wallace_branch = [branch for branch in branches
                               if branch.name == 'wallace_branch'][0]
        wallace_model = cls.TEST_wallace_branch_model = QGitModel(cls.TEST_dir)
        wallace_model.set_current_branch(cls.TEST_wallace_branch)
        wallace_model.populate()

        cls.run_command("git checkout master")
        cls.TEST_master_branch_commits = cls.read_commits_from_log()

        cls.run_command("git checkout wallace_branch")
        cls.TEST_wallace_branch_commits = cls.read_commits_from_log()

        stdout, stderr = cls.run_command("git branch")
        cls.TEST_branches = []
        for line in stdout:
            branch_name = line.split(' ')[-1].strip()
            if line[0] == '*':
                cls.TEST_current_branch_name = branch_name
            cls.TEST_branches.append(branch_name)
Esempio n. 2
0
    def set_current_directory(self, directory, reset_all=False):
        """
            Sets the current directory.

            :param directory:
                The git directory.
        """
        self._models = {}
        a_model = QGitModel(directory)
        self.current_branch = a_model.get_current_branch()

        for branch in a_model.get_branches():
            model = QEditableGitModel(self._models, directory=directory,
                                      parent=self)
            model.set_current_branch(branch)
            model.setMerge(False)
            model.enable_option("filters")
            model.populate()
            self._models[branch] = model

            QObject.connect(model, SIGNAL("newHistoryEvent"),
                            self.new_history_event)

        if reset_all:
            self.rebase_main_class.reset_interface(self._models)
            self.filter_main_class.reset_interface(self._models)
 def test_set_branch_twice_fails(self):
     fails = False
     dummy_model = QGitModel(self.TEST_dir)
     dummy_model.set_current_branch(self.TEST_wallace_branch)
     try:
         dummy_model.set_current_branch(self.TEST_master_branch)
     except GfbiException, err:
         fails = True
 def name_to_display(self):
     """
         Returns the name that should be displayed for this model.
         It can be the name of the current branch, the name of the remote
         reference, or the new branch name.
     """
     return self.get_new_branch_name() or QGitModel.name_to_display(self)
    def test_filter_message(self):
        dummy_model = QGitModel(self.TEST_dir)
        dummy_model.set_current_branch(self.TEST_master_branch)
        dummy_model.populate()
        message = "rodney"
        dummy_model.filter_set("message", QRegExp(message))

        error = "On the master branch model, wrong message filter score for %d:%d"
        message_column = dummy_model.get_columns().index('message')
        for row, commit in enumerate(self.TEST_master_branch_commits):
            index = dummy_model.createIndex(row, message_column)
            score = dummy_model.filter_score(index)

            if message in commit[1]:
                self.check(score, 1, error % (row, message_column))
            else:
                self.check(score, 0, error % (row, message_column))
    def __init__(self, models_dict, directory=".", fake_branch_name="",
                 from_model_row=None, parent=None):
        """
            Initializes the git model with the repository root directory.

            :param directory:
                Root directory of the git repository.

            Non editable QGitModel can be initialized with a GitModel(to limit
            the number of GitModels).
        """
        QGitModel.__init__(self,
                           directory=directory,
                           fake_branch_name=fake_branch_name,
                           parent=parent)

        if from_model_row:
            from_model, from_row = from_model_row
            git_model = from_model.get_orig_git_model()
            from_commits = git_model.get_commits()[from_row:]
        else:
            from_commits = False

        # Overwrite the non editable git_model set in QGitModel.__init__
        self.git_model = EditableGitModel(directory=directory,
                                          fake_branch_name=fake_branch_name,
                                          from_commits=from_commits)

        self._enabled_options = []
        self._all_models_dict = models_dict

        # The following is used to store the write options
        self._previous_log_option = True
        self._previous_force_option = False

        if not fake_branch_name:
            # If this is not a fake model
            self.orig_q_git_model = QGitModel(self,
                                        parent=parent,
                                        model=self.git_model.get_orig_model())
        else:
            self.orig_q_git_model = None
    def flags(self, index):
        """
            Returns the flags for the given index.
        """
        if not index.isValid():
            return Qt.ItemFlags(QAbstractTableModel.flags(self, index) |
                                Qt.ItemIsDropEnabled |
                                Qt.NoItemFlags)

        column = index.column()
        field_name = self.git_model.get_columns()[column]

        # Neither first commits nor deleted commits can be edited.
        if field_name not in NOT_EDITABLE_FIELDS and \
           not self.is_first_commit(index) and\
           not self.is_deleted(index):
            return Qt.ItemFlags(QGitModel.flags(self, index) |
                                Qt.ItemIsEditable)

        return QGitModel.flags(self, index)
    def data(self, index, role):
        """
            Returns the data of the model.
        """
        if not index.isValid() or not (0 <= index.row() < self.rowCount()):
            return QVariant()

        if role == Qt.FontRole:
            return self._data_font(index)
        else:
            return QGitModel.data(self, index, role)
    def _data_background(self, index, field_name):
        """
            Returns a yellow background that should be displayed for the given
            index if the index is modified, or calls the QGitModel method
            instead.
        """
        commits = self.git_model.get_commits()
        commit = commits[index.row()]
        conflicting_commit = self.git_model.get_conflicting_commit()

        modifications = self.git_model.get_modifications()
        if conflicting_commit is not None and commit == conflicting_commit:
            return QVariant(QColor(Qt.red))
        elif self.git_model.is_modified(index) or self.is_fake_model():
            return QVariant(QColor(Qt.yellow))

        return QGitModel._data_background(self, index, field_name)
 def populate(self):
     """
         This populates the model.
         We may want to build orig_q_git_model too.
     """
     QGitModel.populate(self)
Esempio n. 11
0
 def test_default_branch(self):
     error = "The default branch should be the current branch of the repository."
     dummy_model = QGitModel(self.TEST_dir)
     default_branch_name = dummy_model.get_current_branch().name
     self.check(self.TEST_current_branch_name, default_branch_name, error)
Esempio n. 12
0
    def test_filter_author(self):
        dummy_model = QGitModel(self.TEST_dir)
        dummy_model.set_current_branch(self.TEST_wallace_branch)
        dummy_model.populate()
        author = "Wallace"
        author_email = "-wallace"

        error = "On the wallace branch model, wrong author_name filter score for %d:%d"
        error_email = "On the wallace branch model, wrong author_email filter score for %d:%d"
        author_name_column = dummy_model.get_columns().index('author_name')
        author_email_column = dummy_model.get_columns().index('author_email')
        for row, commit in enumerate(self.TEST_wallace_branch_commits):
            dummy_model.filter_set("nameEmail", QRegExp(author))
            index = dummy_model.createIndex(row, author_name_column)
            score = dummy_model.filter_score(index)

            dummy_model.filter_set("nameEmail", QRegExp(author_email))
            index_email = dummy_model.createIndex(row, author_email_column)
            score_email = dummy_model.filter_score(index_email)

            if row != dummy_model.rowCount() - 1:
                self.check(score, 1, error % (row, author_name_column))
                self.check(score_email, 1,
                           error_email % (row, author_email_column))
            else:
                self.check(score, 0, error % (row, author_name_column))
                self.check(score_email, 0,
                           error_email % (row, author_email_column))