Merge branch 'git-aliases' of https://github.com/mcarton/thefuck into mcarton-git-aliases

This commit is contained in:
nvbn
2015-07-19 21:27:04 +03:00
15 changed files with 93 additions and 38 deletions
+2 -1
View File
@@ -30,7 +30,8 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES,
'require_confirmation': False,
'no_colors': False,
'debug': False,
'priority': {}}
'priority': {},
'env': {'LANG': 'C', 'GIT_TRACE': '1'}}
ENV_TO_ATTR = {'THEFUCK_RULES': 'rules',
'THEFUCK_WAIT_COMMAND': 'wait_command',
+6 -2
View File
@@ -81,8 +81,12 @@ def get_command(settings, args):
script = shells.from_shell(script)
logs.debug('Call: {}'.format(script), settings)
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE,
env=dict(os.environ, LANG='C'))
env = dict(os.environ)
env.update(settings.env)
logs.debug('Executing with env: {}'.format(env), settings)
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env)
if wait_output(settings, result):
return types.Command(script, result.stdout.read().decode('utf-8'),
result.stderr.read().decode('utf-8'))
+3 -1
View File
@@ -1,13 +1,15 @@
import re
from thefuck import shells
from thefuck import utils, shells
@utils.git_support
def match(command, settings):
return ('git' in command.script
and 'did not match any file(s) known to git.' in command.stderr
and "Did you forget to 'git add'?" in command.stderr)
@utils.git_support
def get_new_command(command, settings):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
+3 -1
View File
@@ -1,10 +1,12 @@
from thefuck import shells
from thefuck import utils, shells
@utils.git_support
def match(command, settings):
# catches "git branch list" in place of "git branch"
return command.script.split() == 'git branch list'.split()
@utils.git_support
def get_new_command(command, settings):
return shells.and_('git branch --delete list', 'git branch')
+3 -1
View File
@@ -1,13 +1,15 @@
import re
from thefuck import shells
from thefuck import shells, utils
@utils.git_support
def match(command, settings):
return ('git' in command.script
and 'did not match any file(s) known to git.' in command.stderr
and "Did you forget to 'git add'?" not in command.stderr)
@utils.git_support
def get_new_command(command, settings):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
+8 -1
View File
@@ -1,6 +1,13 @@
from thefuck import utils
@utils.git_support
def match(command, settings):
return command.script.startswith('git d')
return ('git' in command.script and
'diff' in command.script and
'--staged' not in command.script)
@utils.git_support
def get_new_command(command, settings):
return '{} --staged'.format(command.script)
+3 -2
View File
@@ -1,8 +1,8 @@
from difflib import get_close_matches
import re
from thefuck.utils import get_closest
from thefuck.utils import get_closest, git_support
@git_support
def match(command, settings):
return ('git' in command.script
and " is not a git command. See 'git --help'." in command.stderr
@@ -18,6 +18,7 @@ def _get_all_git_matched_commands(stderr):
yield line.strip()
@git_support
def get_new_command(command, settings):
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
command.stderr)[0]
+3 -1
View File
@@ -1,12 +1,14 @@
from thefuck import shells
from thefuck import shells, utils
@utils.git_support
def match(command, settings):
return ('git' in command.script
and 'pull' in command.script
and 'set-upstream' in command.stderr)
@utils.git_support
def get_new_command(command, settings):
line = command.stderr.split('\n')[-3].strip()
branch = line.split(' ')[-1]
+5
View File
@@ -1,8 +1,13 @@
from thefuck import utils
@utils.git_support
def match(command, settings):
return ('git' in command.script
and 'push' in command.script
and 'set-upstream' in command.stderr)
@utils.git_support
def get_new_command(command, settings):
return command.stderr.split('\n')[-3].strip()
+3 -1
View File
@@ -1,12 +1,14 @@
from thefuck import shells
from thefuck import shells, utils
@utils.git_support
def match(command, settings):
# catches "Please commit or stash them" and "Please, commit your changes or
# stash them before you can switch branches."
return 'git' in command.script and 'or stash them' in command.stderr
@utils.git_support
def get_new_command(command, settings):
formatme = shells.and_('git stash', '{}')
return formatme.format(command.script)
+28 -4
View File
@@ -1,7 +1,9 @@
from difflib import get_close_matches
from functools import wraps
from shlex import split
import os
import pickle
import re
import six
from .types import Command
@@ -9,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):
@@ -73,6 +73,30 @@ def sudo_support(fn):
return wrapper
def git_support(fn):
"""Resolve git aliases."""
@wraps(fn)
def wrapper(command, settings):
if (command.script.startswith('git') and
'trace: alias expansion:' in command.stderr):
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
command.stderr)
alias = search.group(1)
# 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)
return fn(command, settings)
return wrapper
def memoize(fn):
"""Caches previous calls to the function."""
memo = {}