3
3
4
4
namespace SourceGit . Commands
5
5
{
6
- public static class Branch
6
+ public class Branch : Command
7
7
{
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 )
9
15
{
10
16
var builder = new StringBuilder ( ) ;
11
17
builder . Append ( "branch " ) ;
@@ -15,61 +21,36 @@ public static async Task<bool> CreateAsync(string repo, string name, string base
15
21
builder . Append ( " " ) ;
16
22
builder . Append ( basedOn ) ;
17
23
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 ) ;
24
26
}
25
27
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 )
27
29
{
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 ) ;
34
32
}
35
33
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 )
37
35
{
38
- var cmd = new Command ( ) ;
39
- cmd . WorkingDirectory = repo ;
40
- cmd . Context = repo ;
41
- cmd . Log = log ;
42
-
43
36
if ( string . IsNullOrEmpty ( upstream ) )
44
- cmd . Args = $ "branch { name } --unset-upstream";
37
+ Args = $ "branch { name } --unset-upstream";
45
38
else
46
- cmd . Args = $ "branch { name } -u { upstream } ";
39
+ Args = $ "branch { name } -u { upstream } ";
47
40
48
- return await cmd . ExecAsync ( ) . ConfigureAwait ( false ) ;
41
+ return await ExecAsync ( ) . ConfigureAwait ( false ) ;
49
42
}
50
43
51
- public static async Task < bool > DeleteLocalAsync ( string repo , string name , Models . ICommandLog log )
44
+ public async Task < bool > DeleteLocalAsync ( string name )
52
45
{
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 ) ;
59
48
}
60
49
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 )
62
51
{
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 ) ;
73
54
}
74
55
}
75
56
}
0 commit comments