Unquote over-quoted commands in @git_support

This allows writing rules more easily (eg. the git_branch_list rule
tests for `command.script.split() == 'git branch list'.split()`) and
looks nicer when `require_confirmation` is set.
This commit is contained in:
mcarton
2015-07-17 13:51:22 +02:00
parent f6a4902074
commit 5d0912fee8
2 changed files with 11 additions and 7 deletions
+9 -5
View File
@@ -1,5 +1,6 @@
from difflib import get_close_matches
from functools import wraps
from shlex import split
import os
import pickle
import re
@@ -10,11 +11,9 @@ from .types import Command
DEVNULL = open(os.devnull, 'w')
if six.PY2:
import pipes
quote = pipes.quote
from pipes import quote
else:
import shlex
quote = shlex.quote
from shlex import quote
def which(program):
@@ -84,7 +83,12 @@ def git_support(fn):
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
command.stderr)
alias = search.group(1)
expansion = search.group(2)
# by default git quotes everthing, for example:
# 'commit' '--amend'
# which is surprising and does not allow to easily test for
# eg. 'git commit'
expansion = ' '.join(map(quote, split(search.group(2))))
new_script = command.script.replace(alias, expansion)
command = Command._replace(command, script=new_script)