Skip to content

Commit 45869c2

Browse files
committed
enhance: ignore untracked files when staging all changes with INCLUDE UNTRACKED FILES turned off (#577)
1 parent 7c25363 commit 45869c2

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/Commands/Add.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ namespace SourceGit.Commands
55
{
66
public class Add : Command
77
{
8-
public Add(string repo, List<Models.Change> changes = null)
8+
public Add(string repo, bool includeUntracked)
9+
{
10+
WorkingDirectory = repo;
11+
Context = repo;
12+
Args = includeUntracked ? "add ." : "add -u .";
13+
}
14+
15+
public Add(string repo, List<Models.Change> changes)
916
{
1017
WorkingDirectory = repo;
1118
Context = repo;
1219

13-
if (changes == null || changes.Count == 0)
14-
{
15-
Args = "add .";
16-
}
17-
else
20+
var builder = new StringBuilder();
21+
builder.Append("add --");
22+
foreach (var c in changes)
1823
{
19-
var builder = new StringBuilder();
20-
builder.Append("add --");
21-
foreach (var c in changes)
22-
{
23-
builder.Append(" \"");
24-
builder.Append(c.Path);
25-
builder.Append("\"");
26-
}
27-
Args = builder.ToString();
24+
builder.Append(" \"");
25+
builder.Append(c.Path);
26+
builder.Append("\"");
2827
}
28+
Args = builder.ToString();
2929
}
3030
}
3131
}

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public async void StageChanges(List<Models.Change> changes, Models.Change next)
345345
_repo.SetWatcherEnabled(false);
346346
if (changes.Count == _unstaged.Count)
347347
{
348-
await Task.Run(() => new Commands.Add(_repo.FullPath).Exec());
348+
await Task.Run(() => new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec());
349349
}
350350
else
351351
{
@@ -1316,7 +1316,7 @@ private void DoCommit(bool autoStage, bool autoPush)
13161316
{
13171317
var succ = true;
13181318
if (autoStage && _unstaged.Count > 0)
1319-
succ = new Commands.Add(_repo.FullPath).Exec();
1319+
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec();
13201320

13211321
if (succ)
13221322
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend).Exec();

0 commit comments

Comments
 (0)