From ce6855fd97bda2fd456cd2842f50d44cb111995e Mon Sep 17 00:00:00 2001 From: nvbn Date: Wed, 20 May 2015 02:40:36 +0300 Subject: [PATCH] Add `git_pull` rule --- README.md | 1 + tests/rules/test_git_pull.py | 29 +++++++++++++++++++++++++++++ thefuck/rules/git_pull.py | 12 ++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/rules/test_git_pull.py create mode 100644 thefuck/rules/git_pull.py diff --git a/README.md b/README.md index 1ac70f45..f2406b19 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_checkout` – creates the branch before checking-out; * `git_no_command` – fixes wrong git commands like `git brnch`; * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; +* `git_pull` – sets upstream before executing previous `git pull`; * `git_stash` – stashes you local modifications before rebasing or switching branch; * `has_exists_script` – prepends `./` when script/binary exists; * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`; diff --git a/tests/rules/test_git_pull.py b/tests/rules/test_git_pull.py new file mode 100644 index 00000000..87725f5a --- /dev/null +++ b/tests/rules/test_git_pull.py @@ -0,0 +1,29 @@ +import pytest +from thefuck.rules.git_pull import match, get_new_command +from tests.utils import Command + + +@pytest.fixture +def stderr(): + return '''There is no tracking information for the current branch. +Please specify which branch you want to merge with. +See git-pull(1) for details + + git pull + +If you wish to set tracking information for this branch you can do so with: + + git branch --set-upstream-to=/ master + +''' + + +def test_match(stderr): + assert match(Command('git pull', stderr=stderr), None) + assert not match(Command('git pull'), None) + assert not match(Command('ls', stderr=stderr), None) + + +def test_get_new_command(stderr): + assert get_new_command(Command('git pull', stderr=stderr), None) \ + == "git branch --set-upstream-to=origin/master master && git pull" diff --git a/thefuck/rules/git_pull.py b/thefuck/rules/git_pull.py new file mode 100644 index 00000000..cee34616 --- /dev/null +++ b/thefuck/rules/git_pull.py @@ -0,0 +1,12 @@ +def match(command, settings): + return ('git' in command.script + and 'pull' in command.script + and 'set-upstream' in command.stderr) + + +def get_new_command(command, settings): + line = command.stderr.split('\n')[-3].strip() + branch = line.split(' ')[-1] + set_upstream = line.replace('', 'origin')\ + .replace('', branch) + return u'{} && {}'.format(set_upstream, command.script)