Skip to content

Commit

Permalink
refactor: optmized repo opening. adding only modified and untracked f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
KaueSabinoSRV17 committed Jun 21, 2023
1 parent 54d39bb commit d986ea8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var commitCmd = &cobra.Command{
repo := use_cases.GetRepository(".")
var message string

unstagedFiles := use_cases.GetUnstaggedFiles()
unstagedFiles := use_cases.GetUnstaggedFiles(repo)
if len(unstagedFiles) > 0 {
filesToStage := use_cases.AskWhatFilesToAddForStaging(unstagedFiles)
go use_cases.StageFiles(filesToStage, repo)
Expand All @@ -37,7 +37,7 @@ var commitCmd = &cobra.Command{
message = args[0]
}

use_cases.ConventionalCommit(prefix, message)
use_cases.ConventionalCommit(prefix, message, repo)
},
}

Expand Down
16 changes: 4 additions & 12 deletions use_cases/conventional_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ func GetRepository(pathToRepository string) *git.Worktree {

}

func GetUnstaggedFiles() []string {
func GetUnstaggedFiles(worktree *git.Worktree) []string {

worktree := GetRepository(".")
status, err := worktree.Status()
if err != nil {
log.Fatal("Could not get Git Status")
}

var modifiedOrUntrackedFiles []string
for file, s := range status {
if s.Staging == git.Unmodified && s.Worktree == git.Unmodified {
continue
if s.Worktree == git.Modified || s.Worktree == git.Untracked {
modifiedOrUntrackedFiles = append(modifiedOrUntrackedFiles, file)
}
modifiedOrUntrackedFiles = append(modifiedOrUntrackedFiles, file)
}

return modifiedOrUntrackedFiles
Expand Down Expand Up @@ -103,14 +101,8 @@ func ResolveCommitMessage() string {

}

func ConventionalCommit(prefix string, message string) {

worktree := GetRepository(".")

func ConventionalCommit(prefix string, message string, worktree *git.Worktree) {
formatedMessage := fmt.Sprintf("%s: %s", prefix, message)

worktree.Commit(formatedMessage, &git.CommitOptions{})

fmt.Println("Sucessfully added a commit!")

}

0 comments on commit d986ea8

Please sign in to comment.