-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathSubmodule.cs
More file actions
78 lines (66 loc) · 2.59 KB
/
Submodule.cs
File metadata and controls
78 lines (66 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class Submodule : Command
{
public Submodule(string repo)
{
WorkingDirectory = repo;
Context = repo;
}
public async Task<bool> AddAsync(string url, string relativePath, bool recursive)
{
Args = $"-c protocol.file.allow=always submodule add {url.Quoted()} {relativePath.Quoted()}";
var succ = await ExecAsync().ConfigureAwait(false);
if (!succ)
return false;
if (recursive)
Args = $"submodule update --init --recursive -- {relativePath.Quoted()}";
else
Args = $"submodule update --init -- {relativePath.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> SetURLAsync(string path, string url)
{
Args = $"submodule set-url -- {path.Quoted()} {url.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> SetBranchAsync(string path, string branch)
{
if (string.IsNullOrEmpty(branch))
Args = $"submodule set-branch -d -- {path.Quoted()}";
else
Args = $"submodule set-branch -b {branch.Quoted()} -- {path.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> UpdateAsync(List<string> modules, bool init = false, bool useRemote = false)
{
var builder = new StringBuilder();
builder.Append("submodule update --recursive");
if (init)
builder.Append(" --init");
if (useRemote)
builder.Append(" --remote");
if (modules.Count > 0)
{
builder.Append(" --");
foreach (var module in modules)
builder.Append(' ').Append(module.Quoted());
}
Args = builder.ToString();
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> DeinitAsync(string module, bool force)
{
Args = force ? $"submodule deinit -f -- {module.Quoted()}" : $"submodule deinit -- {module.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> DeleteAsync(string module)
{
Args = $"rm -rf {module.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
}
}