Skip to content

Commit 3fc2435

Browse files
Alexander OvchinnikovAlexander Ovchinnikov
Alexander Ovchinnikov
authored and
Alexander Ovchinnikov
committed
Add an option to set initial head to InitOptions
1 parent b5f6042 commit 3fc2435

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

LibGit2Sharp/Core/GitRepositoryInitOptions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics;
33
using System.Runtime.InteropServices;
44

@@ -36,13 +36,21 @@ public static GitRepositoryInitOptions BuildFrom(InitOptions initOptions)
3636
opts.Flags |= GitRepositoryInitFlags.GIT_REPOSITORY_INIT_BARE;
3737
}
3838

39+
if (initOptions.InitialHead != null)
40+
{
41+
opts.InitialHead = StrictUtf8Marshaler.FromManaged(initOptions.InitialHead);
42+
}
43+
3944
return opts;
4045
}
4146

4247
public void Dispose()
4348
{
4449
EncodingMarshaler.Cleanup(WorkDirPath);
4550
WorkDirPath = IntPtr.Zero;
51+
52+
EncodingMarshaler.Cleanup(InitialHead);
53+
InitialHead = IntPtr.Zero;
4654
}
4755
}
4856

LibGit2Sharp/InitOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ public sealed class InitOptions
1111
/// Default behavior:
1212
/// The workdirPath is null.
1313
/// Not a bare repository.
14+
/// Default initial head.
1415
/// </para>
1516
/// </summary>
1617
public InitOptions()
1718
{
1819
WorkdirPath = null;
1920
IsBare = false;
21+
InitialHead = null;
2022
}
2123

2224
/// <summary>
@@ -28,5 +30,12 @@ public InitOptions()
2830
/// True to initialize a bare repository. False otherwise, to initialize a standard ".git" repository.
2931
/// </summary>
3032
public bool IsBare { get; set; }
33+
34+
/// <summary>
35+
/// The name of the head to point HEAD at.
36+
/// If null, then this will be treated as "master" and the HEAD ref will be set to "refs/heads/master".
37+
/// If this begins with "refs/" it will be used verbatim; otherwise "refs/heads/" will be prefixed.
38+
/// </summary>
39+
public string InitialHead { get; set; }
3140
}
3241
}

0 commit comments

Comments
 (0)