@@ -37,6 +37,25 @@ public sealed class Repository : IRepository
37
37
private readonly SubmoduleCollection submodules ;
38
38
private readonly Lazy < PathCase > pathCase ;
39
39
40
+ private enum RepositoryRequiredParameter
41
+ {
42
+ None = 0 ,
43
+ Path = 1 ,
44
+ Options = 2 ,
45
+ }
46
+
47
+ /// <summary>
48
+ /// Initializes a new instance of the <see cref="Repository"/> class
49
+ /// that does not point to an on-disk Git repository. This is
50
+ /// suitable only for custom, in-memory Git repositories that are
51
+ /// configured with custom object database, reference database and/or
52
+ /// configuration backends.
53
+ /// </summary>
54
+ public Repository ( )
55
+ : this ( null , null , RepositoryRequiredParameter . None )
56
+ {
57
+ }
58
+
40
59
/// <summary>
41
60
/// Initializes a new instance of the <see cref="Repository"/> class.
42
61
/// <para>For a standard repository, <paramref name="path"/> may
@@ -51,7 +70,7 @@ public sealed class Repository : IRepository
51
70
/// or the path to the working directory.
52
71
/// </param>
53
72
public Repository ( string path ) :
54
- this ( path , null )
73
+ this ( path , null , RepositoryRequiredParameter . Path )
55
74
{
56
75
}
57
76
@@ -73,9 +92,22 @@ public Repository(string path) :
73
92
/// <param name="options">
74
93
/// Overrides to the way a repository is opened.
75
94
/// </param>
76
- public Repository ( string path , RepositoryOptions options )
95
+ public Repository ( string path , RepositoryOptions options ) :
96
+ this ( path , options , RepositoryRequiredParameter . Path | RepositoryRequiredParameter . Options )
77
97
{
78
- Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
98
+ }
99
+
100
+ private Repository ( string path , RepositoryOptions options , RepositoryRequiredParameter requiredParameter )
101
+ {
102
+ if ( ( requiredParameter & RepositoryRequiredParameter . Path ) == RepositoryRequiredParameter . Path )
103
+ {
104
+ Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
105
+ }
106
+
107
+ if ( ( requiredParameter & RepositoryRequiredParameter . Options ) == RepositoryRequiredParameter . Options )
108
+ {
109
+ Ensure . ArgumentNotNull ( options , "options" ) ;
110
+ }
79
111
80
112
try
81
113
{
@@ -84,6 +116,14 @@ public Repository(string path, RepositoryOptions options)
84
116
85
117
isBare = Proxy . git_repository_is_bare ( handle ) ;
86
118
119
+ /* TODO: bug in libgit2, update when fixed by
120
+ * https://github.com/libgit2/libgit2/pull/2970
121
+ */
122
+ if ( path == null )
123
+ {
124
+ isBare = true ;
125
+ }
126
+
87
127
Func < Index > indexBuilder = ( ) => new Index ( this ) ;
88
128
89
129
string configurationGlobalFilePath = null ;
@@ -764,7 +804,7 @@ private void CheckoutTree(
764
804
IConvertableToGitCheckoutOpts opts )
765
805
{
766
806
767
- using ( GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper ( opts , ToFilePaths ( paths ) ) )
807
+ using ( GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper ( opts , ToFilePaths ( paths ) ) )
768
808
{
769
809
var options = checkoutOptionsWrapper . Options ;
770
810
Proxy . git_checkout_tree ( Handle , tree . Id , ref options ) ;
@@ -935,7 +975,7 @@ private void UpdateHeadAndTerminalReference(Commit commit, string reflogMessage)
935
975
return ;
936
976
}
937
977
938
- var symRef = ( SymbolicReference ) reference ;
978
+ var symRef = ( SymbolicReference ) reference ;
939
979
940
980
reference = symRef . Target ;
941
981
@@ -1294,7 +1334,7 @@ private MergeResult Merge(GitAnnotatedCommitHandle[] annotatedCommits, Signature
1294
1334
FastForwardStrategy fastForwardStrategy = ( options . FastForwardStrategy != FastForwardStrategy . Default ) ?
1295
1335
options . FastForwardStrategy : FastForwardStrategyFromMergePreference ( mergePreference ) ;
1296
1336
1297
- switch ( fastForwardStrategy )
1337
+ switch ( fastForwardStrategy )
1298
1338
{
1299
1339
case FastForwardStrategy . Default :
1300
1340
if ( mergeAnalysis . HasFlag ( GitMergeAnalysis . GIT_MERGE_ANALYSIS_FASTFORWARD ) )
@@ -1362,14 +1402,14 @@ private MergeResult NormalMerge(GitAnnotatedCommitHandle[] annotatedCommits, Sig
1362
1402
MergeResult mergeResult ;
1363
1403
1364
1404
var mergeOptions = new GitMergeOpts
1365
- {
1366
- Version = 1 ,
1367
- MergeFileFavorFlags = options . MergeFileFavor ,
1368
- MergeTreeFlags = options . FindRenames ? GitMergeTreeFlags . GIT_MERGE_TREE_FIND_RENAMES :
1369
- GitMergeTreeFlags . GIT_MERGE_TREE_NORMAL ,
1370
- RenameThreshold = ( uint ) options . RenameThreshold ,
1371
- TargetLimit = ( uint ) options . TargetLimit ,
1372
- } ;
1405
+ {
1406
+ Version = 1 ,
1407
+ MergeFileFavorFlags = options . MergeFileFavor ,
1408
+ MergeTreeFlags = options . FindRenames ? GitMergeTreeFlags . GIT_MERGE_TREE_FIND_RENAMES :
1409
+ GitMergeTreeFlags . GIT_MERGE_TREE_NORMAL ,
1410
+ RenameThreshold = ( uint ) options . RenameThreshold ,
1411
+ TargetLimit = ( uint ) options . TargetLimit ,
1412
+ } ;
1373
1413
1374
1414
using ( GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper ( options ) )
1375
1415
{
@@ -1407,7 +1447,7 @@ private MergeResult NormalMerge(GitAnnotatedCommitHandle[] annotatedCommits, Sig
1407
1447
private MergeResult FastForwardMerge ( GitAnnotatedCommitHandle annotatedCommit , Signature merger , MergeOptions options )
1408
1448
{
1409
1449
ObjectId id = Proxy . git_annotated_commit_id ( annotatedCommit ) ;
1410
- Commit fastForwardCommit = ( Commit ) Lookup ( id , ObjectType . Commit ) ;
1450
+ Commit fastForwardCommit = ( Commit ) Lookup ( id , ObjectType . Commit ) ;
1411
1451
Ensure . GitObjectIsNotNull ( fastForwardCommit , id . Sha ) ;
1412
1452
1413
1453
CheckoutTree ( fastForwardCommit . Tree , null , new FastForwardCheckoutOptionsAdapter ( options ) ) ;
@@ -1882,7 +1922,7 @@ private IEnumerable<string> RemoveStagedItems(IEnumerable<string> paths, bool re
1882
1922
case ChangeKind . Unmodified :
1883
1923
if ( removeFromWorkingDirectory && (
1884
1924
status . HasFlag ( FileStatus . Staged ) ||
1885
- status . HasFlag ( FileStatus . Added ) ) )
1925
+ status . HasFlag ( FileStatus . Added ) ) )
1886
1926
{
1887
1927
throw new RemoveFromIndexException ( string . Format ( CultureInfo . InvariantCulture , "Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only." ,
1888
1928
treeEntryChanges . Path ) ) ;
0 commit comments