prompt: Fix crash when ref is nil
Anirudh Oppiliappan x@icyphox.sh
Sun, 12 Sep 2021 09:46:39 +0530
1 files changed,
5 insertions(+),
0 deletions(-)
jump to
M
prompt/git.go
→
prompt/git.go
@@ -27,6 +27,11 @@
// Returns the current git branch or current ref sha. func gitBranch(repo *git.Repository) string { ref, _ := repo.Head() + // Quick hack to fix crash when ref is nil; + // i.e., new repo with no commits. + if ref == nil { + return "no commit" + } if ref.IsBranch() { name, _ := ref.Branch().Name() return name