Esempio n. 1
0
    def do(self):
        if not self.filenames:
            return
        filename = self.filenames[0]
        if not core.exists(filename):
            return
        editor = prefs.editor()
        opts = []

        if self.line_number is None:
            opts = self.filenames
        else:
            # Single-file w/ line-numbers (likely from grep)
            editor_opts = {
                    '*vim*': ['+'+self.line_number, filename],
                    '*emacs*': ['+'+self.line_number, filename],
                    '*textpad*': ['%s(%s,0)' % (filename, self.line_number)],
                    '*notepad++*': ['-n'+self.line_number, filename],
            }

            opts = self.filenames
            for pattern, opt in editor_opts.items():
                if fnmatch(editor, pattern):
                    opts = opt
                    break

        try:
            core.fork(utils.shell_split(editor) + opts)
        except Exception as e:
            message = (N_('Cannot exec "%s": please configure your editor') %
                       editor)
            Interaction.critical(N_('Error Editing File'),
                                 message, str(e))
Esempio n. 2
0
    def do(self):
        if not self.filenames:
            return
        filename = self.filenames[0]
        if not core.exists(filename):
            return
        editor = prefs.editor()
        opts = []

        if self.line_number is None:
            opts = self.filenames
        else:
            # Single-file w/ line-numbers (likely from grep)
            editor_opts = {
                    '*vim*': ['+'+self.line_number, filename],
                    '*emacs*': ['+'+self.line_number, filename],
                    '*textpad*': ['%s(%s,0)' % (filename, self.line_number)],
                    '*notepad++*': ['-n'+self.line_number, filename],
            }

            opts = self.filenames
            for pattern, opt in editor_opts.items():
                if fnmatch(editor, pattern):
                    opts = opt
                    break

        try:
            core.fork(utils.shell_split(editor) + opts)
        except Exception as e:
            message = (N_('Cannot exec "%s": please configure your editor')
                       % editor)
            details = core.decode(e.strerror)
            Interaction.critical(N_('Error Editing File'), message, details)
Esempio n. 3
0
    def do(self):
        if not self.filenames:
            return
        filename = self.filenames[0]
        if not core.exists(filename):
            return
        editor = prefs.editor()
        opts = []

        if self.line_number is None:
            opts = self.filenames
        else:
            # Single-file w/ line-numbers (likely from grep)
            editor_opts = {
                "*vim*": ["+" + self.line_number, filename],
                "*emacs*": ["+" + self.line_number, filename],
                "*textpad*": ["%s(%s,0)" % (filename, self.line_number)],
                "*notepad++*": ["-n" + self.line_number, filename],
            }

            opts = self.filenames
            for pattern, opt in editor_opts.items():
                if fnmatch(editor, pattern):
                    opts = opt
                    break

        try:
            core.fork(utils.shell_split(editor) + opts)
        except Exception as e:
            message = N_('Cannot exec "%s": please configure your editor') % editor
            details = core.decode(e.strerror)
            Interaction.critical(N_("Error Editing File"), message, details)
Esempio n. 4
0
def launch_history_browser(argv):
    try:
        core.fork(argv)
    except Exception as e:
        _, details = utils.format_exception(e)
        title = N_("Error Launching History Browser")
        msg = N_('Cannot exec "%s": please configure a history browser') % " ".join(argv)
        Interaction.critical(title, message=msg, details=details)
Esempio n. 5
0
def launch_history_browser(argv):
    try:
        core.fork(argv)
    except Exception as e:
        _, details = utils.format_exception(e)
        title = N_('Error Launching History Browser')
        msg = (N_('Cannot exec "%s": please configure a history browser') %
               ' '.join(argv))
        Interaction.critical(title, message=msg, details=details)
Esempio n. 6
0
 def do(self):
     s = selection.selection()
     if s.unmerged:
         paths = s.unmerged
         if utils.is_win32():
             core.fork(['git', 'mergetool', '--no-prompt', '--'] + paths)
         else:
             core.fork(['xterm', '-e',
                        'git', 'mergetool', '--no-prompt', '--'] + paths)
     else:
         difftool.run()
Esempio n. 7
0
 def do(self):
     status, out, err = self.model.git.clone(self.url, self.new_directory)
     if status != 0:
         Interaction.information(
             N_('Error: could not clone "%s"') % self.url,
             (N_('git clone returned exit code %s') % status) +
             ((out + err) and ('\n\n' + out + err) or ''))
         return False
     if self.spawn:
         core.fork(
             [sys.executable, sys.argv[0], '--repo', self.new_directory])
     return True
Esempio n. 8
0
 def do(self):
     status, out, err = self.model.git.clone(self.url, self.new_directory)
     if status != 0:
         Interaction.information(
                 N_('Error: could not clone "%s"') % self.url,
                 (N_('git clone returned exit code %s') % status) +
                 ((out+err) and ('\n\n' + out + err) or ''))
         return False
     if self.spawn:
         core.fork([sys.executable, sys.argv[0],
                    '--repo', self.new_directory])
     return True
Esempio n. 9
0
 def do(self):
     s = selection.selection()
     if s.unmerged:
         paths = s.unmerged
         if utils.is_win32():
             core.fork(['git', 'mergetool', '--no-prompt', '--'] + paths)
         else:
             core.fork(
                 ['xterm', '-e', 'git', 'mergetool', '--no-prompt', '--'] +
                 paths)
     else:
         difftool.run()
Esempio n. 10
0
 def do(self):
     s = selection.selection()
     if s.unmerged:
         paths = s.unmerged
         if utils.is_win32():
             core.fork(['git', 'mergetool', '--no-prompt', '--'] + paths)
         else:
             cmd = _config.terminal()
             argv = utils.shell_split(cmd)
             argv.extend(['git', 'mergetool', '--no-prompt', '--'])
             argv.extend(paths)
             core.fork(argv)
     else:
         difftool.run()
Esempio n. 11
0
 def do(self):
     s = selection.selection()
     if s.unmerged:
         paths = s.unmerged
         if utils.is_win32():
             core.fork(['git', 'mergetool', '--no-prompt', '--'] + paths)
         else:
             cmd = _config.terminal()
             argv = utils.shell_split(cmd)
             argv.extend(['git', 'mergetool', '--no-prompt', '--'])
             argv.extend(paths)
             core.fork(argv)
     else:
         difftool.run()
Esempio n. 12
0
    def do(self):
        status, out, err = self.model.git.clone(self.url, self.new_directory)
        self.ok = status == 0

        if self.ok:
            if self.spawn:
                core.fork([sys.executable, sys.argv[0], "--repo", self.new_directory])
        else:
            self.error_message = N_('Error: could not clone "%s"') % self.url
            self.error_details = (N_("git clone returned exit code %s") % status) + (
                (out + err) and ("\n\n" + out + err) or ""
            )

        return self
Esempio n. 13
0
 def do(self):
     s = selection.selection()
     if s.unmerged:
         paths = s.unmerged
         if utils.is_win32():
             core.fork(["git", "mergetool", "--no-prompt", "--"] + paths)
         else:
             cfg = gitcfg.current()
             cmd = cfg.terminal()
             argv = utils.shell_split(cmd)
             argv.extend(["git", "mergetool", "--no-prompt", "--"])
             argv.extend(paths)
             core.fork(argv)
     else:
         difftool.run()
Esempio n. 14
0
    def do(self):
        status, out, err = self.model.git.clone(self.url, self.new_directory)
        self.ok = status == 0

        if self.ok:
            if self.spawn:
                core.fork([sys.executable, sys.argv[0],
                           '--repo', self.new_directory])
        else:
            self.error_message = N_('Error: could not clone "%s"') % self.url
            self.error_details = (
                    (N_('git clone returned exit code %s') % status) +
                     ((out+err) and ('\n\n' + out + err) or ''))

        return self
Esempio n. 15
0
    def do(self):
        argv = utils.shell_split(prefs.history_browser())
        if self.revision:
            argv.append(self.revision)
        if self.paths:
            argv.append('--')
            argv.extend(self.paths)

        try:
            core.fork(argv)
        except Exception as e:
            _, details = utils.format_exception(e)
            title = N_('Error Launching History Browser')
            msg = (N_('Cannot exec "%s": please configure a history browser') %
                   ' '.join(argv))
            Interaction.critical(title, message=msg, details=details)
Esempio n. 16
0
    def do(self):
        argv = utils.shell_split(prefs.history_browser())
        if self.revision:
            argv.append(self.revision)
        if self.paths:
            argv.append('--')
            argv.extend(self.paths)

        try:
            core.fork(argv)
        except Exception as e:
            _, details = utils.format_exception(e)
            title = N_('Error Launching History Browser')
            msg = (N_('Cannot exec "%s": please configure a history browser') %
                   ' '.join(argv))
            Interaction.critical(title, message=msg, details=details)
Esempio n. 17
0
def launch(left=None,
           right=None,
           paths=None,
           left_take_parent=False,
           staged=False):
    """Launches 'git difftool' with given parameters"""

    difftool_args = ['git', 'difftool', '--no-prompt']
    if staged:
        difftool_args.append('--cached')

    if left:
        if left_take_parent:
            # Check root commit (no parents and thus cannot execute '~')
            model = main.model()
            git = model.git
            status, out, err = git.rev_list(left, parents=True, n=1)
            Interaction.log_status(status, out, err)
            if status:
                raise OSError('git rev-list command failed')

            if len(out.split()) >= 2:
                # Commit has a parent, so we can take its child as requested
                left += '~'
            else:
                # No parent, assume it's the root commit, so we have to diff
                # against the empty tree.  The empty tree is a built-in
                # git constant SHA1.  The empty tree is a built-in Git SHA1.
                left = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
        difftool_args.append(left)

    if right:
        difftool_args.append(right)

    if paths:
        difftool_args.append('--')
        difftool_args.extend(paths)

    core.fork(difftool_args)
Esempio n. 18
0
def launch(left=None, right=None, paths=None,
           left_take_parent=False, staged=False):
    """Launches 'git difftool' with given parameters"""

    difftool_args = ['git', 'difftool', '--no-prompt']
    if staged:
        difftool_args.append('--cached')

    if left:
        if left_take_parent:
            # Check root commit (no parents and thus cannot execute '~')
            model = main.model()
            git = model.git
            status, out, err = git.rev_list(left, parents=True, n=1)
            Interaction.log_status(status, out, err)
            if status:
                raise StandardError('git rev-list command failed')

            if len(out.split()) >= 2:
                # Commit has a parent, so we can take its child as requested
                left += '~'
            else:
                # No parent, assume it's the root commit, so we have to diff
                # against the empty tree.  The empty tree is a built-in
                # git constant SHA1.  The empty tree is a built-in Git SHA1.
                left = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
        difftool_args.append(left)

    if right:
        difftool_args.append(right)

    if paths:
        difftool_args.append('--')
        difftool_args.extend(paths)

    core.fork(difftool_args)
Esempio n. 19
0
 def do(self):
     browser = utils.shell_split(prefs.history_browser())
     core.fork(browser + [self.model.currentbranch])
Esempio n. 20
0
 def do(self):
     browser = utils.shell_split(prefs.history_browser())
     core.fork(browser + ['--all'])
Esempio n. 21
0
 def open_repo(self):
     """Opens a new git-cola session on a bookmark"""
     for repo in self.selection():
         core.fork([sys.executable, sys.argv[0], '--repo', repo])
Esempio n. 22
0
 def do(self):
     self.model.set_directory(self.repo_path)
     core.fork([sys.executable, sys.argv[0], '--repo', self.repo_path])
Esempio n. 23
0
 def do(self):
     if not self.filenames:
         return
     dirs = list(set(map(os.path.dirname, self.filenames)))
     core.fork([self.launcher] + dirs)
Esempio n. 24
0
 def do(self):
     if not self.filenames:
         return
     core.fork([self.launcher] + self.filenames)
Esempio n. 25
0
 def do(self):
     cmd = _config.terminal()
     argv = utils.shell_split(cmd)
     argv.append(os.getenv('SHELL', '/bin/sh'))
     core.fork(argv, cwd=self.path)
Esempio n. 26
0
 def do(self):
     cmd = _config.get('cola.terminal', 'xterm -e $SHELL')
     cmd = os.path.expandvars(cmd)
     argv = utils.shell_split(cmd)
     core.fork(argv, cwd=self.path)
Esempio n. 27
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        cfg = gitcfg.current()
        opts = cfg.get_guitool_opts(self.action_name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = N_('Run "%s"?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information(
                        N_('Please select a file'),
                        N_('"%s" requires a selected file.') % cmd)
                return False
            compat.setenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = N_('Invalid Revision')
                    msg = N_('The revision expression cannot be empty.')
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.setenv('REVISION', rev)
        if args:
            compat.setenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log(N_('Running command: %s') % title)
        cmd = ['sh', '-c', cmd]

        if opts.get('background'):
            core.fork(cmd)
            status, out, err = (0, '', '')
        elif opts.get('noconsole'):
            status, out, err = core.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status,
                               out and (N_('Output: %s') % out) or '',
                               err and (N_('Errors: %s') % err) or '')

        if not opts.get('background') and not opts.get('norescan'):
            self.model.update_status()
        return status
Esempio n. 28
0
 def do(self):
     cmd = _config.terminal()
     argv = utils.shell_split(cmd)
     argv.append(os.getenv('SHELL', '/bin/sh'))
     core.fork(argv, cwd=self.path)
Esempio n. 29
0
 def do(self):
     browser = utils.shell_split(prefs.history_browser())
     core.fork(browser + ['--all'])
Esempio n. 30
0
 def do(self):
     if not self.filenames:
         return
     dirs = set(map(os.path.dirname, self.filenames))
     core.fork([self.launcher] + dirs)
Esempio n. 31
0
 def do(self):
     cmd = _config.get('cola.terminal', 'xterm -e $SHELL')
     cmd = os.path.expandvars(cmd)
     argv = utils.shell_split(cmd)
     core.fork(argv, cwd=self.path)
Esempio n. 32
0
 def do(self):
     core.fork(self.argv)
Esempio n. 33
0
 def do(self):
     core.fork(self.argv)
Esempio n. 34
0
 def do(self):
     browser = utils.shell_split(prefs.history_browser())
     core.fork(browser + [self.model.currentbranch])
Esempio n. 35
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        cfg = gitcfg.current()
        opts = cfg.get_guitool_opts(self.action_name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = N_('Run "%s"?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information(
                        N_('Please select a file'),
                        N_('"%s" requires a selected file.') % cmd)
                return False
            compat.setenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = N_('Invalid Revision')
                    msg = N_('The revision expression cannot be empty.')
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.setenv('REVISION', rev)
        if args:
            compat.setenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log(N_('Running command: %s') % title)
        cmd = ['sh', '-c', cmd]

        if opts.get('background'):
            core.fork(cmd)
            status, out, err = (0, '', '')
        elif opts.get('noconsole'):
            status, out, err = core.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status,
                               out and (N_('Output: %s') % out) or '',
                               err and (N_('Errors: %s') % err) or '')

        if not opts.get('background') and not opts.get('norescan'):
            self.model.update_status()
        return status
Esempio n. 36
0
 def do(self):
     cfg = gitcfg.current()
     cmd = cfg.terminal()
     argv = utils.shell_split(cmd)
     argv.append(os.getenv('SHELL', '/bin/sh'))
     core.fork(argv, cwd=self.path)
Esempio n. 37
0
 def do(self):
     if not self.filenames:
         return
     core.fork([self.launcher] + self.filenames)
Esempio n. 38
0
 def do(self):
     cfg = gitcfg.current()
     cmd = cfg.terminal()
     argv = utils.shell_split(cmd)
     argv.append(os.getenv('SHELL', '/bin/sh'))
     core.fork(argv, cwd=self.path)
Esempio n. 39
0
 def do(self):
     self.model.set_directory(self.repo_path)
     core.fork([sys.executable, sys.argv[0], '--repo', self.repo_path])
Esempio n. 40
0
def launch(args):
    """Launches 'git difftool' with args"""
    difftool_args = ['git', 'difftool', '--no-prompt']
    difftool_args.extend(args)
    core.fork(difftool_args)
Esempio n. 41
0
 def open_repo(self):
     """Opens a new git-cola session on a bookmark"""
     for repo in self.selection():
         core.fork([sys.executable, sys.argv[0], '--repo', repo])
Esempio n. 42
0
    def do(self):
        for env in ("FILENAME", "REVISION", "ARGS"):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        cfg = gitcfg.current()
        opts = cfg.get_guitool_opts(self.action_name)
        cmd = opts.get("cmd")
        if "title" not in opts:
            opts["title"] = cmd

        if "prompt" not in opts or opts.get("prompt") is True:
            prompt = N_('Run "%s"?') % cmd
            opts["prompt"] = prompt

        if opts.get("needsfile"):
            filename = selection.filename()
            if not filename:
                Interaction.information(N_("Please select a file"), N_('"%s" requires a selected file.') % cmd)
                return False
            compat.setenv("FILENAME", filename)

        if opts.get("revprompt") or opts.get("argprompt"):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get("revision")
                args = opts.get("args")
                if opts.get("revprompt") and not rev:
                    title = N_("Invalid Revision")
                    msg = N_("The revision expression cannot be empty.")
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get("confirm"):
            title = os.path.expandvars(opts.get("title"))
            prompt = os.path.expandvars(opts.get("prompt"))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.setenv("REVISION", rev)
        if args:
            compat.setenv("ARGS", args)
        title = os.path.expandvars(cmd)
        Interaction.log(N_("Running command: %s") % title)
        cmd = ["sh", "-c", cmd]

        if opts.get("background"):
            core.fork(cmd)
            status, out, err = (0, "", "")
        elif opts.get("noconsole"):
            status, out, err = core.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status, out and (N_("Output: %s") % out) or "", err and (N_("Errors: %s") % err) or "")

        if not opts.get("background") and not opts.get("norescan"):
            self.model.update_status()
        return status