Skip to content

Commit cb72f50

Browse files
committed
fixup! Ensure Tags can be created in detached Head state
1 parent 4180b3f commit cb72f50

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

LibGit2Sharp/Core/Ensure.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -209,34 +209,21 @@ public static void ArgumentConformsTo<T>(T argumentValue, Func<T, bool> checker,
209209
}
210210

211211
public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
212-
{
213-
Func<string, LibGit2SharpException> exceptionBuilder;
214-
215-
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
216-
{
217-
exceptionBuilder = m => new UnbornBranchException(m);
218-
}
219-
else
220-
{
221-
exceptionBuilder = m => new LibGit2SharpException(m);
222-
}
223-
224-
GitObjectIsNotNull(gitObject, identifier, exceptionBuilder);
225-
}
226-
227-
public static void GitObjectIsNotNull(
228-
GitObject gitObject,
229-
string identifier,
230-
Func<string, LibGit2SharpException> exceptionBuilder)
231212
{
232213
if (gitObject != null)
233214
{
234215
return;
235216
}
236217

237-
throw exceptionBuilder(string.Format(CultureInfo.InvariantCulture,
238-
"No valid git object identified by '{0}' exists in the repository.",
239-
identifier));
218+
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
219+
{
220+
throw new UnbornBranchException(
221+
"HEAD points at a branch that is yet to be created.");
222+
}
223+
224+
throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture,
225+
"No valid git object identified by '{0}' exists in the repository.",
226+
identifier));
240227
}
241228
}
242229
}

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static Commit RetrieveHeadCommit(IRepository repository)
9898
{
9999
Commit commit = repository.Head.Tip;
100100

101-
Ensure.GitObjectIsNotNull(commit, "HEAD", m => new UnbornBranchException(m));
101+
Ensure.GitObjectIsNotNull(commit, "HEAD");
102102

103103
return commit;
104104
}

0 commit comments

Comments
 (0)