Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Clem <timothy.clem@gmail.com>2011-04-26 19:15:08 +0400
committerTim Clem <timothy.clem@gmail.com>2011-04-26 19:15:08 +0400
commita974a91a261578d32433dc97f61901a86c9f56d2 (patch)
treeaca024c6e263d045ac4863048ba054cbc26123fc /LibGit2Sharp/RepositoryInformation.cs
parentf309e2d4b4feb8f11cf0094a53cc65635af7b253 (diff)
define IsDetachedHead for empty repo
This required added an IsEmpty property to repo.Info. Associated tests were updated to make sure this property behaves as expected.
Diffstat (limited to 'LibGit2Sharp/RepositoryInformation.cs')
-rw-r--r--LibGit2Sharp/RepositoryInformation.cs27
1 files changed, 21 insertions, 6 deletions
diff --git a/LibGit2Sharp/RepositoryInformation.cs b/LibGit2Sharp/RepositoryInformation.cs
index 6eb00568..e07c387d 100644
--- a/LibGit2Sharp/RepositoryInformation.cs
+++ b/LibGit2Sharp/RepositoryInformation.cs
@@ -1,5 +1,4 @@
-using System.IO;
-using LibGit2Sharp.Core;
+using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
@@ -16,6 +15,7 @@ namespace LibGit2Sharp
Path = PosixPathHelper.ToNative(posixPath);
IsBare = isBare;
WorkingDirectory = PosixPathHelper.ToNative(posixWorkingDirectoryPath);
+ IsEmpty = NativeMethods.git_repository_is_empty(repo.Handle);
}
/// <summary>
@@ -25,9 +25,9 @@ namespace LibGit2Sharp
/// <summary>
/// Gets the normalized path to the working directory.
- /// <para>
- /// Is the repository is bare, null is returned.
- /// </para>
+ /// <para>
+ /// Is the repository is bare, null is returned.
+ /// </para>
/// </summary>
public string WorkingDirectory { get; private set; }
@@ -37,8 +37,23 @@ namespace LibGit2Sharp
public bool IsBare { get; private set; }
/// <summary>
+ /// Gets a value indicating whether this repository is empty.
+ /// </summary>
+ /// <value>
+ /// <c>true</c> if this repository is empty; otherwise, <c>false</c>.
+ /// </value>
+ public bool IsEmpty { get; private set; }
+
+ /// <summary>
/// Indicates whether the Head points to an arbitrary commit instead of the tip of a local banch.
/// </summary>
- public bool IsHeadDetached { get { return repo.Refs.Head is DirectReference; } }
+ public bool IsHeadDetached
+ {
+ get
+ {
+ if (repo.Info.IsEmpty) return false; // Detached HEAD doesn't mean anything for an empty repo, just return false
+ return repo.Refs.Head is DirectReference;
+ }
+ }
}
} \ No newline at end of file