@@ -3,7 +3,10 @@ VERSION = "1.0.0"
33local micro = import (" micro" )
44local buffer = import (" micro/buffer" )
55local config = import (" micro/config" )
6+ local shell = import (" micro/shell" )
7+ local filepath = import (" filepath" )
68local humanize = import (" humanize" )
9+ local strings = import (" strings" )
710
811function init ()
912 micro .SetStatusInfoFn (" status.branch" )
@@ -32,30 +35,23 @@ function size(b)
3235 return humanize .Bytes (b :Size ())
3336end
3437
35- function branch ( b )
38+ local function parseRevision ( b , opt )
3639 if b .Type .Kind ~= buffer .BTInfo then
37- local shell = import (" micro/shell" )
38- local strings = import (" strings" )
39-
40- local branch , err = shell .ExecCommand (" git" , " rev-parse" , " --abbrev-ref" , " HEAD" )
40+ local dir = filepath .Dir (b .Path )
41+ local str , err = shell .ExecCommand (" git" , " -C" , dir , " rev-parse" , opt , " HEAD" )
4142 if err == nil then
42- return strings .TrimSpace (branch )
43+ return strings .TrimSpace (str )
4344 end
44- return " "
4545 end
46+ return " "
4647end
4748
48- function hash (b )
49- if b .Type .Kind ~= 5 then
50- local shell = import (" micro/shell" )
51- local strings = import (" strings" )
49+ function branch (b )
50+ return parseRevision (b , " --abbrev-ref" )
51+ end
5252
53- local hash , err = shell .ExecCommand (" git" , " rev-parse" , " --short" , " HEAD" )
54- if err == nil then
55- return strings .TrimSpace (hash )
56- end
57- return " "
58- end
53+ function hash (b )
54+ return parseRevision (b , " --short" )
5955end
6056
6157function paste (b )
0 commit comments