Fix untracked files being staged when hidden

This commit is contained in:
Nadav Tau 2024-10-19 14:57:21 -07:00
parent efc14fed36
commit dead9d2527
2 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,24 @@
namespace SourceGit.Commands
{
public partial class QueryHasUntrackedFiles : Command
{
private bool _hasUntracked = false;
public QueryHasUntrackedFiles(string repo) {
WorkingDirectory = repo;
Context = repo;
Args = "ls-files --others --exclude-standard";
}
public bool Result()
{
Exec();
return _hasUntracked;
}
protected override void OnReadline(string line)
{
_hasUntracked = true;
}
}
}

View file

@ -343,7 +343,18 @@ namespace SourceGit.ViewModels
IsStaging = true;
_repo.SetWatcherEnabled(false);
if (changes.Count == _unstaged.Count)
var canAddAll = changes.Count == _unstaged.Count;
if (canAddAll && !IncludeUntracked) {
// If the user chose to hide untracked files, we have to make sure to not
// add those by mistake when performing `git add <repo path>`, otherwise those
// untracked files will be added as well
var hasUntracked = new Commands.QueryHasUntrackedFiles(_repo.FullPath).Exec();
canAddAll = !hasUntracked;
}
if (canAddAll)
{
await Task.Run(() => new Commands.Add(_repo.FullPath).Exec());
}