forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLFS.cs
More file actions
112 lines (95 loc) · 3.22 KB
/
Copy pathLFS.cs
File metadata and controls
112 lines (95 loc) · 3.22 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class LFS : Command
{
public LFS(string repo)
{
WorkingDirectory = repo;
Context = repo;
}
public async Task<bool> InstallAsync()
{
Args = "lfs install --local";
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> TrackAsync(string pattern, bool isFilenameMode)
{
var builder = new StringBuilder();
builder.Append("lfs track ");
builder.Append(isFilenameMode ? "--filename " : string.Empty);
builder.Append(pattern.Quoted());
Args = builder.ToString();
return await ExecAsync().ConfigureAwait(false);
}
public async Task FetchAsync(string remote)
{
Args = $"lfs fetch {remote}";
await ExecAsync().ConfigureAwait(false);
}
public async Task PullAsync(string remote)
{
Args = $"lfs pull {remote}";
await ExecAsync().ConfigureAwait(false);
}
public async Task PushAsync(string remote)
{
Args = $"lfs push {remote}";
await ExecAsync().ConfigureAwait(false);
}
public async Task PruneAsync()
{
Args = "lfs prune";
await ExecAsync().ConfigureAwait(false);
}
public async Task<List<Models.LFSLock>> GetLocksAsync(string remote)
{
Args = $"lfs locks --json --remote={remote}";
var rs = await ReadToEndAsync().ConfigureAwait(false);
if (rs.IsSuccess)
{
try
{
var locks = JsonSerializer.Deserialize(rs.StdOut, JsonCodeGen.Default.ListLFSLock);
return locks;
}
catch
{
// Ignore exceptions.
}
}
return [];
}
public async Task<bool> LockAsync(string remote, string file)
{
Args = $"lfs lock --remote={remote} {file.Quoted()}";
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> UnlockAsync(string remote, string file, bool force)
{
var builder = new StringBuilder();
builder
.Append("lfs unlock --remote=")
.Append(remote)
.Append(force ? " -f " : " ")
.Append(file.Quoted());
Args = builder.ToString();
return await ExecAsync().ConfigureAwait(false);
}
public async Task<bool> UnlockMultipleAsync(string remote, List<string> files, bool force)
{
var builder = new StringBuilder();
builder
.Append("lfs unlock --remote=")
.Append(remote)
.Append(force ? " -f" : " ");
foreach (string file in files)
builder.Append(' ').Append(file.Quoted());
Args = builder.ToString();
return await ExecAsync().ConfigureAwait(false);
}
}
}