From 04b83cf7e8f40fe44824448b0ab941aa48352f91 Mon Sep 17 00:00:00 2001 From: Paul-Louis NECH Date: Fri, 4 Mar 2016 13:47:07 +0100 Subject: [PATCH] Rules: git remote add instead of set-url if remote does not exist Tests: Added test for git_remote_seturl_add Rules: renamed new rule with a more appropriate name README: added new rule Style: Formatting New rule: corrected test name Developed tests --- README.md | 1 + tests/rules/test_git_remote_seturl_add.py | 26 +++++++++++++++++++++++ thefuck/rules/git_remote_seturl_add.py | 14 ++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/rules/test_git_remote_seturl_add.py create mode 100644 thefuck/rules/git_remote_seturl_add.py diff --git a/README.md b/README.md index 36bf881..0a1eedd 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_pull_clone` – clones instead of pulling when the repo does not exist; * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; * `git_push_pull` – runs `git pull` when `push` was rejected; +* `git_remote_seturl_add` – runs `git remote add` when `git remote set_url` on nonexistant remote; * `git_stash` – stashes you local modifications before rebasing or switching branch; * `git_two_dashes` – adds a missing dash to commands like `git commit -amend` or `git rebase -continue`; * `go_run` – appends `.go` extension when compiling/running Go programs; diff --git a/tests/rules/test_git_remote_seturl_add.py b/tests/rules/test_git_remote_seturl_add.py new file mode 100644 index 0000000..8b8667e --- /dev/null +++ b/tests/rules/test_git_remote_seturl_add.py @@ -0,0 +1,26 @@ +import pytest +from thefuck.rules.git_remote_seturl_add import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='git remote set-url origin url', stderr="fatal: No such remote")]) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize('command', [ + Command('git remote set-url origin url', stderr=""), + Command('git remote add origin url'), + Command('git remote remove origin'), + Command('git remote prune origin'), + Command('git remote set-branches origin branch') + ]) +def test_not_match(command): + assert not match(command) + +@pytest.mark.parametrize('command, new_command', [ + (Command('git remote set-url origin git@github.com:nvbn/thefuck.git'), + 'git remote add origin git@github.com:nvbn/thefuck.git')]) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command diff --git a/thefuck/rules/git_remote_seturl_add.py b/thefuck/rules/git_remote_seturl_add.py new file mode 100644 index 0000000..4468b10 --- /dev/null +++ b/thefuck/rules/git_remote_seturl_add.py @@ -0,0 +1,14 @@ +from thefuck.utils import replace_argument +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return ('set-url' in command.script and 'fatal: No such remote' in command.stderr) + + +def get_new_command(command): + return replace_argument(command.script, 'set-url', 'add') + + +enabled_by_default = True