diff --git a/patch.Make.go b/patch.Make.go index cca74c4..97d325d 100644 --- a/patch.Make.go +++ b/patch.Make.go @@ -102,67 +102,16 @@ func (pset *Patchs) makePatchSetNew(repo *gitpb.Repo) error { return nil } - return pset.addPatchFiles(repoDir) -} - -// var pset *Patchs - -func (f *Forge) MakePatchSet() (*Patchs, error) { - pset := new(Patchs) - dir, err := os.MkdirTemp("", "forge") - if err != nil { - return nil, err - } - defer os.RemoveAll(dir) // clean up - - all := f.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - userb := repo.GetUserBranchName() - develb := repo.GetDevelBranchName() - - if develb == "" { - continue - } - if userb == "" { - continue - } - - repoDir := filepath.Join(dir, repo.GetGoPath()) - err := os.MkdirAll(repoDir, 0755) - if err != nil { - return nil, err - } - - // git format-patch branch1..branch2 - cmd := []string{"git", "format-patch", "-o", repoDir, develb + ".." + userb} - r := repo.Run(cmd) - if r.Error != nil { - log.Info("git format-patch", repo.FullPath) - log.Info("git format-patch", cmd) - log.Info("git format-patch error", r.Error) - return nil, r.Error - } - if r.Exit != 0 { - log.Info("git format-patch", repo.FullPath) - log.Info("git format-patch", cmd) - log.Info("git format-patch exit", r.Exit) - return nil, r.Error - } - if len(r.Stdout) == 0 { - continue - } - - pset.addPatchFiles(repoDir) - } - return pset, nil + return pset.addPatchFiles(repo.GetGoPath()) } // process each file in pDir/ -func (p *Patchs) addPatchFiles(pDir string) error { - // log.Info("ADD PATCH FILES ADDED DIR", pDir) +func (p *Patchs) addPatchFiles(psetDir string) error { + tmpDir := p.TmpDir + log.Info("ADD PATCH FILES ADDED DIR", tmpDir) + fullDir := filepath.Join(tmpDir, psetDir) var baderr error - filepath.Walk(pDir, func(path string, info os.FileInfo, err error) error { + filepath.Walk(fullDir, func(path string, info os.FileInfo, err error) error { if err != nil { // Handle possible errors, like permission issues fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err) @@ -173,7 +122,10 @@ func (p *Patchs) addPatchFiles(pDir string) error { if info.IsDir() { return nil } - // log.Info("TESTING FILE", path) + log.Info("IS THIS A FULL PATH ?", path) + log.Info("trim this from path ?", fullDir) + log.Info("trim this from path ?", psetDir) + log.Info("trim this from path ?", tmpDir) data, err := os.ReadFile(path) if err != nil { log.Info("addPatchFile() failed", path) @@ -181,7 +133,7 @@ func (p *Patchs) addPatchFiles(pDir string) error { return err } patch := new(Patch) - patch.Filename = path + patch.Filename = psetDir patch.Data = data p.Patchs = append(p.Patchs, patch) // log.Info("ADDED PATCH FILE", path)