From 495a66088bfe8a3e1f4175198cddb09d9ea469b8 Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Tue, 6 Sep 2016 17:01:09 +0100 Subject: [PATCH 1/4] readme: add -H flag to second sudo pip command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d96494f0..d4dbac48 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,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.** From af9d34c299e3ac70aab89d20b63c72c5c40d500f Mon Sep 17 00:00:00 2001 From: Julian Zimmermann Date: Mon, 19 Sep 2016 12:52:23 +0200 Subject: [PATCH 2/4] Added rule that stashes changed files before pulling and pops them afterwards. --- README.md | 3 ++- .../test_git_pull_uncommitted_changes.py | 19 +++++++++++++++++++ tests/rules/test_git_pull_unstaged_changes.py | 19 +++++++++++++++++++ thefuck/rules/git_pull_uncommitted_changes.py | 14 ++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/rules/test_git_pull_uncommitted_changes.py create mode 100644 tests/rules/test_git_pull_unstaged_changes.py create mode 100644 thefuck/rules/git_pull_uncommitted_changes.py diff --git a/README.md b/README.md index d4dbac48..45e41e9b 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ brew install thefuck ``` On Ubuntu you can install `The Fuck` with: - + ```bash sudo apt update sudo apt install python3-dev python3-pip @@ -174,6 +174,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..71db6d8d --- /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 'git stash && git pull && git stash pop' From 6e2b82911f974dbfb4b7c210affe39fc7943a74b Mon Sep 17 00:00:00 2001 From: Julian Zimmermann Date: Mon, 19 Sep 2016 13:07:48 +0200 Subject: [PATCH 3/4] Removed linebreak --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 45e41e9b..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 From 9ac47d8f78842448a104b879f4986723d69fdd27 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Tue, 20 Sep 2016 00:28:09 +0200 Subject: [PATCH 4/4] #550: Use `shell.and_` --- thefuck/rules/git_pull_uncommitted_changes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thefuck/rules/git_pull_uncommitted_changes.py b/thefuck/rules/git_pull_uncommitted_changes.py index 71db6d8d..8e9a640d 100644 --- a/thefuck/rules/git_pull_uncommitted_changes.py +++ b/thefuck/rules/git_pull_uncommitted_changes.py @@ -11,4 +11,4 @@ def match(command): @git_support def get_new_command(command): - return 'git stash && git pull && git stash pop' + return shell.and_('git stash', 'git pull', 'git stash pop')