@@ -65,352 +65,6 @@ public void GetHeight_Merge()
6565 Assert . Equal ( 3 , this . Repo . Head . GetHeight ( c => c != secondCommit && c != branchCommits [ 2 ] ) ) ;
6666 }
6767
68- [ Fact ]
69- public void GetVersionHeight_Test ( )
70- {
71- var first = this . Repo . Commit ( "First" , this . Signer , this . Signer , new CommitOptions { AllowEmptyCommit = true } ) ;
72- var second = this . Repo . Commit ( "Second" , this . Signer , this . Signer , new CommitOptions { AllowEmptyCommit = true } ) ;
73- this . WriteVersionFile ( ) ;
74- var third = this . Repo . Commit ( "Third" , this . Signer , this . Signer , new CommitOptions { AllowEmptyCommit = true } ) ;
75- Assert . Equal ( 2 , this . GetVersionHeight ( this . Repo . Head ) ) ;
76- }
77-
78- [ Fact ]
79- public void GetVersionHeight_VersionJsonHasUnrelatedHistory ( )
80- {
81- // Emulate a repo that used version.json for something else.
82- string versionJsonPath = Path . Combine ( this . RepoPath , "version.json" ) ;
83- File . WriteAllText ( versionJsonPath , @"{ ""unrelated"": false }" ) ;
84- Assert . Equal ( 0 , this . GetVersionHeight ( ) ) ; // exercise code that handles the file not yet checked in.
85- Commands . Stage ( this . Repo , versionJsonPath ) ;
86- this . Repo . Commit ( "Add unrelated version.json file." , this . Signer , this . Signer ) ;
87- Assert . Equal ( 0 , this . GetVersionHeight ( ) ) ; // exercise code that handles a checked in file.
88-
89- // And now the repo has decided to use this package.
90- this . WriteVersionFile ( ) ;
91-
92- Assert . Equal ( 1 , this . GetVersionHeight ( this . Repo . Head ) ) ;
93- Assert . Equal ( 1 , this . GetVersionHeight ( ) ) ;
94-
95- // Also emulate case of where the related version.json was just changed to conform,
96- // but not yet checked in.
97- this . Repo . Reset ( ResetMode . Mixed , this . Repo . Head . Tip . Parents . Single ( ) ) ;
98- Assert . Equal ( 0 , this . GetVersionHeight ( ) ) ;
99- }
100-
101- [ Fact ]
102- public void GetVersionHeight_VersionJsonHasParsingErrorsInHistory ( )
103- {
104- this . WriteVersionFile ( ) ;
105- Assert . Equal ( 1 , this . GetVersionHeight ( ) ) ;
106-
107- // Now introduce a parsing error.
108- string versionJsonPath = Path . Combine ( this . RepoPath , "version.json" ) ;
109- File . WriteAllText ( versionJsonPath , @"{ ""version"": ""1.0""" ) ; // no closing curly brace for parsing error
110- Assert . Equal ( 0 , this . GetVersionHeight ( ) ) ;
111- Commands . Stage ( this . Repo , versionJsonPath ) ;
112- this . Repo . Commit ( "Add broken version.json file." , this . Signer , this . Signer ) ;
113- Assert . Equal ( 0 , this . GetVersionHeight ( ) ) ;
114-
115- // Now fix it.
116- this . WriteVersionFile ( ) ;
117- Assert . Equal ( 1 , this . GetVersionHeight ( ) ) ;
118-
119- // And emulate fixing it without having checked in yet.
120- this . Repo . Reset ( ResetMode . Mixed , this . Repo . Head . Tip . Parents . Single ( ) ) ;
121- Assert . Equal ( 0 , this . GetVersionHeight ( ) ) ;
122- }
123-
124- [ Fact ]
125- public void GetVersionHeight_IntroducingFiltersIncrementsHeight ( )
126- {
127- string relativeDirectory = "some-sub-dir" ;
128-
129- this . WriteVersionFile ( relativeDirectory : relativeDirectory ) ;
130- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
131-
132- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
133- versionData . PathFilters = new [ ] { new FilterPath ( "./" , relativeDirectory ) } ;
134- this . WriteVersionFile ( versionData , relativeDirectory ) ;
135- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
136- }
137-
138- [ Theory ]
139- [ InlineData ( "./" ) ]
140- [ InlineData ( "../some-sub-dir" ) ]
141- [ InlineData ( "/some-sub-dir" ) ]
142- [ InlineData ( ":/some-sub-dir" ) ]
143- public void GetVersionHeight_IncludeFilter ( string includeFilter )
144- {
145- string relativeDirectory = "some-sub-dir" ;
146-
147- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
148- versionData . PathFilters = new [ ] { new FilterPath ( includeFilter , relativeDirectory ) } ;
149- this . WriteVersionFile ( versionData , relativeDirectory ) ;
150- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
151-
152- // Expect commit outside of project tree to not affect version height
153- var otherFilePath = Path . Combine ( this . RepoPath , "my-file.txt" ) ;
154- File . WriteAllText ( otherFilePath , "hello" ) ;
155- Commands . Stage ( this . Repo , otherFilePath ) ;
156- this . Repo . Commit ( "Add other file outside of project root" , this . Signer , this . Signer ) ;
157- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
158-
159- // Expect commit inside project tree to affect version height
160- var containedFilePath = Path . Combine ( this . RepoPath , relativeDirectory , "another-file.txt" ) ;
161- File . WriteAllText ( containedFilePath , "hello" ) ;
162- Commands . Stage ( this . Repo , containedFilePath ) ;
163- this . Repo . Commit ( "Add file within project root" , this . Signer , this . Signer ) ;
164- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
165- }
166-
167- [ Fact ]
168- public void GetVersionHeight_IncludeExcludeFilter ( )
169- {
170- string relativeDirectory = "some-sub-dir" ;
171-
172- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
173- versionData . PathFilters = new [ ]
174- {
175- new FilterPath ( "./" , relativeDirectory ) ,
176- new FilterPath ( ":^/some-sub-dir/ignore.txt" , relativeDirectory ) ,
177- new FilterPath ( ":^excluded-dir" , relativeDirectory )
178- } ;
179- this . WriteVersionFile ( versionData , relativeDirectory ) ;
180- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
181-
182- // Commit touching excluded path does not affect version height
183- var ignoredFilePath = Path . Combine ( this . RepoPath , relativeDirectory , "ignore.txt" ) ;
184- File . WriteAllText ( ignoredFilePath , "hello" ) ;
185- Commands . Stage ( this . Repo , ignoredFilePath ) ;
186- this . Repo . Commit ( "Add excluded file" , this . Signer , this . Signer ) ;
187- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
188-
189- // Commit touching both excluded and included path does affect height
190- var includedFilePath = Path . Combine ( this . RepoPath , relativeDirectory , "another-file.txt" ) ;
191- File . WriteAllText ( includedFilePath , "hello" ) ;
192- File . WriteAllText ( ignoredFilePath , "changed" ) ;
193- Commands . Stage ( this . Repo , includedFilePath ) ;
194- Commands . Stage ( this . Repo , ignoredFilePath ) ;
195- this . Repo . Commit ( "Change both excluded and included file" , this . Signer , this . Signer ) ;
196- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
197-
198- // Commit touching excluded directory does not affect version height
199- var fileInExcludedDirPath = Path . Combine ( this . RepoPath , relativeDirectory , "excluded-dir" , "ignore.txt" ) ;
200- Directory . CreateDirectory ( Path . GetDirectoryName ( fileInExcludedDirPath ) ) ;
201- File . WriteAllText ( fileInExcludedDirPath , "hello" ) ;
202- Commands . Stage ( this . Repo , fileInExcludedDirPath ) ;
203- this . Repo . Commit ( "Add file to excluded dir" , this . Signer , this . Signer ) ;
204- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
205- }
206-
207- [ Fact ]
208- public void GetVersionHeight_IncludeExcludeFilter_NoProjectDirectory ( )
209- {
210- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
211- versionData . PathFilters = new [ ]
212- {
213- new FilterPath ( "./" , "." ) ,
214- new FilterPath ( ":^/some-sub-dir/ignore.txt" , "." ) ,
215- new FilterPath ( ":^/excluded-dir" , "." )
216- } ;
217- this . WriteVersionFile ( versionData ) ;
218- Assert . Equal ( 1 , this . GetVersionHeight ( ) ) ;
219-
220- // Commit touching excluded path does not affect version height
221- var ignoredFilePath = Path . Combine ( this . RepoPath , "some-sub-dir" , "ignore.txt" ) ;
222- Directory . CreateDirectory ( Path . GetDirectoryName ( ignoredFilePath ) ) ;
223- File . WriteAllText ( ignoredFilePath , "hello" ) ;
224- Commands . Stage ( this . Repo , ignoredFilePath ) ;
225- this . Repo . Commit ( "Add excluded file" , this . Signer , this . Signer ) ;
226- Assert . Equal ( 1 , this . GetVersionHeight ( ) ) ;
227-
228- // Commit touching both excluded and included path does affect height
229- var includedFilePath = Path . Combine ( this . RepoPath , "some-sub-dir" , "another-file.txt" ) ;
230- File . WriteAllText ( includedFilePath , "hello" ) ;
231- File . WriteAllText ( ignoredFilePath , "changed" ) ;
232- Commands . Stage ( this . Repo , includedFilePath ) ;
233- Commands . Stage ( this . Repo , ignoredFilePath ) ;
234- this . Repo . Commit ( "Change both excluded and included file" , this . Signer , this . Signer ) ;
235- Assert . Equal ( 2 , this . GetVersionHeight ( ) ) ;
236-
237- // Commit touching excluded directory does not affect version height
238- var fileInExcludedDirPath = Path . Combine ( this . RepoPath , "excluded-dir" , "ignore.txt" ) ;
239- Directory . CreateDirectory ( Path . GetDirectoryName ( fileInExcludedDirPath ) ) ;
240- File . WriteAllText ( fileInExcludedDirPath , "hello" ) ;
241- Commands . Stage ( this . Repo , fileInExcludedDirPath ) ;
242- this . Repo . Commit ( "Add file to excluded dir" , this . Signer , this . Signer ) ;
243- Assert . Equal ( 2 , this . GetVersionHeight ( ) ) ;
244- }
245-
246- [ Theory ]
247- [ InlineData ( ":^/excluded-dir" ) ]
248- [ InlineData ( ":^../excluded-dir" ) ]
249- public void GetVersionHeight_AddingExcludeDoesNotLowerHeight ( string excludePathFilter )
250- {
251- string relativeDirectory = "some-sub-dir" ;
252-
253- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
254- this . WriteVersionFile ( versionData , relativeDirectory ) ;
255- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
256-
257- // Commit a file which will later be ignored
258- var ignoredFilePath = Path . Combine ( this . RepoPath , "excluded-dir" , "ignore.txt" ) ;
259- Directory . CreateDirectory ( Path . GetDirectoryName ( ignoredFilePath ) ) ;
260- File . WriteAllText ( ignoredFilePath , "hello" ) ;
261- Commands . Stage ( this . Repo , ignoredFilePath ) ;
262- this . Repo . Commit ( "Add file which will later be excluded" , this . Signer , this . Signer ) ;
263- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
264-
265- versionData . PathFilters = new [ ] { new FilterPath ( excludePathFilter , relativeDirectory ) , } ;
266- this . WriteVersionFile ( versionData , relativeDirectory ) ;
267- Assert . Equal ( 3 , this . GetVersionHeight ( relativeDirectory ) ) ;
268-
269- // Committing a change to an ignored file does not increment the version height
270- File . WriteAllText ( ignoredFilePath , "changed" ) ;
271- Commands . Stage ( this . Repo , ignoredFilePath ) ;
272- this . Repo . Commit ( "Change now excluded file" , this . Signer , this . Signer ) ;
273- Assert . Equal ( 3 , this . GetVersionHeight ( relativeDirectory ) ) ;
274- }
275-
276- [ Fact ]
277- public void GetVersionHeight_IncludeRoot ( )
278- {
279- string relativeDirectory = "some-sub-dir" ;
280-
281- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
282- versionData . PathFilters = new [ ] { new FilterPath ( ":/" , relativeDirectory ) } ;
283- this . WriteVersionFile ( versionData , relativeDirectory ) ;
284- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
285-
286- // Expect commit outside of project tree to affect version height
287- var otherFilePath = Path . Combine ( this . RepoPath , "my-file.txt" ) ;
288- File . WriteAllText ( otherFilePath , "hello" ) ;
289- Commands . Stage ( this . Repo , otherFilePath ) ;
290- this . Repo . Commit ( "Add other file outside of project root" , this . Signer , this . Signer ) ;
291- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
292-
293- // Expect commit inside project tree to affect version height
294- var containedFilePath = Path . Combine ( this . RepoPath , relativeDirectory , "another-file.txt" ) ;
295- File . WriteAllText ( containedFilePath , "hello" ) ;
296- Commands . Stage ( this . Repo , containedFilePath ) ;
297- this . Repo . Commit ( "Add file within project root" , this . Signer , this . Signer ) ;
298- Assert . Equal ( 3 , this . GetVersionHeight ( relativeDirectory ) ) ;
299- }
300-
301- [ Fact ]
302- public void GetVersionHeight_IncludeRootExcludeSome ( )
303- {
304- string relativeDirectory = "some-sub-dir" ;
305-
306- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
307- versionData . PathFilters = new [ ]
308- {
309- new FilterPath ( ":/" , relativeDirectory ) ,
310- new FilterPath ( ":^/excluded-dir" , relativeDirectory ) ,
311- } ;
312- this . WriteVersionFile ( versionData , relativeDirectory ) ;
313- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
314-
315- // Expect commit in an excluded directory to not affect version height
316- var ignoredFilePath = Path . Combine ( this . RepoPath , "excluded-dir" , "my-file.txt" ) ;
317- Directory . CreateDirectory ( Path . GetDirectoryName ( ignoredFilePath ) ) ;
318- File . WriteAllText ( ignoredFilePath , "hello" ) ;
319- Commands . Stage ( this . Repo , ignoredFilePath ) ;
320- this . Repo . Commit ( "Add other file to excluded directory" , this . Signer , this . Signer ) ;
321- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
322-
323- // Expect commit within another directory to affect version height
324- var otherFilePath = Path . Combine ( this . RepoPath , "another-dir" , "another-file.txt" ) ;
325- Directory . CreateDirectory ( Path . GetDirectoryName ( otherFilePath ) ) ;
326- File . WriteAllText ( otherFilePath , "hello" ) ;
327- Commands . Stage ( this . Repo , otherFilePath ) ;
328- this . Repo . Commit ( "Add file within project root" , this . Signer , this . Signer ) ;
329- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
330- }
331-
332- [ Fact ]
333- public void GetVersionHeight_ProjectDirectoryDifferentToVersionJsonDirectory ( )
334- {
335- string relativeDirectory = "some-sub-dir" ;
336-
337- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
338- versionData . PathFilters = new [ ]
339- {
340- new FilterPath ( "." , "" )
341- } ;
342- this . WriteVersionFile ( versionData , "" ) ;
343- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
344-
345- // Expect commit in an excluded directory to not affect version height
346- var ignoredFilePath = Path . Combine ( this . RepoPath , "other-dir" , "my-file.txt" ) ;
347- Directory . CreateDirectory ( Path . GetDirectoryName ( ignoredFilePath ) ) ;
348- File . WriteAllText ( ignoredFilePath , "hello" ) ;
349- Commands . Stage ( this . Repo , ignoredFilePath ) ;
350- this . Repo . Commit ( "Add file to other directory" , this . Signer , this . Signer ) ;
351- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
352- }
353-
354- [ Fact ]
355- public void GetVersionHeight_ProjectDirectoryIsMoved ( )
356- {
357- string relativeDirectory = "some-sub-dir" ;
358-
359- var versionData = VersionOptions . FromVersion ( new Version ( "1.2" ) ) ;
360- versionData . PathFilters = new [ ]
361- {
362- new FilterPath ( "./" , relativeDirectory ) ,
363- new FilterPath ( ":^/some-sub-dir/ignore.txt" , relativeDirectory ) ,
364- new FilterPath ( ":^excluded-dir" , relativeDirectory ) ,
365- } ;
366- this . WriteVersionFile ( versionData , relativeDirectory ) ;
367- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
368-
369- // Commit touching excluded path does not affect version height
370- var ignoredFilePath = Path . Combine ( this . RepoPath , relativeDirectory , "ignore.txt" ) ;
371- File . WriteAllText ( ignoredFilePath , "hello" ) ;
372- Commands . Stage ( this . Repo , ignoredFilePath ) ;
373- this . Repo . Commit ( "Add excluded file" , this . Signer , this . Signer ) ;
374- Assert . Equal ( 1 , this . GetVersionHeight ( relativeDirectory ) ) ;
375-
376- // Commit touching both excluded and included path does affect height
377- var includedFilePath = Path . Combine ( this . RepoPath , relativeDirectory , "another-file.txt" ) ;
378- File . WriteAllText ( includedFilePath , "hello" ) ;
379- File . WriteAllText ( ignoredFilePath , "changed" ) ;
380- Commands . Stage ( this . Repo , includedFilePath ) ;
381- Commands . Stage ( this . Repo , ignoredFilePath ) ;
382- this . Repo . Commit ( "Change both excluded and included file" , this . Signer , this . Signer ) ;
383- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
384-
385- // Commit touching excluded directory does not affect version height
386- var fileInExcludedDirPath = Path . Combine ( this . RepoPath , relativeDirectory , "excluded-dir" , "ignore.txt" ) ;
387- Directory . CreateDirectory ( Path . GetDirectoryName ( fileInExcludedDirPath ) ) ;
388- File . WriteAllText ( fileInExcludedDirPath , "hello" ) ;
389- Commands . Stage ( this . Repo , fileInExcludedDirPath ) ;
390- this . Repo . Commit ( "Add file to excluded dir" , this . Signer , this . Signer ) ;
391- Assert . Equal ( 2 , this . GetVersionHeight ( relativeDirectory ) ) ;
392-
393- // Rename the project directory
394- Directory . Move ( Path . Combine ( this . RepoPath , relativeDirectory ) , Path . Combine ( this . RepoPath , "new-project-dir" ) ) ;
395- Commands . Stage ( this . Repo , relativeDirectory ) ;
396- Commands . Stage ( this . Repo , "new-project-dir" ) ;
397- this . Repo . Commit ( "Move project directory" , this . Signer , this . Signer ) ;
398-
399- // Version is reset as project directory cannot be find in the ancestor commit
400- Assert . Equal ( 1 , this . GetVersionHeight ( "new-project-dir" ) ) ;
401- }
402-
403- [ Fact ( Skip = "Slow test" ) ]
404- public void GetVersionHeight_VeryLongHistory ( )
405- {
406- this . WriteVersionFile ( ) ;
407-
408- // Make a *lot* of commits
409- this . AddCommits ( 2000 ) ;
410-
411- this . GetVersionHeight ( ) ;
412- }
413-
41468 [ Fact ]
41569 public void GetCommitsFromVersion_WithPathFilters ( )
41670 {
0 commit comments