Skip to content

Commit 1a815ac

Browse files
author
Edward Thomson
committed
Repository: remove optional params on ctor
1 parent 1533ddf commit 1a815ac

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

LibGit2Sharp/Repository.cs

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,48 @@ public sealed class Repository : IRepository
3838
private readonly Lazy<PathCase> pathCase;
3939

4040
/// <summary>
41-
/// Initializes a new instance of the <see cref="Repository"/> class, providing ooptional behavioral overrides through <paramref name="options"/> parameter.
42-
/// <para>For a standard repository, <paramref name="path"/> should either point to the ".git" folder or to the working directory. For a bare repository, <paramref name="path"/> should directly point to the repository folder.</para>
41+
/// Initializes a new instance of the <see cref="Repository"/> class.
42+
/// <para>For a standard repository, <paramref name="path"/> may
43+
/// either point to the ".git" folder or to the working directory.
44+
/// For a bare repository, <paramref name="path"/> should directly
45+
/// point to the repository folder.</para>
4346
/// </summary>
4447
/// <param name="path">
45-
/// The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this
46-
/// would be the ".git" folder inside the working directory) or the path to the working directory.
48+
/// The path to the git repository to open, can be either the
49+
/// path to the git directory (for non-bare repositories this
50+
/// would be the ".git" folder inside the working directory)
51+
/// or the path to the working directory.
52+
/// </param>
53+
public Repository(string path) :
54+
this(path, null)
55+
{
56+
}
57+
58+
/// <summary>
59+
/// Initializes a new instance of the <see cref="Repository"/> class,
60+
/// providing optional behavioral overrides through the
61+
/// <paramref name="options"/> parameter.
62+
/// <para>For a standard repository, <paramref name="path"/> may
63+
/// either point to the ".git" folder or to the working directory.
64+
/// For a bare repository, <paramref name="path"/> should directly
65+
/// point to the repository folder.</para>
66+
/// </summary>
67+
/// <param name="path">
68+
/// The path to the git repository to open, can be either the
69+
/// path to the git directory (for non-bare repositories this
70+
/// would be the ".git" folder inside the working directory)
71+
/// or the path to the working directory.
4772
/// </param>
4873
/// <param name="options">
4974
/// Overrides to the way a repository is opened.
5075
/// </param>
51-
public Repository(string path, RepositoryOptions options = null)
76+
public Repository(string path, RepositoryOptions options)
5277
{
5378
Ensure.ArgumentNotNullOrEmptyString(path, "path");
5479

5580
try
5681
{
57-
handle = Proxy.git_repository_open(path);
82+
handle = (path != null) ? Proxy.git_repository_open(path) : Proxy.git_repository_new();
5883
RegisterForCleanup(handle);
5984

6085
isBare = Proxy.git_repository_is_bare(handle);
@@ -739,7 +764,7 @@ private void CheckoutTree(
739764
IConvertableToGitCheckoutOpts opts)
740765
{
741766

742-
using(GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(opts, ToFilePaths(paths)))
767+
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(opts, ToFilePaths(paths)))
743768
{
744769
var options = checkoutOptionsWrapper.Options;
745770
Proxy.git_checkout_tree(Handle, tree.Id, ref options);
@@ -910,7 +935,7 @@ private void UpdateHeadAndTerminalReference(Commit commit, string reflogMessage)
910935
return;
911936
}
912937

913-
var symRef = (SymbolicReference) reference;
938+
var symRef = (SymbolicReference)reference;
914939

915940
reference = symRef.Target;
916941

@@ -1269,7 +1294,7 @@ private MergeResult Merge(GitAnnotatedCommitHandle[] annotatedCommits, Signature
12691294
FastForwardStrategy fastForwardStrategy = (options.FastForwardStrategy != FastForwardStrategy.Default) ?
12701295
options.FastForwardStrategy : FastForwardStrategyFromMergePreference(mergePreference);
12711296

1272-
switch(fastForwardStrategy)
1297+
switch (fastForwardStrategy)
12731298
{
12741299
case FastForwardStrategy.Default:
12751300
if (mergeAnalysis.HasFlag(GitMergeAnalysis.GIT_MERGE_ANALYSIS_FASTFORWARD))
@@ -1337,14 +1362,14 @@ private MergeResult NormalMerge(GitAnnotatedCommitHandle[] annotatedCommits, Sig
13371362
MergeResult mergeResult;
13381363

13391364
var mergeOptions = new GitMergeOpts
1340-
{
1341-
Version = 1,
1342-
MergeFileFavorFlags = options.MergeFileFavor,
1343-
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES :
1344-
GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
1345-
RenameThreshold = (uint) options.RenameThreshold,
1346-
TargetLimit = (uint) options.TargetLimit,
1347-
};
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+
};
13481373

13491374
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
13501375
{
@@ -1382,7 +1407,7 @@ private MergeResult NormalMerge(GitAnnotatedCommitHandle[] annotatedCommits, Sig
13821407
private MergeResult FastForwardMerge(GitAnnotatedCommitHandle annotatedCommit, Signature merger, MergeOptions options)
13831408
{
13841409
ObjectId id = Proxy.git_annotated_commit_id(annotatedCommit);
1385-
Commit fastForwardCommit = (Commit) Lookup(id, ObjectType.Commit);
1410+
Commit fastForwardCommit = (Commit)Lookup(id, ObjectType.Commit);
13861411
Ensure.GitObjectIsNotNull(fastForwardCommit, id.Sha);
13871412

13881413
CheckoutTree(fastForwardCommit.Tree, null, new FastForwardCheckoutOptionsAdapter(options));
@@ -1857,7 +1882,7 @@ private IEnumerable<string> RemoveStagedItems(IEnumerable<string> paths, bool re
18571882
case ChangeKind.Unmodified:
18581883
if (removeFromWorkingDirectory && (
18591884
status.HasFlag(FileStatus.Staged) ||
1860-
status.HasFlag(FileStatus.Added) ))
1885+
status.HasFlag(FileStatus.Added)))
18611886
{
18621887
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.",
18631888
treeEntryChanges.Path));

0 commit comments

Comments
 (0)