diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb8196f8..805c3b335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,14 @@ - Issue tracker: - @libgit2sharp: +## v0.6.2 + +### Fixes + + - Make Index methods (Stage, Unstage, Move... ) able to cope with native Windows directory separator char + ## v0.6.1 - + ### Changes - Update libgit2 binaries to libgit2/libgit2@e3baa3c @@ -33,7 +39,7 @@ - Provide default value for non existent configuration setting (#67) - Change the tree structure into which libgit2 binaries are located (#70) - Update libgit2 binaries to libgit2/libgit2@28c1451 - + ### Fixes - Prevent enumeration of branches from throwing when the repository contains remote branches (#69) diff --git a/LibGit2Sharp.Tests/IndexFixture.cs b/LibGit2Sharp.Tests/IndexFixture.cs index 43a2363d5..91b685514 100644 --- a/LibGit2Sharp.Tests/IndexFixture.cs +++ b/LibGit2Sharp.Tests/IndexFixture.cs @@ -166,20 +166,21 @@ public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOf { int count = repo.Index.Count; - const string fileName = "1/branch_file.txt"; - ObjectId blobId = repo.Index[fileName].Id; + string filename = "1" + Path.DirectorySeparatorChar + "branch_file.txt"; + const string posixifiedFileName = "1/branch_file.txt"; + ObjectId blobId = repo.Index[posixifiedFileName].Id; - string fullpath = Path.Combine(repo.Info.WorkingDirectory, fileName); + string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename); File.AppendAllText(fullpath, "Is there there anybody out there?"); - repo.Index.Stage(fileName); + repo.Index.Stage(filename); repo.Index.Count.ShouldEqual(count); - repo.Index[fileName].Id.ShouldNotEqual((blobId)); + repo.Index[posixifiedFileName].Id.ShouldNotEqual((blobId)); - repo.Index.Unstage(fileName); + repo.Index.Unstage(posixifiedFileName); repo.Index.Count.ShouldEqual(count); - repo.Index[fileName].Id.ShouldEqual((blobId)); + repo.Index[posixifiedFileName].Id.ShouldEqual((blobId)); } } @@ -231,6 +232,29 @@ public void CanStageANewFileWithAFullPath() } } + [Test] + public void CanStageANewFileWithARelativePathContainingNativeDirectorySeparatorCharacters() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(Constants.StandardTestRepoWorkingDirPath); + using (var repo = new Repository(path.RepositoryPath)) + { + int count = repo.Index.Count; + + DirectoryInfo di = Directory.CreateDirectory(Path.Combine(repo.Info.WorkingDirectory, "Project")); + string file = "Project" + Path.DirectorySeparatorChar + "a_file.txt"; + + File.WriteAllText(Path.Combine(di.FullName, "a_file.txt"), "With backward slash on Windows!"); + + repo.Index.Stage(file); + + repo.Index.Count.ShouldEqual(count + 1); + + const string posixifiedPath = "Project/a_file.txt"; + repo.Index[posixifiedPath].ShouldNotBeNull(); + repo.Index[posixifiedPath].Path.ShouldEqual(posixifiedPath); + } + } + [Test] public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows() { @@ -308,8 +332,8 @@ public void UnstagingFileWithBadParamsThrows() { using (var repo = new Repository(Constants.StandardTestRepoPath)) { - Assert.Throws(() => repo.Index.Stage(string.Empty)); - Assert.Throws(() => repo.Index.Stage(null)); + Assert.Throws(() => repo.Index.Unstage(string.Empty)); + Assert.Throws(() => repo.Index.Unstage(null)); } } @@ -373,7 +397,7 @@ public void CanRemoveAFile() { int count = repo.Index.Count; - const string filename = "1/branch_file.txt"; + string filename = "1" + Path.DirectorySeparatorChar + "branch_file.txt"; string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename); File.Exists(fullpath).ShouldBeTrue(); diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index ee7726e6c..ff1c73c97 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -74,21 +74,33 @@ public virtual bool IsRemote get { return IsRemoteBranch(CanonicalName); } } + /// + /// Gets the remote branch which is connected to this local one. + /// public Branch TrackedBranch { get { return trackedBranch.Value; } } + /// + /// Determines if this local branch is connected to a remote one. + /// public bool IsTracking { get { return TrackedBranch != null; } } + /// + /// Gets the number of commits, starting from the , that have been performed on this local branch and aren't known from the remote one. + /// public int AheadBy { get { return IsTracking ? repo.Commits.QueryBy(new Filter { Since = Tip, Until = TrackedBranch }).Count() : 0; } } + /// + /// Gets the number of commits that exist in the remote branch, on top of , and aren't known from the local one. + /// public int BehindBy { get { return IsTracking ? repo.Commits.QueryBy(new Filter { Since = TrackedBranch, Until = Tip }).Count() : 0; } @@ -183,19 +195,24 @@ private static bool IsRemoteBranch(string canonicalName) return canonicalName.StartsWith("refs/remotes/", StringComparison.Ordinal); } - protected override string Shorten(string branchName) + /// + /// Returns the friendly shortened name from a canonical name. + /// + /// The canonical name to shorten. + /// + protected override string Shorten(string canonicalName) { - if (branchName.StartsWith("refs/heads/", StringComparison.Ordinal)) + if (canonicalName.StartsWith("refs/heads/", StringComparison.Ordinal)) { - return branchName.Substring("refs/heads/".Length); + return canonicalName.Substring("refs/heads/".Length); } - if (branchName.StartsWith("refs/remotes/", StringComparison.Ordinal)) + if (canonicalName.StartsWith("refs/remotes/", StringComparison.Ordinal)) { - return branchName.Substring("refs/remotes/".Length); + return canonicalName.Substring("refs/remotes/".Length); } - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "'{0}' does not look like a valid branch name.", branchName)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "'{0}' does not look like a valid branch name.", canonicalName)); } /// diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs index 1ab194ea4..d6155cc92 100644 --- a/LibGit2Sharp/Configuration.cs +++ b/LibGit2Sharp/Configuration.cs @@ -29,11 +29,17 @@ internal Configuration(Repository repository) Init(); } + /// + /// Determines if a Git configuration file specific to the current interactive user has been found. + /// public bool HasGlobalConfig { get { return globalConfigPath != null; } } + /// + /// Determines if a system-wide Git configuration file has been found. + /// public bool HasSystemConfig { get { return systemConfigPath != null; } diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs index 93ddd9cfd..145d47bd3 100644 --- a/LibGit2Sharp/Index.cs +++ b/LibGit2Sharp/Index.cs @@ -224,12 +224,16 @@ public void Remove(string path) private void AddToIndex(string relativePath) { + relativePath = PosixPathHelper.ToPosix(relativePath); + int res = NativeMethods.git_index_add(handle, relativePath); Ensure.Success(res); } private void RemoveFromIndex(string relativePath) { + relativePath = PosixPathHelper.ToPosix(relativePath); + int res = NativeMethods.git_index_find(handle, relativePath); Ensure.Success(res, true); @@ -306,7 +310,7 @@ public FileStatus RetrieveStatus(string filePath) FileStatus status; - int res = NativeMethods.git_status_file(out status, repo.Handle, relativePath); + int res = NativeMethods.git_status_file(out status, repo.Handle, PosixPathHelper.ToPosix(relativePath)); if (res == (int)GitErrorCode.GIT_ENOTFOUND) { return FileStatus.Nonexistent; diff --git a/LibGit2Sharp/IndexEntry.cs b/LibGit2Sharp/IndexEntry.cs index 87441b649..5261e0618 100644 --- a/LibGit2Sharp/IndexEntry.cs +++ b/LibGit2Sharp/IndexEntry.cs @@ -4,16 +4,30 @@ namespace LibGit2Sharp { + /// + /// A reference to a known by the . + /// public class IndexEntry { private Func state; + /// + /// State of the version of the pointed at by this , + /// compared against the known from the and the file in the working directory. + /// public FileStatus State { get { return state(); } } + /// + /// Gets the relative path to the file within the working directory. + /// public string Path { get; private set; } + + /// + /// Gets the id of the pointed at by this index entry. + /// public ObjectId Id { get; private set; } internal static IndexEntry CreateFromPtr(Repository repo, IntPtr ptr) diff --git a/LibGit2Sharp/NamedReference.cs b/LibGit2Sharp/NamedReference.cs index 32a097b31..8eb9035a4 100644 --- a/LibGit2Sharp/NamedReference.cs +++ b/LibGit2Sharp/NamedReference.cs @@ -48,7 +48,12 @@ protected TObject TargetObject get { return objectBuilder.Value; } } - protected abstract string Shorten(string tagName); + /// + /// Returns the friendly shortened name from a canonical name. + /// + /// The canonical name to shorten. + /// + protected abstract string Shorten(string canonicalName); private TObject RetrieveTargetObject(Reference reference) { diff --git a/LibGit2Sharp/Properties/AssemblyInfo.cs b/LibGit2Sharp/Properties/AssemblyInfo.cs index 9ac35fc38..8a6309ab8 100644 --- a/LibGit2Sharp/Properties/AssemblyInfo.cs +++ b/LibGit2Sharp/Properties/AssemblyInfo.cs @@ -42,5 +42,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.6.1")] -[assembly: AssemblyFileVersion("0.6.1")] +[assembly: AssemblyVersion("0.6.2")] +[assembly: AssemblyFileVersion("0.6.2")] diff --git a/LibGit2Sharp/Tag.cs b/LibGit2Sharp/Tag.cs index c2fdad642..38e019df9 100644 --- a/LibGit2Sharp/Tag.cs +++ b/LibGit2Sharp/Tag.cs @@ -51,11 +51,16 @@ public bool IsAnnotated get { return Annotation != null; } } - protected override string Shorten(string tagName) + /// + /// Returns the friendly shortened name from a canonical name. + /// + /// The canonical name to shorten. + /// + protected override string Shorten(string canonicalName) { - Ensure.ArgumentConformsTo(tagName, s => s.StartsWith("refs/tags/", StringComparison.Ordinal), "tagName"); + Ensure.ArgumentConformsTo(canonicalName, s => s.StartsWith("refs/tags/", StringComparison.Ordinal), "tagName"); - return tagName.Substring("refs/tags/".Length); + return canonicalName.Substring("refs/tags/".Length); } /// diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs index f4811e81a..91aad6541 100644 --- a/LibGit2Sharp/Tree.cs +++ b/LibGit2Sharp/Tree.cs @@ -6,6 +6,9 @@ namespace LibGit2Sharp { + /// + /// A container which references a list of other s and s. + /// public class Tree : GitObject, IEnumerable { private Repository repo;