Skip to content

Commit 03429fa

Browse files
gma2thnvbn
authored andcommitted
git_push: Handle command containing force argument (nvbn#818)
1 parent 4ab430f commit 03429fa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

tests/rules/test_git_push.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def test_not_match(output, script, branch_name):
6666
('git -c test=test push --quiet origin', 'master',
6767
'git -c test=test push --set-upstream origin master --quiet'),
6868
('git push', "test's",
69-
"git push --set-upstream origin test\\'s")])
69+
"git push --set-upstream origin test\\'s"),
70+
('git push --force', 'master',
71+
'git push --set-upstream origin master --force'),
72+
('git push --force-with-lease', 'master',
73+
'git push --set-upstream origin master --force-with-lease')])
7074
def test_get_new_command(output, script, branch_name, new_command):
7175
assert get_new_command(Command(script, output)) == new_command

thefuck/rules/git_push.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ def get_new_command(command):
3939
while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-':
4040
command_parts.pop(len(command_parts) - 1)
4141

42-
arguments = re.findall(r'git push (.*)', command.output)[0].replace("'", r"\'").strip()
42+
arguments = re.findall(r'git push (.*)', command.output)[-1].replace("'", r"\'").strip()
4343
return replace_argument(" ".join(command_parts), 'push',
4444
'push {}'.format(arguments))

0 commit comments

Comments
 (0)