Skip to content

Commit

Permalink
fix 🐛: disabling go-git commit
Browse files Browse the repository at this point in the history
go-git commits dont support loading git config

Signed-off-by: moualhi zine el abidine <[email protected]>
  • Loading branch information
muandane committed Mar 24, 2024
1 parent 1003f35 commit f20ddcf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ var rootCmd = &cobra.Command{
}
var gitCommitError error
action := func() {
// signOff := config.SignOff
// gitCommitError = commit(commitMessage, commitBody, signOff)
gitCommitError = config.GitCommit(".", commitMessage, commitBody)
signOff := config.SignOff
gitCommitError = commit(commitMessage, commitBody, signOff)
// gitCommitError = config.GitCommit(".", commitMessage, commitBody)
}

err = spinner.New().
Expand Down
54 changes: 29 additions & 25 deletions pkg/config/git.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
package config

import (
"fmt"
"os/exec"
"strings"

"github.com/charmbracelet/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
// "github.com/go-git/go-git/v5"
// "github.com/go-git/go-git/v5/plumbing"
)

func GitRepo() (string, error) {
revParse := exec.Command("git", "rev-parse", "--show-toplevel")
repoDirBytes, err := revParse.Output()
repo, err := git.PlainOpen(".")
if err != nil {
if err == git.ErrRepositoryNotExists {
return "", err
}
log.Fatalf("Error finding git root directory: %v", err)
}
repoDir := strings.TrimRight(string(repoDirBytes), "\n")

return repoDir, nil
}
func (c *Config) GitCommit(repoPath, message, description string) error {
// Open the repository
repo, err := git.PlainOpen(repoPath)
repoPath, err := repo.Worktree()
if err != nil {
return err
log.Fatalf("Error finding git root directory: %v", err)
}

// Get the working tree
wt, err := repo.Worktree()
if err != nil {
return err
}
return repoPath.Filesystem.Root(), nil
}

// Commit the changes
_, err = wt.Commit(fmt.Sprintf("%s\n\n%s", message, description), &git.CommitOptions{
Parents: []plumbing.Hash{},
})
// func (c *Config) GitCommit(repoPath, message, description string) error {
// // Open the repository
// repo, err := git.PlainOpen(repoPath)
// if err != nil {
// return err
// }

return err
}
// // Get the working tree
// wt, err := repo.Worktree()
// if err != nil {
// return err
// }

// // Commit the changes
// _, err = wt.Commit(fmt.Sprintf("%s\n\n%s", message, description), &git.CommitOptions{
// Parents: []plumbing.Hash{},
// })

// return err
// }
14 changes: 6 additions & 8 deletions pkg/config/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package config
import "testing"

func TestGitRepo(t *testing.T) {
repo, err := GitRepo()
if err != nil {
t.Errorf("Error finding git root directory: %v", err)
}
t.Run("repo dir is found", func(t *testing.T) {
_, err := GitRepo()
if err != nil {
t.Errorf("Error finding git root directory: %v", err)

// Check if the repo path is not empty
if repo == "" {
t.Errorf("Expected a repository path, got an empty string")
}
}
})
}

0 comments on commit f20ddcf

Please sign in to comment.