Skip to content
Draft
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
8 changes: 5 additions & 3 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ gint rm_file_relpaths_cmp(const RmFile *file_a, const RmFile *file_b) {
gint diff = file_a->depth - file_b->depth;
RETURN_IF_NONZERO(diff);

/* If both files have depth 0, we still need to distinguish them by at
* least their basenames; otherwise, they would always compare equal. */
/* Depth 0 means both commandline inputs were explicit files.
* Compare full paths to avoid overmatching by basename only. */
if(file_a->depth == 0) {
return rm_file_basenames_cmp(file_a, file_b);
RM_DEFINE_PATH(file_a);
RM_DEFINE_PATH(file_b);
return g_ascii_strcasecmp(file_a_path, file_b_path);
}
RmNode *node_a = file_a->folder;
RmNode *node_b = file_b->folder;
Expand Down
13 changes: 13 additions & 0 deletions tests/test_options/test_match_relative_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ def test_negative_match_relative_path_explicit_files(usual_setup_usual_teardown)
assert footer['total_files'] == 2
assert footer['total_lint_size'] == 0
assert footer['duplicates'] == 0


def test_negative_match_relative_path_explicit_files_same_basename(usual_setup_usual_teardown):
path_a = create_file('xxx', 'base_a/file')
path_b = create_file('xxx', 'base_b/file')

head, *data, footer = run_rmlint(
'--match-relative-path', path_a, path_b,
use_default_dir=False
)
assert footer['total_files'] == 2
assert footer['total_lint_size'] == 0
assert footer['duplicates'] == 0