Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When hiding untracked files, adding a folder adds also untracked files (git add instead of git add -u) #4245

Open
clotodex opened this issue Feb 7, 2025 · 7 comments · May be fixed by #4386
Labels
bug Something isn't working

Comments

@clotodex
Copy link

clotodex commented Feb 7, 2025

Describe the bug
When hiding untracked files, adding a folder adds also untracked files (git add instead of git add -u).
This means you are also in the commit only shown a subset of the files that will be actually commited.

To Reproduce
In a repo, create a folder, add two files, track one file.
Then change the tracked file.
Open lazy git. Filter to tracked files (ctrl+b, t).
Now with space select the folder to commit.
Without your knowledge it also adds the untracked file.

Expected behavior
It should only add from the tracked files, if the view is filtered.

Version info:
commit=, build date=, build source=nix, version=0.45.2, os=linux, arch=amd64, git version=2.47.1

Additional context
There might be a reason to do it this way. If that is the case, at least a warning should be displayed.

@clotodex clotodex added the bug Something isn't working label Feb 7, 2025
@parthokunda
Copy link

Yeah, I think this is a problem. I will try to put a PR soon.

@parthokunda
Copy link

parthokunda commented Mar 7, 2025

Sorry for being so late. I have been very busy for the last couple of weeks.
Anyway, I am a bit confused about how this thing will work. Suppose some untracked files were already staged before applying track filter. If I commit in that filter view what should I do?

  • Keep the unstaged files in commit. This might be confusing like before.
  • Only commit the files staged in current filter view.

Also, during unstaging in filter view, what should be the expected behavior?

In my opinion, when in filtered view, we should only consider files in current view for all things (staging, unstaging, commit). But this will complicate a lot of things and might be confusing in many use cases.

@stefanhaller
Copy link
Collaborator

Interesting questions. I don't use the filter feature much, but when playing with it just now, I found it confusing that untracked but staged files don't show up when I filter for only tracked files. In my intuition, a staged file already counts as a tracked file (even though I know that it technically isn't). So I would propose to simply include them (and, for symmetry, probably exclude them when filtering for only untracked files? Not so sure about that).

This would solve the problems you brought up, or am I still missing scenarios where it doesn't?

Here's a patch that does this:

diff --git i/pkg/gui/filetree/file_tree.go w/pkg/gui/filetree/file_tree.go
index 9ef980faa..5298f79e8 100644
--- i/pkg/gui/filetree/file_tree.go
+++ w/pkg/gui/filetree/file_tree.go
@@ -88,9 +88,9 @@ func (self *FileTree) getFilesForDisplay() []*models.File {
 	case DisplayUnstaged:
 		return self.FilterFiles(func(file *models.File) bool { return file.HasUnstagedChanges })
 	case DisplayTracked:
-		return self.FilterFiles(func(file *models.File) bool { return file.Tracked })
+		return self.FilterFiles(func(file *models.File) bool { return file.Tracked || file.HasStagedChanges })
 	case DisplayUntracked:
-		return self.FilterFiles(func(file *models.File) bool { return !file.Tracked })
+		return self.FilterFiles(func(file *models.File) bool { return !(file.Tracked || file.HasStagedChanges) })
 	case DisplayConflicted:
 		return self.FilterFiles(func(file *models.File) bool { return file.HasMergeConflicts })
 	default:

@clotodex
Copy link
Author

That is a good point.
I still find the behavior of it adding the whole folder unintuitive but i can also see that for some people it might be the other way around.
This way, no matter the implementation you DO have a proper view of what will be committed though - which i like!

@stefanhaller
Copy link
Collaborator

I still find the behavior of it adding the whole folder unintuitive

Well yes of course. The patch above wasn't meant as the only measure we take, we still also want to do git add -u, which I understand @parthokunda is working on. The patch was only meant to address the issue that Partho was running into while doing that.

@parthokunda parthokunda linked a pull request Mar 10, 2025 that will close this issue
7 tasks
@parthokunda
Copy link

Interesting questions. I don't use the filter feature much, but when playing with it just now, I found it confusing that untracked but staged files don't show up when I filter for only tracked files. In my intuition, a staged file already counts as a tracked file (even though I know that it technically isn't). So I would propose to simply include them (and, for symmetry, probably exclude them when filtering for only untracked files? Not so sure about that).

This is a nice solution. However, if we unstage in tracked filter view, the untracked files will disappear. This might be a bit confusing, but nevertheless, seems like a good tradeoff to make.
Created a draft PR for now. Gonna clean this up hopefully tomorrow.

@stefanhaller
Copy link
Collaborator

However, if we unstage in tracked filter view, the untracked files will disappear. This might be a bit confusing,

I don't find this confusing at all. This is not really very different from filtering by staged files, and then unstaging a file (or vice versa); of course the file then disappears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants