Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a rule for trying to push a new repository with no commits. #618

Merged
merged 3 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `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_push_without_commits` – Creates an initial commit if you forget and only `git add .`, when setting up a new project;
* `git_rebase_no_changes` – runs `git rebase --skip` instead of `git rebase --continue` when there are no changes;
* `git_rm_local_modifications` – adds `-f` or `--cached` when you try to `rm` a locally modified file;
* `git_rm_recursive` – adds `-r` when you try to `rm` a directory;
Expand Down
27 changes: 27 additions & 0 deletions tests/rules/test_git_push_without_commits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

from tests.utils import Command
from thefuck.rules.git_push_without_commits import (
fix,
get_new_command,
match,
)

command = 'git push -u origin master'
expected_error = '''
error: src refspec master does not match any.
error: failed to push some refs to '[email protected]:User/repo.git'
'''


@pytest.mark.parametrize('command', [Command(command, stderr=expected_error)])
def test_match(command):
assert match(command)


@pytest.mark.parametrize('command, result', [(
Command(command, stderr=expected_error),
fix.format(command=command),
)])
def test_get_new_command(command, result):
assert get_new_command(command) == result
15 changes: 15 additions & 0 deletions thefuck/rules/git_push_without_commits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import re

fix = 'git commit -m "Initial commit." && {command}'
refspec_does_not_match = re.compile(r'src refspec \w+ does not match any\.')


def match(command):
if refspec_does_not_match.search(command.stderr):
return True

return False


def get_new_command(command):
return fix.format(command=command.script)