Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Submodules.Add: use_gitlink as bool, and use clone instead of fetch
  • Loading branch information
olmobrutall committed Aug 7, 2013
commit 362f6242da94363cd2802096a396b1502c8ef67d
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ internal static extern int git_submodule_add_setup(
RepositorySafeHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(Utf8Marshaler))] string url,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path,
int use_gitlink);
bool use_gitlink);

[DllImport(libgit2)]
internal static extern int git_submodule_add_finalize(
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,12 +2010,12 @@ public static ICollection<TResult> git_submodule_foreach<TResult>(RepositorySafe
return git_foreach(resultSelector, c => NativeMethods.git_submodule_foreach(repo, (x, y, p) => c(x, y, p), IntPtr.Zero));
}

public static SubmoduleSafeHandle git_submodule_add_setup(RepositorySafeHandle repo, string url, FilePath path, int use_gitlink)
public static SubmoduleSafeHandle git_submodule_add_setup(RepositorySafeHandle repo, string url, FilePath path, bool useGitLink)
{
using (ThreadAffinity())
{
SubmoduleSafeHandle sub;
var res = NativeMethods.git_submodule_add_setup(out sub, repo, url, path, use_gitlink);
var res = NativeMethods.git_submodule_add_setup(out sub, repo, url, path, useGitLink);
Ensure.ZeroResult(res);
return sub;
}
Expand Down
21 changes: 13 additions & 8 deletions LibGit2Sharp/SubmoduleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ internal SubmoduleCollection(Repository repo)
/// <param name="relativePath">The path of the submodule inside of the super repository, if none, name is taken.</param>
/// <param name="use_GitLink"></param>
/// <returns></returns>
public Submodule Add(string name, string url, string branch = "master", string relativePath = null, int use_GitLink = 0)
public Submodule Add(string name, string url, string committish = null, string relativePath = null, bool useGitLink = true)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");

Ensure.ArgumentNotNullOrEmptyString(url, "url");

relativePath = relativePath ?? name;

SubmoduleSafeHandle handle = Proxy.git_submodule_add_setup(repo.Handle, url, relativePath, use_GitLink);

using (Repository subRepo = new Repository(Path.Combine(repo.Info.WorkingDirectory, relativePath)))
using (SubmoduleSafeHandle handle = Proxy.git_submodule_add_setup(repo.Handle, url, relativePath, useGitLink))
{
subRepo.Fetch("origin");
subRepo.Checkout(subRepo.Branches["origin/" + branch]);
}
string subPath = Path.Combine(repo.Info.WorkingDirectory, relativePath);

Repository.Clone(url, subPath);

Proxy.git_submodule_add_finalize(handle);
if (committish != null)
{
using (Repository subRepo = new Repository(subPath))
subRepo.Checkout(subRepo.Branches[committish]);
}

Proxy.git_submodule_add_finalize(handle);
}

return this[name];
}
Expand Down