diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..f8766572a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# LibGit2Sharp releases + +## v0.1.1 + + - [Fix] Fix NuGet packaging + - [Add] Update staging mechanism to authorize full paths to be used + +## v0.1.0 + + - Initial release \ No newline at end of file diff --git a/Lib/NuGet/NuGet.exe b/Lib/NuGet/NuGet.exe new file mode 100644 index 000000000..3bf120c38 Binary files /dev/null and b/Lib/NuGet/NuGet.exe differ diff --git a/LibGit2Sharp.Tests/IndexFixture.cs b/LibGit2Sharp.Tests/IndexFixture.cs index e9e8dfa81..cec992763 100644 --- a/LibGit2Sharp.Tests/IndexFixture.cs +++ b/LibGit2Sharp.Tests/IndexFixture.cs @@ -118,6 +118,43 @@ public void CanStageANewFile() } } + [Test] + public void CanStageANewFileWithAFullPath() + { + using (var path = new TemporaryCloneOfTestRepo(Constants.TestRepoWithWorkingDirPath)) + using (var repo = new Repository(path.RepositoryPath)) + { + var count = repo.Index.Count; + const string filename = "unit_test.txt"; + string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename); + File.WriteAllText(fullPath, "some contents"); + + repo.Index.Stage(fullPath); + + repo.Index.Count.ShouldEqual(count + 1); + repo.Index[filename].ShouldNotBeNull(); + } + } + + [Test] + public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows() + { + string tempPath = new DirectoryInfo("./temp").FullName; + + using (new SelfCleaningDirectory(tempPath)) + using (var path = new TemporaryCloneOfTestRepo(Constants.TestRepoWithWorkingDirPath)) + using (var repo = new Repository(path.RepositoryPath)) + { + Directory.CreateDirectory(tempPath); + + const string filename = "unit_test.txt"; + string fullPath = Path.Combine(tempPath, filename); + File.WriteAllText(fullPath, "some contents"); + + Assert.Throws(() => repo.Index.Stage(fullPath)); + } + } + [Test] [Ignore("Not implemented yet.")] public void CanStageAPath() diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 2bb5d61ff..61d8cd7bc 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -187,6 +187,9 @@ internal class NativeMethods [DllImport(libgit2, SetLastError = true)] public static extern int git_tag_create_f(out GitOid oid, RepositorySafeHandle repo, string name, ref GitOid target, GitObjectType type, GitSignature signature, string message); + [DllImport(libgit2, SetLastError = true)] + public static extern int git_tag_delete(RepositorySafeHandle repo, string tagName); + [DllImport(libgit2, SetLastError = true)] [return: MarshalAs(UnmanagedType.AnsiBStr)] public static extern string git_tag_message(IntPtr tag); diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs index 1488691a1..a0d6a56eb 100644 --- a/LibGit2Sharp/Index.cs +++ b/LibGit2Sharp/Index.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using LibGit2Sharp.Core; namespace LibGit2Sharp @@ -111,10 +112,27 @@ public void Stage(string path) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); - var res = NativeMethods.git_index_add(handle, path); + var res = NativeMethods.git_index_add(handle, BuildRelativePathFrom(path)); Ensure.Success(res); } + private string BuildRelativePathFrom(string path) //TODO: To be removed when libgit2 natively implements this + { + if (!Path.IsPathRooted(path)) + { + return path; + } + + var normalizedPath = new DirectoryInfo(path).FullName; + + if (!normalizedPath.StartsWith(repo.Info.WorkingDirectory)) + { + throw new ArgumentException(string.Format("Unable to stage file '{0}'. This file is not located under the working directory of the repository ('{1}').", normalizedPath, repo.Info.WorkingDirectory)); + } + + return normalizedPath.Substring(repo.Info.WorkingDirectory.Length); + } + public void Unstage(string path) { throw new NotImplementedException(); diff --git a/LibGit2Sharp/Properties/AssemblyInfo.cs b/LibGit2Sharp/Properties/AssemblyInfo.cs index efdc8538e..691ebf24d 100644 --- a/LibGit2Sharp/Properties/AssemblyInfo.cs +++ b/LibGit2Sharp/Properties/AssemblyInfo.cs @@ -41,5 +41,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0")] -[assembly: AssemblyFileVersion("0.1.0")] \ No newline at end of file +[assembly: AssemblyVersion("0.1.1")] +[assembly: AssemblyFileVersion("0.1.1")] \ No newline at end of file diff --git a/LibGit2Sharp/TagCollection.cs b/LibGit2Sharp/TagCollection.cs index 929cc5fba..f8693b539 100644 --- a/LibGit2Sharp/TagCollection.cs +++ b/LibGit2Sharp/TagCollection.cs @@ -13,6 +13,7 @@ namespace LibGit2Sharp public class TagCollection : IEnumerable { private readonly Repository repo; + private static readonly string RefsTagsPrefix = "refs/tags/"; /// /// Initializes a new instance of the class. @@ -116,19 +117,13 @@ public Tag Create(string name, string target, bool allowOverwrite = false) /// /// Deletes the tag with the specified name. /// - /// The name of the tag to delete. + /// The short or canonical name of the tag or the to delete. public void Delete(string name) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Tag tag = this[name]; - - if (tag == null) - { - throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, "No tag identified by '{0}' can be found in the repository.", name)); - } - - repo.Refs.Delete(tag.CanonicalName); //TODO: To be replaced by native libgit2 git_tag_delete() when available. + int res = NativeMethods.git_tag_delete(repo.Handle, UnCanonicalizeName(name)); + Ensure.Success(res); } private GitObject RetrieveObjectToTag(string target) @@ -147,12 +142,24 @@ private static string NormalizeToCanonicalName(string name) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); - if (name.StartsWith("refs/tags/", StringComparison.Ordinal)) + if (name.StartsWith(RefsTagsPrefix, StringComparison.Ordinal)) + { + return name; + } + + return string.Concat(RefsTagsPrefix, name); + } + + private static string UnCanonicalizeName(string name) + { + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + if (!name.StartsWith(RefsTagsPrefix, StringComparison.Ordinal)) { return name; } - return string.Format(CultureInfo.InvariantCulture, "refs/tags/{0}", name); + return name.Substring(RefsTagsPrefix.Length); } } } \ No newline at end of file diff --git a/backlog.md b/backlog.md index 40f12cf3c..a0e159518 100644 --- a/backlog.md +++ b/backlog.md @@ -2,6 +2,8 @@ ### LibGit2Sharp + - Add a Path property to SelfCleaningDirectory + - Set up a Assembly versioning strategy - Add branch renaming (public Branch Move(string oldName, string newName, bool allowOverwrite = false)) - Turn duplicated strings "refs/xxx" into properties of a generic Constants helper type - Refactor the error handling (OutputResult -> Exceptions) diff --git a/LibGit2Sharp.nuspec b/nuget.package/LibGit2Sharp.nuspec similarity index 51% rename from LibGit2Sharp.nuspec rename to nuget.package/LibGit2Sharp.nuspec index 4d252c1ea..49a6c85cb 100644 --- a/LibGit2Sharp.nuspec +++ b/nuget.package/LibGit2Sharp.nuspec @@ -2,7 +2,7 @@ LibGit2Sharp - 0.1.0 + 0.1.1 LibGit2Sharp contributors nulltoken https://github.com/libgit2/libgit2sharp/raw/master/LICENSE.md @@ -12,11 +12,13 @@ libgit2 git wrapper bindings API - - - - - - + + + + + + + + \ No newline at end of file diff --git a/nuget.package/Tools/GetLibGit2SharpPostBuildCmd.ps1 b/nuget.package/Tools/GetLibGit2SharpPostBuildCmd.ps1 new file mode 100644 index 000000000..35cf68efa --- /dev/null +++ b/nuget.package/Tools/GetLibGit2SharpPostBuildCmd.ps1 @@ -0,0 +1,8 @@ +$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\" +$path = $installPath.Replace($solutionDir, "`$(SolutionDir)") + +$NativeAssembliesDir = Join-Path $path "NativeBinaries" +$x86 = $(Join-Path $NativeAssembliesDir "x86\*.*") + +$LibGit2SharpPostBuildCmd = " +xcopy /s /y `"$x86`" `"`$(TargetDir)`"" \ No newline at end of file diff --git a/nuget.package/Tools/install.ps1 b/nuget.package/Tools/install.ps1 new file mode 100644 index 000000000..bc403c27b --- /dev/null +++ b/nuget.package/Tools/install.ps1 @@ -0,0 +1,11 @@ +param($installPath, $toolsPath, $package, $project) + +. (Join-Path $toolsPath "GetLibGit2SharpPostBuildCmd.ps1") + +# Get the current Post Build Event cmd +$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value + +# Append our post build command if it's not already there +if (!$currentPostBuildCmd.Contains($LibGit2SharpPostBuildCmd)) { + $project.Properties.Item("PostBuildEvent").Value += $LibGit2SharpPostBuildCmd +} \ No newline at end of file diff --git a/nuget.package/Tools/uninstall.ps1 b/nuget.package/Tools/uninstall.ps1 new file mode 100644 index 000000000..a1854cb32 --- /dev/null +++ b/nuget.package/Tools/uninstall.ps1 @@ -0,0 +1,9 @@ +param($installPath, $toolsPath, $package, $project) + +. (Join-Path $toolsPath "GetLibGit2SharpPostBuildCmd.ps1") + +# Get the current Post Build Event cmd +$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value + +# Remove our post build command from it (if it's there) +$project.Properties.Item("PostBuildEvent").Value = $currentPostBuildCmd.Replace($LibGit2SharpPostBuildCmd, "") \ No newline at end of file