Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Commands/QueryHasUntrackedFiles.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
13 changes: 12 additions & 1 deletion src/ViewModels/WorkingCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,18 @@ public async void StageChanges(List<Models.Change> changes, Models.Change next)

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());
}
Expand Down