Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Squash up commits on devel branch

This is being done to clean up commit history on master.
  • Loading branch information...
commit 0bee0993b607b4fb09b148e7a74ef452e72a7600 1 parent 55863d6
@tclem tclem authored
Showing with 11,108 additions and 2,600 deletions.
  1. +34 −0 .gitignore
  2. +3 −0  .gitmodules
  3. +22 −0 LICENSE
  4. +51 −0 LibGit2Sharp.Core.Generator/AssemblyInfo.cs
  5. +61 −0 LibGit2Sharp.Core.Generator/HelperExtensions.cs
  6. +51 −0 LibGit2Sharp.Core.Generator/LibGit2Sharp.Core.Generator.csproj
  7. +442 −0 LibGit2Sharp.Core.Generator/Main.cs
  8. +23 −0 LibGit2Sharp.Core.Generator/license.txt
  9. +150 −0 LibGit2Sharp.Tests/Api/ApplyingATag.cs
  10. +57 −0 LibGit2Sharp.Tests/Api/InitializingARepository.cs
  11. +93 −69 LibGit2Sharp.Tests/{ → Api}/InstantiatingARepository.cs
  12. +83 −0 LibGit2Sharp.Tests/Api/LookingUpAHeadReference.cs
  13. +68 −44 LibGit2Sharp.Tests/{ → Api}/ObjectIdFixture.cs
  14. +250 −254 LibGit2Sharp.Tests/{ → Api}/RepositoryFixtures.cs
  15. +46 −0 LibGit2Sharp.Tests/Api/ResolvingAHeadReference.cs
  16. +46 −0 LibGit2Sharp.Tests/Api/ResolvingATagReference.cs
  17. +43 −0 LibGit2Sharp.Tests/Api/RetrievingAllReferences.cs
  18. +0 −95 LibGit2Sharp.Tests/ApplyingATag.cs
  19. +62 −0 LibGit2Sharp.Tests/Core/DatabaseFixture.cs
  20. +106 −0 LibGit2Sharp.Tests/Core/EpochFixture.cs
  21. +45 −0 LibGit2Sharp.Tests/Core/IndexTests.cs
  22. +49 −0 LibGit2Sharp.Tests/Core/SignatureTest.cs
  23. +0 −91 LibGit2Sharp.Tests/GitDateFixture.cs
  24. +0 −33 LibGit2Sharp.Tests/InitializingARepository.cs
  25. +83 −75 LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
  26. +36 −36 LibGit2Sharp.Tests/Properties/AssemblyInfo.cs
  27. +33 −9 LibGit2Sharp.Tests/ReadOnlyRepositoryFixtureBase.cs
  28. +62 −38 LibGit2Sharp.Tests/ReadWriteRepositoryFixtureBase.cs
  29. +92 −68 LibGit2Sharp.Tests/RepositoryToBeCreatedFixtureBase.cs
  30. +41 −0 LibGit2Sharp.Tests/TestHelper.cs
  31. +82 −57 LibGit2Sharp.sln
  32. +34 −10 LibGit2Sharp/Blob.cs
  33. +52 −28 LibGit2Sharp/Commit.cs
  34. +36 −0 LibGit2Sharp/Core/Constants.cs
  35. +95 −0 LibGit2Sharp/Core/Database.cs
  36. +96 −0 LibGit2Sharp/Core/DatabaseObject.cs
  37. +46 −0 LibGit2Sharp/Core/Epoch.cs
  38. +40 −0 LibGit2Sharp/Core/Exceptions/GitException.cs
  39. +51 −0 LibGit2Sharp/Core/Exceptions/GitInternalException.cs
  40. +76 −0 LibGit2Sharp/Core/GitError.cs
  41. +39 −0 LibGit2Sharp/Core/Helper.cs
  42. +160 −0 LibGit2Sharp/Core/Index.cs
  43. +68 −0 LibGit2Sharp/Core/IndexEntry.cs
  44. +135 −0 LibGit2Sharp/Core/NativeMemoryStream.cs
  45. +394 −0 LibGit2Sharp/Core/NativeMethods.cs
  46. +114 −0 LibGit2Sharp/Core/ObjectId.cs
  47. +90 −0 LibGit2Sharp/Core/Objects/Blob.cs
  48. +158 −0 LibGit2Sharp/Core/Objects/Commit.cs
  49. +157 −0 LibGit2Sharp/Core/Objects/GitObject.cs
  50. +113 −0 LibGit2Sharp/Core/Objects/Tag.cs
  51. +110 −0 LibGit2Sharp/Core/Objects/Tree.cs
  52. +83 −0 LibGit2Sharp/Core/Objects/TreeEntry.cs
  53. +60 −0 LibGit2Sharp/Core/References/ObjectIdReference.cs
  54. +157 −0 LibGit2Sharp/Core/References/Reference.cs
  55. +59 −0 LibGit2Sharp/Core/References/SymbolicReference.cs
  56. +273 −0 LibGit2Sharp/Core/Repository.cs
  57. +116 −0 LibGit2Sharp/Core/RevisionWalker.cs
  58. +98 −0 LibGit2Sharp/Core/Signature.cs
  59. +288 −0 LibGit2Sharp/Core/Wrapper.cs
  60. +0 −12 LibGit2Sharp/DateTimeOffsetExtensions.cs
  61. +0 −33 LibGit2Sharp/Epoch.cs
  62. +0 −56 LibGit2Sharp/GitDate.cs
  63. +38 −14 LibGit2Sharp/GitObject.cs
  64. +0 −16 LibGit2Sharp/Header.cs
  65. +0 −9 LibGit2Sharp/IBuilder.cs
  66. +0 −10 LibGit2Sharp/ILifecycleManager.cs
  67. +33 −9 LibGit2Sharp/IObjectResolver.cs
  68. +0 −7 LibGit2Sharp/IRefsResolver.cs
  69. +32 −0 LibGit2Sharp/InvalidReferenceException.cs
  70. +34 −0 LibGit2Sharp/InvalidReferenceNameException.cs
  71. +34 −0 LibGit2Sharp/InvalidTypeException.cs
  72. +110 −99 LibGit2Sharp/LibGit2Sharp.csproj
  73. +34 −9 LibGit2Sharp/NotAValidRepositoryException.cs
  74. +117 −106 LibGit2Sharp/ObjectBuilder.cs
  75. +115 −91 LibGit2Sharp/ObjectId.cs
  76. +34 −9 LibGit2Sharp/ObjectNotFoundException.cs
  77. +109 −84 LibGit2Sharp/ObjectResolver.cs
  78. +39 −0 LibGit2Sharp/ObjectResolverExtensions.cs
  79. +35 −12 LibGit2Sharp/ObjectType.cs
  80. +60 −36 LibGit2Sharp/Properties/AssemblyInfo.cs
  81. +0 −14 LibGit2Sharp/RawObject.cs
  82. +38 −9 LibGit2Sharp/Ref.cs
  83. +89 −0 LibGit2Sharp/ReferenceManager.cs
  84. +0 −12 LibGit2Sharp/RefsResolver.cs
  85. +178 −139 LibGit2Sharp/Repository.cs
  86. +49 −25 LibGit2Sharp/RepositoryDetails.cs
  87. +144 −141 LibGit2Sharp/RepositoryLifecycleManager.cs
  88. +0 −15 LibGit2Sharp/ResolverExtensions.cs
  89. +53 −33 LibGit2Sharp/Signature.cs
  90. +43 −19 LibGit2Sharp/Tag.cs
  91. +34 −10 LibGit2Sharp/Tree.cs
  92. +0 −11 LibGit2Sharp/Wrapper/Constants.cs
  93. +0 −38 LibGit2Sharp/Wrapper/NativeMethods.cs
  94. +0 −58 LibGit2Sharp/Wrapper/OperationResult.cs
  95. +0 −26 LibGit2Sharp/Wrapper/git_commit.cs
  96. +0 −19 LibGit2Sharp/Wrapper/git_object.cs
  97. +0 −16 LibGit2Sharp/Wrapper/git_odb_source.cs
  98. +0 −11 LibGit2Sharp/Wrapper/git_oid.cs
  99. +0 −16 LibGit2Sharp/Wrapper/git_otype.cs
  100. +0 −33 LibGit2Sharp/Wrapper/git_rawobj.cs
  101. +0 −47 LibGit2Sharp/Wrapper/git_repository.cs
  102. +0 −18 LibGit2Sharp/Wrapper/git_signature.cs
  103. +0 −21 LibGit2Sharp/Wrapper/git_tag.cs
  104. +0 −11 LibGit2Sharp/Wrapper/git_tree.cs
  105. +0 −17 LibGit2Sharp/Wrapper/git_vector.cs
  106. +90 −0 README.md
  107. +11 −0 Resources/Makefile
  108. +28 −0 Resources/formatting.patch
  109. +2 −0  Resources/libgit2.h
  110. +4,112 −0 Resources/libgit2.xml
  111. BIN  deps/git2.dll
  112. BIN  deps/git2.lib
  113. +1 −0  libgit2
  114. +0 −90 libgit2wrap/libgit2.wrap.vcxproj
  115. +0 −27 libgit2wrap/libgit2.wrap.vcxproj.filters
  116. +0 −185 libgit2wrap/src/libgit2wrap.c
  117. +0 −20 libgit2wrap/src/libgit2wrap.h
View
34 .gitignore
@@ -0,0 +1,34 @@
+
+#ignore thumbnails created by windows
+Thumbs.db
+#Ignore files build by Visual Studio
+*.obj
+*.exe
+*.pdb
+*.user
+*.aps
+*.pch
+*.vspscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.cache
+*.ilk
+*.log
+[Bb]in
+[Dd]ebug*/
+*.lib
+*.sbr
+obj/
+[Rr]elease*/
+_ReSharper*/
+[Tt]est[Rr]esult*
+build/
+*.pidb
+*.userprefs
+*.swp
+%temp%
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "libgit2"]
+ path = libgit2
+ url = https://github.com/libgit2/libgit2.git
View
22 LICENSE
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2011 LibGit2Sharp committers
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
View
51 LibGit2Sharp.Core.Generator/AssemblyInfo.cs
@@ -0,0 +1,51 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 Andrius Bentkus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("LibGit2Sharp.Core.Generator")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
View
61 LibGit2Sharp.Core.Generator/HelperExtensions.cs
@@ -0,0 +1,61 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 Andrius Bentkus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+
+namespace LibGit2Sharp.Core.Generator
+{
+ public static class HelperExtensions
+ {
+ public static string Join(this string[] stringArray, char c)
+ {
+ return stringArray.Join(new string(new char[] { c }));
+ }
+
+ public static string Join(this string[] stringArray, string delimeter)
+ {
+ return stringArray.Join(0, delimeter);
+ }
+
+ public static string Join(this string[] stringArray, int startIndex, char c)
+ {
+ return stringArray.Join(startIndex, new string(new char[] { c }));
+ }
+
+ public static string Join(this string[] stringArray, int startIndex, string delimeter)
+ {
+ if (stringArray.Length < startIndex)
+ return string.Empty;
+
+ System.Text.StringBuilder sb = new System.Text.StringBuilder(stringArray[startIndex]);
+
+ for (int i = startIndex + 1; i < stringArray.Length; i++) {
+ sb.Append(delimeter);
+ sb.Append(stringArray[i]);
+ }
+
+ return sb.ToString();
+ }
+ }
+}
View
51 LibGit2Sharp.Core.Generator/LibGit2Sharp.Core.Generator.csproj
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{2F434CB5-FB41-4B43-83E4-79C9B57DF622}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>LibGit2Sharp.Generator</RootNamespace>
+ <AssemblyName>LibGit2Sharp.Core.Generator</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\build\Debug\</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Externalconsole>true</Externalconsole>
+ <Commandlineparameters>../../LibGit2Sharp/Core/NativeMethods.cs</Commandlineparameters>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\build\Release\</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Externalconsole>true</Externalconsole>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.Linq" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Main.cs" />
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="HelperExtensions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="license.txt">
+ <LogicalName>license.txt</LogicalName>
+ </EmbeddedResource>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
View
442 LibGit2Sharp.Core.Generator/Main.cs
@@ -0,0 +1,442 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 Andrius Bentkus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+using System.Reflection;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+using System.Xml;
+using System.Xml.XPath;
+using System.Xml.Linq;
+
+namespace LibGit2Sharp.Core.Generator
+{
+ public static class XmlExtensions
+ {
+ public static string Get(this XmlNode node, string attribute)
+ {
+ return node.Attributes[attribute].Value;
+ }
+
+ public static string Id(this XmlNode node)
+ {
+ return node.Get("id");
+ }
+
+ public static string Name(this XmlNode node)
+ {
+ return node.Get("name");
+ }
+
+ public static string Type(this XmlNode node)
+ {
+ return node.Get("type");
+ }
+
+ public static string Returns(this XmlNode node)
+ {
+ return node.Get("returns");
+ }
+ }
+
+ public interface INet
+ {
+ string GetNetString();
+ string GetNetString(bool returnType);
+ }
+
+ public class BaseType : INet
+ {
+ public string Object { get; set; }
+ public int Pointer { get; set; }
+ public bool Const { get; set; }
+ public bool ReturnType { get; set; }
+
+ public string PointerString
+ {
+ get {
+ string star = "";
+
+ for (int i = 0; i < Pointer; i++)
+ star += '*';
+
+ return star;
+ }
+ }
+
+ public override string ToString()
+ {
+ if (Pointer > 0)
+ return string.Format("{0} {1}", Object, PointerString);
+ else
+ return string.Format("{0} ", Object);
+ }
+
+ public string GetNetString(bool returnType)
+ {
+ string obj = Object;
+
+ switch (obj)
+ {
+ case "long long int":
+ return "long ";
+ case "unsigned char":
+ if (Pointer == 1)
+ return "string ";
+ break;
+ case "unsigned int":
+ obj = "uint";
+ break;
+ case "long int":
+ return "long ";
+ case "char":
+ if (Pointer == 1)
+ if (returnType ? !Const : Const)
+ return "string ";
+ else
+ return "sbyte *";
+ break;
+ }
+
+ Object = obj;
+ return ToString();
+ }
+
+ public string GetNetString()
+ {
+ return GetNetString(false);
+ }
+ }
+
+ public class Function : INet
+ {
+ public class Argument : INet
+ {
+ public string Name { get; set; }
+ public BaseType BaseType { get; set; }
+
+ public override string ToString ()
+ {
+ return BaseType + Name;
+ }
+
+ public string GetNetString(bool returnType)
+ {
+ string name = Name;
+ switch (name)
+ {
+ case "object":
+ name = "obj";
+ break;
+ case "out":
+ name = "outt";
+ break;
+ case "ref":
+ name = "reference";
+ break;
+ }
+
+ return BaseType.GetNetString(returnType) + name;
+ }
+
+ public string GetNetString()
+ {
+ return GetNetString(false);
+ }
+ }
+
+ public string Name { get; set; }
+ public Argument[] Arguments { get; set; }
+ public BaseType ReturnType { get; set; }
+
+ public string ArgumentsString
+ {
+ get {
+ return Arguments.Select(s => s.ToString()).ToArray().Join(", ");
+ }
+ }
+
+ public override string ToString ()
+ {
+ return string.Format("{0} {1}{2}({3})", ReturnType.Object,
+ ReturnType.PointerString,
+ Name,
+ ArgumentsString);
+ }
+
+ public string ArgumentsNetString
+ {
+ get {
+ return Arguments.Select(s => s.GetNetString()).ToArray().Join(", ");
+ }
+ }
+
+ public string GetNetString(bool returnType)
+ {
+ return string.Format("{0}{1}({2})", ReturnType.GetNetString(returnType),
+ Name,
+ ArgumentsNetString);
+ }
+
+ public string GetNetString()
+ {
+ return GetNetString(true);
+ }
+ }
+
+ public class GCCXmlParser
+ {
+ private Dictionary<string, XmlNode> ids = new Dictionary<string, XmlNode>();
+
+ private XmlDocument xmldoc;
+
+ public GCCXmlParser(XmlDocument xmldoc)
+ {
+ this.xmldoc = xmldoc;
+
+ this.ParseIds();
+ }
+
+ private void ParseIds()
+ {
+ var gccxml = xmldoc.SelectSingleNode("/GCC_XML");
+
+ foreach (XmlNode node in gccxml.ChildNodes)
+ {
+ ids[node.Id()] = node;
+ }
+ }
+
+ private XmlNode GetById(string id)
+ {
+ if (ids.ContainsKey(id))
+ return ids[id];
+
+ return null;
+ }
+
+ private BaseType ResolveType(string id)
+ {
+ BaseType bt = new BaseType();
+ ResolveType(bt, id);
+ return bt;
+ }
+
+ private void ResolveType(BaseType basetype, string id)
+ {
+
+ XmlNode type = GetById(id);
+ switch (type.Name)
+ {
+ case "PointerType":
+ basetype.Pointer++;
+ ResolveType(basetype, type.Type());
+ break;
+ case "Typedef":
+ ResolveType(basetype, type.Type());
+ break;
+ case "CvQualifiedType":
+ basetype.Const = true;
+ ResolveType(basetype, type.Type());
+ break;
+ case "FundamentalType":
+ basetype.Object = type.Name();
+ break;
+ case "Enumeration":
+ basetype.Object = type.Name();
+ break;
+ case "Struct":
+ basetype.Object = type.Name();
+ break;
+ default:
+ throw new Exception();
+ }
+ }
+
+ private Function ParseFunction(XmlNode node)
+ {
+ Function func = new Function();
+
+ func.Name = node.Name();
+
+ func.ReturnType = ResolveType(node.Returns());
+
+ List<Function.Argument> args = new List<Function.Argument>();
+
+ foreach (XmlNode attribute in node.ChildNodes)
+ {
+ if (attribute.Name == "Ellipsis")
+ continue;
+
+ args.Add(new Function.Argument() {
+ Name = attribute.Name(),
+ BaseType = ResolveType(attribute.Type())
+ });
+ }
+
+ func.Arguments = args.ToArray();
+
+ return func;
+ }
+
+ public Function ParseFunction(string name)
+ {
+ var list = xmldoc.SelectNodes("/GCC_XML/Function");
+ foreach (XmlNode node in list) {
+ if (node.Name() == name)
+ return ParseFunction(node);
+ }
+
+ return null;
+ }
+
+ public void ParseFunctions()
+ {
+ var list = xmldoc.SelectNodes("/GCC_XML/Function");
+ foreach (XmlNode node in list) {
+ ParseFunction(node);
+ }
+ }
+ }
+
+ public class GitHeaderParser
+ {
+ private static Regex regex1 = new Regex(@"GIT_EXTERN\(.+\) (.+)\(.+\);", RegexOptions.Compiled);
+ private static Regex regex2 = new Regex(@"GIT_EXTERN\(.+\) (.+)\(", RegexOptions.Compiled);
+
+ public static List<string> ParseFile(Stream stream)
+ {
+ StreamReader sr = new StreamReader(stream);
+
+ List<string> list = new List<string>();
+
+ while (!sr.EndOfStream)
+ {
+ string line = sr.ReadLine();
+ Match match = regex1.Match(line);
+ if (match.Success)
+ {
+ list.Add(match.Groups[1].Value);
+ }
+ else
+ {
+ match = regex2.Match(line);
+ if (match.Success)
+ {
+ list.Add(match.Groups[1].Value);
+ }
+ }
+ }
+
+ return list;
+ }
+
+ public static List<string> ParseExternFunctions(string directory)
+ {
+ List<string> list = new List<string>();
+
+ DirectoryInfo di = new DirectoryInfo(directory);
+
+ foreach (var file in di.GetFiles("*.h"))
+ {
+ FileStream fs = File.Open(file.FullName, FileMode.Open);
+ list.AddRange(ParseFile(fs));
+ fs.Close();
+ }
+
+ return list;
+ }
+ }
+
+ class MainClass
+ {
+ public static string License
+ {
+ get {
+ StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("license.txt"));
+ string ret = sr.ReadToEnd();
+ sr.Close();
+ return ret;
+ }
+ }
+
+ private static string SourceDirectory = "../../libgit2/include/git2/";
+ private static string XmlOutput = "../../Resources/libgit2.xml";
+
+ public static void Main(string[] args)
+ {
+ var functions = GitHeaderParser.ParseExternFunctions(SourceDirectory);
+
+ XmlDocument xmldoc = new XmlDocument();
+ xmldoc.Load(XmlOutput);
+
+ GCCXmlParser p = new GCCXmlParser(xmldoc);
+
+
+ TextWriter tw = null;
+
+ if (args.Length > 0)
+ tw = new StreamWriter(File.Open(args[0], FileMode.Create));
+ else
+ tw = System.Console.Out;
+
+ tw.WriteLine(License);
+ tw.WriteLine();
+ tw.WriteLine("// This code is autogenerated, do not modify");
+ tw.WriteLine();
+ tw.WriteLine("using System;");
+ tw.WriteLine("using System.Runtime.InteropServices;");
+ tw.WriteLine();
+ tw.WriteLine("namespace LibGit2Sharp.Core");
+ tw.WriteLine("{");
+ tw.WriteLine(" unsafe internal class NativeMethods");
+ tw.WriteLine(" {");
+ tw.WriteLine(" private const string libgit2 = \"git2.dll\";");
+ tw.WriteLine();
+
+ foreach (string function in functions)
+ {
+ var func = p.ParseFunction(function);
+ if (func != null)
+ Function(tw, func);
+ }
+
+ tw.WriteLine(" }");
+ tw.WriteLine("}");
+
+ tw.Close();
+ }
+
+ public static void Function(TextWriter tw, Function func)
+ {
+ tw.WriteLine();
+ tw.WriteLine(" [DllImport(libgit2)]");
+ tw.Write(" public static extern ");
+ tw.Write(func.GetNetString());
+ tw.WriteLine(";");
+ }
+ }
+}
View
23 LibGit2Sharp.Core.Generator/license.txt
@@ -0,0 +1,23 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 Andrius Bentkus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
View
150 LibGit2Sharp.Tests/Api/ApplyingATag.cs
@@ -0,0 +1,150 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using LibGit2Sharp.Core;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class ApplyingATag : ReadWriteRepositoryFixtureBase
+ {
+ private static readonly Signature _signature = new Signature("nulltoken", "emeric.fermas@gmail.com", Epoch.ToDateTimeOffset(1300557894, 60));
+ private const string _tagTargetId = "e90810b8df3e80c413d903f631643c716887138d";
+ private const string _tagName = "nullTAGen";
+ private const string _tagMessage = "I've been tagged!";
+
+ [Test]
+ public void ShouldThrowIfPassedANonExistingTarget()
+ {
+ const string invalidTargetId = "deadbeef1b46c854b31185ea97743be6a8774479";
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ Assert.Throws<ObjectNotFoundException>(() => repo.ApplyTag(invalidTargetId, "tagged", "messaged", _signature));
+ }
+ }
+
+ [Test]
+ public void ShouldThrowIfPassedAExistingTagName()
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ Assert.Throws<InvalidReferenceNameException>(() => repo.ApplyTag(_tagTargetId, "very-simple", "messaged", _signature));
+ }
+ }
+
+ [Test]
+ public void ShouldReturnATag()
+ {
+ Tag appliedTag = ApplyTag();
+
+ AssertTag(appliedTag);
+ }
+
+ private static void AssertTag(Tag appliedTag)
+ {
+ Assert.IsNotNull(appliedTag);
+ Assert.IsNotNullOrEmpty(appliedTag.Id);
+ Assert.AreEqual(ObjectType.Tag, appliedTag.Type);
+ Assert.AreEqual(_tagTargetId, appliedTag.Target.Id);
+ AssertSignature(_signature, appliedTag.Tagger);
+ }
+
+ private static void AssertSignature(Signature expected, Signature current)
+ {
+ Assert.AreEqual(expected.Email, current.Email);
+ Assert.AreEqual(expected.Name, current.Name);
+ TestHelper.AssertUnixDateTimeOffset(expected.When, current.When);
+ }
+
+ [Test]
+ public void ShouldReturnATagEmbeddingTheTargetGitObject()
+ {
+ Tag appliedTag = ApplyTag();
+
+ AssertTargetCommit(appliedTag);
+ }
+
+ private static void AssertTargetCommit(Tag appliedTag)
+ {
+ var target = appliedTag.Target as Commit;
+ Assert.IsNotNull(target);
+ Assert.AreEqual(_tagTargetId, target.Id);
+ Assert.IsNotNull(target.Author);
+ Assert.IsNotNull(target.Committer);
+ Assert.IsNotNull(target.Message);
+ }
+
+ [Test]
+ public void ShoulReturnATagWithAKnownId()
+ {
+ Tag appliedTag = ApplyTag();
+ Assert.AreEqual("24f6de34a108d931c6056fc4687637fe36c6bd6b", appliedTag.Id);
+ }
+
+ [Test]
+ public void ShouldAllowToResolveItWithItsId()
+ {
+ Tag appliedTag = ApplyTag();
+
+ Tag retrievedTag;
+ using (var repo = new Repository(PathToRepository))
+ {
+ retrievedTag = repo.Resolve<Tag>(appliedTag.Id);
+ }
+
+ AssertTag(retrievedTag);
+
+ Assert.AreEqual(appliedTag.Id, retrievedTag.Id);
+ }
+
+ [Test]
+ public void ShouldAllowToResolveItWithItsCanonicalName()
+ {
+ Tag appliedTag = ApplyTag();
+
+ Tag retrievedTag;
+ using (var repo = new Repository(PathToRepository))
+ {
+ string canonicalName = string.Format("refs/tags/{0}", _tagName);
+ retrievedTag = repo.Resolve<Tag>(canonicalName);
+ }
+
+ AssertTag(retrievedTag);
+
+ Assert.AreEqual(appliedTag.Id, retrievedTag.Id);
+ }
+
+ private Tag ApplyTag()
+ {
+ Tag appliedTag;
+ using (var repo = new Repository(PathToRepository))
+ {
+ appliedTag = repo.ApplyTag(_tagTargetId, _tagName, _tagMessage, _signature);
+ }
+ return appliedTag;
+ }
+ }
+}
View
57 LibGit2Sharp.Tests/Api/InitializingARepository.cs
@@ -0,0 +1,57 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System.IO;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class InitializingARepository : RepositoryToBeCreatedFixtureBase
+ {
+ [TestCase(true)]
+ [TestCase(false)]
+ public void ShouldReturnAValidGitPath(bool isBare)
+ {
+ var expectedGitDirName = new DirectoryInfo(PathToTempDirectory).Name;
+
+ expectedGitDirName += isBare ? "/" : "/.git/";
+
+ var gitDirPath = Repository.Init(PathToTempDirectory, isBare);
+ StringAssert.EndsWith(expectedGitDirName, gitDirPath);
+ }
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void ShouldGenerateAValidRepository(bool isBare)
+ {
+ var gitDirPath = Repository.Init(PathToTempDirectory, isBare);
+
+ using (var repo = new Repository(gitDirPath))
+ {
+ Assert.AreEqual(gitDirPath, repo.Details.RepositoryDirectory);
+ }
+ }
+ }
+}
View
162 LibGit2Sharp.Tests/InstantiatingARepository.cs → LibGit2Sharp.Tests/Api/InstantiatingARepository.cs
@@ -1,70 +1,94 @@
-using System;
-using System.IO;
-using NUnit.Framework;
-
-namespace LibGit2Sharp.Tests
-{
- [TestFixture]
- public class InstantiatingARepository : ReadOnlyRepositoryFixtureBase
- {
- [Test]
- public void ShouldThrowIfPassedANonValidGitDirectory()
- {
- var notAValidRepo = Path.GetTempPath();
- Assert.Throws<NotAValidRepositoryException>(() => new Repository(notAValidRepo));
- }
-
- [Test]
- public void ShouldThrowIfPassedANonExistingFolder()
- {
- var notAValidRepo = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString());
- Assert.Throws<NotAValidRepositoryException>(() => new Repository(notAValidRepo));
- }
-
- [Test]
- public void ShouldAcceptPlatormNativeRelativePath()
- {
- string repoPath = PathToRepository.Replace('/', Path.DirectorySeparatorChar);
-
- AssertRepositoryPath(repoPath);
- }
-
- [Test]
- public void ShouldAcceptPlatormNativeAbsolutePath()
- {
- string repoPath = Path.GetFullPath(PathToRepository);
-
- AssertRepositoryPath(repoPath);
- }
-
- [Test]
- public void ShouldAcceptPlatormNativeRelativePathWithATrailingDirectorySeparatorChar()
- {
- string repoPath = PathToRepository.Replace('/', Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
-
- AssertRepositoryPath(repoPath);
- }
-
- [Test]
- public void ShouldAcceptPlatormNativeAbsolutePathWithATrailingDirectorySeparatorChar()
- {
- string repoPath = Path.GetFullPath(PathToRepository) + Path.DirectorySeparatorChar;
-
- AssertRepositoryPath(repoPath);
- }
-
- private static void AssertRepositoryPath(string repoPath)
- {
- var expected = new DirectoryInfo(repoPath);
-
- DirectoryInfo current;
-
- using (var repo = new Repository(repoPath))
- {
- current = new DirectoryInfo(repo.Details.RepositoryDirectory);
- }
-
- Assert.AreEqual(expected, current);
- }
- }
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+using System.IO;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class InstantiatingARepository : ReadOnlyRepositoryFixtureBase
+ {
+ [Test]
+ public void ShouldThrowIfPassedANonValidGitDirectory()
+ {
+ var notAValidRepo = Path.GetTempPath();
+ Assert.Throws<NotAValidRepositoryException>(() => new Repository(notAValidRepo));
+ }
+
+ [Test]
+ public void ShouldThrowIfPassedANonExistingFolder()
+ {
+ var notAValidRepo = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString());
+ Assert.Throws<NotAValidRepositoryException>(() => new Repository(notAValidRepo));
+ }
+
+ [Test]
+ public void ShouldAcceptPlatormNativeRelativePath()
+ {
+ string repoPath = PathToRepository.Replace('/', Path.DirectorySeparatorChar);
+
+ AssertRepositoryPath(repoPath);
+ }
+
+ [Test]
+ public void ShouldAcceptPlatormNativeAbsolutePath()
+ {
+ string repoPath = Path.GetFullPath(PathToRepository);
+
+ AssertRepositoryPath(repoPath);
+ }
+
+ [Test]
+ public void ShouldAcceptPlatormNativeRelativePathWithATrailingDirectorySeparatorChar()
+ {
+ string repoPath = PathToRepository.Replace('/', Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
+
+ AssertRepositoryPath(repoPath);
+ }
+
+ [Test]
+ public void ShouldAcceptPlatormNativeAbsolutePathWithATrailingDirectorySeparatorChar()
+ {
+ string repoPath = Path.GetFullPath(PathToRepository) + Path.DirectorySeparatorChar;
+
+ AssertRepositoryPath(repoPath);
+ }
+
+ private static void AssertRepositoryPath(string repoPath)
+ {
+ var expected = new DirectoryInfo(repoPath);
+
+ DirectoryInfo current;
+
+ using (var repo = new Repository(repoPath))
+ {
+ current = new DirectoryInfo(repo.Details.RepositoryDirectory);
+ }
+
+ Assert.AreEqual(expected, current);
+ }
+ }
}
View
83 LibGit2Sharp.Tests/Api/LookingUpAHeadReference.cs
@@ -0,0 +1,83 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class LookingUpAHeadReference : ReadOnlyRepositoryFixtureBase
+ {
+ [TestCase("HEAD", true, "refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ [TestCase("HEAD", false, "HEAD", "refs/heads/master")]
+ [TestCase("head-tracker", true, "refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ [TestCase("head-tracker", false, "head-tracker", "HEAD")]
+ [TestCase("refs/heads/master", true, "refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ public void ShouldReturnARef(string referenceName, bool shouldPeel, string expectedReferenceName, string expectedTarget)
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ Ref reference = repo.Refs.Lookup(referenceName, shouldPeel);
+ Assert.IsNotNull(reference);
+ Assert.AreEqual(expectedReferenceName, reference.CanonicalName);
+ Assert.AreEqual(expectedTarget, reference.Target);
+ }
+ }
+
+ //TODO: This requires some additional testing with a HEAD pointing to a symref pointing to refs/heads/master
+ [TestCase("refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ public void ShouldReturnAPeeledRef(string expectedReferenceName, string expectedTarget)
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ Ref reference = repo.Refs.Head;
+ Assert.IsNotNull(reference);
+ Assert.AreEqual(expectedReferenceName, reference.CanonicalName);
+ Assert.AreEqual(expectedTarget, reference.Target);
+ }
+ }
+
+ [TestCase("refs//heads//////master", true, "refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ public void ShouldNormalizeTheReferenceName(string referenceName, bool shouldPeel, string expectedReferenceName, string expectedTarget)
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ Ref reference = repo.Refs.Lookup(referenceName, shouldPeel);
+ Assert.IsNotNull(reference);
+ Assert.AreEqual(expectedReferenceName, reference.CanonicalName);
+ Assert.AreEqual(expectedTarget, reference.Target);
+ }
+ }
+
+ [TestCase("refs/../toto/heads//////master")]
+ public void ShouldThrowIfBeingPassedAnInvalidReferenceName(string referenceName)
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ Assert.Throws<InvalidReferenceNameException>(() => repo.Refs.Lookup(referenceName, false));
+
+ }
+ }
+ }
+}
View
112 LibGit2Sharp.Tests/ObjectIdFixture.cs → LibGit2Sharp.Tests/Api/ObjectIdFixture.cs
@@ -1,45 +1,69 @@
-using System;
-using NUnit.Framework;
-
-namespace LibGit2Sharp.Tests
-{
- [TestFixture]
- public class ObjectIdFixture
- {
- [TestCase("DDelORu/9Dw38NA3GCOlUJ7tWx0=", "0c37a5391bbff43c37f0d0371823a5509eed5b1d")]
- [TestCase("FqASNFZ4mrze9Ld1ITwjqL109eA=", "16a0123456789abcdef4b775213c23a8bd74f5e0")]
- public void ToString(string encoded, string expected)
- {
- byte[] id = Convert.FromBase64String(encoded);
-
- string objectId = ObjectId.ToString(id);
-
- Assert.AreEqual(expected, objectId);
- }
-
- [TestCase("0c37a5391bbff43c37f0d0371823a5509eed5b1d", "DDelORu/9Dw38NA3GCOlUJ7tWx0=")]
- [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e0", "FqASNFZ4mrze9Ld1ITwjqL109eA=")]
- public void ToByteArray(string objectId, string expected)
- {
- byte[] id = Convert.FromBase64String(expected);
-
- byte[] rawId = ObjectId.ToByteArray(objectId);
-
- CollectionAssert.AreEqual(id, rawId);
- }
-
- [TestCase("0c37a5391bbff43c37f0d0371823a5509eed5b1d", true)]
- [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e0", true)]
- [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e", false)]
- [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e01", false)]
- [TestCase("16=0123456789abcdef4b775213c23a8bd74f5e0", false)]
- [TestCase("", false)]
- [TestCase(null, false)]
- public void IsValid(string objectId, bool expected)
- {
- bool result = ObjectId.IsValid(objectId);
-
- Assert.AreEqual(expected, result);
- }
- }
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class ObjectIdFixture
+ {
+ [TestCase("DDelORu/9Dw38NA3GCOlUJ7tWx0=", "0c37a5391bbff43c37f0d0371823a5509eed5b1d")]
+ [TestCase("FqASNFZ4mrze9Ld1ITwjqL109eA=", "16a0123456789abcdef4b775213c23a8bd74f5e0")]
+ public void ToString(string encoded, string expected)
+ {
+ byte[] id = Convert.FromBase64String(encoded);
+
+ string objectId = ObjectId.ToString(id);
+
+ Assert.AreEqual(expected, objectId);
+ }
+
+ [TestCase("0c37a5391bbff43c37f0d0371823a5509eed5b1d", "DDelORu/9Dw38NA3GCOlUJ7tWx0=")]
+ [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e0", "FqASNFZ4mrze9Ld1ITwjqL109eA=")]
+ public void ToByteArray(string objectId, string expected)
+ {
+ byte[] id = Convert.FromBase64String(expected);
+
+ byte[] rawId = ObjectId.ToByteArray(objectId);
+
+ CollectionAssert.AreEqual(id, rawId);
+ }
+
+ [TestCase("0c37a5391bbff43c37f0d0371823a5509eed5b1d", true)]
+ [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e0", true)]
+ [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e", false)]
+ [TestCase("16a0123456789abcdef4b775213c23a8bd74f5e01", false)]
+ [TestCase("16=0123456789abcdef4b775213c23a8bd74f5e0", false)]
+ [TestCase("", false)]
+ [TestCase(null, false)]
+ public void IsValid(string objectId, bool expected)
+ {
+ bool result = ObjectId.IsValid(objectId);
+
+ Assert.AreEqual(expected, result);
+ }
+ }
}
View
504 LibGit2Sharp.Tests/RepositoryFixtures.cs → LibGit2Sharp.Tests/Api/RepositoryFixtures.cs
@@ -1,254 +1,250 @@
-using System;
-using System.Linq;
-using NUnit.Framework;
-using System.IO;
-
-namespace LibGit2Sharp.Tests
-{
- [TestFixture]
- public class RepositoryFixtures : ReadOnlyRepositoryFixtureBase
- {
- [Test]
- public void Ctor_RetrieveDetails()
- {
- using (var repo = new Repository(PathToRepository))
- {
- Assert.AreEqual(true, repo.Details.IsBare);
-
- var gitDir = new DirectoryInfo(PathToRepository);
- Assert.AreEqual(gitDir, new DirectoryInfo(repo.Details.RepositoryDirectory));
-
- var odb = new DirectoryInfo(repo.Details.DatabaseDirectory);
- Assert.AreEqual("objects", odb.Name);
- }
- }
-
- [Test]
- public void HeadersOfAnExistingObjectCanBeRead()
- {
- const string objectId = "8496071c1b46c854b31185ea97743be6a8774479";
- Header header;
-
- using (var repo = new Repository(PathToRepository))
- {
- header = repo.ReadHeader(objectId);
- }
-
- Assert.IsNotNull(header);
- Assert.AreEqual(objectId, header.Id);
- Assert.AreEqual(ObjectType.Commit, header.Type);
- Assert.AreEqual(172, header.Length);
- }
-
- [Test]
- public void AnExistingObjectCanBeRead()
- {
- const string objectId = "8496071c1b46c854b31185ea97743be6a8774479";
- RawObject rawObject;
-
- using (var repo = new Repository(PathToRepository))
- {
- rawObject = repo.Read(objectId);
- }
-
- using (var ms = new MemoryStream(rawObject.Data))
- using (var sr = new StreamReader(ms))
- {
- string content = sr.ReadToEnd();
- StringAssert.StartsWith("tree ", content);
- StringAssert.EndsWith("testing\n", content);
- }
- }
-
- [Test]
- public void AnExistingObjectCanBeFound()
- {
- const string objectId = "8496071c1b46c854b31185ea97743be6a8774479";
- bool hasBeenFound;
-
- using (var repo = new Repository(PathToRepository))
- {
- hasBeenFound = repo.Exists(objectId);
- }
-
- Assert.AreEqual(true, hasBeenFound);
- }
-
- [Test]
- public void AnNonExistingObjectCanNotBeFound()
- {
- const string objectId = "a496071c1b46c854b31185ea97743be6a8774471";
- bool hasBeenFound;
-
- using (var repo = new Repository(PathToRepository))
- {
- hasBeenFound = repo.Exists(objectId);
- }
-
- Assert.AreEqual(false, hasBeenFound);
- }
-
- [Test]
- public void AnExistingTagCanBeResolvedWithoutSpecifyingItsExpectedType()
- {
- const string objectId = "7b4384978d2493e851f9cca7858815fac9b10980";
- GitObject gitObject;
-
- using (var repo = new Repository(PathToRepository))
- {
- gitObject = repo.Resolve(objectId);
- }
-
- Assert.IsNotNull(gitObject);
- Assert.AreEqual(objectId, gitObject.Id);
- Assert.AreEqual(ObjectType.Tag, gitObject.Type);
- Assert.IsAssignableFrom<Tag>(gitObject);
-
- var tag = gitObject as Tag;
-
- AssertTag7b43849(objectId, tag);
- }
-
- [Test]
- public void AnExistingCommitCanBeResolvedThroughChainedTags()
- {
- // Inspired from https://github.com/libgit2/libgit2/blob/44908fe763b1a2097b65c86130ac679c458df7d2/tests/t0801-readtag.c
-
- const string tag1Id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
- const string tag2Id = "7b4384978d2493e851f9cca7858815fac9b10980";
-
- using (var repo = new Repository(PathToRepository))
- {
- var tag1 = repo.Resolve<Tag>(tag1Id);
- Assert.IsNotNull(tag1);
- Assert.AreEqual("test", tag1.Name);
- Assert.AreEqual(tag1Id, tag1.Id);
-
- Assert.IsNotNull(tag1.Target);
- Assert.AreEqual(ObjectType.Tag, tag1.Target.Type);
-
- var tag2 = (Tag) tag1.Target;
- Assert.AreEqual(tag2Id, tag2.Id);
-
- Assert.IsNotNull(tag2.Target);
- Assert.AreEqual(ObjectType.Commit, tag2.Target.Type);
-
- var commit = (Commit) tag2.Target;
- Assert.IsNotNull(commit.Author);
- }
- }
-
- [Test]
- public void AnExistingTagCanBeResolvedBySpecifyingItsExpectedType()
- {
- const string objectId = "7b4384978d2493e851f9cca7858815fac9b10980";
- Tag tag;
-
- using (var repo = new Repository(PathToRepository))
- {
- tag = repo.Resolve<Tag>(objectId);
- }
-
- AssertTag7b43849(objectId, tag);
- }
-
- [Test]
- [Ignore]
- public void AnExistingCommitCanBeResolvedBySpecifyingItsExpectedType()
- {
- const string objectId = "36060c58702ed4c2a40832c51758d5344201d89a";
- Commit commit;
-
- using (var repo = new Repository(PathToRepository))
- {
- commit = repo.Resolve<Commit>(objectId);
- }
-
- AssertCommit36060c5(objectId, commit);
- }
-
- private static void AssertCommit36060c5(string objectId, Commit commit)
- {
- Assert.IsNotNull(commit);
- Assert.AreEqual(objectId, commit.Id);
- Assert.AreEqual(ObjectType.Commit, commit.Type);
- Assert.Fail("To be finalized.");
- }
-
- private static void AssertTag7b43849(string objectId, Tag tag)
- {
- Assert.IsNotNull(tag);
- Assert.AreEqual(objectId, tag.Id);
- Assert.AreEqual(ObjectType.Tag, tag.Type);
- Assert.AreEqual("e90810b", tag.Name);
- Assert.AreEqual("tanoku@gmail.com", tag.Tagger.Email);
- Assert.AreEqual("This is a very simple tag.\n", tag.Message);
- Assert.AreEqual(new GitDate(1281578357, 120), tag.Tagger.When.ToGitDate());
- Assert.AreEqual("e90810b8df3e80c413d903f631643c716887138d", tag.Target.Id);
- Assert.AreEqual(ObjectType.Commit, tag.Target.Type);
-
- var targetCommit = (Commit) tag.Target;
- Assert.AreEqual(1, targetCommit.Parents.Count());
- Assert.AreEqual("6dcf9bf7541ee10456529833502442f385010c3d", targetCommit.Parents.First().Id);
- Assert.AreEqual(ObjectType.Commit, targetCommit.Parents.First().Type);
-
- }
-
- [TestCase("7b4384978d2493e851f9cca7858815fac9b10980", typeof(Tag))]
- [TestCase("8496071c1b46c854b31185ea97743be6a8774479", typeof(Commit))]
- public void ShouldResolveWhenSpecifyingAValidObjectIdAndAValidExpectedType(string objectId, Type expectedType)
- {
- object gitObject;
- using (var repo = new Repository(PathToRepository))
- {
- gitObject = repo.Resolve(objectId, expectedType);
- }
-
- Assert.IsNotNull(gitObject);
- Assert.IsInstanceOf<GitObject>(gitObject);
- Assert.IsAssignableFrom(expectedType, gitObject);
- Assert.AreEqual(objectId, ((GitObject)(gitObject)).Id);
- }
-
- [TestCase("7b4384978d2493e851f9cca7858815fac9b10980", typeof(Tag))]
- [TestCase("c47800c7266a2be04c571c04d5a6614691ea99bd", typeof(Commit))]
- public void ShouldResolveWhenSpecifyingAValidObjectId(string objectId, Type expectedType)
- {
- object gitObject;
- using (var repo = new Repository(PathToRepository))
- {
- gitObject = repo.Resolve(objectId);
- }
-
- Assert.IsNotNull(gitObject);
- Assert.IsInstanceOf<GitObject>(gitObject);
- Assert.IsAssignableFrom(expectedType, gitObject);
- Assert.AreEqual(objectId, ((GitObject)(gitObject)).Id);
- }
-
- [TestCase("deadbeef1bbff43c37f0d0371823a5509eed5b1d", typeof(Tag))]
- public void ShouldNotResolveWhenSpecifyingAnInvalidObjectIdAndAValidExpectedType(string objectId, Type expectedType)
- {
- object gitObject;
- using (var repo = new Repository(PathToRepository))
- {
- gitObject = repo.Resolve(objectId, expectedType);
- }
-
- Assert.IsNull(gitObject);
- }
-
- [TestCase("7b4384978d2493e851f9cca7858815fac9b10980", typeof(Commit))]
- public void ShouldNotResolveWhenSpecifyingAValidObjectIdAndAnInvalidExpectedType(string objectId, Type expectedType)
- {
- object gitObject;
- using (var repo = new Repository(PathToRepository))
- {
- gitObject = repo.Resolve(objectId, expectedType);
- }
-
- Assert.IsNull(gitObject);
- }
-
- }
-}
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+using System.Linq;
+using LibGit2Sharp.Core;
+using NUnit.Framework;
+using System.IO;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class RepositoryFixtures : ReadOnlyRepositoryFixtureBase
+ {
+ [Test]
+ public void Ctor_RetrieveDetails()
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ Assert.AreEqual(true, repo.Details.IsBare);
+
+ var gitDir = new DirectoryInfo(PathToRepository);
+ Assert.AreEqual(gitDir, new DirectoryInfo(repo.Details.RepositoryDirectory));
+
+ var odb = new DirectoryInfo(repo.Details.DatabaseDirectory);
+ Assert.AreEqual("objects", odb.Name);
+ }
+ }
+
+ [Test]
+ public void AnExistingObjectCanBeFound()
+ {
+ const string objectId = "8496071c1b46c854b31185ea97743be6a8774479";
+ bool hasBeenFound;
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ hasBeenFound = repo.Exists(objectId);
+ }
+
+ Assert.AreEqual(true, hasBeenFound);
+ }
+
+ [Test]
+ public void AnNonExistingObjectCanNotBeFound()
+ {
+ const string objectId = "a496071c1b46c854b31185ea97743be6a8774471";
+ bool hasBeenFound;
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ hasBeenFound = repo.Exists(objectId);
+ }
+
+ Assert.AreEqual(false, hasBeenFound);
+ }
+
+ [Test]
+ public void AnExistingTagCanBeResolvedWithoutSpecifyingItsExpectedType()
+ {
+ const string objectId = "7b4384978d2493e851f9cca7858815fac9b10980";
+ GitObject gitObject;
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ gitObject = repo.Resolve(objectId);
+ }
+
+ Assert.IsNotNull(gitObject);
+ Assert.AreEqual(objectId, gitObject.Id);
+ Assert.AreEqual(ObjectType.Tag, gitObject.Type);
+ Assert.IsAssignableFrom<Tag>(gitObject);
+
+ var tag = gitObject as Tag;
+
+ AssertTag_7b43849(objectId, tag);
+ }
+
+ [Test]
+ public void AnExistingCommitCanBeResolvedThroughChainedTags()
+ {
+ // Inspired from https://github.com/libgit2/libgit2/blob/44908fe763b1a2097b65c86130ac679c458df7d2/tests/t0801-readtag.c
+
+ const string tag1Id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
+ const string tag2Id = "7b4384978d2493e851f9cca7858815fac9b10980";
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ var tag1 = repo.Resolve<Tag>(tag1Id);
+ Assert.IsNotNull(tag1);
+ Assert.AreEqual("test", tag1.Name);
+ Assert.AreEqual(tag1Id, tag1.Id);
+
+ Assert.IsNotNull(tag1.Target);
+ Assert.AreEqual(ObjectType.Tag, tag1.Target.Type);
+
+ var tag2 = (Tag) tag1.Target;
+ Assert.AreEqual(tag2Id, tag2.Id);
+
+ Assert.IsNotNull(tag2.Target);
+ Assert.AreEqual(ObjectType.Commit, tag2.Target.Type);
+
+ var commit = (Commit) tag2.Target;
+ Assert.IsNotNull(commit.Author);
+ }
+ }
+
+ [Test]
+ public void AnExistingTagCanBeResolvedBySpecifyingItsExpectedType()
+ {
+ const string objectId = "7b4384978d2493e851f9cca7858815fac9b10980";
+ Tag tag;
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ tag = repo.Resolve<Tag>(objectId);
+ }
+
+ AssertTag_7b43849(objectId, tag);
+ }
+
+ [Test]
+ public void AnExistingCommitCanBeResolvedBySpecifyingItsExpectedType()
+ {
+ const string objectId = "a4a7dce85cf63874e984719f4fdd239f5145052f";
+ Commit commit;
+
+ using (var repo = new Repository(PathToRepository))
+ {
+ commit = repo.Resolve<Commit>(objectId);
+ }
+
+ AssertCommit_a4a7dce(objectId, commit);
+ }
+
+ private static void AssertCommit_a4a7dce(string objectId, Commit commit)
+ {
+ Assert.IsNotNull(commit);
+ Assert.AreEqual(objectId, commit.Id);
+ Assert.AreEqual(ObjectType.Commit, commit.Type);
+ Assert.AreEqual("schacon@gmail.com", commit.Author.Email);
+ Assert.AreEqual("Scott Chacon", commit.Committer.Name);
+ Assert.AreEqual("Merge branch 'master' into br2\n", commit.Message);
+ Assert.AreEqual("Merge branch 'master' into br2", commit.MessageShort);
+ Assert.AreEqual(Epoch.ToDateTimeOffset(1274814023, -420), commit.Committer.When);
+ Assert.AreEqual(2, commit.Parents.Count());
+
+ }
+
+ private static void AssertTag_7b43849(string objectId, Tag tag)
+ {
+ Assert.IsNotNull(tag);
+ Assert.AreEqual(objectId, tag.Id);
+ Assert.AreEqual(ObjectType.Tag, tag.Type);
+ Assert.AreEqual("e90810b", tag.Name);
+ Assert.AreEqual("tanoku@gmail.com", tag.Tagger.Email);
+ Assert.AreEqual("This is a very simple tag.\n", tag.Message);
+ Assert.IsNotNull(tag.Tagger);
+ Assert.IsNotNull(tag.Tagger.When);
+ Assert.AreEqual(Epoch.ToDateTimeOffset(1281578357, 120), tag.Tagger.When);
+ Assert.IsNotNull(tag.Target);
+ Assert.AreEqual("e90810b8df3e80c413d903f631643c716887138d", tag.Target.Id);
+ Assert.AreEqual(ObjectType.Commit, tag.Target.Type);
+
+ var targetCommit = (Commit) tag.Target;
+ Assert.AreEqual(1, targetCommit.Parents.Count());
+ Assert.AreEqual("6dcf9bf7541ee10456529833502442f385010c3d", targetCommit.Parents.First().Id);
+ Assert.AreEqual(ObjectType.Commit, targetCommit.Parents.First().Type);
+
+ }
+
+ [TestCase("7b4384978d2493e851f9cca7858815fac9b10980", typeof(Tag))]
+ [TestCase("8496071c1b46c854b31185ea97743be6a8774479", typeof(Commit))]
+ public void ShouldResolveWhenSpecifyingAValidObjectIdAndAValidExpectedType(string objectId, Type expectedType)
+ {
+ object gitObject;
+ using (var repo = new Repository(PathToRepository))
+ {
+ gitObject = repo.Resolve(objectId, expectedType);
+ }
+
+ Assert.IsNotNull(gitObject);
+ Assert.IsInstanceOf<GitObject>(gitObject);
+ Assert.IsAssignableFrom(expectedType, gitObject);
+ Assert.AreEqual(objectId, ((GitObject)(gitObject)).Id);
+ }
+
+ [TestCase("7b4384978d2493e851f9cca7858815fac9b10980", typeof(Tag))]
+ [TestCase("c47800c7266a2be04c571c04d5a6614691ea99bd", typeof(Commit))]
+ public void ShouldResolveWhenSpecifyingAValidObjectId(string objectId, Type expectedType)
+ {
+ object gitObject;
+ using (var repo = new Repository(PathToRepository))
+ {
+ gitObject = repo.Resolve(objectId);
+ }
+
+ Assert.IsNotNull(gitObject);
+ Assert.IsInstanceOf<GitObject>(gitObject);
+ Assert.IsAssignableFrom(expectedType, gitObject);
+ Assert.AreEqual(objectId, ((GitObject)(gitObject)).Id);
+ }
+
+ [TestCase("deadbeef1bbff43c37f0d0371823a5509eed5b1d", typeof(Tag))]
+ public void ShouldNotResolveWhenSpecifyingAnInvalidObjectIdAndAValidExpectedType(string objectId, Type expectedType)
+ {
+ object gitObject;
+ using (var repo = new Repository(PathToRepository))
+ {
+ gitObject = repo.Resolve(objectId, expectedType);
+ }
+
+ Assert.IsNull(gitObject);
+ }
+
+ [TestCase("7b4384978d2493e851f9cca7858815fac9b10980", typeof(Commit))]
+ public void ShouldNotResolveWhenSpecifyingAValidObjectIdAndAnInvalidExpectedType(string objectId, Type expectedType)
+ {
+ object gitObject;
+ using (var repo = new Repository(PathToRepository))
+ {
+ gitObject = repo.Resolve(objectId, expectedType);
+ }
+
+ Assert.IsNull(gitObject);
+ }
+
+ }
+}
View
46 LibGit2Sharp.Tests/Api/ResolvingAHeadReference.cs
@@ -0,0 +1,46 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class ResolvingAHeadReference : ReadOnlyRepositoryFixtureBase
+ {
+ [TestCase("HEAD", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ [TestCase("refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")]
+ public void ShouldReturnACommit(string reference, string expectedId)
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ GitObject gitObject = repo.Resolve(reference);
+ Assert.IsNotNull(gitObject);
+ Assert.IsAssignableFrom(typeof(Commit), gitObject);
+ Assert.AreEqual(ObjectType.Commit, gitObject.Type);
+ Assert.AreEqual(expectedId, gitObject.Id);
+ }
+ }
+ }
+}
View
46 LibGit2Sharp.Tests/Api/ResolvingATagReference.cs
@@ -0,0 +1,46 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class ResolvingATagReference : ReadOnlyRepositoryFixtureBase
+ {
+ [TestCase("refs/tags/test", "b25fa35b38051e4ae45d4222e795f9df2e43f1d1")]
+ [TestCase("refs/tags/very-simple", "7b4384978d2493e851f9cca7858815fac9b10980")]
+ public void ShouldReturnATag(string reference, string expectedId)
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ var gitObject = repo.Resolve(reference);
+ Assert.IsNotNull(gitObject);
+ Assert.IsAssignableFrom(typeof(Tag), gitObject);
+ Assert.AreEqual(ObjectType.Tag, gitObject.Type);
+ Assert.AreEqual(expectedId, gitObject.Id);
+ }
+ }
+ }
+}
View
43 LibGit2Sharp.Tests/Api/RetrievingAllReferences.cs
@@ -0,0 +1,43 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Api
+{
+ [TestFixture]
+ public class RetrievingAllReferences : ReadOnlyRepositoryFixtureBase
+ {
+ [Test]
+ public void ShouldNotReturnDuplicateRefsWhenTheyExistInBothPackedAndLooseState()
+ {
+ using (var repo = new Repository(PathToRepository))
+ {
+ IList<Ref> refs = repo.Refs.RetrieveAll();
+ Assert.AreEqual(7, refs.Count); //TODO: This test will pass once https://github.com/libgit2/libgit2/commit/7ad96e51ca81974c417914edbc81a63e390c4301 gets ported
+ }
+ }
+ }
+}
View
95 LibGit2Sharp.Tests/ApplyingATag.cs
@@ -1,95 +0,0 @@
-using System;
-using NUnit.Framework;
-
-namespace LibGit2Sharp.Tests
-{
- [TestFixture]
- public class ApplyingATag : ReadWriteRepositoryFixtureBase
- {
- private static readonly Signature _signature = new Signature("me", "me@me.me", DateTimeOffset.Now);
-
- [Test]
- public void ShouldThrowIfPassedANonExistingTarget()
- {
- const string invalidTargetId = "deadbeef1b46c854b31185ea97743be6a8774479";
-
- using (var repo = new Repository(PathToRepository))
- {
- Assert.Throws<ObjectNotFoundException>(() => repo.ApplyTag(invalidTargetId, "tagged", "messaged", _signature));
- }
- }
-
- [Test]
- public void ShouldReturnATag()
- {
- const string targetId = "8496071c1b46c854b31185ea97743be6a8774479";
-
- Tag appliedTag;
-
- const string tagName = "tagged";
- const string tagMessage = "messaged";
-
- using (var repo = new Repository(PathToRepository))
- {
- appliedTag = repo.ApplyTag(targetId, tagName, tagMessage, _signature);
- }
-
- Assert.IsNotNull(appliedTag);
- Assert.IsNotNullOrEmpty(appliedTag.Id);
- Assert.AreEqual(ObjectType.Tag, appliedTag.Type);
- Assert.AreEqual(targetId, appliedTag.Target.Id);
- AssertSignature(_signature, appliedTag.Tagger);
- }
-
- private static void AssertSignature(Signature expected, Signature current)
- {
- Assert.AreEqual(expected.Email, current.Email);
- Assert.AreEqual(expected.Name, current.Name);
- Assert.AreEqual(expected.When.ToGitDate(), current.When.ToGitDate());
- }
-
- [Test]
- public void ShouldReturnATagEmbeddingTheTargetGitObject()
- {
- Assert.Ignore();
- }
-
- [Test]
- public void ShouldWork() // TODO: Split into different tests (returnATag, PersistTheObject, MultipleApplies, ...)
- {
- const string targetId = "8496071c1b46c854b31185ea97743be6a8774479";
-
- Tag appliedTag;
- using (var repo = new Repository(PathToRepository))
- {
- appliedTag = repo.ApplyTag(targetId, "tagged", "messaged", _signature);
- }
-
- var target = appliedTag.Target as Commit;
- Assert.IsNotNull(target);
-
- Assert.IsNotNull(target.Author);
- Assert.IsNotNull(target.Committer);
- Assert.IsNotNull(target.Message);
-
- Tag retrievedTag;
- using (var repo = new Repository(PathToRepository))
- {
- retrievedTag = repo.Resolve<Tag>(appliedTag.Id);
- }
-
- var target2 = retrievedTag.Target as Commit;
- Assert.IsNotNull(target2);
-
- Assert.IsNotNull(target2.Author);
- Assert.IsNotNull(target2.Committer);
- Assert.IsNotNull(target2.Message);
-
-
- Assert.AreEqual(appliedTag.Id, retrievedTag.Id);
- // TODO: Finalize comparison
-
- //
- }
- }
-}
View
62 LibGit2Sharp.Tests/Core/DatabaseFixture.cs
@@ -0,0 +1,62 @@
+/*
+* The MIT License
+*
+* Copyright (c) 2011 LibGit2Sharp committers
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
+using System.IO;
+using LibGit2Sharp.Core;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Core
+{
+ [TestFixture]
+ public class DatabaseFixture : ReadOnlyRepositoryFixtureBase
+ {
+ [Test]
+ public void AnExistingObjectCanBeRead()
+ {
+ const string objectId = "8496071c1b46c854b31185ea97743be6a8774479";
+ DatabaseObject databaseObject;
+
+ using (var repo = new LibGit2Sharp.Core.Repository(PathToRepository))
+ {
+ databaseObject = repo.Database.Read(objectId);
+ }
+
+ Assert.IsNotNull(databaseObject);
+ Assert.AreEqual(objectId, databaseObject.ObjectId.ToString());
+ Assert.AreEqual(git_otype.GIT_OBJ_COMMIT, databaseObject.Type);
+ Assert.AreEqual(172, databaseObject.Length);
+
+
+ using (var ms = new MemoryStream(databaseObject.GetData()))
+ using (var sr = new StreamReader(ms))
+ {
+ string content = sr.ReadToEnd();
+ StringAssert.StartsWith("tree ", content);
+ StringAssert.EndsWith("testing\n", content);
+ }
+
+ databaseObject.Close();
+ }
+ }
+}
View
106 LibGit2Sharp.Tests/Core/EpochFixture.cs
@@ -0,0 +1,106 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+using LibGit2Sharp.Core;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Core
+{
+ [TestFixture]
+ public class EpochFixture
+ {
+ [TestCase(0)]
+ [TestCase(17)]
+ public void UnixTimestampShouldBeCastIntoAUtcBasedDateTimeOffset(long secondsSinceEpoch)
+ {
+ var date = Epoch.ToDateTimeOffset(secondsSinceEpoch, 0);
+ Assert.AreEqual(0, date.Offset.TotalMinutes);
+
+ Assert.AreEqual(TimeSpan.Zero, date.Offset);
+ Assert.AreEqual(DateTimeKind.Utc, date.UtcDateTime.Kind);
+ }
+
+ [TestCase(0, 0)]
+ [TestCase(17, -120)]
+ [TestCase(31, 60)]
+ public void AreEqual(long secondsSinceEpoch, int timezoneOffset)
+ {
+ var one = Epoch.ToDateTimeOffset(secondsSinceEpoch, timezoneOffset);
+ var another = Epoch.ToDateTimeOffset(secondsSinceEpoch, timezoneOffset);
+
+ Assert.AreEqual(one, another);
+ Assert.AreEqual(another, one);
+
+ Assert.IsTrue(one == another);
+ Assert.IsTrue(another == one);
+
+ Assert.IsFalse(one != another);
+ Assert.IsFalse(another != one);
+
+ Assert.AreEqual(one.GetHashCode(), another.GetHashCode());
+ }
+
+ [TestCase(1291801952, "Wed, 08 Dec 2010 09:52:32 GMT")]
+ [TestCase(1234567890, "Fri, 13 Feb 2009 23:31:30 GMT")]
+ [TestCase(1288114383, "Tue, 26 Oct 2010 17:33:03 GMT")]
+ public void UnixTimestampShouldShouldBeCastIntoAPlainUtcDate(long secondsSinceEpoch, string expected)
+ {
+ var expectedDate = DateTimeOffset.Parse(expected);
+
+ var date = Epoch.ToDateTimeOffset(secondsSinceEpoch, 0);
+
+ Assert.AreEqual(secondsSinceEpoch, Epoch.ToSecondsSinceEpoch(date));
+ Assert.AreEqual(expectedDate, date);
+ Assert.AreEqual(TimeSpan.Zero, date.Offset);
+ }
+
+ [TestCase(1250379778, -210, "Sat, 15 Aug 2009 20:12:58 -0330")]
+ public void UnixTimestampAndTimezoneOffsetShouldBeCastIntoAUtcDateBearingAnOffset(long secondsSinceEpoch, Int32 offset, string expected)
+ {
+ var expectedDate = DateTimeOffset.Parse(expected);
+
+ var date = Epoch.ToDateTimeOffset(secondsSinceEpoch, offset);
+ Assert.AreEqual(offset, date.Offset.TotalMinutes);
+ Assert.AreEqual(secondsSinceEpoch, Epoch.ToSecondsSinceEpoch(date));
+
+ Assert.AreEqual(expectedDate, date);
+ Assert.AreEqual(expectedDate.Offset, date.Offset);
+ }
+
+ [TestCase("Wed, 08 Dec 2010 09:52:32 GMT", 1291801952, 0)]
+ [TestCase("Fri, 13 Feb 2009 23:31:30 GMT", 1234567890, 0)]
+ [TestCase("Tue, 26 Oct 2010 17:33:03 GMT", 1288114383, 0)]
+ [TestCase("Sat, 14 Feb 2009 00:31:30 +0100", 1234567890, 60)]
+ [TestCase("Sat, 15 Aug 2009 20:12:58 -0330", 1250379778, -210)]
+ [TestCase("Sat, 15 Aug 2009 23:42:58 GMT", 1250379778, 0)]
+ [TestCase("Sun, 16 Aug 2009 00:42:58 +0100", 1250379778, 60)]
+ public void DateTimeOffsetShoudlBeCastIntoAUnixTimestampAndATimezoneOffset(string formattedDate, long expectedSeconds, Int32 expectedOffset)
+ {
+ var when = DateTimeOffset.Parse(formattedDate);
+ var date = Epoch.ToDateTimeOffset(expectedSeconds, expectedOffset);
+ Assert.AreEqual(when, date);
+ }
+ }
+}
View
45 LibGit2Sharp.Tests/Core/IndexTests.cs
@@ -0,0 +1,45 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using LibGit2Sharp.Core;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Core
+{
+ [TestFixture]
+ public class IndexTests : ReadOnlyRepositoryFixtureBase
+ {
+ [Test]
+ public void IndexTest()
+ {
+ var index = new Index(string.Format("{0}/index", PathToRepository));
+
+ index.Read();
+
+ Assert.AreEqual(109, index.Count);
+ Assert.AreEqual(index[4].Path, "Makefile");
+ Assert.AreEqual(index[62].Path, "tests/Makefile");
+ }
+ }
+}
View
49 LibGit2Sharp.Tests/Core/SignatureTest.cs
@@ -0,0 +1,49 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 LibGit2Sharp committers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+using System;
+using NUnit.Framework;
+
+namespace LibGit2Sharp.Tests.Core
+{
+ [TestFixture]
+ public class CreatingASignature : ReadOnlyRepositoryFixtureBase
+ {
+ [Test]
+ public void ShouldNotAlterOriginalProperties()
+ {
+ const string name = "me";
+ const string email = "me@me.me";
+ DateTimeOffset now = DateTimeOffset.Now;
+
+ var sign = new LibGit2Sharp.Core.Signature(name, email, now);
+
+ Assert.AreEqual(name, sign.Name);
+ Assert.AreEqual(email, sign.Email);
+ TestHelper.AssertUnixDateTimeOffset(now, sign.When);
+
+ sign.Free();
+ }
+ }
+}
View
91 LibGit2Sharp.Tests/GitDateFixture.cs
@@ -1,91 +0,0 @@
-using System;
-using NUnit.Framework;
-
-namespace LibGit2Sharp.Tests
-{
- [TestFixture]
- public class GitDateFixture
- {
- [TestCase(0)]
- [TestCase(17)]
- public void UnixTimestampShouldBeCastIntoAUtcBasedDateTimeOffset(Int32 secondsSinceEpoch)
- {
- var date = new GitDate(secondsSinceEpoch, 0);
- Assert.AreEqual(0, date.TimeZoneOffset);
-
- var when = date.ToDateTimeOffset();
-
- Assert.AreEqual(TimeSpan.Zero, when.Offset);
- Assert.AreEqual(DateTimeKind.Utc, when.UtcDateTime.Kind);
- }
-
- [TestCase(0, 0)]
- [TestCase(17, -120)]
- [TestCase(31, 60)]
- public void AreEqual(Int32 secondsSinceEpoch, int timezoneOffset)
- {
- var one = new GitDate(secondsSinceEpoch, timezoneOffset);
- var another = new GitDate(secondsSinceEpoch, timezoneOffset);
-
- Assert.AreEqual(one, another);
- Assert.AreEqual(another, one);
-
- Assert.IsTrue(one == another);
- Assert.IsTrue(another == one);
-
- Assert.IsFalse(one != another);
- Assert.IsFalse(another != one);
-
- Assert.AreEqual(one.GetHashCode(), another.GetHashCode());
- }
-
- [TestCase(1291801952, "Wed, 08 Dec 2010 09:52:32 GMT")]
- [TestCase(1234567890, "Fri, 13 Feb 2009 23:31:30 GMT")]
- [TestCase(1288114383, "Tue, 26 Oct 2010 17:33:03 GMT")]
- public void UnixTimestampShouldShouldBeCastIntoAPlainUtcDate(Int32 secondsSinceEpoch, string expected)
- {
- var expectedDate = DateTimeOffset.Parse(expected);
-
- var date = new GitDate(secondsSinceEpoch, 0);
- Assert.AreEqual(0, date.TimeZoneOffset);
- Assert.AreEqual(secondsSinceEpoch, date.UnixTimeStamp);
-
- var when = date.ToDateTimeOffset();
-
- Assert.AreEqual(expectedDate, when);
- Assert.AreEqual(TimeSpan.Zero, when.Offset);
- }
-
- [TestCase(1250379778, -210, "Sat, 15 Aug 2009 20:12:58 -0330")]
- public void UnixTimestampAndTimezoneOffsetShouldBeCastIntoAUtcDateBearingAnOffset(Int32 secondsSinceEpoch, Int32 offset, string expected)
- {
- var expectedDate = DateTimeOffset.Parse(expected);
-
- var date = new GitDate(secondsSinceEpoch, offset);
- Assert.AreEqual(offset, date.TimeZoneOffset);
- Assert.AreEqual(secondsSinceEpoch, date.UnixTimeStamp);
-
- var when = date.ToDateTimeOffset();
-
- Assert.AreEqual(expectedDate, when);
- Assert.AreEqual(expectedDate.Offset, when.Offset);
- }
-
- [TestCase("Wed, 08 Dec 2010 09:52:32 GMT", 1291801952, 0)]
- [TestCase("Fri, 13 Feb 2009 23:31:30 GMT", 1234567890, 0)]
- [TestCase("Tue, 26 Oct 2010 17:33:03 GMT", 1288114383, 0)]
- [TestCase("Sat, 14 Feb 2009 00:31:30 +0100", 1234567890, 60)]
- [TestCase("Sat, 15 Aug 2009 20:12:58 -0330", 1250379778, -210)]
- [TestCase("Sat, 15 Aug 2009 23:42:58 GMT", 1250379778, 0)]
- [TestCase("Sun, 16 Aug 2009 00:42:58 +0100", 1250379778, 60)]
- public void DateTimeOffsetShoudlBeCastIntoAUnixTimestampAndATimezoneOffset(string formattedDate, Int32 expectedSeconds, Int32 expectedOffset)
- {
- var when = DateTimeOffset.Parse(formattedDate);
-
- var date = when.ToGitDate();
-
- Assert.AreEqual(expectedSeconds, date.UnixTimeStamp);
- Assert.AreEqual(expectedOffset, date.TimeZoneOffset);
- }
- }
-}
View
33 LibGit2Sharp.Tests/InitializingARepository.cs
@@ -1,33 +0,0 @@
-using System.IO;
-using NUnit.Framework;
-
-namespace LibGit2Sharp.Tests
-{
- [TestFixture]
- public class InitializingARepository : RepositoryToBeCreatedFixtureBase
- {
- [TestCase(true)]
- [TestCase(false)]
- public void ShouldReturnAValidGitPath(bool isBare)
- {
- var expectedGitDirName = new DirectoryInfo(PathToTempDirectory).Name;
-
- expectedGitDirName += isBare ? "/" : "/.git/";
-
- var gitDirPath = Repository.Init(PathToTempDirectory, isBare);
- StringAssert.EndsWith(expectedGitDirName, gitDirPath);
- }
-
- [TestCase(true)]
- [TestCase(false)]
- public void ShouldGenerateAValidRepository(bool isBare)
- {
- var gitDirPath = Repository.Init(PathToTempDirectory, isBare);
-
- using (var repo = new Repository(gitDirPath))
- {
- Assert.AreEqual(gitDirPath, repo.Details.RepositoryDirectory);
- }
- }
- }
-}
View
158 LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,76 +1,84 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{286E63EB-04DD-4ADE-88D6-041B57800761}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>LibGit2Sharp.Tests</RootNamespace>
- <AssemblyName>LibGit2Sharp.Tests</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\build\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>..\build\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="nunit.framework">
- <HintPath>..\libs\nunit.framework.dll</HintPath>