Skip to content

Files/directories with a shared name prefix are dropped from a multi-selection (custom patch, discard) #5866

Closed

Description

@ZekiLiu

Describe the bug

When I select multiple files in a commit's file view and their names share a prefix, one of them is silently left out of the operation.

I hit this while building a custom patch from a commit: I range-selected a couple of entries and pressed space to add them all to the patch, but one of them just never got added — no error, it simply stayed unselected. It turned out the two names shared a prefix (in my case a file and its .orig leftover). The same thing happens with directories like foo and foobar, and it also affects "discard changes" on a multi-selection, not just custom patches.

To Reproduce

Minimal repro with two sibling directories whose names share a prefix:

mkdir repro && cd repro && git init
mkdir foo foobar
echo x > foo/file
echo x > foobar/file
git add -A && git commit -m "first commit"
lazygit

Then:

  1. Focus the Commits panel and press enter on first commit to open its files.
  2. You'll see the tree:
    ▼ /
      ▼ foo
        A file
      ▼ foobar
        A file
    
  3. Put the cursor on the foo directory, press v to start a range selection, and move down to the foobar directory so both directories are selected.
  4. Press space to add the selection to a custom patch.

Result — only foo gets added:

▼ /
  ▼ foo
    ● file
  ▼ foobar
    A file      <- never added to the patch

The same happens with plain files whose names share a prefix, e.g. a.txt and a.txt.orig, or app.js and app.js.map: select both, and the longer-named one is dropped.

Expected behavior

Both selected entries should be added to the patch (both showing ●). foobar is not inside foo, and a.txt.orig is not inside a.txt, so neither should be treated as a descendant of the other and skipped.

Screenshots

(Text output above shows it — foobar/file stays A instead of becoming ●.)

Version info:

commit=, build date=, build source=Homebrew, version=0.63.1, os=darwin, arch=arm64, git version=2.55.0

I also built and confirmed it's still present on latest master (commit 292035709).

Terminal info:

iTerm2 3.5.14, running inside tmux 3.7b (TERM=tmux-256color).

Additional context

I had a quick look out of curiosity. In pkg/gui/controllers/commits_files_controller.go, isDescendentOfSelectedCommitFileNodes filters a node out of the selection when its path starts with another selected node's path:

if strings.HasPrefix(nodePath, selectedNodePath) && nodePath != selectedNodePath {

That matches foobar against foo (and a.txt.orig against a.txt) even though neither is actually a descendant. There's even a comment right above saying this function is "identical to those in files_controller.go", and the version there (isDescendentOfSelectedNodes) does the check differently — it skips selected files and requires a path-segment boundary (selectedNodePath + "/"), which wouldn't have this problem. So the two seem to have drifted apart. (Just a hunch from reading.)

Activity

  1. stefanhaller commented on Jul 28, 2026

    @stefanhaller
    Collaborator

    @ZekiLiu Thanks; you are right that the code has drifted. This is a bug that was fixed in the Files panel a long time ago, but we forgot to make the equivalent change in the commit files panel. Fixed in #5868.

  2. added a commit that references this issue on Jul 28, 2026
    df0943a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions