11using System ;
22using System . Collections . Generic ;
3- using System . IO ;
3+ using System . Text ;
44using System . Text . RegularExpressions ;
55using System . Threading . Tasks ;
66
77namespace SourceGit . Commands
88{
9- public partial class LFS
9+ public partial class LFS : Command
1010 {
1111 [ GeneratedRegex ( @"^(.+)\s+([\w.]+)\s+\w+:(\d+)$" ) ]
1212 private static partial Regex REG_LOCK ( ) ;
1313
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-
3014 public LFS ( string repo )
3115 {
32- _repo = repo ;
16+ WorkingDirectory = repo ;
17+ Context = repo ;
3318 }
3419
35- public bool IsEnabled ( )
20+ public async Task < bool > InstallAsync ( )
3621 {
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 ) ;
4324 }
4425
45- public async Task < bool > InstallAsync ( Models . ICommandLog log )
26+ public async Task < bool > TrackAsync ( string pattern , bool isFilenameMode )
4627 {
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 ( ) ) ;
4932
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 ) ;
5435 }
5536
56- public async Task FetchAsync ( string remote , Models . ICommandLog log )
37+ public async Task FetchAsync ( string remote )
5738 {
58- await new SubCmd ( _repo , $ "lfs fetch { remote } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
39+ Args = $ "lfs fetch { remote } ";
40+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
5941 }
6042
61- public async Task PullAsync ( string remote , Models . ICommandLog log )
43+ public async Task PullAsync ( string remote )
6244 {
63- await new SubCmd ( _repo , $ "lfs pull { remote } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
45+ Args = $ "lfs pull { remote } ";
46+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
6447 }
6548
66- public async Task PushAsync ( string remote , Models . ICommandLog log )
49+ public async Task PushAsync ( string remote )
6750 {
68- await new SubCmd ( _repo , $ "lfs push { remote } ", log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
51+ Args = $ "lfs push { remote } ";
52+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
6953 }
7054
71- public async Task PruneAsync ( Models . ICommandLog log )
55+ public async Task PruneAsync ( )
7256 {
73- await new SubCmd ( _repo , "lfs prune" , log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
57+ Args = "lfs prune" ;
58+ await ExecAsync ( ) . ConfigureAwait ( false ) ;
7459 }
7560
7661 public async Task < List < Models . LFSLock > > GetLocksAsync ( string remote )
7762 {
63+ Args = $ "lfs locks --remote={ remote } ";
64+
65+ var rs = await ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
7866 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+
8168 if ( rs . IsSuccess )
8269 {
8370 var lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -99,23 +86,23 @@ public async Task PruneAsync(Models.ICommandLog log)
9986 return locks ;
10087 }
10188
102- public async Task < bool > LockAsync ( string remote , string file , Models . ICommandLog log )
89+ public async Task < bool > LockAsync ( string remote , string file )
10390 {
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 ) ;
10593 }
10694
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 )
10896 {
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 ) ;
111106 }
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 ;
120107 }
121108}
0 commit comments