Exemple #1
0
    def do(self):
        log_msg = 'Tagging: "%s" as "%s"' % (self._revision, self._name)
        opts = {}
        if self._message:
            opts['F'] = utils.tmp_filename('tag-message')
            utils.write(opts['F'], self._message)

        if self._sign:
            log_msg += ', GPG-signed'
            opts['s'] = True
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        else:
            opts['a'] = bool(self._message)
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        if 'F' in opts:
            os.unlink(opts['F'])

        if output:
            log_msg += '\nOutput:\n%s' % output

        Interaction.log_status(status, log_msg, '')
        if status == 0:
            self.model.update_status()
Exemple #2
0
    def do(self):
        log_msg = 'Tagging: "%s" as "%s"' % (self._revision, self._name)
        opts = {}
        if self._message:
            opts['F'] = self.model.tmp_filename()
            utils.write(opts['F'], self._message)

        if self._sign:
            log_msg += ', GPG-signed'
            opts['s'] = True
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        else:
            opts['a'] = bool(self._message)
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        if 'F' in opts:
            os.unlink(opts['F'])

        if output:
            log_msg += '\nOutput:\n%s' % output

        _notifier.broadcast(signals.log_cmd, status, log_msg)
        if status == 0:
            self.model.update_status()
Exemple #3
0
    def do(self):
        log_msg = (N_('Tagging "%(revision)s" as "%(name)s"') %
                   dict(revision=self._revision, name=self._name))
        opts = {}
        if self._message:
            opts['F'] = utils.tmp_filename('tag-message')
            utils.write(opts['F'], self._message)

        if self._sign:
            log_msg += ' (%s)' % N_('GPG-signed')
            opts['s'] = True
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        else:
            opts['a'] = bool(self._message)
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        if 'F' in opts:
            os.unlink(opts['F'])

        if output:
            log_msg += '\n' + N_('Output: %s') % output

        Interaction.log_status(status, log_msg, '')
        if status == 0:
            self.model.update_status()
Exemple #4
0
    def process_diff_selection(self,
                               selected,
                               offset,
                               selection,
                               apply_to_worktree=False):
        """Processes a diff selection and applies changes to git."""
        if selection:
            # qt destroys \r\n and makes it \n with no way of going back.
            # boo!  we work around that here.
            # I think this was win32-specific.  We might want to do
            # this on win32 only (TODO verify)
            if selection not in self.fwd_diff:
                special_selection = selection.replace('\n', '\r\n')
                if special_selection in self.fwd_diff:
                    selection = special_selection
                else:
                    return 0, ''
            start = self.fwd_diff.index(selection)
            end = start + len(selection)
            self.set_diffs_to_range(start, end)
        else:
            self.set_diff_to_offset(offset)
            selected = False

        output = ''
        status = 0
        # Process diff selection only
        if selected:
            encoding = self.config.file_encoding(self.filename)
            for idx in self.selected:
                contents = self.diff_subset(idx, start, end)
                if not contents:
                    continue
                tmpfile = utils.tmp_filename('selection')
                utils.write(tmpfile, contents, encoding=encoding)
                if apply_to_worktree:
                    stat, out = self.model.apply_diff_to_worktree(tmpfile)
                    output += out
                    status = max(status, stat)
                else:
                    stat, out = self.model.apply_diff(tmpfile)
                    output += out
                    status = max(status, stat)
                os.unlink(tmpfile)
        # Process a complete hunk
        else:
            for idx, diff in enumerate(self.diff_sel):
                tmpfile = utils.tmp_filename('patch%02d' % idx)
                if not self.write_diff(tmpfile, idx):
                    continue
                if apply_to_worktree:
                    stat, out = self.model.apply_diff_to_worktree(tmpfile)
                    output += out
                    status = max(status, stat)
                else:
                    stat, out = self.model.apply_diff(tmpfile)
                    output += out
                    status = max(status, stat)
                os.unlink(tmpfile)
        return status, output
Exemple #5
0
    def do(self):
        log_msg = 'Tagging: "%s" as "%s"' % (self._revision, self._name)
        opts = {}
        if self._message:
            opts['F'] = utils.tmp_filename('tag-message')
            utils.write(opts['F'], self._message)

        if self._sign:
            log_msg += ', GPG-signed'
            opts['s'] = True
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        else:
            opts['a'] = bool(self._message)
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        if 'F' in opts:
            os.unlink(opts['F'])

        if output:
            log_msg += '\nOutput:\n%s' % output

        _notifier.broadcast(signals.log_cmd, status, log_msg)
        if status == 0:
            self.model.update_status()
Exemple #6
0
    def do(self):
        log_msg = (N_('Tagging "%(revision)s" as "%(name)s"') %
                   dict(revision=self._revision, name=self._name))
        opts = {}
        if self._message:
            opts['F'] = utils.tmp_filename('tag-message')
            utils.write(opts['F'], self._message)

        if self._sign:
            log_msg += ' (%s)' % N_('GPG-signed')
            opts['s'] = True
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        else:
            opts['a'] = bool(self._message)
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True,
                                                **opts)
        if 'F' in opts:
            os.unlink(opts['F'])

        if output:
            log_msg += '\n' + N_('Output: %s') % output

        Interaction.log_status(status, log_msg, '')
        if status == 0:
            self.model.update_status()
Exemple #7
0
 def write_diff(self, filename, which, selected=False, noop=False):
     """Writes a new diff corresponding to the user's selection."""
     if not noop and which < len(self.diffs):
         diff = self.diffs[which]
         utils.write(filename, self.header + "\n" + diff + "\n")
         return True
     else:
         return False
Exemple #8
0
    def process_diff_selection(self, selected, offset, selection,
                               apply_to_worktree=False):
        """Processes a diff selection and applies changes to git."""
        if selection:
            # qt destroys \r\n and makes it \n with no way of going back.
            # boo!  we work around that here.
            # I think this was win32-specific.  We might want to do
            # this on win32 only (TODO verify)
            if selection not in self.fwd_diff:
                special_selection = selection.replace('\n', '\r\n')
                if special_selection in self.fwd_diff:
                    selection = special_selection
                else:
                    return 0, ''
            start = self.fwd_diff.index(selection)
            end = start + len(selection)
            self.set_diffs_to_range(start, end)
        else:
            self.set_diff_to_offset(offset)
            selected = False

        output = ''
        status = 0
        # Process diff selection only
        if selected:
            encoding = self.config.file_encoding(self.filename)
            for idx in self.selected:
                contents = self.diff_subset(idx, start, end)
                if not contents:
                    continue
                tmpfile = utils.tmp_filename('selection')
                utils.write(tmpfile, contents, encoding=encoding)
                if apply_to_worktree:
                    stat, out = self.model.apply_diff_to_worktree(tmpfile)
                    output += out
                    status = max(status, stat)
                else:
                    stat, out = self.model.apply_diff(tmpfile)
                    output += out
                    status = max(status, stat)
                os.unlink(tmpfile)
        # Process a complete hunk
        else:
            for idx, diff in enumerate(self.diff_sel):
                tmpfile = utils.tmp_filename('patch%02d' % idx)
                if not self.write_diff(tmpfile,idx):
                    continue
                if apply_to_worktree:
                    stat, out = self.model.apply_diff_to_worktree(tmpfile)
                    output += out
                    status = max(status, stat)
                else:
                    stat, out = self.model.apply_diff(tmpfile)
                    output += out
                    status = max(status, stat)
                os.unlink(tmpfile)
        return status, output
Exemple #9
0
 def write_diff(self,filename,which,selected=False,noop=False):
     """Writes a new diff corresponding to the user's selection."""
     if not noop and which < len(self.diff_sel):
         diff = self.diff_sel[which]
         encoding = self.config.file_encoding(self.filename)
         utils.write(filename, self.header + '\n' + diff + '\n',
                     encoding=encoding)
         return True
     else:
         return False
Exemple #10
0
 def write_diff(self, filename, which, selected=False, noop=False):
     """Writes a new diff corresponding to the user's selection."""
     if not noop and which < len(self.diff_sel):
         diff = self.diff_sel[which]
         encoding = self.config.file_encoding(self.filename)
         utils.write(filename,
                     self.header + '\n' + diff + '\n',
                     encoding=encoding)
         return True
     else:
         return False
Exemple #11
0
 def do(self):
     new_additions = ""
     for fname in self.filenames:
         new_additions = new_additions + fname + "\n"
     for_status = new_additions
     if new_additions:
         if os.path.exists(".gitignore"):
             current_list = utils.slurp(".gitignore")
             new_additions = new_additions + current_list
         utils.write(".gitignore", new_additions)
         Interaction.log_status(0, "Added to .gitignore:\n%s" % for_status, "")
         self.model.update_file_status()
Exemple #12
0
 def do(self):
     new_additions = ""
     for fname in self.filenames:
         new_additions = new_additions + fname + "\n"
     for_status = new_additions
     if new_additions:
         if os.path.exists(".gitignore"):
             current_list = utils.slurp(".gitignore")
             new_additions = new_additions + current_list
         utils.write(".gitignore", new_additions)
         _notifier.broadcast(signals.log_cmd, 0, "Added to .gitignore:\n%s" % for_status)
         self.model.update_file_status()
Exemple #13
0
 def do(self):
     new_additions = ''
     for fname in self.filenames:
         new_additions = new_additions + fname + '\n'
     for_status = new_additions
     if new_additions:
         if os.path.exists('.gitignore'):
             current_list = utils.slurp('.gitignore')
             new_additions = new_additions + current_list
         utils.write('.gitignore', new_additions)
         Interaction.log_status(0, 'Added to .gitignore:\n%s' % for_status,
                                '')
         self.model.update_file_status()
Exemple #14
0
 def do(self):
     new_additions = ''
     for fname in self.filenames:
         new_additions = new_additions + fname + '\n'
     for_status = new_additions
     if new_additions:
         if os.path.exists('.gitignore'):
             current_list = utils.slurp('.gitignore')
             new_additions = new_additions + current_list
         utils.write('.gitignore', new_additions)
         Interaction.log_status(
                 0, 'Added to .gitignore:\n%s' % for_status, '')
         self.model.update_file_status()
Exemple #15
0
    def commit_list_doubleclick(self,*rest):
        """
        Called when an entry is double-clicked.

        This callback changes the model's directory when
        invoked on a directory item.  When invoked on a file
        it allows the file to be saved.

        """
        current = self.view.commit_list.currentRow()
        directories = self.model.directories

        # A file item was double-clicked.
        # Create a save-as dialog and export the file,
        # or if in get_file mode, grab the filename and finish the dialog.
        if current >= len(directories):
            idx = current - len(directories)

            objtype, sha1, name = self.model.subtree_node(idx)

            if self.get_file:
                if self.model.directory:
                    curdir = self.model.directory
                    self.filename = os.path.join(curdir, name)
                else:
                    self.filename = name
                self.view.accept()
                return

            nameguess = os.path.join(self.model.directory, name)
            filename = qtutils.save_dialog(self.view, 'Save', nameguess)
            if not filename:
                return
            self.model.set_directory(os.path.dirname(filename))
            contents = git.cat_file(objtype, sha1, with_raw_output=True)
            utils.write(filename, contents)
            return

        dirent = directories[current]
        curdir = self.model.directory

        # "change directories"
        # '..' is a special case--it doesn't really exist...
        if dirent == '..':
            newdir = os.path.dirname(os.path.dirname(curdir))
            if newdir == '':
                self.model.set_directory(newdir)
            else:
                self.model.set_directory(newdir + os.sep)
        else:
            self.model.set_directory(curdir + dirent)
Exemple #16
0
 def do(self):
     new_additions = ''
     for fname in self.filenames:
         new_additions = new_additions + fname + '\n'
     for_status = new_additions
     if new_additions:
         if '.gitignore' in gitcmds.all_files():
             current_list = utils.slurp('.gitignore')
             new_additions = new_additions + current_list
         utils.write('.gitignore', new_additions)
         _notifier.broadcast(signals.log_cmd,
                             0,
                             'Added to .gitignore:\n%s' % for_status)
         self.model.update_file_status()
Exemple #17
0
 def do(self):
     new_additions = ''
     for fname in self.filenames:
         new_additions = new_additions + fname + '\n'
     for_status = new_additions
     if new_additions:
         if os.path.exists('.gitignore'):
             current_list = utils.slurp('.gitignore')
             new_additions = new_additions + current_list
         utils.write('.gitignore', new_additions)
         _notifier.broadcast(signals.log_cmd,
                             0,
                             'Added to .gitignore:\n%s' % for_status)
         self.model.update_file_status()
Exemple #18
0
 def process_diff_selection(self, selected, offset, selection, apply_to_worktree=False):
     """Processes a diff selection and applies changes to git."""
     if selection:
         # qt destroys \r\n and makes it \n with no way of going back.
         # boo!  we work around that here.
         # I think this was win32-specific.  We might want to do
         # this on win32 only (TODO verify)
         if selection not in self.fwd_diff:
             special_selection = selection.replace("\n", "\r\n")
             if special_selection in self.fwd_diff:
                 selection = special_selection
             else:
                 return
         start = self.fwd_diff.index(selection)
         end = start + len(selection)
         self.set_diffs_to_range(start, end)
     else:
         self.set_diff_to_offset(offset)
         selected = False
     # Process diff selection only
     if selected:
         for idx in self.selected:
             contents = self.diff_subset(idx, start, end)
             if contents:
                 tmpfile = self.model.tmp_filename()
                 utils.write(tmpfile, contents)
                 if apply_to_worktree:
                     self.model.apply_diff_to_worktree(tmpfile)
                 else:
                     self.model.apply_diff(tmpfile)
                 os.unlink(tmpfile)
     # Process a complete hunk
     else:
         for idx, diff in enumerate(self.diffs):
             tmpfile = self.model.tmp_filename()
             if self.write_diff(tmpfile, idx):
                 if apply_to_worktree:
                     self.model.apply_diff_to_worktree(tmpfile)
                 else:
                     self.model.apply_diff(tmpfile)
                 os.unlink(tmpfile)
Exemple #19
0
    def do(self):
        log_msg = 'Tagging: "%s" as "%s"' % (self._revision, self._name)
        opts = {}
        if self._message:
            opts["F"] = utils.tmp_filename("tag-message")
            utils.write(opts["F"], self._message)

        if self._sign:
            log_msg += ", GPG-signed"
            opts["s"] = True
            status, output = self.model.git.tag(self._name, self._revision, with_status=True, with_stderr=True, **opts)
        else:
            opts["a"] = bool(self._message)
            status, output = self.model.git.tag(self._name, self._revision, with_status=True, with_stderr=True, **opts)
        if "F" in opts:
            os.unlink(opts["F"])

        if output:
            log_msg += "\nOutput:\n%s" % output

        _notifier.broadcast(signals.log_cmd, status, log_msg)
        if status == 0:
            self.model.update_status()
Exemple #20
0
    def do(self):
        log_msg = 'Tagging: "%s" as "%s"' % (self._revision, self._name)
        if self._sign:
            log_msg += ', GPG-signed'
            path = self.model.tmp_filename()
            utils.write(path, self._message)
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                s=True,
                                                F=path,
                                                with_status=True,
                                                with_stderr=True)
            os.unlink(path)
        else:
            status, output = self.model.git.tag(self._name,
                                                self._revision,
                                                with_status=True,
                                                with_stderr=True)
        if output:
            log_msg += '\nOutput:\n%s' % output

        _notifier.broadcast(signals.log_cmd, status, log_msg)
        if status == 0:
            self.model.update_status()
Exemple #21
0
 def save_commitmsg(self, msg):
     path = git.git.git_path('GIT_COLA_MSG')
     utils.write(path, msg)
Exemple #22
0
def save(obj, path):
    utils.write(path, encode(obj))
Exemple #23
0
 def save_commitmsg(self, msg):
     path = git.git.git_path('GIT_COLA_MSG')
     utils.write(path, msg)