From: George Dunlap Date: Wed, 17 May 2017 15:17:17 +0000 (+0100) Subject: git: Use full path for AM operations X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6c68a03d98396ab91261e0542d6bf06a41224fab;p=people%2Fgdunlap%2Fxsatool git: Use full path for AM operations ...so that Repo.Am() works regardless of your cwd. Factor "normalization" into normalizePath. Implement globToFullPath, which will take a glob and return a slice of normalized filenames. Use globToFullPath() for Repo.Am() and Repo.AmClean(). Signed-off-by: George Dunlap --- diff --git a/git.go b/git.go index 845d153..b015c75 100644 --- a/git.go +++ b/git.go @@ -13,16 +13,20 @@ type Repo struct { Path string } -func GitOpen(gpath string) (r Repo, err error) { +func normalizePath(gpath string) string { if !path.IsAbs(gpath) { cwd, err := os.Getwd() if err != nil { - fmt.Printf("Getwd failed?\n") - return r, err + panic("Getwd failed?\n") } gpath = cwd + "/" + gpath gpath = path.Clean(gpath) } + return gpath +} + +func GitOpen(gpath string) (r Repo, err error) { + gpath = normalizePath(gpath) fmt.Printf("Path: %s\n", gpath) r.Path = gpath @@ -124,8 +128,19 @@ func (r Repo) FormatPatch(path string, baseline string, branch string) (out []by return } +func globToFullPath(glob string) (files []string, err error) { + files, err = filepath.Glob(glob) + if err != nil { + return + } + for i := range files { + files[i] = normalizePath(files[i]) + } + return +} + func (r Repo) Am(amglob string) (out []byte, err error) { - files, err := filepath.Glob(amglob) + files, err := globToFullPath(amglob) if err != nil { return } @@ -133,6 +148,7 @@ func (r Repo) Am(amglob string) (out []byte, err error) { err = fmt.Errorf("%s didn't match any files", amglob) return } + out, err = r.gitCmd(append([]string{"am", "--reject"}, files...)...) return @@ -157,7 +173,7 @@ func (r Repo) DeleteTag(tag string) (err error) { // Do a 'git am', and if it fails, clean up the tree func (r Repo) AmClean(amglob string) (out []byte, err error) { - files, err := filepath.Glob(amglob) + files, err := globToFullPath(amglob) if err != nil { return }