Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit bbf2ac4

Browse files
Checking if all files are being committed
1 parent 2b75171 commit bbf2ac4

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ ITask<string> Commit(string message, string body,
6262
ITask<string> Add(IList<string> files,
6363
IOutputProcessor<string> processor = null);
6464

65+
ITask<string> Add(GitAddTask.AddFileOption addFileOption,
66+
IOutputProcessor<string> processor = null);
67+
6568
ITask<string> Remove(IList<string> files,
6669
IOutputProcessor<string> processor = null);
6770

@@ -262,11 +265,31 @@ public ITask<string> Commit(string message, string body,
262265
.Configure(processManager);
263266
}
264267

268+
public ITask<string> Add(GitAddTask.AddFileOption addFileOption, IOutputProcessor<string> processor = null)
269+
{
270+
return new GitAddTask(addFileOption, cancellationToken, processor)
271+
.Configure(processManager);
272+
}
273+
265274
public ITask<string> Add(IList<string> files,
266275
IOutputProcessor<string> processor = null)
267276
{
268-
return new GitAddTask(files, cancellationToken, processor)
269-
.Configure(processManager);
277+
GitAddTask last = null;
278+
foreach (var batch in files.Spool(5000))
279+
{
280+
var current = new GitAddTask(batch, cancellationToken, processor).Configure(processManager);
281+
if (last == null)
282+
{
283+
last = current;
284+
}
285+
else
286+
{
287+
last.Then(current);
288+
last = current;
289+
}
290+
}
291+
292+
return last;
270293
}
271294

272295
public ITask<string> Remove(IList<string> files,

src/GitHub.Api/Git/Tasks/GitAddTask.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Threading;
34

45
namespace GitHub.Unity
56
{
67
class GitAddTask : ProcessTask<string>
78
{
9+
public enum AddFileOption
10+
{
11+
All,
12+
CurrentDirectory
13+
}
14+
815
private readonly string arguments;
916

10-
public GitAddTask(IEnumerable<string> files,
11-
CancellationToken token, IOutputProcessor<string> processor = null)
12-
: base(token, processor ?? new SimpleOutputProcessor())
17+
public GitAddTask(IEnumerable<string> files, CancellationToken token,
18+
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
1319
{
1420
Guard.ArgumentNotNull(files, "files");
1521

@@ -22,6 +28,25 @@ public GitAddTask(IEnumerable<string> files,
2228
}
2329
}
2430

31+
public GitAddTask(AddFileOption addFileOption, CancellationToken token,
32+
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
33+
{
34+
arguments = "add ";
35+
36+
switch (addFileOption)
37+
{
38+
case AddFileOption.All:
39+
arguments += "-A";
40+
break;
41+
42+
case AddFileOption.CurrentDirectory:
43+
arguments += ".";
44+
break;
45+
46+
default: throw new ArgumentOutOfRangeException(nameof(addFileOption), addFileOption, null);
47+
}
48+
}
49+
2550
public override string Name { get { return "git add"; } }
2651
public override string ProcessArguments { get { return arguments; } }
2752
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,23 @@ private void Commit()
189189
// Do not allow new commits before we have received one successful update
190190
busy = true;
191191

192-
var files = Enumerable.Range(0, tree.Entries.Count).Where(i => tree.CommitTargets[i].All).Select(i => tree.Entries[i].Path).ToArray();
192+
var files = Enumerable.Range(0, tree.Entries.Count)
193+
.Where(i => tree.CommitTargets[i].All)
194+
.Select(i => tree.Entries[i].Path)
195+
.ToArray();
193196

194-
GitClient.Add(files)
197+
ITask<string> addTask;
198+
199+
if (files.Length == tree.Entries.Count)
200+
{
201+
addTask = GitClient.Add(GitAddTask.AddFileOption.All);
202+
}
203+
else
204+
{
205+
addTask = GitClient.Add(files);
206+
}
207+
208+
addTask
195209
.Then(GitClient.Commit(commitMessage, commitBody))
196210
.Then(GitClient.Status())
197211
.FinallyInUI((b, exception) =>

0 commit comments

Comments
 (0)