Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
manual git add
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-crumbaugh committed Feb 15, 2024
1 parent d894b50 commit 67445fa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
@@ -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() {

Check failure on line 11 in test.go

View workflow job for this annotation

GitHub Actions / Build

main redeclared in this block
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())
}

0 comments on commit 67445fa

Please sign in to comment.