-
Notifications
You must be signed in to change notification settings - Fork 925
Expand file tree
/
Copy pathAddSubmodule.cs
More file actions
48 lines (40 loc) · 1.98 KB
/
AddSubmodule.cs
File metadata and controls
48 lines (40 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using LibGit2Sharp;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
using System.IO;
namespace LibGit2Sharp
{
/// <summary>
/// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD.
/// </summary>
public static partial class Commands
{
/// <summary>
/// Adds a new repository, checkout the selected branch and add it to superproject index
/// </summary>
/// <param name="repository">The repository to add the Submodule to</param>
/// <param name="name">The name of the Submodule</param>
/// <param name="url">The url of the remote repository</param>
/// <param name="relativePath">The path of the submodule inside of the super repository, if none, name is taken.</param>
/// <param name="useGitLink">Should workdir contain a gitlink to the repo in .git/modules vs. repo directly in workdir.</param>
/// <param name="initiRepository">Should workdir contain a gitlink to the repo in .git/modules vs. repo directly in workdir.</param>
/// <returns></returns>
public static Submodule AddSubmodule(IRepository repository, string name, string url, string relativePath, bool useGitLink, Action<Repository> initiRepository)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(url, "url");
relativePath = relativePath ?? name;
using (SubmoduleHandle handle = Proxy.git_submodule_add_setup(((Repository)repository).Handle, url, relativePath, useGitLink ? 1 : 0))
{
string subPath = Path.Combine(repository.Info.WorkingDirectory, relativePath);
using (Repository subRep = new Repository(subPath))
{
initiRepository(subRep);
}
Proxy.git_submodule_add_finalize(handle);
}
return repository.Submodules[name];
}
}
}