33
44namespace SourceGit . Commands
55{
6- public static class Branch
6+ public class Branch : Command
77 {
8- public static async Task < bool > CreateAsync ( string repo , string name , string basedOn , bool force , Models . ICommandLog log )
8+ public Branch ( string repo )
9+ {
10+ WorkingDirectory = repo ;
11+ Context = repo ;
12+ }
13+
14+ public async Task < bool > CreateAsync ( string name , string basedOn , bool force )
915 {
1016 var builder = new StringBuilder ( ) ;
1117 builder . Append ( "branch " ) ;
@@ -15,61 +21,36 @@ public static async Task<bool> CreateAsync(string repo, string name, string base
1521 builder . Append ( " " ) ;
1622 builder . Append ( basedOn ) ;
1723
18- var cmd = new Command ( ) ;
19- cmd . WorkingDirectory = repo ;
20- cmd . Context = repo ;
21- cmd . Args = builder . ToString ( ) ;
22- cmd . Log = log ;
23- return await cmd . ExecAsync ( ) . ConfigureAwait ( false ) ;
24+ Args = builder . ToString ( ) ;
25+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
2426 }
2527
26- public static async Task < bool > RenameAsync ( string repo , string name , string to , Models . ICommandLog log )
28+ public async Task < bool > RenameAsync ( string name , string to )
2729 {
28- var cmd = new Command ( ) ;
29- cmd . WorkingDirectory = repo ;
30- cmd . Context = repo ;
31- cmd . Args = $ "branch -M { name } { to } ";
32- cmd . Log = log ;
33- return await cmd . ExecAsync ( ) . ConfigureAwait ( false ) ;
30+ Args = $ "branch -M { name } { to } ";
31+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
3432 }
3533
36- public static async Task < bool > SetUpstreamAsync ( string repo , string name , string upstream , Models . ICommandLog log )
34+ public async Task < bool > SetUpstreamAsync ( string name , string upstream )
3735 {
38- var cmd = new Command ( ) ;
39- cmd . WorkingDirectory = repo ;
40- cmd . Context = repo ;
41- cmd . Log = log ;
42-
4336 if ( string . IsNullOrEmpty ( upstream ) )
44- cmd . Args = $ "branch { name } --unset-upstream";
37+ Args = $ "branch { name } --unset-upstream";
4538 else
46- cmd . Args = $ "branch { name } -u { upstream } ";
39+ Args = $ "branch { name } -u { upstream } ";
4740
48- return await cmd . ExecAsync ( ) . ConfigureAwait ( false ) ;
41+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
4942 }
5043
51- public static async Task < bool > DeleteLocalAsync ( string repo , string name , Models . ICommandLog log )
44+ public async Task < bool > DeleteLocalAsync ( string name )
5245 {
53- var cmd = new Command ( ) ;
54- cmd . WorkingDirectory = repo ;
55- cmd . Context = repo ;
56- cmd . Args = $ "branch -D { name } ";
57- cmd . Log = log ;
58- return await cmd . ExecAsync ( ) . ConfigureAwait ( false ) ;
46+ Args = $ "branch -D { name } ";
47+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
5948 }
6049
61- public static async Task < bool > DeleteRemoteAsync ( string repo , string remote , string name , Models . ICommandLog log )
50+ public async Task < bool > DeleteRemoteAsync ( string remote , string name )
6251 {
63- bool exists = await new Remote ( repo ) . HasBranchAsync ( remote , name ) . ConfigureAwait ( false ) ;
64- if ( exists )
65- return await new Push ( repo , remote , $ "refs/heads/{ name } ", true ) { Log = log } . RunAsync ( ) . ConfigureAwait ( false ) ;
66-
67- var cmd = new Command ( ) ;
68- cmd . WorkingDirectory = repo ;
69- cmd . Context = repo ;
70- cmd . Args = $ "branch -D -r { remote } /{ name } ";
71- cmd . Log = log ;
72- return await cmd . ExecAsync ( ) . ConfigureAwait ( false ) ;
52+ Args = $ "branch -D -r { remote } /{ name } ";
53+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
7354 }
7455 }
7556}
0 commit comments