mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
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:
parent
f6a4902074
commit
5d0912fee8
@ -27,8 +27,8 @@ def test_sudo_support(return_value, command, called, result):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('called, command, stderr', [
|
@pytest.mark.parametrize('called, command, stderr', [
|
||||||
('git co', "git 'checkout'", "19:22:36.299340 git.c:282 trace: alias expansion: co => 'checkout'"),
|
('git co', 'git checkout', "19:22:36.299340 git.c:282 trace: alias expansion: co => 'checkout'"),
|
||||||
('git com file', "git 'commit' '--verbose' file", "19:23:25.470911 git.c:282 trace: alias expansion: com => 'commit' '--verbose'")])
|
('git com file', 'git commit --verbose file', "19:23:25.470911 git.c:282 trace: alias expansion: com => 'commit' '--verbose'")])
|
||||||
def test_git_support(called, command, stderr):
|
def test_git_support(called, command, stderr):
|
||||||
@git_support
|
@git_support
|
||||||
def fn(command, settings): return command.script
|
def fn(command, settings): return command.script
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from difflib import get_close_matches
|
from difflib import get_close_matches
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from shlex import split
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
import re
|
import re
|
||||||
@ -10,11 +11,9 @@ from .types import Command
|
|||||||
DEVNULL = open(os.devnull, 'w')
|
DEVNULL = open(os.devnull, 'w')
|
||||||
|
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
import pipes
|
from pipes import quote
|
||||||
quote = pipes.quote
|
|
||||||
else:
|
else:
|
||||||
import shlex
|
from shlex import quote
|
||||||
quote = shlex.quote
|
|
||||||
|
|
||||||
|
|
||||||
def which(program):
|
def which(program):
|
||||||
@ -84,7 +83,12 @@ def git_support(fn):
|
|||||||
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
|
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
|
||||||
command.stderr)
|
command.stderr)
|
||||||
alias = search.group(1)
|
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)
|
new_script = command.script.replace(alias, expansion)
|
||||||
|
|
||||||
command = Command._replace(command, script=new_script)
|
command = Command._replace(command, script=new_script)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user