1- using System . Linq ;
1+ using System . Collections . Generic ;
2+ using System . Linq ;
23using LibGit2Sharp . Tests . TestHelpers ;
34using Xunit ;
45using Xunit . Extensions ;
@@ -75,25 +76,30 @@ public void CanReplaceRefSpecs(string[] newFetchRefSpecs, string[] newPushRefSpe
7576 var path = SandboxStandardTestRepo ( ) ;
7677 using ( var repo = new Repository ( path ) )
7778 {
78- var remote = repo . Network . Remotes [ "origin" ] ;
79- var oldRefSpecs = remote . RefSpecs . ToList ( ) ;
80-
81- var newRemote = repo . Network . Remotes . Update ( remote ,
82- r => r . FetchRefSpecs = newFetchRefSpecs , r => r . PushRefSpecs = newPushRefSpecs ) ;
83-
84- Assert . Equal ( oldRefSpecs , remote . RefSpecs . ToList ( ) ) ;
79+ List < RefSpec > oldRefSpecs ;
80+ using ( var remote = repo . Network . Remotes [ "origin" ] )
81+ {
82+ oldRefSpecs = remote . RefSpecs . ToList ( ) ;
8583
86- var actualNewFetchRefSpecs = newRemote . RefSpecs
87- . Where ( s => s . Direction == RefSpecDirection . Fetch )
88- . Select ( r => r . Specification )
89- . ToArray ( ) ;
90- Assert . Equal ( newFetchRefSpecs , actualNewFetchRefSpecs ) ;
84+ repo . Network . Remotes . Update ( "origin" ,
85+ r => r . FetchRefSpecs = newFetchRefSpecs , r => r . PushRefSpecs = newPushRefSpecs ) ;
86+ Assert . Equal ( oldRefSpecs , remote . RefSpecs . ToList ( ) ) ;
87+ }
9188
92- var actualNewPushRefSpecs = newRemote . RefSpecs
93- . Where ( s => s . Direction == RefSpecDirection . Push )
94- . Select ( r => r . Specification )
95- . ToArray ( ) ;
96- Assert . Equal ( newPushRefSpecs , actualNewPushRefSpecs ) ;
89+ using ( var newRemote = repo . Network . Remotes [ "origin" ] )
90+ {
91+ var actualNewFetchRefSpecs = newRemote . RefSpecs
92+ . Where ( s => s . Direction == RefSpecDirection . Fetch )
93+ . Select ( r => r . Specification )
94+ . ToArray ( ) ;
95+ Assert . Equal ( newFetchRefSpecs , actualNewFetchRefSpecs ) ;
96+
97+ var actualNewPushRefSpecs = newRemote . RefSpecs
98+ . Where ( s => s . Direction == RefSpecDirection . Push )
99+ . Select ( r => r . Specification )
100+ . ToArray ( ) ;
101+ Assert . Equal ( newPushRefSpecs , actualNewPushRefSpecs ) ;
102+ }
97103 }
98104 }
99105
@@ -105,15 +111,12 @@ public void RemoteUpdaterSavesRefSpecsPermanently()
105111
106112 using ( var repo = new Repository ( path ) )
107113 {
108- using ( var remote = repo . Network . Remotes [ "origin" ] )
109- {
110- repo . Network . Remotes . Update ( remote , r => r . FetchRefSpecs = fetchRefSpecs ) ;
111- }
114+ repo . Network . Remotes . Update ( "origin" , r => r . FetchRefSpecs = fetchRefSpecs ) ;
112115 }
113116
114117 using ( var repo = new Repository ( path ) )
118+ using ( var remote = repo . Network . Remotes [ "origin" ] )
115119 {
116- var remote = repo . Network . Remotes [ "origin" ] ;
117120 var actualRefSpecs = remote . RefSpecs
118121 . Where ( r => r . Direction == RefSpecDirection . Fetch )
119122 . Select ( r => r . Specification )
@@ -129,22 +132,25 @@ public void CanAddAndRemoveRefSpecs()
129132 var path = SandboxStandardTestRepo ( ) ;
130133
131134 using ( var repo = new Repository ( path ) )
132- using ( var remote = repo . Network . Remotes [ "origin" ] )
133135 {
134- using ( var updatedRemote = repo . Network . Remotes . Update ( remote ,
136+ repo . Network . Remotes . Update ( "origin" ,
135137 r => r . FetchRefSpecs . Add ( newRefSpec ) ,
136- r => r . PushRefSpecs . Add ( newRefSpec ) ) )
138+ r => r . PushRefSpecs . Add ( newRefSpec ) ) ;
139+
140+ using ( var remote = repo . Network . Remotes [ "origin" ] )
141+ {
142+ Assert . Contains ( newRefSpec , remote . FetchRefSpecs . Select ( r => r . Specification ) ) ;
143+ Assert . Contains ( newRefSpec , remote . PushRefSpecs . Select ( r => r . Specification ) ) ;
144+ }
145+
146+ repo . Network . Remotes . Update ( "origin" ,
147+ r => r . FetchRefSpecs . Remove ( newRefSpec ) ,
148+ r => r . PushRefSpecs . Remove ( newRefSpec ) ) ;
149+
150+ using ( var remote = repo . Network . Remotes [ "origin" ] )
137151 {
138- Assert . Contains ( newRefSpec , updatedRemote . FetchRefSpecs . Select ( r => r . Specification ) ) ;
139- Assert . Contains ( newRefSpec , updatedRemote . PushRefSpecs . Select ( r => r . Specification ) ) ;
140-
141- using ( var updatedRemote2 = repo . Network . Remotes . Update ( updatedRemote ,
142- r => r . FetchRefSpecs . Remove ( newRefSpec ) ,
143- r => r . PushRefSpecs . Remove ( newRefSpec ) ) )
144- {
145- Assert . DoesNotContain ( newRefSpec , updatedRemote2 . FetchRefSpecs . Select ( r => r . Specification ) ) ;
146- Assert . DoesNotContain ( newRefSpec , updatedRemote2 . PushRefSpecs . Select ( r => r . Specification ) ) ;
147- }
152+ Assert . DoesNotContain ( newRefSpec , remote . FetchRefSpecs . Select ( r => r . Specification ) ) ;
153+ Assert . DoesNotContain ( newRefSpec , remote . PushRefSpecs . Select ( r => r . Specification ) ) ;
148154 }
149155 }
150156 }
@@ -155,18 +161,20 @@ public void CanClearRefSpecs()
155161 var path = SandboxStandardTestRepo ( ) ;
156162 using ( var repo = new Repository ( path ) )
157163 {
158- var remote = repo . Network . Remotes [ "origin" ] ;
159164
160165 // Push refspec does not exist in cloned repository
161- remote = repo . Network . Remotes . Update ( remote , r => r . PushRefSpecs . Add ( "+refs/test:refs/test" ) ) ;
166+ repo . Network . Remotes . Update ( "origin" , r => r . PushRefSpecs . Add ( "+refs/test:refs/test" ) ) ;
162167
163- remote = repo . Network . Remotes . Update ( remote ,
168+ repo . Network . Remotes . Update ( "origin" ,
164169 r => r . FetchRefSpecs . Clear ( ) ,
165170 r => r . PushRefSpecs . Clear ( ) ) ;
166171
167- Assert . Empty ( remote . FetchRefSpecs ) ;
168- Assert . Empty ( remote . PushRefSpecs ) ;
169- Assert . Empty ( remote . RefSpecs ) ;
172+ using ( var remote = repo . Network . Remotes [ "origin" ] )
173+ {
174+ Assert . Empty ( remote . FetchRefSpecs ) ;
175+ Assert . Empty ( remote . PushRefSpecs ) ;
176+ Assert . Empty ( remote . RefSpecs ) ;
177+ }
170178 }
171179 }
172180
@@ -183,11 +191,14 @@ public void SettingInvalidRefSpecsThrows(string refSpec)
183191 var path = SandboxStandardTestRepo ( ) ;
184192 using ( var repo = new Repository ( path ) )
185193 {
186- var remote = repo . Network . Remotes [ "origin" ] ;
187- var oldRefSpecs = remote . RefSpecs . Select ( r => r . Specification ) . ToList ( ) ;
194+ IEnumerable < string > oldRefSpecs ;
195+ using ( var remote = repo . Network . Remotes [ "origin" ] )
196+ {
197+ oldRefSpecs = remote . RefSpecs . Select ( r => r . Specification ) . ToList ( ) ;
198+ }
188199
189200 Assert . Throws < InvalidSpecificationException > ( ( ) =>
190- repo . Network . Remotes . Update ( remote , r => r . FetchRefSpecs . Add ( refSpec ) ) ) ;
201+ repo . Network . Remotes . Update ( "origin" , r => r . FetchRefSpecs . Add ( refSpec ) ) ) ;
191202
192203 var newRemote = repo . Network . Remotes [ "origin" ] ;
193204 Assert . Equal ( oldRefSpecs , newRemote . RefSpecs . Select ( r => r . Specification ) . ToList ( ) ) ;
0 commit comments