| 1 |
VERSION = "1.0.0" |
| 2 |
|
| 3 |
local os = import("os") |
| 4 |
local filepath = import("path/filepath") |
| 5 |
local shell = import("micro/shell") |
| 6 |
|
| 7 |
function onBufferOpen(buf) |
| 8 |
if buf.Settings["diffgutter"] and (not buf.Type.Scratch) and (buf.Path ~= "") then |
| 9 |
-- check that file exists |
| 10 |
local _, err = os.Stat(buf.AbsPath) |
| 11 |
if err == nil then |
| 12 |
local dirName, fileName = filepath.Split(buf.AbsPath) |
| 13 |
local diffBase, err = shell.ExecCommand("git", "-C", dirName, "show", "HEAD:./" .. fileName) |
| 14 |
if err ~= nil then |
| 15 |
diffBase = buf:Bytes() |
| 16 |
end |
| 17 |
buf:SetDiffBase(diffBase) |
| 18 |
end |
| 19 |
end |
| 20 |
end |