Skip to content

Use a consistent file path label when paths share no suffix - #997

Open
StressTestor wants to merge 1 commit into
Wilfred:masterfrom
StressTestor:fix/925-consistent-display-path
Open

Use a consistent file path label when paths share no suffix#997
StressTestor wants to merge 1 commit into
Wilfred:masterfrom
StressTestor:fix/925-consistent-display-path

Conversation

@StressTestor

Copy link
Copy Markdown

what

When diffing two files whose paths share no common trailing component, the path shown in the hunk header depends on whether the files have an extension:

$ difft a b
a --- Text
$ difft a.txt b.txt
b.txt --- Text

a vs b labels with the left path, but a.txt vs b.txt labels with the right path. This is #925.

why

build_display_path's no-common-suffix arm picked the rhs path when rhs had an extension and the lhs path otherwise:

None => {
    if rhs.extension().is_some() {
        rhs.display().to_string()
    } else {
        lhs.display().to_string()
    }
}

so the side shown was driven by the extension.

fix

Use the rhs path consistently here, matching the git-tmpfile branch just above (which already returns rhs) and the usual convention of showing the new/destination file.

None => rhs.display().to_string(),

The change is scoped to that one match arm. The reporter also suggested detecting a rename and showing both paths; that is a larger behaviour change, so I kept this minimal and easy to extend if you would rather take the show-both approach.

tests

test_build_display_path_consistent_without_common_suffix covers the extensionless and extensioned cases (both now use rhs) and the shared-suffix case (unchanged). It fails before the fix and passes after. Full suite green.

Fixes #925.

When two paths have no common trailing component, build_display_path
chose the rhs path if it had an extension and the lhs path otherwise, so
the label shown depended on whether the files had an extension (e.g. `a`
vs `b` showed `a`, but `a.txt` vs `b.txt` showed `b.txt`). Always use the
rhs path in this case, matching the git-tmpfile branch above.

Fixes Wilfred#925.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent choice for shown file path

1 participant