Skip to content

Commit 8faf9b1

Browse files
Ryan Delaneyrpdelaney
authored andcommitted
Resolve paths before checking app identity
Commands entered with a path do not match is_app. I encountered this when working with a test for the rm_dir rule. This rule did not use the @for_app decorator, but when I migrated it, the test for "./bin/hdfs.." failed because 'hdfs' was recognized as a command, while "./bin/hdfs" was not. This commit addresses the false negative by resolving path names in the command, via os.path.basename.
1 parent c196e29 commit 8faf9b1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tests/test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def test_get_all_matched_commands(stderr, result):
132132

133133
@pytest.mark.usefixtures('no_memoize')
134134
@pytest.mark.parametrize('script, names, result', [
135+
('/usr/bin/git diff', ['git', 'hub'], True),
136+
('/bin/hdfs dfs -rm foo', ['hdfs'], True),
135137
('git diff', ['git', 'hub'], True),
136138
('hub diff', ['git', 'hub'], True),
137139
('hg diff', ['git', 'hub'], False)])
@@ -141,6 +143,8 @@ def test_is_app(script, names, result):
141143

142144
@pytest.mark.usefixtures('no_memoize')
143145
@pytest.mark.parametrize('script, names, result', [
146+
('/usr/bin/git diff', ['git', 'hub'], True),
147+
('/bin/hdfs dfs -rm foo', ['hdfs'], True),
144148
('git diff', ['git', 'hub'], True),
145149
('hub diff', ['git', 'hub'], True),
146150
('hg diff', ['git', 'hub'], False)])

thefuck/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def is_app(command, *app_names, **kwargs):
175175
raise TypeError("got an unexpected keyword argument '{}'".format(kwargs.keys()))
176176

177177
if len(command.script_parts) > at_least:
178-
return command.script_parts[0] in app_names
178+
return os.path.basename(command.script_parts[0]) in app_names
179179

180180
return False
181181

0 commit comments

Comments
 (0)