Skip to content
Open

tf 5 #23

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
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ Each test case below corresponds to a buggy-to-fixed repository pair.
- thefuck_9
- Related issues:
- https://github.com/nvbn/thefuck/pull/559
- https://github.com/nvbn/thefuck/issues/558
- https://github.com/nvbn/thefuck/issues/558
17 changes: 0 additions & 17 deletions thefuck_5/tests/rules/test_git_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,13 @@ def output(branch_name):
'''.format(branch_name, branch_name)


@pytest.fixture
def output_bitbucket():
return '''Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for feature/set-upstream:
remote: https://bitbucket.org/set-upstream
remote:
To [email protected]:test.git
e5e7fbb..700d998 feature/set-upstream -> feature/set-upstream
Branch feature/set-upstream set up to track remote branch feature/set-upstream from origin.
'''


@pytest.mark.parametrize('script, branch_name', [
('git push', 'master'),
('git push origin', 'master')])
def test_match(output, script, branch_name):
assert match(Command(script, output))


def test_match_bitbucket(output_bitbucket):
assert not match(Command('git push origin', output_bitbucket))


@pytest.mark.parametrize('script, branch_name', [
('git push master', None),
('ls', 'master')])
Expand Down
2 changes: 1 addition & 1 deletion thefuck_5/thefuck/rules/git_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@git_support
def match(command):
return ('push' in command.script_parts
and 'git push --set-upstream' in command.output)
and 'set-upstream' in command.output)
Comment on lines 7 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Warning 🐛 Bug

Substring matching in git_push.py.match() fails when ANSI escape codes are present in output.

Issue Explanation
  • The match function checks for 'set-upstream' substring directly in command.output without sanitization.
  • There is no stripping of ANSI escape sequences before substring matching.
  • This causes false negatives if Git output contains ANSI color codes or formatting that split 'set-upstream'.

Reply if you have any questions or let me know if I missed something.

Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.



def _get_upstream_option_index(command_parts):
Expand Down