diff --git a/src/Commands/QueryHasUntrackedFiles.cs b/src/Commands/QueryHasUntrackedFiles.cs new file mode 100644 index 00000000..69488dc1 --- /dev/null +++ b/src/Commands/QueryHasUntrackedFiles.cs @@ -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; + } + } +} diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index e4acf8ca..29adaf4b 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -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 `, 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()); }