mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
Suggest git diff --no-index
when relevant
This makes it easier to use `git diff` on untracked files.
This commit is contained in:
parent
db7dffdb44
commit
2b88ea11ea
@ -169,6 +169,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `git_branch_exists` – offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists;
|
||||
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
||||
* `git_checkout` – fixes branch name or creates new branch;
|
||||
* `git_diff_no_index` – adds `--no-index` to previous `git diff` on untracked files;
|
||||
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
||||
* `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`);
|
||||
* `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command;
|
||||
|
23
tests/rules/test_git_diff_no_index.py
Normal file
23
tests/rules/test_git_diff_no_index.py
Normal file
@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_diff_no_index import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git diff foo bar')])
|
||||
def test_match(command):
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git diff --no-index foo bar'),
|
||||
Command(script='git diff foo'),
|
||||
Command(script='git diff foo bar baz')])
|
||||
def test_not_match(command):
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('git diff foo bar'), 'git diff --no-index foo bar')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command) == new_command
|
20
thefuck/rules/git_diff_no_index.py
Normal file
20
thefuck/rules/git_diff_no_index.py
Normal file
@ -0,0 +1,20 @@
|
||||
from six.moves import filterfalse
|
||||
from thefuck.utils import replace_argument
|
||||
from thefuck.specific.git import git_support
|
||||
|
||||
|
||||
@git_support
|
||||
def match(command):
|
||||
args = command.script_parts[2:]
|
||||
files = list(filterfalse(is_option, args))
|
||||
return ('diff' in command.script and
|
||||
'--no-index' not in command.script and
|
||||
len(command.stdout) is 0 and
|
||||
len(files) is 2)
|
||||
|
||||
def is_option(script_part):
|
||||
return script_part.startswith('-')
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
return replace_argument(command.script, 'diff', 'diff --no-index')
|
Loading…
x
Reference in New Issue
Block a user