From 45869c27b89f709eab98b13a0274ac05a5bd9b26 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 20 Oct 2024 18:32:05 +0800 Subject: [PATCH] enhance: ignore untracked files when staging all changes with `INCLUDE UNTRACKED FILES` turned off (#577) --- src/Commands/Add.cs | 30 +++++++++++++++--------------- src/ViewModels/WorkingCopy.cs | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Commands/Add.cs b/src/Commands/Add.cs index 2251c892..7134ec4a 100644 --- a/src/Commands/Add.cs +++ b/src/Commands/Add.cs @@ -5,27 +5,27 @@ namespace SourceGit.Commands { public class Add : Command { - public Add(string repo, List changes = null) + public Add(string repo, bool includeUntracked) + { + WorkingDirectory = repo; + Context = repo; + Args = includeUntracked ? "add ." : "add -u ."; + } + + public Add(string repo, List changes) { WorkingDirectory = repo; Context = repo; - if (changes == null || changes.Count == 0) + var builder = new StringBuilder(); + builder.Append("add --"); + foreach (var c in changes) { - Args = "add ."; - } - else - { - var builder = new StringBuilder(); - builder.Append("add --"); - foreach (var c in changes) - { - builder.Append(" \""); - builder.Append(c.Path); - builder.Append("\""); - } - Args = builder.ToString(); + builder.Append(" \""); + builder.Append(c.Path); + builder.Append("\""); } + Args = builder.ToString(); } } } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 98ae7776..70b4f11f 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -345,7 +345,7 @@ namespace SourceGit.ViewModels _repo.SetWatcherEnabled(false); if (changes.Count == _unstaged.Count) { - await Task.Run(() => new Commands.Add(_repo.FullPath).Exec()); + await Task.Run(() => new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec()); } else { @@ -1316,7 +1316,7 @@ namespace SourceGit.ViewModels { var succ = true; if (autoStage && _unstaged.Count > 0) - succ = new Commands.Add(_repo.FullPath).Exec(); + succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec(); if (succ) succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend).Exec();