From 900a3fb7d1e4df3dcf15d79c3e9be0015b6f8c57 Mon Sep 17 00:00:00 2001 From: Daniel Kurashige-Gollub Date: Fri, 8 May 2015 11:31:13 +0900 Subject: [PATCH] Fix issue #12 branches with / in it are cut-off This fixes the cut off branch names when a branch has a / in the name. Example: "dev/2.7.x" was cut off to "2.7.x". --- git.d | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/git.d b/git.d index 1dac666..769983f 100644 --- a/git.d +++ b/git.d @@ -7,7 +7,7 @@ import std.path : baseName, buildPath, relativePath; import std.process; // : A whole lotta stuff import std.range : empty, front, back; import std.stdio : File; -import std.string : startsWith, strip; +import std.string : startsWith, strip, countchars, chompPrefix; import time; import vcs; @@ -144,8 +144,12 @@ string getHead(string repoRoot, Duration allottedTime) // If we're on a branch head, .git/HEAD will look like // ref: refs/heads/ - if (headSHA.startsWith("ref:")) - return headSHA.baseName; + if (headSHA.startsWith("ref:")) { + if (headSHA.countchars("/") == 2) + return headSHA.baseName; + else + return headSHA.chompPrefix("ref: refs/heads/"); + } // Otherwise let's go rummaging through the refs to find something immutable refsPath = buildPath(repoRoot, ".git", "refs");