From 8684e49dd4c58da6cfb2d2996bc74dbefafc49aa Mon Sep 17 00:00:00 2001 From: Dmitriy Olshevskiy Date: Sun, 28 Jan 2018 21:58:18 +0300 Subject: [PATCH] find and open conflict files from root git directory --- conflict/parse.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/conflict/parse.go b/conflict/parse.go index d83c04e..527aef6 100644 --- a/conflict/parse.go +++ b/conflict/parse.go @@ -149,7 +149,16 @@ Run below command to change to a compatible conflict style func Find() (err error) { cwd, _ := os.Getwd() - stdout, stderr, _ := RunCommand("git", cwd, "--no-pager", "diff", "--check") + + stdout, stderr, _ := RunCommand("git", cwd, "rev-parse", "--show-toplevel") + if len(stderr) != 0 { + return errors.New(stderr) + } else if len(stdout) == 0 { + return errors.New("no git top-level path") + } + topLevelPath := string(strings.Split(stdout, "\n")[0]) + + stdout, stderr, _ = RunCommand("git", cwd, "--no-pager", "diff", "--check") if len(stderr) != 0 { return errors.New(stderr) @@ -172,7 +181,7 @@ func Find() (err error) { } for fname := range diffMap { - absPath := path.Join(cwd, fname) + absPath := path.Join(topLevelPath, fname) if err = ReadFile(absPath); err != nil { return }