From 67445faab117c1f0755ffd2ae18ed412fe2a5962 Mon Sep 17 00:00:00 2001 From: Robert Crumbaugh Date: Thu, 15 Feb 2024 14:07:56 -0800 Subject: [PATCH] manual git add --- internal/git/git.go | 18 +++++++++++++- test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 test.go diff --git a/internal/git/git.go b/internal/git/git.go index da5e2154..b765f9cc 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -301,7 +301,7 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act logging.Info("Commit and pushing changes to git") - if _, err := w.Add("."); err != nil { + if err := g.Add("."); err != nil { return "", fmt.Errorf("error adding changes: %w", err) } @@ -332,6 +332,22 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act return commitHash.String(), nil } +func (g *Git) Add(arg string) error { + baseDir := environment.GetBaseDir() + + cmdPath := filepath.Join(baseDir, "bin", "git") + + cmd := exec.Command(cmdPath, "add", arg) + cmd.Dir = filepath.Join(environment.GetWorkspace(), "repo", environment.GetWorkingDirectory()) + cmd.Env = os.Environ() + output, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("error running `git add %s`: %w %s", arg, err, string(output)) + } + + return nil +} + func (g *Git) CreateOrUpdatePR(branchName string, releaseInfo releases.ReleasesInfo, previousGenVersion string, pr *github.PullRequest) error { var changelog string var err error diff --git a/test.go b/test.go new file mode 100644 index 00000000..f795b8a7 --- /dev/null +++ b/test.go @@ -0,0 +1,57 @@ +package main + +import ( + "fmt" + "github.com/go-git/go-billy/v5/memfs" + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/storage/memory" + "os" +) + +func main() { + fs := memfs.New() + r, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{ + URL: "https://github.com/speakeasy-api/speakeasy-client-sdk-java", + }) + if err != nil { + fmt.Printf("error getting worktree: %s", err) + os.Exit(0) + } + + w, err := r.Worktree() + if err != nil { + fmt.Printf("error getting worktree: %s", err) + os.Exit(0) + } + + status, err := w.Status() + if err != nil { + fmt.Printf("error getting status: %s", err) + os.Exit(0) + } + fmt.Printf("status clean before rename: %t\n", status.IsClean()) + + err = fs.Rename("build/pom.xml", "build/pom.xml.old") + if err != nil { + fmt.Printf("error renaming: %s", err) + os.Exit(0) + } + + for _, e := range w.Excludes { + fmt.Printf("exclude: %s\n", e) + } + + err = w.AddGlob("*") + if err != nil { + fmt.Printf("error renaming: %s", err) + os.Exit(0) + } + + status, err = w.Status() + if err != nil { + fmt.Printf("error getting status: %s", err) + os.Exit(0) + } + + fmt.Printf("status clean after rename: %t", status.IsClean()) +}