Skip to content

Commit

Permalink
Merge pull request #253 from living180/no_shell_subprocess
Browse files Browse the repository at this point in the history
Don't pass shell=True to core.run_command()
  • Loading branch information
davvid committed May 9, 2014
2 parents e6b5559 + bb00eaf commit 92ed6c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
9 changes: 5 additions & 4 deletions cola/core.py
Expand Up @@ -90,11 +90,12 @@ def readline(fh, encoding=None):


@interruptable
def start_command(cmd, cwd=None, shell=False, add_env=None,
def start_command(cmd, cwd=None, add_env=None,
universal_newlines=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE):
stderr=subprocess.PIPE,
**extra):
"""Start the given command, and return a subprocess object.
This provides a simpler interface to the subprocess module.
Expand All @@ -116,8 +117,8 @@ def start_command(cmd, cwd=None, shell=False, add_env=None,
else:
cmd = [encode(c) for c in cmd]
return subprocess.Popen(cmd, bufsize=1, stdin=stdin, stdout=stdout,
stderr=stderr, cwd=cwd, shell=shell, env=env,
universal_newlines=universal_newlines)
stderr=stderr, cwd=cwd, env=env,
universal_newlines=universal_newlines, **extra)


@interruptable
Expand Down
24 changes: 8 additions & 16 deletions cola/git.py
Expand Up @@ -164,8 +164,14 @@ def execute(command,

extra = {}
if sys.platform == 'win32':
command = map(replace_carot, command)
extra['shell'] = True
# 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
Expand Down Expand Up @@ -237,20 +243,6 @@ def git(self, cmd, *args, **kwargs):
sys.exit(1)


def replace_carot(cmd_arg):
"""
Guard against the windows command shell.
In the Windows shell, a carat character (^) may be used for
line continuation. To guard against this, escape the carat
by using two of them.
http://technet.microsoft.com/en-us/library/cc723564.aspx
"""
return cmd_arg.replace('^', '^^')


@memoize
def instance():
"""Return the Git singleton"""
Expand Down

0 comments on commit 92ed6c3

Please sign in to comment.