Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Submodules! #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions LibGit2Sharp.Tests/SubmoduleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ public void CanRetrieveTheCommitIdsOfASubmodule(string name, string headId, stri
Assert.Equal((ObjectId)headId, submodule.HeadCommitId);
Assert.Equal((ObjectId)indexId, submodule.IndexCommitId);
Assert.Equal((ObjectId)workDirId, submodule.WorkDirCommitId);

AssertEntryId((ObjectId)headId, repo.Head[name], c => c.Target.Id);
AssertEntryId((ObjectId)indexId, repo.Index[name], i => i.Id);
}
}

private static void AssertEntryId<T>(ObjectId expected, T entry, Func<T, ObjectId> selector)
{
Assert.Equal(expected, ReferenceEquals(entry, null) ? null : selector(entry));
}

[Fact]
public void CanEnumerateRepositorySubmodules()
{
Expand Down
27 changes: 27 additions & 0 deletions LibGit2Sharp/GitLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;

namespace LibGit2Sharp
{
/// <summary>
/// Represents a gitlink (a reference to a commit in another Git repository)
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class GitLink : GitObject
{
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected GitLink()
{ }

internal GitLink(Repository repo, ObjectId id)
: base(repo, id)
{
}

private string DebuggerDisplay
{
get { return Id.ToString(); }
}
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Conflict.cs" />
<Compile Include="ConflictCollection.cs" />
<Compile Include="Core\Handles\GitRefSpecHandle.cs" />
<Compile Include="GitLink.cs" />
<Compile Include="UnmatchedPathException.cs" />
<Compile Include="Core\Handles\ReflogEntrySafeHandle.cs" />
<Compile Include="Core\Handles\ReflogSafeHandle.cs" />
Expand Down
15 changes: 11 additions & 4 deletions LibGit2Sharp/TreeEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ internal ObjectId TargetId

private GitObject RetrieveTreeEntryTarget()
{
if (!Type.HasAny(new[]{GitObjectType.Tree, GitObjectType.Blob}))
switch (Type)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "TreeEntry target of type '{0}' are not supported.", Type));
case GitObjectType.Commit:
return new GitLink(repo, targetOid);
case GitObjectType.Blob:
case GitObjectType.Tree:
return GitObject.BuildFrom(repo, targetOid, Type, Path);
default:
throw new InvalidOperationException(
string.Format(CultureInfo.InvariantCulture,
"TreeEntry target of type '{0}' is not supported.",
Type));
}

return GitObject.BuildFrom(repo, targetOid, Type, Path);
}

/// <summary>
Expand Down