def git(self, cmd, *args, **kwargs): # Handle optional arguments prior to calling transform_kwargs # otherwise they'll end up in args, which is bad. _kwargs = dict(_cwd=self._git_cwd) execute_kwargs = ( '_cwd', '_decode', '_encoding', '_stdin', '_stdout', '_stderr', '_raw', ) for kwarg in execute_kwargs: if kwarg in kwargs: _kwargs[kwarg] = kwargs.pop(kwarg) # Prepare the argument list opt_args = self.transform_kwargs(**kwargs) call = ['git', dashify(cmd)] + opt_args call.extend(args) try: return self.execute(call, **_kwargs) except OSError as e: if e.errno != errno.ENOENT: raise e core.stderr("ERROR: Unable to execute 'git'.\n" "Ensure that 'git' is in your $PATH, or specify the " "path to 'git' using the --git-path argument.") sys.exit(1)
def git(self, cmd, *args, **kwargs): # Handle optional arguments prior to calling transform_kwargs # otherwise they'll end up in args, which is bad. _kwargs = dict(_cwd=self._git_cwd) execute_kwargs = ( '_cwd', '_decode', '_encoding', '_stdin', '_stdout', '_stderr', '_raw', '_readonly', ) for kwarg in execute_kwargs: if kwarg in kwargs: _kwargs[kwarg] = kwargs.pop(kwarg) # Prepare the argument list git_args = ['git', '-c', 'diff.suppressBlankEmpty=false', dashify(cmd)] opt_args = self.transform_kwargs(**kwargs) call = git_args + opt_args call.extend(args) try: return self.execute(call, **_kwargs) except OSError as e: if e.errno != errno.ENOENT: raise e core.stderr("error: unable to execute 'git'\n" "error: please ensure that 'git' is in your $PATH") if sys.platform == 'win32': _print_win32_git_hint() sys.exit(1)
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(0) # Handle session management restore_session(args) if args.git_path: # Adds git to the PATH. This is needed on Windows. path_entries = core.getenv('PATH', '').split(os.pathsep) path_entries.insert(0, os.path.dirname(core.decode(args.git_path))) compat.setenv('PATH', os.pathsep.join(path_entries)) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' 'Please specify --repo <path>.') % repo core.stderr(errmsg) sys.exit(-1) # We do everything relative to the repo root os.chdir(args.repo) return repo
def git(self, cmd, *args, **kwargs): # Handle optional arguments prior to calling transform_kwargs # otherwise they'll end up in args, which is bad. _kwargs = dict(_cwd=self._git_cwd) execute_kwargs = ("_cwd", "_decode", "_encoding", "_stdin", "_stdout", "_stderr", "_raw", "_readonly") for kwarg in execute_kwargs: if kwarg in kwargs: _kwargs[kwarg] = kwargs.pop(kwarg) # Prepare the argument list opt_args = self.transform_kwargs(**kwargs) call = ["git", dashify(cmd)] + opt_args call.extend(args) try: return self.execute(call, **_kwargs) except OSError as e: if e.errno != errno.ENOENT: raise e core.stderr("error: unable to execute 'git'\n" "error: please ensure that 'git' is in your $PATH") if sys.platform == "win32": hint = ( "\n" "hint: If you have Git installed in a custom location, e.g.\n" "hint: C:\\Tools\\Git, then you can create a file at\n" "hint: ~/.config/git-cola/git-bindir with the following text\n" "hint: and git-cola will add the specified location to your $PATH\n" "hint: automatically when starting cola:\n" "hint:\n" "hint: C:\\Tools\\Git\\bin\n" ) core.stderr(hint) sys.exit(1)
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(0) # Handle session management restore_session(args) if args.git_path: # Adds git to the PATH. This is needed on Windows. path_entries = core.getenv('PATH', '').split(os.pathsep) path_entries.insert(0, os.path.dirname(core.decode(args.git_path))) compat.setenv('PATH', os.pathsep.join(path_entries)) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' 'Please specify a correct --repo <path>.') % repo core.stderr(errmsg) sys.exit(-1) # We do everything relative to the repo root os.chdir(args.repo) return repo
def _print_win32_git_hint(): hint = ('\n' 'hint: If you have Git installed in a custom location, e.g.\n' 'hint: C:\\Tools\\Git, then you can create a file at\n' 'hint: ~/.config/git-cola/git-bindir with following text\n' 'hint: and git-cola will add the specified location to your $PATH\n' 'hint: automatically when starting cola:\n' 'hint:\n' 'hint: C:\\Tools\\Git\\bin\n') core.stderr(hint)
def _print_win32_git_hint(): hint = ( '\n' 'hint: If you have Git installed in a custom location, e.g.\n' 'hint: C:\\Tools\\Git, then you can create a file at\n' 'hint: ~/.config/git-cola/git-bindir with following text\n' 'hint: and git-cola will add the specified location to your $PATH\n' 'hint: automatically when starting cola:\n' 'hint:\n' 'hint: C:\\Tools\\Git\\bin\n') core.stderr(hint)
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(EX_OK) # Handle session management restore_session(args) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' 'Please specify a correct --repo <path>.') % repo core.stderr(errmsg) sys.exit(EX_USAGE)
def git(self, cmd, *args, **kwargs): # Handle optional arguments prior to calling transform_kwargs # otherwise they'll end up in args, which is bad. _kwargs = dict(_cwd=self._git_cwd) execute_kwargs = ( '_cwd', '_decode', '_encoding', '_stdin', '_stdout', '_stderr', '_raw', '_readonly', ) for kwarg in execute_kwargs: if kwarg in kwargs: _kwargs[kwarg] = kwargs.pop(kwarg) # Prepare the argument list git_args = ['git', '-c', 'diff.suppressBlankEmpty=false', dashify(cmd)] opt_args = self.transform_kwargs(**kwargs) call = git_args + opt_args call.extend(args) try: return self.execute(call, **_kwargs) except OSError as e: if e.errno != errno.ENOENT: raise e core.stderr("error: unable to execute 'git'\n" "error: please ensure that 'git' is in your $PATH") if sys.platform == 'win32': hint = ( '\n' 'hint: If you have Git installed in a custom location, e.g.\n' 'hint: C:\\Tools\\Git, then you can create a file at\n' 'hint: ~/.config/git-cola/git-bindir with the following text\n' 'hint: and git-cola will add the specified location to your $PATH\n' 'hint: automatically when starting cola:\n' 'hint:\n' 'hint: C:\\Tools\\Git\\bin\n') core.stderr(hint) sys.exit(1)
def cmd_rebase(args): kwargs = { 'verbose': args.verbose, 'quiet': args.quiet, 'autostash': args.autostash, 'fork_point': args.fork_point, 'onto': args.onto, 'preserve_merges': args.preserve_merges, 'strategy': args.strategy, 'no_ff': args.no_ff, 'merge': args.merge, 'exec': getattr(args, 'exec', None), # python keyword 'keep_empty': args.keep_empty, 'force_rebase': args.force_rebase, 'strategy_option': args.strategy_option, 'stat': args.stat, 'no_stat': args.no_stat, 'verify': args.verify, 'rerere_autoupdate': args.rerere_autoupdate, 'root': args.root, 'autosquash': args.autosquash, 'committer_date_is_author_date': args.committer_date_is_author_date, 'ignore_date': args.ignore_date, 'whitespace': args.whitespace, 'ignore_whitespace': args.ignore_whitespace, 'C': args.context_lines, 'continue': getattr(args, 'continue', False), # python keyword 'abort': args.abort, 'skip': args.skip, 'edit_todo': args.edit_todo, 'upstream': args.upstream, 'branch': args.branch, 'capture_output': False, } status, out, err = cmds.do(cmds.Rebase, **kwargs) if out: core.stdout(out) if err: core.stderr(err) return status
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(EX_OK) # Handle session management restore_session(args) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith("file:"): repo = repo[len("file:") :] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' "Please specify a correct --repo <path>.") % repo core.stderr(errmsg) sys.exit(EX_USAGE) # We do everything relative to the repo root os.chdir(args.repo) return repo
def execute(command, _cwd=None, _decode=True, _encoding=None, _raw=False, _stdin=None, _stderr=subprocess.PIPE, _stdout=subprocess.PIPE): """ Execute a command and returns its output :param command: argument list to execute. :param _cwd: working directory, defaults to the current directory. :param _decode: whether to decode output, defaults to True. :param _encoding: default encoding, defaults to None (utf-8). :param _raw: do not strip trailing whitespace. :param _stdin: optional stdin filehandle. :returns (status, out, err): exit status, stdout, stderr """ # Allow the user to have the command executed in their working dir. if not _cwd: _cwd = core.getcwd() extra = {} if sys.platform == 'win32': command = map(replace_carot, command) extra['shell'] = True # Start the process # Guard against thread-unsafe .git/index.lock files INDEX_LOCK.acquire() status, out, err = core.run_command(command, cwd=_cwd, encoding=_encoding, stdin=_stdin, stdout=_stdout, stderr=_stderr, **extra) # Let the next thread in INDEX_LOCK.release() if not _raw and out is not None: out = out.rstrip('\n') cola_trace = GIT_COLA_TRACE if cola_trace == 'trace': msg = 'trace: ' + subprocess.list2cmdline(command) Interaction.log_status(status, msg, '') elif cola_trace == 'full': if out: core.stderr("%s -> %d: '%s' '%s'" % (' '.join(command), status, out, err)) else: core.stderr("%s -> %d" % (' '.join(command), status)) elif cola_trace: core.stderr(' '.join(command)) # Allow access to the command's status code return (status, out, err)
def execute(command, _cwd=None, _decode=True, _encoding=None, _raw=False, _stdin=None, _stderr=subprocess.PIPE, _stdout=subprocess.PIPE): """ Execute a command and returns its output :param command: argument list to execute. :param _cwd: working directory, defaults to the current directory. :param _decode: whether to decode output, defaults to True. :param _encoding: default encoding, defaults to None (utf-8). :param _raw: do not strip trailing whitespace. :param _stdin: optional stdin filehandle. :returns (status, out, err): exit status, stdout, stderr """ # Allow the user to have the command executed in their working dir. if not _cwd: _cwd = core.getcwd() extra = {} if sys.platform == 'win32': # If git-cola is invoked on Windows using "start pythonw git-cola", # a console window will briefly flash on the screen each time # git-cola invokes git, which is very annoying. The code below # prevents this by ensuring that any window will be hidden. startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE extra['startupinfo'] = startupinfo if hasattr(os, 'setsid'): # SSH uses the SSH_ASKPASS variable only if the process is really # detached from the TTY (stdin redirection and setting the # SSH_ASKPASS environment variable is not enough). To detach a # process from the console it should fork and call os.setsid(). extra['preexec_fn'] = os.setsid # Start the process # Guard against thread-unsafe .git/index.lock files INDEX_LOCK.acquire() status, out, err = core.run_command(command, cwd=_cwd, encoding=_encoding, stdin=_stdin, stdout=_stdout, stderr=_stderr, **extra) # Let the next thread in INDEX_LOCK.release() if not _raw and out is not None: out = out.rstrip('\n') cola_trace = GIT_COLA_TRACE if cola_trace == 'trace': msg = 'trace: ' + subprocess.list2cmdline(command) Interaction.log_status(status, msg, '') elif cola_trace == 'full': if out or err: core.stderr("%s -> %d: '%s' '%s'" % (' '.join(command), status, out, err)) else: core.stderr("%s -> %d" % (' '.join(command), status)) elif cola_trace: core.stderr(' '.join(command)) # Allow access to the command's status code return (status, out, err)
def execute(command, _cwd=None, _decode=True, _encoding=None, _raw=False, _stdin=None, _stderr=subprocess.PIPE, _stdout=subprocess.PIPE): """ Execute a command and returns its output :param command: argument list to execute. :param _cwd: working directory, defaults to the current directory. :param _decode: whether to decode output, defaults to True. :param _encoding: default encoding, defaults to None (utf-8). :param _raw: do not strip trailing whitespace. :param _stdin: optional stdin filehandle. :returns (status, out, err): exit status, stdout, stderr """ # Allow the user to have the command executed in their working dir. if not _cwd: _cwd = core.getcwd() extra = {} if sys.platform == 'win32': # If git-cola is invoked on Windows using "start pythonw git-cola", # a console window will briefly flash on the screen each time # git-cola invokes git, which is very annoying. The code below # prevents this by ensuring that any window will be hidden. startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE extra['startupinfo'] = startupinfo # Start the process # Guard against thread-unsafe .git/index.lock files INDEX_LOCK.acquire() status, out, err = core.run_command(command, cwd=_cwd, encoding=_encoding, stdin=_stdin, stdout=_stdout, stderr=_stderr, **extra) # Let the next thread in INDEX_LOCK.release() if not _raw and out is not None: out = out.rstrip('\n') cola_trace = GIT_COLA_TRACE if cola_trace == 'trace': msg = 'trace: ' + subprocess.list2cmdline(command) Interaction.log_status(status, msg, '') elif cola_trace == 'full': if out or err: core.stderr("%s -> %d: '%s' '%s'" % (' '.join(command), status, out, err)) else: core.stderr("%s -> %d" % (' '.join(command), status)) elif cola_trace: core.stderr(' '.join(command)) # Allow access to the command's status code return (status, out, err)
def _add_watch_failed_warning(self, directory, e): core.stderr('inotify: failed to watch "%s"' % directory) core.stderr(ustr(e)) core.stderr('') core.stderr('If you have run out of watches then you may be able to') core.stderr('increase the number of allowed watches by running:') core.stderr('') core.stderr(' echo fs.inotify.max_user_watches=100000 |') core.stderr(' sudo tee -a /etc/sysctl.conf &&') core.stderr(' sudo sysctl -p\n')
def execute( command, _cwd=None, _decode=True, _encoding=None, _raw=False, _stdin=None, _stderr=subprocess.PIPE, _stdout=subprocess.PIPE, _readonly=False, ): """ Execute a command and returns its output :param command: argument list to execute. :param _cwd: working directory, defaults to the current directory. :param _decode: whether to decode output, defaults to True. :param _encoding: default encoding, defaults to None (utf-8). :param _raw: do not strip trailing whitespace. :param _stdin: optional stdin filehandle. :returns (status, out, err): exit status, stdout, stderr """ # Allow the user to have the command executed in their working dir. if not _cwd: _cwd = core.getcwd() extra = {} if sys.platform == "win32": # If git-cola is invoked on Windows using "start pythonw git-cola", # a console window will briefly flash on the screen each time # git-cola invokes git, which is very annoying. The code below # prevents this by ensuring that any window will be hidden. startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE extra["startupinfo"] = startupinfo if hasattr(os, "setsid"): # SSH uses the SSH_ASKPASS variable only if the process is really # detached from the TTY (stdin redirection and setting the # SSH_ASKPASS environment variable is not enough). To detach a # process from the console it should fork and call os.setsid(). extra["preexec_fn"] = os.setsid # Start the process # Guard against thread-unsafe .git/index.lock files if not _readonly: INDEX_LOCK.acquire() status, out, err = core.run_command( command, cwd=_cwd, encoding=_encoding, stdin=_stdin, stdout=_stdout, stderr=_stderr, **extra ) # Let the next thread in if not _readonly: INDEX_LOCK.release() if not _raw and out is not None: out = out.rstrip("\n") cola_trace = GIT_COLA_TRACE if cola_trace == "trace": msg = "trace: " + subprocess.list2cmdline(command) Interaction.log_status(status, msg, "") elif cola_trace == "full": if out or err: core.stderr("%s -> %d: '%s' '%s'" % (" ".join(command), status, out, err)) else: core.stderr("%s -> %d" % (" ".join(command), status)) elif cola_trace: core.stderr(" ".join(command)) # Allow access to the command's status code return (status, out, err)