1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Text ;
4
3
5
4
using Avalonia . Threading ;
@@ -8,34 +7,6 @@ namespace SourceGit.Commands
8
7
{
9
8
public static class GitFlow
10
9
{
11
- public class BranchDetectResult
12
- {
13
- public bool IsGitFlowBranch { get ; set ; } = false ;
14
- public string Type { get ; set ; } = string . Empty ;
15
- public string Prefix { get ; set ; } = string . Empty ;
16
- }
17
-
18
- public static bool IsEnabled ( string repo , List < Models . Branch > branches )
19
- {
20
- var localBrancheNames = new HashSet < string > ( ) ;
21
- foreach ( var branch in branches )
22
- {
23
- if ( branch . IsLocal )
24
- localBrancheNames . Add ( branch . Name ) ;
25
- }
26
-
27
- var config = new Config ( repo ) . ListAll ( ) ;
28
- if ( ! config . TryGetValue ( "gitflow.branch.master" , out string master ) || ! localBrancheNames . Contains ( master ) )
29
- return false ;
30
-
31
- if ( ! config . TryGetValue ( "gitflow.branch.develop" , out string develop ) || ! localBrancheNames . Contains ( develop ) )
32
- return false ;
33
-
34
- return config . ContainsKey ( "gitflow.prefix.feature" ) &&
35
- config . ContainsKey ( "gitflow.prefix.release" ) &&
36
- config . ContainsKey ( "gitflow.prefix.hotfix" ) ;
37
- }
38
-
39
10
public static bool Init ( string repo , List < Models . Branch > branches , string master , string develop , string feature , string release , string hotfix , string version , Models . ICommandLog log )
40
11
{
41
12
var current = branches . Find ( x => x . IsCurrent ) ;
@@ -66,90 +37,53 @@ public static bool Init(string repo, List<Models.Branch> branches, string master
66
37
return init . Exec ( ) ;
67
38
}
68
39
69
- public static string GetPrefix ( string repo , string type )
40
+ public static bool Start ( string repo , Models . GitFlowBranchType type , string name , Models . ICommandLog log )
70
41
{
71
- return new Config ( repo ) . Get ( $ "gitflow.prefix.{ type } ") ;
72
- }
73
-
74
- public static BranchDetectResult DetectType ( string repo , List < Models . Branch > branches , string branch )
75
- {
76
- var rs = new BranchDetectResult ( ) ;
77
- var localBrancheNames = new HashSet < string > ( ) ;
78
- foreach ( var b in branches )
79
- {
80
- if ( b . IsLocal )
81
- localBrancheNames . Add ( b . Name ) ;
82
- }
83
-
84
- var config = new Config ( repo ) . ListAll ( ) ;
85
- if ( ! config . TryGetValue ( "gitflow.branch.master" , out string master ) || ! localBrancheNames . Contains ( master ) )
86
- return rs ;
87
-
88
- if ( ! config . TryGetValue ( "gitflow.branch.develop" , out string develop ) || ! localBrancheNames . Contains ( develop ) )
89
- return rs ;
90
-
91
- if ( ! config . TryGetValue ( "gitflow.prefix.feature" , out var feature ) ||
92
- ! config . TryGetValue ( "gitflow.prefix.release" , out var release ) ||
93
- ! config . TryGetValue ( "gitflow.prefix.hotfix" , out var hotfix ) )
94
- return rs ;
95
-
96
- if ( branch . StartsWith ( feature , StringComparison . Ordinal ) )
97
- {
98
- rs . IsGitFlowBranch = true ;
99
- rs . Type = "feature" ;
100
- rs . Prefix = feature ;
101
- }
102
- else if ( branch . StartsWith ( release , StringComparison . Ordinal ) )
103
- {
104
- rs . IsGitFlowBranch = true ;
105
- rs . Type = "release" ;
106
- rs . Prefix = release ;
107
- }
108
- else if ( branch . StartsWith ( hotfix , StringComparison . Ordinal ) )
109
- {
110
- rs . IsGitFlowBranch = true ;
111
- rs . Type = "hotfix" ;
112
- rs . Prefix = hotfix ;
113
- }
114
-
115
- return rs ;
116
- }
42
+ var start = new Command ( ) ;
43
+ start . WorkingDirectory = repo ;
44
+ start . Context = repo ;
117
45
118
- public static bool Start ( string repo , string type , string name , Models . ICommandLog log )
119
- {
120
- if ( ! SUPPORTED_BRANCH_TYPES . Contains ( type ) )
46
+ switch ( type )
121
47
{
122
- Dispatcher . UIThread . Post ( ( ) =>
123
- {
124
- App . RaiseException ( repo , "Bad branch type!!!" ) ;
125
- } ) ;
126
-
127
- return false ;
48
+ case Models . GitFlowBranchType . Feature :
49
+ start . Args = $ "flow feature start { name } ";
50
+ break ;
51
+ case Models . GitFlowBranchType . Release :
52
+ start . Args = $ "flow release start { name } ";
53
+ break ;
54
+ case Models . GitFlowBranchType . Hotfix :
55
+ start . Args = $ "flow hotfix start { name } ";
56
+ break ;
57
+ default :
58
+ Dispatcher . UIThread . Invoke ( ( ) => App . RaiseException ( repo , "Bad git-flow branch type!!!" ) ) ;
59
+ return false ;
128
60
}
129
61
130
- var start = new Command ( ) ;
131
- start . WorkingDirectory = repo ;
132
- start . Context = repo ;
133
- start . Args = $ "flow { type } start { name } ";
134
62
start . Log = log ;
135
63
return start . Exec ( ) ;
136
64
}
137
65
138
- public static bool Finish ( string repo , string type , string name , bool squash , bool push , bool keepBranch , Models . ICommandLog log )
66
+ public static bool Finish ( string repo , Models . GitFlowBranchType type , string name , bool squash , bool push , bool keepBranch , Models . ICommandLog log )
139
67
{
140
- if ( ! SUPPORTED_BRANCH_TYPES . Contains ( type ) )
141
- {
142
- Dispatcher . UIThread . Post ( ( ) =>
143
- {
144
- App . RaiseException ( repo , "Bad branch type!!!" ) ;
145
- } ) ;
68
+ var builder = new StringBuilder ( ) ;
69
+ builder . Append ( "flow " ) ;
146
70
147
- return false ;
71
+ switch ( type )
72
+ {
73
+ case Models . GitFlowBranchType . Feature :
74
+ builder . Append ( "feature" ) ;
75
+ break ;
76
+ case Models . GitFlowBranchType . Release :
77
+ builder . Append ( "release" ) ;
78
+ break ;
79
+ case Models . GitFlowBranchType . Hotfix :
80
+ builder . Append ( "hotfix" ) ;
81
+ break ;
82
+ default :
83
+ Dispatcher . UIThread . Invoke ( ( ) => App . RaiseException ( repo , "Bad git-flow branch type!!!" ) ) ;
84
+ return false ;
148
85
}
149
86
150
- var builder = new StringBuilder ( ) ;
151
- builder . Append ( "flow " ) ;
152
- builder . Append ( type ) ;
153
87
builder . Append ( " finish " ) ;
154
88
if ( squash )
155
89
builder . Append ( "--squash " ) ;
@@ -166,14 +100,5 @@ public static bool Finish(string repo, string type, string name, bool squash, bo
166
100
finish . Log = log ;
167
101
return finish . Exec ( ) ;
168
102
}
169
-
170
- private static readonly List < string > SUPPORTED_BRANCH_TYPES = new List < string > ( )
171
- {
172
- "feature" ,
173
- "release" ,
174
- "bugfix" ,
175
- "hotfix" ,
176
- "support" ,
177
- } ;
178
103
}
179
104
}
0 commit comments