File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using LibGit2Sharp . Tests . TestHelpers ;
3
+ using Xunit ;
4
+ using Xunit . Extensions ;
5
+
6
+ namespace LibGit2Sharp . Tests
7
+ {
8
+ public class CommitFilterFixture : BaseFixture
9
+ {
10
+ [ Theory ]
11
+ [ InlineData ( "HEAD^" , "HEAD^" , null ) ]
12
+ [ InlineData ( "HEAD^..HEAD" , "HEAD" , "HEAD^" ) ]
13
+ [ InlineData ( "HEAD^.." , null , "HEAD^" ) ]
14
+ public void tada ( string expression , object includeReachableFrom , object excludeReachableFrom )
15
+ {
16
+ CommitFilter cf = CommitFilter . Parse ( expression ) ;
17
+
18
+ Assert . Equal ( includeReachableFrom , cf . IncludeReachableFrom ) ;
19
+ Assert . Equal ( excludeReachableFrom , cf . ExcludeReachableFrom ) ;
20
+ }
21
+
22
+ [ Fact ]
23
+ public void throws ( )
24
+ {
25
+ Assert . Throws < ArgumentException > ( ( ) => CommitFilter . Parse ( "" ) ) ;
26
+ Assert . Throws < ArgumentNullException > ( ( ) => CommitFilter . Parse ( default ( string ) ) ) ;
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change 60
60
<Compile Include =" ArchiveTarFixture.cs" />
61
61
<Compile Include =" CheckoutFixture.cs" />
62
62
<Compile Include =" CherryPickFixture.cs" />
63
+ <Compile Include =" CommitFilterFixture.cs" />
63
64
<Compile Include =" DescribeFixture.cs" />
64
65
<Compile Include =" FileHistoryFixture.cs" />
65
66
<Compile Include =" FilterFixture.cs" />
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
+ using System . Diagnostics ;
4
5
using System . Linq ;
6
+ using LibGit2Sharp . Core ;
5
7
6
8
namespace LibGit2Sharp
7
9
{
@@ -121,5 +123,43 @@ private static IList<object> ToList(object obj)
121
123
list . AddRange ( ( ( IEnumerable ) obj ) . Cast < object > ( ) ) ;
122
124
return list ;
123
125
}
126
+
127
+ public static CommitFilter Parse ( string expression )
128
+ {
129
+ Ensure . ArgumentNotNullOrEmptyString ( expression , "expression" ) ;
130
+
131
+ if ( expression . Contains ( " " ) )
132
+ {
133
+ throw new NotSupportedException ( ) ;
134
+ }
135
+
136
+ if ( expression . Contains ( "..." ) )
137
+ {
138
+ return MergeRangeParse ( expression ) ;
139
+ }
140
+
141
+ if ( expression . Contains ( ".." ) )
142
+ {
143
+ return RangeParse ( expression ) ;
144
+ }
145
+
146
+ return new CommitFilter { IncludeReachableFrom = expression } ;
147
+ }
148
+
149
+ private static CommitFilter MergeRangeParse ( string expression )
150
+ {
151
+ throw new NotImplementedException ( ) ;
152
+ }
153
+
154
+ private static CommitFilter RangeParse ( string expression )
155
+ {
156
+ var parts = expression . Split ( new [ ] { ".." } , StringSplitOptions . None ) ;
157
+
158
+ Debug . Assert ( parts . Length == 2 ) ;
159
+
160
+ Func < string , string > nullify = ( s ) => s == string . Empty ? null : s ;
161
+
162
+ return new CommitFilter { IncludeReachableFrom = nullify ( parts [ 1 ] ) , ExcludeReachableFrom = nullify ( parts [ 0 ] ) } ;
163
+ }
124
164
}
125
165
}
You can’t perform that action at this time.
0 commit comments