提交 0bee0993 编写于 作者: T Tim Clem

Squash up commits on devel branch

This is being done to clean up commit history on master.
上级 55863d68
#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%
\ No newline at end of file
[submodule "libgit2"]
path = libgit2
url = https://github.com/libgit2/libgit2.git
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.
/*
* 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("")]
/*
* 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();
}
}
}
<?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>
/*
* 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(";");
}
}
}
/*
* 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.
*/
\ No newline at end of file
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
//
}
}
/*
* 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;
}
}
}
\ No newline at end of file
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);
}
}
}
/*
* 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);
}
}
}
}
\ No newline at end of file
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);
}
}
}
\ No newline at end of file
/*
* 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));
}
}
}
}
\ No newline at end of file
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);
}
}
}
\ No newline at end of file
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);
}
}
}
/*
* 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);
}
}
}
}
\ No newline at end of file
/*
* 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);
}
}
}
}
\ No newline at end of file
/*
* 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
}
}
}
}
\ No newline at end of file
/*
* 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();
}
}
}
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);
}
}
}
/*
* 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);
}
}
}
/*
* 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");
}
}
}
/*
* 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();
}
}
}
\ No newline at end of file
<?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>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplyingATag.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="GitDateFixture.cs" />
<Compile Include="InitializingARepository.cs" />
<Compile Include="ObjectIdFixture.cs" />
<Compile Include="ReadOnlyRepositoryFixtureBase.cs" />
<Compile Include="ReadWriteRepositoryFixtureBase.cs" />
<Compile Include="RepositoryFixtures.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="InstantiatingARepository.cs" />
<Compile Include="RepositoryToBeCreatedFixtureBase.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibGit2Sharp\LibGit2Sharp.csproj">
<Project>{EE6ED99F-CB12-4683-B055-D28FC7357A34}</Project>
<Name>libgit2net</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>xcopy "$(SolutionDir)/Resources/*.*" "./Resources" /Y /E /F /I</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<?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>v3.5</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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=2.5.8.10295, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<HintPath>..\libs\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Api\ApplyingATag.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Api\LookingUpAHeadReference.cs" />
<Compile Include="Api\ResolvingAHeadReference.cs" />
<Compile Include="Api\InitializingARepository.cs" />
<Compile Include="Api\ObjectIdFixture.cs" />
<Compile Include="Api\RetrievingAllReferences.cs" />
<Compile Include="Core\DatabaseFixture.cs" />
<Compile Include="Core\EpochFixture.cs" />
<Compile Include="Core\IndexTests.cs" />
<Compile Include="Core\SignatureTest.cs" />
<Compile Include="ReadOnlyRepositoryFixtureBase.cs" />
<Compile Include="ReadWriteRepositoryFixtureBase.cs" />
<Compile Include="Api\RepositoryFixtures.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Api\InstantiatingARepository.cs" />
<Compile Include="RepositoryToBeCreatedFixtureBase.cs" />
<Compile Include="Api\ResolvingATagReference.cs" />
<Compile Include="TestHelper.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibGit2Sharp\LibGit2Sharp.csproj">
<Project>{EE6ED99F-CB12-4683-B055-D28FC7357A34}</Project>
<Name>LibGit2Sharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>xcopy "$(SolutionDir)/Resources/*.*" "./Resources" /Y /E /F /I</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("libgit2sharp.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("libgit2sharp.Tests")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("808554a4-f9fd-4035-8ab9-325793c7da51")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("libgit2sharp.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("libgit2sharp.Tests")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("808554a4-f9fd-4035-8ab9-325793c7da51")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
namespace LibGit2Sharp.Tests
{
public class ReadOnlyRepositoryFixtureBase
{
private const string readOnlyGitRepository = "./Resources/testrepo.git";
protected virtual string PathToRepository { get { return readOnlyGitRepository; } }
}
}
\ No newline at end of file
/*
* 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.
*/
namespace LibGit2Sharp.Tests
{
public class ReadOnlyRepositoryFixtureBase
{
private const string readOnlyGitRepository = "./Resources/testrepo.git";
protected virtual string PathToRepository { get { return readOnlyGitRepository; } }
}
}
using System;
using System.IO;
using System.Reflection;
using NUnit.Framework;
namespace LibGit2Sharp.Tests
{
public class ReadWriteRepositoryFixtureBase : RepositoryToBeCreatedFixtureBase
{
private const string readOnlyGitRepository = "./Resources/testrepo.git";
private string _pathToRepository;
protected string PathToRepository { get { return _pathToRepository; } }
[SetUp]
public override void Setup()
{
base.Setup();
var source = new DirectoryInfo(readOnlyGitRepository);
var tempRepository = new DirectoryInfo(Path.Combine(PathToTempDirectory, source.Name));
CopyFilesRecursively(source, tempRepository);
_pathToRepository = tempRepository.FullName;
}
public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target)
{
// From http://stackoverflow.com/questions/58744/best-way-to-copy-the-entire-contents-of-a-directory-in-c/58779#58779
foreach (DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
foreach (FileInfo file in source.GetFiles())
file.CopyTo(Path.Combine(target.FullName, file.Name));
}
}
/*
* 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 System.Reflection;
using NUnit.Framework;
namespace LibGit2Sharp.Tests
{
public class ReadWriteRepositoryFixtureBase : RepositoryToBeCreatedFixtureBase
{
private const string readOnlyGitRepository = "./Resources/testrepo.git";
private string _pathToRepository;
protected string PathToRepository { get { return _pathToRepository; } }
[SetUp]
public override void Setup()
{
base.Setup();
var source = new DirectoryInfo(readOnlyGitRepository);
var tempRepository = new DirectoryInfo(Path.Combine(PathToTempDirectory, source.Name));
CopyFilesRecursively(source, tempRepository);
_pathToRepository = tempRepository.FullName;
}
public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target)
{
// From http://stackoverflow.com/questions/58744/best-way-to-copy-the-entire-contents-of-a-directory-in-c/58779#58779
foreach (DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
foreach (FileInfo file in source.GetFiles())
file.CopyTo(Path.Combine(target.FullName, file.Name));
}
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Reflection;
using NUnit.Framework;
namespace LibGit2Sharp.Tests
{
public class RepositoryToBeCreatedFixtureBase
{
private const string TestRepositoriesDirectoryName = "TestRepos";
private static readonly string _testRepositoriesDirectoryPath = RetrieveTestRepositoriesDirectory();
private string _pathToTempDirectory;
protected string PathToTempDirectory { get { return _pathToTempDirectory; } }
[SetUp]
public virtual void Setup()
{
string workDirpath = Path.Combine(_testRepositoriesDirectoryPath, this.GetType().Name, Guid.NewGuid().ToString().Substring(0, 8));
Directory.CreateDirectory(workDirpath);
_pathToTempDirectory = workDirpath;
}
[TestFixtureTearDown]
public virtual void TestFixtureTearDown()
{
DeleteDirectory(_testRepositoriesDirectoryPath);
}
private static void DeleteDirectory(string directoryPath)
{
// From http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true/329502#329502
string[] files = Directory.GetFiles(directoryPath);
string[] dirs = Directory.GetDirectories(directoryPath);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
File.SetAttributes(directoryPath, FileAttributes.Normal);
Directory.Delete(directoryPath, false);
}
static private string RetrieveAssemblyDirectory()
{
// From http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in/283917#283917
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
static private string RetrieveTestRepositoriesDirectory()
{
return Path.Combine(RetrieveAssemblyDirectory(), TestRepositoriesDirectoryName);
}
}
/*
* 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 System.Reflection;
using NUnit.Framework;
namespace LibGit2Sharp.Tests
{
public class RepositoryToBeCreatedFixtureBase
{
private const string TestRepositoriesDirectoryName = "TestRepos";
private static readonly string _testRepositoriesDirectoryPath = RetrieveTestRepositoriesDirectory();
private string _pathToTempDirectory;
protected string PathToTempDirectory { get { return _pathToTempDirectory; } }
[SetUp]
public virtual void Setup()
{
string workDirpath = Path.Combine(Path.Combine(_testRepositoriesDirectoryPath, this.GetType().Name), Guid.NewGuid().ToString().Substring(0, 8));
Directory.CreateDirectory(workDirpath);
_pathToTempDirectory = workDirpath;
}
[TestFixtureTearDown]
public virtual void TestFixtureTearDown()
{
DeleteDirectory(_testRepositoriesDirectoryPath);
}
private static void DeleteDirectory(string directoryPath)
{
// From http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true/329502#329502
string[] files = Directory.GetFiles(directoryPath);
string[] dirs = Directory.GetDirectories(directoryPath);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
File.SetAttributes(directoryPath, FileAttributes.Normal);
Directory.Delete(directoryPath, false);
}
static private string RetrieveAssemblyDirectory()
{
// From http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in/283917#283917
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
static private string RetrieveTestRepositoriesDirectory()
{
return Path.Combine(RetrieveAssemblyDirectory(), TestRepositoriesDirectoryName);
}
}
}
\ No newline at end of file
/*
* 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
{
public static class TestHelper
{
public static void AssertUnixDateTimeOffset(DateTimeOffset expected, DateTimeOffset current)
{
Assert.AreEqual(expected.Date, current.Date);
Assert.AreEqual(expected.Offset, current.Offset);
Assert.AreEqual(expected.Hour, current.Hour);
Assert.AreEqual(expected.Minute, current.Minute);
Assert.AreEqual(expected.Second, current.Second);
}
}
}
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libgit2wrap", "libgit2wrap\libgit2.wrap.vcxproj", "{45FF8275-1165-4FEE-B16A-6D270E14A455}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGitSharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}"
ProjectSection(ProjectDependencies) = postProject
{45FF8275-1165-4FEE-B16A-6D270E14A455} = {45FF8275-1165-4FEE-B16A-6D270E14A455}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp.Tests", "LibGit2Sharp.Tests\LibGit2Sharp.Tests.csproj", "{286E63EB-04DD-4ADE-88D6-041B57800761}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Debug|Any CPU.ActiveCfg = Debug|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Debug|Win32.ActiveCfg = Debug|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Debug|Win32.Build.0 = Debug|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Release|Any CPU.ActiveCfg = Release|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Release|Mixed Platforms.Build.0 = Release|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Release|Win32.ActiveCfg = Release|Win32
{45FF8275-1165-4FEE-B16A-6D270E14A455}.Release|Win32.Build.0 = Release|Win32
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Win32.ActiveCfg = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.Build.0 = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Win32.ActiveCfg = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.Build.0 = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Win32.ActiveCfg = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.ActiveCfg = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.Build.0 = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Win32.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp.Tests", "LibGit2Sharp.Tests\LibGit2Sharp.Tests.csproj", "{286E63EB-04DD-4ADE-88D6-041B57800761}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp.Core.Generator", "LibGit2Sharp.Core.Generator\LibGit2Sharp.Core.Generator.csproj", "{2F434CB5-FB41-4B43-83E4-79C9B57DF622}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Win32.ActiveCfg = Debug|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.Build.0 = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Win32.ActiveCfg = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.Build.0 = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Win32.ActiveCfg = Debug|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.ActiveCfg = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.Build.0 = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Win32.ActiveCfg = Release|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Debug|Win32.ActiveCfg = Debug|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Debug|Win32.Build.0 = Debug|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Release|Any CPU.Build.0 = Release|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Release|Win32.ActiveCfg = Release|Any CPU
{2F434CB5-FB41-4B43-83E4-79C9B57DF622}.Release|Win32.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = LibGit2Sharp.Core.Generator\LibGit2Sharp.Core.Generator.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = null
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.IndentSwitchBody = True
$2.BeforeMethodCallParentheses = False
$2.BeforeMethodDeclarationParentheses = False
$2.BeforeConstructorDeclarationParentheses = False
$2.BeforeDelegateDeclarationParentheses = False
$2.NewParentheses = False
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
$0.StandardHeader = $3
$3.Text =
$3.inheritsSet = Apache2License
$0.TextStylePolicy = $4
$4.FileWidth = 120
$4.RemoveTrailingWhitespace = True
$4.inheritsSet = VisualStudio
$4.inheritsScope = text/plain
$4.scope = text/plain
EndGlobalSection
EndGlobal
namespace LibGit2Sharp
{
public class Blob : GitObject
{
public Blob(string objectId)
: base(objectId, ObjectType.Blob)
{
}
}
}
/*
* 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.
*/
namespace LibGit2Sharp
{
public class Blob : GitObject
{
public Blob(string objectId)
: base(objectId, ObjectType.Blob)
{
}
}
}
using System;
using System.Collections.Generic;
namespace LibGit2Sharp
{
public class Commit : GitObject
{
public IEnumerable<GitObject> Parents { get; private set; }
public Signature Author { get; private set; }
public Signature Committer { get; private set; }
public DateTimeOffset When { get; private set; }
public string Message { get; private set; }
public string MessageShort { get; private set; }
public Tree Tree { get; private set; }
public Commit(string objectId, Signature author, Signature committer, string message, string messageShort, Tree tree, IEnumerable<GitObject> parents)
: base(objectId, ObjectType.Commit)
{
Parents = parents;
Author = author;
Committer = committer;
When = committer.When;
Message = message;
MessageShort = messageShort;
Tree = tree;
}
}
}
\ No newline at end of file
/*
* 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.Collections.Generic;
namespace LibGit2Sharp
{
public class Commit : GitObject
{
public IEnumerable<GitObject> Parents { get; private set; }
public Signature Author { get; private set; }
public Signature Committer { get; private set; }
public DateTimeOffset When { get; private set; }
public string Message { get; private set; }
public string MessageShort { get; private set; }
public Tree Tree { get; private set; }
public Commit(string objectId, Signature author, Signature committer, string message, string messageShort, Tree tree, IEnumerable<GitObject> parents)
: base(objectId, ObjectType.Commit)
{
Parents = parents;
Author = author;
Committer = committer;
When = committer.When;
Message = message;
MessageShort = messageShort;
Tree = tree;
}
}
}
/*
* 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.
*/
namespace LibGit2Sharp.Core
{
public static class Constants
{
public static char DirectorySeparatorChar = '/';
public const int GIT_OID_RAWSZ = 20;
public const int GIT_OID_HEXSZ = GIT_OID_RAWSZ * 2;
public static string GIT_HEAD_FILE = "HEAD";
}
}
/*
* 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
{
unsafe public class Database
{
internal git_odb *database;
internal Database(git_odb *database)
{
this.database = database;
}
public Database(string objectsDir)
{
int ret;
fixed (git_odb **database = &this.database)
{
ret = NativeMethods.git_odb_open(database, objectsDir);
}
GitError.Check(ret);
}
public bool Exists(string oid)
{
return Exists(new ObjectId(oid));
}
public bool Exists(ObjectId id)
{
return (NativeMethods.git_odb_exists(database, &id.oid) > 0);
}
public void Close()
{
NativeMethods.git_odb_close(database);
}
public void ReadHeader(string oid, out uint len, out git_otype type)
{
ReadHeader(new ObjectId(oid), out len, out type);
}
public void ReadHeader(ObjectId id, out uint len, out git_otype type)
{
int ret = NativeMethods.git_odb_read_header(out len, out type, database, &id.oid);
GitError.Check(ret);
}
public DatabaseObject Read(string oid)
{
return Read(new ObjectId(oid));
}
public DatabaseObject Read(ObjectId id)
{
git_odb_object *obj = null;
int ret = NativeMethods.git_odb_read(&obj, database, &id.oid);
GitError.Check(ret);
return new DatabaseObject(obj);
}
public ObjectId Hash(byte[] data, git_otype type)
{
ObjectId oid = new ObjectId();
int ret = NativeMethods.git_odb_hash(&oid.oid, data, (uint)data.Length, type);
GitError.Check(ret);
return oid;
}
}
}
/*
* 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.Runtime.InteropServices;
namespace LibGit2Sharp.Core
{
unsafe public class DatabaseObject
{
internal git_odb_object *odb_object;
internal DatabaseObject(git_odb_object *odb_object)
{
this.odb_object = odb_object;
}
public ObjectId ObjectId
{
get
{
return new ObjectId(NativeMethods.git_odb_object_id(odb_object));
}
}
public uint Length
{
get {
return NativeMethods.git_odb_object_size(odb_object);
}
}
public git_otype Type
{
get {
return NativeMethods.git_odb_object_type(odb_object);
}
}
internal void *RawData
{
get {
return NativeMethods.git_odb_object_data(odb_object);
}
}
public IntPtr DataPointer
{
get {
return new IntPtr(RawData);
}
}
public byte[] GetData()
{
byte[] rawData = new byte[Length];
Marshal.Copy(DataPointer, rawData, 0, (int)Length);
return rawData;
}
public NativeMemoryStream GetNativeMemoryStream()
{
IntPtr data = DataPointer;
if (data == IntPtr.Zero)
return null;
return new NativeMemoryStream(data, Length);
}
public void Close()
{
NativeMethods.git_odb_object_close(odb_object);
}
}
}
/*
* 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;
namespace LibGit2Sharp.Core
{
public static class Epoch
{
private static readonly DateTimeOffset _epochDateTimeOffset = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
public static DateTimeOffset ToDateTimeOffset(long secondsSinceEpoch, int timeZoneOffsetInMinutes)
{
DateTimeOffset utcDateTime = _epochDateTimeOffset.AddSeconds(secondsSinceEpoch);
TimeSpan offset = TimeSpan.FromMinutes(timeZoneOffsetInMinutes);
return new DateTimeOffset(utcDateTime.DateTime.Add(offset), offset);
}
public static long ToSecondsSinceEpoch(DateTimeOffset date)
{
DateTimeOffset utcDate = date.ToUniversalTime();
return (long)utcDate.Subtract(_epochDateTimeOffset).TotalSeconds;
}
}
}
/*
* 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
{
public class GitException : Exception
{
public GitException()
{
}
public GitException(string message)
: base(message)
{
}
}
}
/*
* 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
{
public class GitInternalException : GitException
{
public GitInternalException(int error)
: this((git_result)error)
{
}
public GitInternalException(git_result error)
: base(string.Format("{0}({1}): {2}", error, (int)error, GitError.Message((int)error)))
{
if (error == git_result.GIT_SUCCESS)
throw new ArgumentException("success is not an error!");
Error = error;
ErrorCode = (int)error;
}
public git_result Error { get; protected set; }
public int ErrorCode { get; protected set; }
}
}
/*
* 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.Collections.Generic;
namespace LibGit2Sharp.Core
{
public static class GitError
{
private static readonly IDictionary<git_result, Func<GitException>> _exceptionsMapper;
static GitError()
{
_exceptionsMapper = BuildMapper();
}
private static IDictionary<git_result, Func<GitException>> BuildMapper()
{
var mapper = new Dictionary<git_result, Func<GitException>>();
mapper.Add(git_result.GIT_ENOTAREPO, () => new NotAValidRepositoryException());
mapper.Add(git_result.GIT_ENOTFOUND, () => new ObjectNotFoundException());
mapper.Add(git_result.GIT_EINVALIDTYPE, () => new InvalidTypeException());
mapper.Add(git_result.GIT_EINVALIDREFNAME, () => new InvalidReferenceNameException());
return mapper;
}
unsafe internal static string Message(int error)
{
if (error < 0)
return string.Empty;
//TODO: Revert to code below once git_strerror() gets properly exposed on Windows
//return new string(NativeMethods.git_strerror(error));
return null;
}
public static void Check(int error)
{
if (error == (int)git_result.GIT_SUCCESS)
{
return;
}
Func<GitException> exceptionBuilder;
if (Enum.IsDefined(typeof (git_result), error) && _exceptionsMapper.TryGetValue((git_result)error, out exceptionBuilder))
{
throw exceptionBuilder();
}
throw new GitInternalException(error);
}
}
}
/*
* 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
{
public static class HelperExtensions
{
internal static DateTime ToDateTime(this git_index_time time)
{
DateTime dt = new DateTime(1900, 1, 1);
dt += TimeSpan.FromSeconds(time.time);
dt += TimeSpan.FromTicks(time.nanoseconds);
return dt;
}
}
}
/*
* 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.Collections;
using System.Collections.Generic;
namespace LibGit2Sharp.Core
{
unsafe public class Index : IEnumerable<IndexEntry>, IDisposable
{
private git_index *index = null;
internal Index(git_index *index)
{
this.index = index;
}
public Index(string indexPath)
{
int ret;
fixed (git_index **pindex = &index)
{
ret = NativeMethods.git_index_open_bare(pindex, indexPath);
}
GitError.Check(ret);
}
public uint Count
{
get {
return NativeMethods.git_index_entrycount(index);
}
}
public void Read()
{
NativeMethods.git_index_read(index);
}
public void Write()
{
NativeMethods.git_index_write(index);
}
public Repository Repository
{
get {
if (index->repository == null)
return null;
return new Repository(index->repository);
}
}
public IndexEntry Get(uint n)
{
git_index_entry *entry = NativeMethods.git_index_get(index, (int)n);
if (entry == null)
return null;
return new IndexEntry(entry);
}
public IndexEntry this[uint index]
{
get {
return Get(index);
}
}
public int Get(string path)
{
return NativeMethods.git_index_find(index, path);
}
public int this[string path]
{
get {
return Get(path);
}
}
public string FilePath
{
get {
return new string(index->index_file_path);
}
}
public void Clear()
{
NativeMethods.git_index_clear(index);
}
public void Add(string path, int stage)
{
int ret = NativeMethods.git_index_add(index, path, stage);
GitError.Check(ret);
}
public void Remove(int position)
{
int ret = NativeMethods.git_index_remove(index, position);
GitError.Check(ret);
}
public void Insert(IndexEntry indexEntry)
{
int ret = NativeMethods.git_index_insert(index, indexEntry.index_entry);
GitError.Check(ret);
}
#region IEnumerable implementation
public IEnumerator<IndexEntry> GetEnumerator()
{
uint count = Count;
for (uint i = 0; i < count; i++)
{
yield return Get(i);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator)this.GetEnumerator();
}
#endregion
#region IDisposable implementation
public void Dispose()
{
if (index != null)
NativeMethods.git_index_free(index);
}
#endregion
}
}
/*
* 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.Collections;
using System.Collections.Generic;
namespace LibGit2Sharp.Core
{
unsafe public class IndexEntry
{
internal git_index_entry *index_entry = null;
internal IndexEntry(git_index_entry *index_entry)
{
this.index_entry = index_entry;
}
public string Path
{
get {
return new string(index_entry->path);
}
}
public long FileSize
{
get {
return index_entry->file_size2 << sizeof(int) | index_entry->file_size1;
}
}
public DateTime MTime
{
get {
return index_entry->mtime.ToDateTime();
}
}
public DateTime CTime
{
get {
return index_entry->ctime.ToDateTime();
}
}
}
}
/*
* 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.IO;
namespace LibGit2Sharp.Core
{
unsafe public class NativeMemoryStream : Stream
{
void *ptr;
private long length;
private long position = 0;
internal NativeMemoryStream(IntPtr ptr, long length)
: this(ptr.ToPointer(), length)
{
}
internal NativeMemoryStream(void *ptr, long length)
{
this.ptr = ptr;
this.length = length;
}
#region implemented abstract members of System.IO.Stream
public override void Flush()
{
throw new System.NotImplementedException();
}
public override void SetLength(long value)
{
throw new System.NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new System.NotImplementedException();
}
public override int Read(byte[] buffer, int offset, int count)
{
int read = 0;
for (int i = 0; i < count; i++)
{
if (position >= Length)
continue;
buffer[i + offset] = ((byte *)ptr)[position];
position++;
read++;
}
return read;
}
public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
position = (long)ptr + offset;
break;
case SeekOrigin.Current:
position += offset;
break;
case SeekOrigin.End:
position = (long)ptr + length + offset;
break;
}
return position;
}
public override bool CanRead {
get {
return true;
}
}
public override bool CanSeek {
get {
return true;
}
}
public override bool CanWrite {
get {
return false;
}
}
public override long Length {
get {
return length;
}
}
public override long Position {
get {
return position;
}
set {
if ((long)ptr + position >= length)
throw new ArgumentException();
position = value;
}
}
#endregion
}
}
/*
* 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.
*/
// This code is autogenerated, do not modify
using System;
using System.Runtime.InteropServices;
namespace LibGit2Sharp.Core
{
unsafe internal class NativeMethods
{
private const string libgit2 = "git2.dll";
[DllImport(libgit2)]
public static extern void *git_blob_rawcontent(git_blob *blob);
[DllImport(libgit2)]
public static extern int git_blob_rawsize(git_blob *blob);
[DllImport(libgit2)]
public static extern int git_blob_create_fromfile(git_oid *oid, git_repository *repo, string path);
[DllImport(libgit2)]
public static extern int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, byte[] buffer, uint len);
[DllImport(libgit2)]
public static extern git_oid *git_commit_id(git_commit *commit);
[DllImport(libgit2)]
public static extern sbyte *git_commit_message_short(git_commit *commit);
[DllImport(libgit2)]
public static extern sbyte *git_commit_message(git_commit *commit);
[DllImport(libgit2)]
public static extern long git_commit_time(git_commit *commit);
[DllImport(libgit2)]
public static extern int git_commit_time_offset(git_commit *commit);
[DllImport(libgit2)]
public static extern git_signature *git_commit_committer(git_commit *commit);
[DllImport(libgit2)]
public static extern git_signature *git_commit_author(git_commit *commit);
[DllImport(libgit2)]
public static extern int git_commit_tree(git_tree **tree_out, git_commit *commit);
[DllImport(libgit2)]
public static extern uint git_commit_parentcount(git_commit *commit);
[DllImport(libgit2)]
public static extern int git_commit_parent(git_commit **parent, git_commit *commit, uint n);
[DllImport(libgit2)]
public static extern int git_commit_create(git_oid *oid, git_repository *repo, string update_ref, git_signature *author, git_signature *committer, string message, git_oid *tree_oid, int parent_count, git_oid **parent_oids);
[DllImport(libgit2)]
public static extern int git_commit_create_o(git_oid *oid, git_repository *repo, string update_ref, git_signature *author, git_signature *committer, string message, git_tree *tree, int parent_count, git_commit **parents);
[DllImport(libgit2)]
public static extern int git_commit_create_ov(git_oid *oid, git_repository *repo, string update_ref, git_signature *author, git_signature *committer, string message, git_tree *tree, int parent_count);
[DllImport(libgit2)]
public static extern int git_commit_create_v(git_oid *oid, git_repository *repo, string update_ref, git_signature *author, git_signature *committer, string message, git_oid *tree_oid, int parent_count);
[DllImport(libgit2)]
public static extern void git_strarray_free(git_strarray *array);
[DllImport(libgit2)]
public static extern sbyte *git_strerror(int num);
[DllImport(libgit2)]
public static extern int git_index_open_bare(git_index **index, string index_path);
[DllImport(libgit2)]
public static extern int git_index_open_inrepo(git_index **index, git_repository *repo);
[DllImport(libgit2)]
public static extern void git_index_clear(git_index *index);
[DllImport(libgit2)]
public static extern void git_index_free(git_index *index);
[DllImport(libgit2)]
public static extern int git_index_read(git_index *index);
[DllImport(libgit2)]
public static extern int git_index_write(git_index *index);
[DllImport(libgit2)]
public static extern int git_index_find(git_index *index, string path);
[DllImport(libgit2)]
public static extern int git_index_add(git_index *index, string path, int stage);
[DllImport(libgit2)]
public static extern int git_index_remove(git_index *index, int position);
[DllImport(libgit2)]
public static extern int git_index_insert(git_index *index, git_index_entry *source_entry);
[DllImport(libgit2)]
public static extern git_index_entry *git_index_get(git_index *index, int n);
[DllImport(libgit2)]
public static extern uint git_index_entrycount(git_index *index);
[DllImport(libgit2)]
public static extern int git_object_lookup(git_object **obj, git_repository *repo, git_oid *id, git_otype type);
[DllImport(libgit2)]
public static extern git_oid *git_object_id(git_object *obj);
[DllImport(libgit2)]
public static extern git_otype git_object_type(git_object *obj);
[DllImport(libgit2)]
public static extern git_repository *git_object_owner(git_object *obj);
[DllImport(libgit2)]
public static extern void git_object_close(git_object *obj);
[DllImport(libgit2)]
public static extern sbyte *git_object_type2string(git_otype type);
[DllImport(libgit2)]
public static extern git_otype git_object_string2type(string str);
[DllImport(libgit2)]
public static extern int git_object_typeisloose(git_otype type);
[DllImport(libgit2)]
public static extern uint git_object__size(git_otype type);
[DllImport(libgit2)]
public static extern int git_odb_new(git_odb **outt);
[DllImport(libgit2)]
public static extern int git_odb_open(git_odb **outt, string objects_dir);
[DllImport(libgit2)]
public static extern int git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
[DllImport(libgit2)]
public static extern int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
[DllImport(libgit2)]
public static extern void git_odb_close(git_odb *db);
[DllImport(libgit2)]
public static extern int git_odb_read(git_odb_object **outt, git_odb *db, git_oid *id);
[DllImport(libgit2)]
public static extern int git_odb_read_header(out uint len_p, out git_otype type_p, git_odb *db, git_oid *id);
[DllImport(libgit2)]
public static extern int git_odb_exists(git_odb *db, git_oid *id);
[DllImport(libgit2)]
public static extern int git_odb_open_wstream(git_odb_stream **stream, git_odb *db, uint size, git_otype type);
[DllImport(libgit2)]
public static extern int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, git_oid *oid);
[DllImport(libgit2)]
public static extern int git_odb_hash(git_oid *id, byte[] data, uint len, git_otype type);
[DllImport(libgit2)]
public static extern void git_odb_object_close(git_odb_object *obj);
[DllImport(libgit2)]
public static extern git_oid *git_odb_object_id(git_odb_object *obj);
[DllImport(libgit2)]
public static extern void *git_odb_object_data(git_odb_object *obj);
[DllImport(libgit2)]
public static extern uint git_odb_object_size(git_odb_object *obj);
[DllImport(libgit2)]
public static extern git_otype git_odb_object_type(git_odb_object *obj);
[DllImport(libgit2)]
public static extern int git_odb_backend_pack(git_odb_backend **backend_out, string objects_dir);
[DllImport(libgit2)]
public static extern int git_odb_backend_loose(git_odb_backend **backend_out, string objects_dir);
[DllImport(libgit2)]
public static extern int git_odb_backend_sqlite(git_odb_backend **backend_out, string sqlite_db);
[DllImport(libgit2)]
public static extern int git_oid_mkstr(git_oid *outt, string str);
[DllImport(libgit2)]
public static extern void git_oid_mkraw(git_oid *outt, string raw);
[DllImport(libgit2)]
public static extern void git_oid_fmt(sbyte *str, git_oid *oid);
[DllImport(libgit2)]
public static extern void git_oid_pathfmt(sbyte *str, git_oid *oid);
[DllImport(libgit2)]
public static extern string git_oid_allocfmt(git_oid *oid);
[DllImport(libgit2)]
public static extern string git_oid_to_string(sbyte *outt, uint n, git_oid *oid);
[DllImport(libgit2)]
public static extern void git_oid_cpy(git_oid *outt, git_oid *src);
[DllImport(libgit2)]
public static extern int git_oid_cmp(git_oid *a, git_oid *b);
[DllImport(libgit2)]
public static extern int git_reference_lookup(git_reference **reference_out, git_repository *repo, string name);
[DllImport(libgit2)]
public static extern int git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, string name, string target);
[DllImport(libgit2)]
public static extern int git_reference_create_oid(git_reference **ref_out, git_repository *repo, string name, git_oid *id);
[DllImport(libgit2)]
public static extern git_oid *git_reference_oid(git_reference *reference);
[DllImport(libgit2)]
public static extern sbyte *git_reference_target(git_reference *reference);
[DllImport(libgit2)]
public static extern git_rtype git_reference_type(git_reference *reference);
[DllImport(libgit2)]
public static extern sbyte *git_reference_name(git_reference *reference);
[DllImport(libgit2)]
public static extern int git_reference_resolve(git_reference **resolved_ref, git_reference *reference);
[DllImport(libgit2)]
public static extern git_repository *git_reference_owner(git_reference *reference);
[DllImport(libgit2)]
public static extern int git_reference_set_target(git_reference *reference, string target);
[DllImport(libgit2)]
public static extern int git_reference_set_oid(git_reference *reference, git_oid *id);
[DllImport(libgit2)]
public static extern int git_reference_rename(git_reference *reference, string new_name);
[DllImport(libgit2)]
public static extern int git_reference_delete(git_reference *reference);
[DllImport(libgit2)]
public static extern int git_reference_packall(git_repository *repo);
[DllImport(libgit2)]
public static extern int git_reference_listall(git_strarray *array, git_repository *repo, uint list_flags);
[DllImport(libgit2)]
public static extern int git_repository_open(git_repository **repository, string path);
[DllImport(libgit2)]
public static extern int git_repository_open2(git_repository **repository, string git_dir, string git_object_directory, string git_index_file, string git_work_tree);
[DllImport(libgit2)]
public static extern int git_repository_open3(git_repository **repository, string git_dir, git_odb *object_database, string git_index_file, string git_work_tree);
[DllImport(libgit2)]
public static extern git_odb *git_repository_database(git_repository *repo);
[DllImport(libgit2)]
public static extern int git_repository_index(git_index **index, git_repository *repo);
[DllImport(libgit2)]
public static extern void git_repository_free(git_repository *repo);
[DllImport(libgit2)]
public static extern int git_repository_gc(git_repository *repo);
[DllImport(libgit2)]
public static extern int git_repository_init(git_repository **repo_out, string path, uint is_bare);
[DllImport(libgit2)]
public static extern int git_revwalk_new(git_revwalk **walker, git_repository *repo);
[DllImport(libgit2)]
public static extern void git_revwalk_reset(git_revwalk *walker);
[DllImport(libgit2)]
public static extern int git_revwalk_push(git_revwalk *walk, git_oid *oid);
[DllImport(libgit2)]
public static extern int git_revwalk_hide(git_revwalk *walk, git_oid *oid);
[DllImport(libgit2)]
public static extern int git_revwalk_next(git_oid *oid, git_revwalk *walk);
[DllImport(libgit2)]
public static extern void git_revwalk_sorting(git_revwalk *walk, uint sort_mode);
[DllImport(libgit2)]
public static extern void git_revwalk_free(git_revwalk *walk);
[DllImport(libgit2)]
public static extern git_repository *git_revwalk_repository(git_revwalk *walk);
[DllImport(libgit2)]
public static extern git_signature *git_signature_new(string name, string email, long time, int offset);
[DllImport(libgit2)]
public static extern git_signature *git_signature_dup(git_signature *sig);
[DllImport(libgit2)]
public static extern void git_signature_free(git_signature *sig);
[DllImport(libgit2)]
public static extern git_oid *git_tag_id(git_tag *tag);
[DllImport(libgit2)]
public static extern int git_tag_target(git_object **target, git_tag *t);
[DllImport(libgit2)]
public static extern git_oid *git_tag_target_oid(git_tag *t);
[DllImport(libgit2)]
public static extern git_otype git_tag_type(git_tag *t);
[DllImport(libgit2)]
public static extern sbyte *git_tag_name(git_tag *t);
[DllImport(libgit2)]
public static extern git_signature *git_tag_tagger(git_tag *t);
[DllImport(libgit2)]
public static extern sbyte *git_tag_message(git_tag *t);
[DllImport(libgit2)]
public static extern int git_tag_create(git_oid *oid, git_repository *repo, string tag_name, git_oid *target, git_otype target_type, git_signature *tagger, string message);
[DllImport(libgit2)]
public static extern int git_tag_create_o(git_oid *oid, git_repository *repo, string tag_name, git_object *target, git_signature *tagger, string message);
[DllImport(libgit2)]
public static extern git_oid *git_tree_id(git_tree *tree);
[DllImport(libgit2)]
public static extern uint git_tree_entrycount(git_tree *tree);
[DllImport(libgit2)]
public static extern git_tree_entry *git_tree_entry_byname(git_tree *tree, string filename);
[DllImport(libgit2)]
public static extern git_tree_entry *git_tree_entry_byindex(git_tree *tree, int idx);
[DllImport(libgit2)]
public static extern uint git_tree_entry_attributes(git_tree_entry *entry);
[DllImport(libgit2)]
public static extern sbyte *git_tree_entry_name(git_tree_entry *entry);
[DllImport(libgit2)]
public static extern git_oid *git_tree_entry_id(git_tree_entry *entry);
[DllImport(libgit2)]
public static extern int git_tree_entry_2object(git_object **object_out, git_repository *repo, git_tree_entry *entry);
}
}
/*
* The MIT License
*
* Copyright (c) 2010 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.Runtime.InteropServices;
namespace LibGit2Sharp.Core
{
unsafe public struct ObjectId
{
public const int RawSize = 20;
public const int HexSize = RawSize * 2;
internal git_oid oid;
internal ObjectId(git_oid *oid)
{
fixed (git_oid *poid = &this.oid)
{
Copy(poid, oid);
}
}
public ObjectId(ObjectId oid)
: this(&oid.oid)
{
}
public ObjectId(string str)
{
fixed (git_oid *p = &oid)
{
int ret = NativeMethods.git_oid_mkstr(p, str);
GitError.Check(ret);
}
}
public void Copy(ObjectId src)
{
Copy(this, src);
}
public static void Copy(ObjectId dst, ObjectId src)
{
Copy(&dst.oid, &src.oid);
}
internal static void Copy(git_oid *dst, git_oid *src)
{
NativeMethods.git_oid_cpy(dst, src);
}
public static int Compare(ObjectId a, ObjectId b)
{
return NativeMethods.git_oid_cmp(&a.oid, &b.oid);
}
public static int Compare(ObjectId a, string b)
{
return Compare(a, new ObjectId(b));
}
public static int Compare(string a, ObjectId b)
{
return Compare(new ObjectId(a), b);
}
public static int Compare(string a, string b)
{
return Compare(new ObjectId(a), new ObjectId(b));
}
public int Compare(ObjectId other)
{
return Compare(this, other);
}
public int Compare(string other)
{
return Compare(this, other);
}
public override string ToString()
{
fixed (git_oid *poid = &oid)
{
// +1 for holding the string terminator
IntPtr ptr = Marshal.AllocHGlobal(HexSize + 1);
return NativeMethods.git_oid_to_string((sbyte *)ptr.ToPointer(), HexSize + 1, poid);
}
}
}
}
/*
* 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.Collections;
using System.Collections.Generic;
namespace LibGit2Sharp.Core
{
unsafe public class Blob : GitObject
{
internal git_blob *blob;
internal Blob(git_object *obj)
: this((git_blob *)obj)
{
}
internal Blob(git_blob *blob)
: base((git_object *)blob)
{
this.blob = blob;
}
public static ObjectId Create(Repository repository, string path)
{
ObjectId oid = new ObjectId();
int ret = NativeMethods.git_blob_create_fromfile(&oid.oid, repository.repository, path);
GitError.Check(ret);
return oid;
}
public static ObjectId Create(Repository repository, byte[] buffer)
{
ObjectId oid = new ObjectId();
int ret = NativeMethods.git_blob_create_frombuffer(&oid.oid, repository.repository, buffer, (uint)buffer.Length);
GitError.Check(ret);
return oid;
}
public byte[] GetContent()
{
byte[] content = new byte[Size];
byte *b = (byte *)GetRawContent();
for (int i = 0; i < Size; i++) {
content[i] = b[i];
}
return content;
}
internal void *GetRawContent()
{
return NativeMethods.git_blob_rawcontent(blob);
}
public NativeMemoryStream GetNativeMemoryStreamContent()
{
return new NativeMemoryStream(GetRawContent(), Size);
}
public int Size
{
get {
return NativeMethods.git_blob_rawsize(blob);
}
}
}
}
/*
* 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.Collections;
using System.Collections.Generic;
namespace LibGit2Sharp.Core
{
unsafe public class Commit : GitObject, IEnumerable<Commit>
{
internal git_commit *commit;
internal Commit(git_object *obj)
: this((git_commit *)obj)
{
}
internal Commit(git_commit *commit)
: base((git_object *)commit)
{
this.commit = commit;
}
public static ObjectId Create(Repository repository,
string updateReference,
Signature author,
Signature committer,
string message,
Tree tree)
{
ObjectId oid = new ObjectId();
ObjectId treeoid = tree.ObjectId;
int ret = NativeMethods.git_commit_create(&oid.oid,
repository.repository,
updateReference,
author.signature,
committer.signature,
message,
&treeoid.oid,
0,
null);
GitError.Check(ret);
return oid;
}
public string MessageShort
{
get {
return new string(NativeMethods.git_commit_message_short(commit));
}
}
public string Message
{
get {
return new string(NativeMethods.git_commit_message(commit));
}
}
public uint ParentCount
{
get {
return NativeMethods.git_commit_parentcount(commit);
}
}
public Commit GetParent(uint n)
{
git_commit *parent = null;
int ret = NativeMethods.git_commit_parent(&parent, commit, n);
GitError.Check(ret);
if (parent == null)
return null;
return new Commit(parent);
}
public IEnumerator<Commit> GetEnumerator()
{
uint count = ParentCount;
for (uint i = 0; i < count; i++)
{
yield return GetParent(i);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator)GetEnumerator();
}
public List<Commit> Parents
{
get {
List<Commit> commits = new List<Commit>();
foreach (Commit commit in this)
commits.Add(commit);
return commits;
}
}
public Tree Tree
{
get {
git_tree *tree = null;
int ret = NativeMethods.git_commit_tree(&tree, commit);
GitError.Check(ret);
if (tree == null)
return null;
return new Tree(tree);
}
}
public Signature Author
{
get {
return new Signature(NativeMethods.git_commit_author(commit));
}
}
public Signature Committer
{
get {
return new Signature(NativeMethods.git_commit_committer(commit));
}
}
}
}
/*
* 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.Collections;
using System.Collections.Generic;
namespace LibGit2Sharp.Core
{
unsafe public class GitObject
{
internal git_object *obj = null;
internal GitObject()
{
}
internal GitObject(git_object *obj)
{
this.obj = obj;
Pointer = new IntPtr(obj);
}
public IntPtr Pointer { get; protected set; }
public ObjectId ObjectId
{
get {
return new ObjectId(NativeMethods.git_object_id(obj));
}
}
public git_otype Type
{
get {
return NativeMethods.git_object_type(obj);
}
}
public string StringType
{
get {
return GetType(Type);
}
}
public Repository Owner
{
get {
return new Repository(NativeMethods.git_object_owner(obj));
}
}
public static string GetType(git_otype type)
{
return new string(NativeMethods.git_object_type2string(type));
}
public static git_otype GetType(string str)
{
return NativeMethods.git_object_string2type(str);
}
public static git_otype GetType(Type type)
{
if (type == typeof(Blob))
return git_otype.GIT_OBJ_BLOB;
else if (type == typeof(Commit))
return git_otype.GIT_OBJ_COMMIT;
else if (type == typeof(Tree))
return git_otype.GIT_OBJ_TREE;
else if (type == typeof(Tag))
return git_otype.GIT_OBJ_TREE;
else
return git_otype.GIT_OBJ_ANY;
}
public static Type GetClass(git_otype type)
{
switch (type)
{
case git_otype.GIT_OBJ_BLOB:
return typeof(Blob);
case git_otype.GIT_OBJ_COMMIT:
return typeof(Commit);
case git_otype.GIT_OBJ_TREE:
return typeof(Tree);
case git_otype.GIT_OBJ_TAG:
return typeof(Tag);
default:
return null;
}
}
public static Type GetClass(string str)
{
return GetClass(GetType(str));
}
internal static GitObject Create(git_object *obj)
{
if (obj == null)
return null;
switch (NativeMethods.git_object_type(obj))
{
case git_otype.GIT_OBJ_BAD:
throw new ArgumentException("The object must not be a bad object");
case git_otype.GIT_OBJ_BLOB:
return new Blob(obj);
case git_otype.GIT_OBJ_COMMIT:
return new Commit(obj);
case git_otype.GIT_OBJ_TREE:
return new Tree(obj);
case git_otype.GIT_OBJ_TAG:
return new Tag(obj);
default:
return new GitObject(obj);
}
}
internal static T Create<T>(git_object *obj) where T : GitObject
{
if (obj == null)
return null;
git_otype type = NativeMethods.git_object_type(obj);
// If class doesn't match type, return the default
if (typeof(T) != GetClass(type))
return default(T);
return (T)Create(obj);
}
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
using System;
namespace LibGit2Sharp
{
public static class DateTimeOffsetExtensions
{
public static GitDate ToGitDate(this DateTimeOffset dateTimeOffset)
{
return Epoch.ToGitDate(dateTimeOffset);
}
}
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册