@@ -9,25 +9,56 @@ namespace GitHub.Unity
9
9
[ Serializable ]
10
10
public struct ConfigRemote
11
11
{
12
- public string Name ;
13
- public string Url ;
12
+ public static ConfigRemote Default = new ConfigRemote ( String . Empty , String . Empty ) ;
13
+
14
+ public string name ;
15
+ public string url ;
16
+
17
+ public ConfigRemote ( string name , string url )
18
+ {
19
+ this . name = name ;
20
+ this . url = url ;
21
+ }
22
+
23
+ public string Name => name ;
24
+
25
+ public string Url => url ;
14
26
15
27
public override string ToString ( )
16
28
{
17
- return String . Format ( "{{Remote {0 } {1 }}}" , Name , Url ) ;
29
+ return $ "{{Remote { Name } { Url } }}";
18
30
}
19
31
}
20
32
21
33
[ Serializable ]
22
34
public struct ConfigBranch
23
35
{
24
- public string Name ;
25
- public ConfigRemote ? Remote ;
36
+ public static ConfigBranch Default = new ConfigBranch ( String . Empty ) ;
37
+
38
+ public string name ;
39
+ public ConfigRemote remote ;
40
+
41
+ public ConfigBranch ( string name )
42
+ {
43
+ this . name = name ;
44
+ remote = ConfigRemote . Default ;
45
+ }
46
+
47
+ public ConfigBranch ( string name , ConfigRemote ? remote )
48
+ {
49
+ this . name = name ;
50
+ this . remote = remote ?? ConfigRemote . Default ;
51
+ }
52
+
26
53
public bool IsTracking => Remote . HasValue ;
27
54
55
+ public string Name => name ;
56
+
57
+ public ConfigRemote ? Remote => Equals ( remote , ConfigRemote . Default ) ? ( ConfigRemote ? ) null : remote ;
58
+
28
59
public override string ToString ( )
29
60
{
30
- return String . Format ( "{{Branch {0 } {1}}}" , Name , Remote ? . ToString ( ) ?? "Untracked" ) ;
61
+ return $ "{{Branch { Name } { Remote ? . ToString ( ) ?? "Untracked" } }}" ;
31
62
}
32
63
}
33
64
@@ -74,11 +105,7 @@ public IEnumerable<ConfigBranch> GetBranches()
74
105
return groups
75
106
. Where ( x => x . Key == "branch" )
76
107
. SelectMany ( x => x . Value )
77
- . Select ( x => new ConfigBranch
78
- {
79
- Name = x . Key ,
80
- Remote = GetRemote ( x . Value . TryGetString ( "remote" ) )
81
- } ) ;
108
+ . Select ( x => new ConfigBranch ( x . Key , GetRemote ( x . Value . TryGetString ( "remote" ) ) ) ) ;
82
109
}
83
110
84
111
public IEnumerable < ConfigRemote > GetRemotes ( )
@@ -87,11 +114,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
87
114
. Where ( x => x . Key == "remote" )
88
115
. SelectMany ( x => x . Value )
89
116
. Where ( x => x . Value . TryGetString ( "url" ) != null )
90
- . Select ( x => new ConfigRemote
91
- {
92
- Name = x . Key ,
93
- Url = x . Value . TryGetString ( "url" )
94
- } ) ;
117
+ . Select ( x => new ConfigRemote ( x . Key , x . Value . TryGetString ( "url" ) ) ) ;
95
118
}
96
119
97
120
public ConfigRemote ? GetRemote ( string remote )
@@ -100,11 +123,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
100
123
. Where ( x => x . Key == "remote" )
101
124
. SelectMany ( x => x . Value )
102
125
. Where ( x => x . Key == remote && x . Value . TryGetString ( "url" ) != null )
103
- . Select ( x => new ConfigRemote
104
- {
105
- Name = x . Key ,
106
- Url = x . Value . GetString ( "url" )
107
- } as ConfigRemote ? )
126
+ . Select ( x => new ConfigRemote ( x . Key , x . Value . GetString ( "url" ) ) as ConfigRemote ? )
108
127
. FirstOrDefault ( ) ;
109
128
}
110
129
@@ -114,11 +133,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
114
133
. Where ( x => x . Key == "branch" )
115
134
. SelectMany ( x => x . Value )
116
135
. Where ( x => x . Key == branch )
117
- . Select ( x => new ConfigBranch
118
- {
119
- Name = x . Key ,
120
- Remote = GetRemote ( x . Value . TryGetString ( "remote" ) )
121
- } as ConfigBranch ? )
136
+ . Select ( x => new ConfigBranch ( x . Key , GetRemote ( x . Value . TryGetString ( "remote" ) ) ) as ConfigBranch ? )
122
137
. FirstOrDefault ( ) ;
123
138
}
124
139
0 commit comments