1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-03 17:28:58 +00:00
thefuck/thefuck/rules/git_push_force.py
Jan Warchoł dc23d67a42 Use --force-with-lease instead of --force for git push
--force flag can be very dangerous, because it unconditionally
overwrites remote branch - if someone pushed new commits to the remote
repo after you last fetched/pulled, and you do push --force, you will
overwrite his commits without even knowing that you did that.  Using
--force-with-lease is much safer because it only overwrites remote
branch when it points to the same commit that you think it points to.

Read more:
https://developer.atlassian.com/blog/2015/04/force-with-lease/
2015-10-30 16:17:56 +01:00

19 lines
534 B
Python

from thefuck.utils import replace_argument
from thefuck.specific.git import git_support
@git_support
def match(command):
return ('push' in command.script
and '! [rejected]' in command.stderr
and 'failed to push some refs to' in command.stderr
and 'Updates were rejected because the tip of your current branch is behind' in command.stderr)
@git_support
def get_new_command(command):
return replace_argument(command.script, 'push', 'push --force-with-lease')
enabled_by_default = False