diff --git a/README.md b/README.md index d96494f0..254f2b2b 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ brew install thefuck ``` On Ubuntu you can install `The Fuck` with: - ```bash sudo apt update sudo apt install python3-dev python3-pip @@ -135,7 +134,7 @@ To make them available immediately, run `source ~/.bashrc` (or your shell config ## Update ```bash -sudo pip install thefuck --upgrade +sudo -H pip install thefuck --upgrade ``` **Aliases changed in 1.34.** @@ -174,6 +173,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_not_command` – fixes wrong git commands like `git brnch`; * `git_pull` – sets upstream before executing previous `git pull`; * `git_pull_clone` – clones instead of pulling when the repo does not exist; +* `git_pull_uncommitted_changes` – stashes changes before pulling and pops them afterwards; * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; * `git_push_pull` – runs `git pull` when `push` was rejected; * `git_rebase_no_changes` – runs `git rebase --skip` instead of `git rebase --continue` when there are no changes; diff --git a/tests/rules/test_git_pull_uncommitted_changes.py b/tests/rules/test_git_pull_uncommitted_changes.py new file mode 100644 index 00000000..480b31d8 --- /dev/null +++ b/tests/rules/test_git_pull_uncommitted_changes.py @@ -0,0 +1,19 @@ +import pytest +from thefuck.rules.git_pull_uncommitted_changes import match, get_new_command +from tests.utils import Command + + +@pytest.fixture +def stderr(): + return '''error: Cannot pull with rebase: You have unstaged changes.''' + + +def test_match(stderr): + assert match(Command('git pull', stderr=stderr)) + assert not match(Command('git pull')) + assert not match(Command('ls', stderr=stderr)) + + +def test_get_new_command(stderr): + assert get_new_command(Command('git pull', stderr=stderr)) \ + == "git stash && git pull && git stash pop" diff --git a/tests/rules/test_git_pull_unstaged_changes.py b/tests/rules/test_git_pull_unstaged_changes.py new file mode 100644 index 00000000..a8cbb4c3 --- /dev/null +++ b/tests/rules/test_git_pull_unstaged_changes.py @@ -0,0 +1,19 @@ +import pytest +from thefuck.rules.git_pull_uncommitted_changes import match, get_new_command +from tests.utils import Command + + +@pytest.fixture +def stderr(): + return '''error: Cannot pull with rebase: Your index contains uncommitted changes.''' + + +def test_match(stderr): + assert match(Command('git pull', stderr=stderr)) + assert not match(Command('git pull')) + assert not match(Command('ls', stderr=stderr)) + + +def test_get_new_command(stderr): + assert get_new_command(Command('git pull', stderr=stderr)) \ + == "git stash && git pull && git stash pop" diff --git a/thefuck/rules/git_pull_uncommitted_changes.py b/thefuck/rules/git_pull_uncommitted_changes.py new file mode 100644 index 00000000..8e9a640d --- /dev/null +++ b/thefuck/rules/git_pull_uncommitted_changes.py @@ -0,0 +1,14 @@ +from thefuck.shells import shell +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return ('pull' in command.script + and ('You have unstaged changes' in command.stderr + or 'contains uncommitted changes' in command.stderr)) + + +@git_support +def get_new_command(command): + return shell.and_('git stash', 'git pull', 'git stash pop')