Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Preventing repo with no commits from throwing error #927

Merged
merged 2 commits into from
Oct 9, 2018
Merged
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
12 changes: 10 additions & 2 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ public ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string other
public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null)
{
return new GitLogTask(new GitObjectFactory(environment), cancellationToken, processor)
.Configure(processManager);
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, list) => success ? list : new List<GitLogEntry>());
}

///<inheritdoc/>
Expand Down Expand Up @@ -596,7 +600,11 @@ public ITask<string> Unlock(NPath file, bool force,
public ITask<string> GetHead(IOutputProcessor<string> processor = null)
{
return new FirstNonNullLineProcessTask(cancellationToken, "rev-parse --short HEAD") { Name = "Getting current head..." }
.Configure(processManager);
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, head) => success ? head : null);
}

protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();
Expand Down