1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . IO ;
3
+ using System . Text ;
4
4
using System . Text . RegularExpressions ;
5
5
using System . Threading . Tasks ;
6
6
7
7
namespace SourceGit . Commands
8
8
{
9
- public partial class LFS
9
+ public partial class LFS : Command
10
10
{
11
11
[ GeneratedRegex ( @"^(.+)\s+([\w.]+)\s+\w+:(\d+)$" ) ]
12
12
private static partial Regex REG_LOCK ( ) ;
13
13
14
- private class SubCmd : Command
15
- {
16
- public SubCmd ( string repo , string args , Models . ICommandLog log )
17
- {
18
- WorkingDirectory = repo ;
19
- Context = repo ;
20
- Args = args ;
21
- Log = log ;
22
- }
23
-
24
- public async Task < Result > ReadAsync ( )
25
- {
26
- return await ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
27
- }
28
- }
29
-
30
14
public LFS ( string repo )
31
15
{
32
- _repo = repo ;
16
+ WorkingDirectory = repo ;
17
+ Context = repo ;
33
18
}
34
19
35
- public bool IsEnabled ( )
20
+ public async Task < bool > InstallAsync ( )
36
21
{
37
- var path = Path . Combine ( _repo , ".git" , "hooks" , "pre-push" ) ;
38
- if ( ! File . Exists ( path ) )
39
- return false ;
40
-
41
- var content = File . ReadAllText ( path ) ;
42
- return content . Contains ( "git lfs pre-push" ) ;
22
+ Args = "lfs install --local" ;
23
+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
43
24
}
44
25
45
- public async Task < bool > InstallAsync ( Models . ICommandLog log )
26
+ public async Task < bool > TrackAsync ( string pattern , bool isFilenameMode )
46
27
{
47
- return await new SubCmd ( _repo , "lfs install --local" , log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
48
- }
28
+ var builder = new StringBuilder ( ) ;
29
+ builder . Append ( "lfs track " ) ;
30
+ builder . Append ( isFilenameMode ? "--filename " : string . Empty ) ;
31
+ builder . Append ( pattern . Quoted ( ) ) ;
49
32
50
- public async Task < bool > TrackAsync ( string pattern , bool isFilenameMode , Models . ICommandLog log )
51
- {
52
- var opt = isFilenameMode ? "--filename" : "" ;
53
- return await new SubCmd ( _repo , $ "lfs track { opt } { pattern . Quoted ( ) } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
33
+ Args = builder . ToString ( ) ;
34
+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
54
35
}
55
36
56
- public async Task FetchAsync ( string remote , Models . ICommandLog log )
37
+ public async Task FetchAsync ( string remote )
57
38
{
58
- await new SubCmd ( _repo , $ "lfs fetch { remote } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
39
+ Args = $ "lfs fetch { remote } ";
40
+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
59
41
}
60
42
61
- public async Task PullAsync ( string remote , Models . ICommandLog log )
43
+ public async Task PullAsync ( string remote )
62
44
{
63
- await new SubCmd ( _repo , $ "lfs pull { remote } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
45
+ Args = $ "lfs pull { remote } ";
46
+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
64
47
}
65
48
66
- public async Task PushAsync ( string remote , Models . ICommandLog log )
49
+ public async Task PushAsync ( string remote )
67
50
{
68
- await new SubCmd ( _repo , $ "lfs push { remote } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
51
+ Args = $ "lfs push { remote } ";
52
+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
69
53
}
70
54
71
- public async Task PruneAsync ( Models . ICommandLog log )
55
+ public async Task PruneAsync ( )
72
56
{
73
- await new SubCmd ( _repo , "lfs prune" , log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
57
+ Args = "lfs prune" ;
58
+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
74
59
}
75
60
76
61
public async Task < List < Models . LFSLock > > GetLocksAsync ( string remote )
77
62
{
63
+ Args = $ "lfs locks --remote={ remote } ";
64
+
65
+ var rs = await ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
78
66
var locks = new List < Models . LFSLock > ( ) ;
79
- var cmd = new SubCmd ( _repo , $ "lfs locks --remote={ remote } ", null ) ;
80
- var rs = await cmd . ReadAsync ( ) . ConfigureAwait ( false ) ;
67
+
81
68
if ( rs . IsSuccess )
82
69
{
83
70
var lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -99,23 +86,23 @@ public async Task PruneAsync(Models.ICommandLog log)
99
86
return locks ;
100
87
}
101
88
102
- public async Task < bool > LockAsync ( string remote , string file , Models . ICommandLog log )
89
+ public async Task < bool > LockAsync ( string remote , string file )
103
90
{
104
- return await new SubCmd ( _repo , $ "lfs lock --remote={ remote } { file . Quoted ( ) } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
91
+ Args = $ "lfs lock --remote={ remote } { file . Quoted ( ) } ";
92
+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
105
93
}
106
94
107
- public async Task < bool > UnlockAsync ( string remote , string file , bool force , Models . ICommandLog log )
95
+ public async Task < bool > UnlockAsync ( string remote , string file , bool force )
108
96
{
109
- var opt = force ? "-f" : "" ;
110
- return await new SubCmd ( _repo , $ "lfs unlock --remote={ remote } { opt } { file . Quoted ( ) } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
97
+ var builder = new StringBuilder ( ) ;
98
+ builder
99
+ . Append ( "lfs unlock --remote=" )
100
+ . Append ( remote )
101
+ . Append ( force ? " -f " : " " )
102
+ . Append ( file . Quoted ( ) ) ;
103
+
104
+ Args = builder . ToString ( ) ;
105
+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
111
106
}
112
-
113
- public async Task < bool > UnlockAsync ( string remote , long id , bool force , Models . ICommandLog log )
114
- {
115
- var opt = force ? "-f" : "" ;
116
- return await new SubCmd ( _repo , $ "lfs unlock --remote={ remote } { opt } --id={ id } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
117
- }
118
-
119
- private readonly string _repo ;
120
107
}
121
108
}
0 commit comments