diff options
author | Markus Olsson <j.markus.olsson@gmail.com> | 2012-02-03 03:25:30 +0400 |
---|---|---|
committer | Markus Olsson <j.markus.olsson@gmail.com> | 2012-02-03 22:57:59 +0400 |
commit | 49fb3fc69881166d63056fadcdbaa1df0fdd45a4 (patch) | |
tree | 62655abb8084e9dc1293fb5ec6ff3d80bbe3f6c0 /LibGit2Sharp | |
parent | e32dba45b0edc7283833d2daad19a5ccc6a6452c (diff) |
Workaround for reference slash prefix in libgit2.
When libgit2 is passed a path to a working directory instead of a
git directory the names returned from git_reference_listall (and
perhaps other similar methods) will be prefixed with a slash such
that insteaf of refs/heads/master it'll return /refs/heads/master.
LibGitSharp always does it's string prefix comparisons without a
starting slash (which seems to be the correct thing to do).
Includes test which verifies the problem by copying the sample working
directory and performing the same test (CanListAllBranches) that's run
for the bare repository.
Update constructor documentation to reflect that it's possible
to pass the path to a working directory.
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/Repository.cs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 11c3b70d..9c23bebe 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Compat; @@ -22,13 +23,28 @@ namespace LibGit2Sharp /// <summary> /// Initializes a new instance of the <see cref = "Repository" /> class. - /// <para>For a standard repository, <paramref name = "path" /> should point to the ".git" folder. For a bare repository, <paramref name = "path" /> should directly point to the repository folder.</para> + /// <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> /// </summary> - /// <param name = "path">The path to the git repository to open.</param> + /// <param name = "path"> + /// The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this + /// would be the ".git" folder inside the working directory) or the path to the working directory. + /// </param> public Repository(string path) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); + // Check if the path points to the working directory instead of the git directory + // by checking if the directory contains a .git directory. The same test is done + // in libgit2 but if it gets to add .git to the path it will mess up the ref paths + // returned from git_reference_listall (and more?) by prefixing them with a '/' such + // that what would normally be refs/heads/master becomes /refs/heads/master and + // LibGit2Sharp doesn't expect that. This is a workaround. + // See https://github.com/libgit2/libgit2sharp/pull/108 + string gitDirPath = Path.Combine(path, ".git"); + + if (Directory.Exists(gitDirPath)) + path = gitDirPath; + int res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path)); Ensure.Success(res); |