Skip to content

Commit

Permalink
feat: 56 show live changes at commit #56
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Martinez committed Mar 12, 2023
1 parent 8c5a0c2 commit 7b7102b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 47 deletions.
1 change: 1 addition & 0 deletions pkg/cli/actions/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func addToStage(raw []string) {

func processFiles(raw []string, unstaged []string, list []string) (newList []string, changesMsg string, defaults []string) {
if len(raw) == 0 {
loading.Stop()
println("No changes to commit ✅")
os.Exit(0)
return
Expand Down
17 changes: 7 additions & 10 deletions pkg/git/Commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ import (
)

func _commit(msg string, body string, ctype string, scope string, ticket string) string {
println("\nCommiting files\n")
cmd := git_controller.Commit(msg, body, ctype, ticket, scope)
out, outErr, err := shell.Out(cmd)
out, _, err := shell.OutLive(cmd)

if err != nil {
loading.Stop()

if strings.Contains(out, "nothing to commit") {
fmt.Println(out)
fmt.Println("Aborting commit...")
fmt.Println("\nAborting commit...")

os.Exit(1)
} else {
fmt.Println(outErr)
log.Fatal("Commit failed")
}
}
Expand Down Expand Up @@ -62,16 +61,14 @@ func Commit(msg string, body string, ctype string, scope string) {
}

ticket := _checkTicket(git_controller.GetTicketNumber())
out := _commit(msg, body, ctype, scope, ticket)

loading.Stop()
fmt.Println(out)
_commit(msg, body, ctype, scope, ticket)

}

func CommitWithoutTicket(msg string, body string, ctype string, scope string) {
loading.Start("Commiting files ")
out := _commit(msg, body, ctype, scope, "")


loading.Stop()
fmt.Println(out)
_commit(msg, body, ctype, scope, "")
}
14 changes: 4 additions & 10 deletions pkg/git/Publish.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package git

import (
"fmt"
"log"

git_controller "github.com/Minnek-Digital-Studio/cominnek/controllers/git"
"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/pkg/shell"
"github.com/fatih/color"
)

func PushPublish() {
loading.Start("Pushing to remote ")
color.Yellow("\nPushing to remote\n")
currentBranch := git_controller.GetCurrentBranch()
cmd := git_controller.Publish(currentBranch)
_, _, err := shell.OutLive(cmd)

out, errout, err := shell.Out(cmd)
if err != nil {
fmt.Println(out)
fmt.Println(errout)
log.Fatal(errout)
log.Fatal("Error pushing to remote")
}

loading.Stop()
fmt.Println(out)
}
13 changes: 4 additions & 9 deletions pkg/git/Push.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package git

import (
"fmt"
"log"

git_controller "github.com/Minnek-Digital-Studio/cominnek/controllers/git"
"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/pkg/shell"
)

func _push() {
loading.Start("Pushing to remote ")
cmd := git_controller.Push()
out, errout, err := shell.Out(cmd)
_, _, err := shell.OutLive(cmd)

if err != nil {
fmt.Println(out)
fmt.Println(errout)
log.Fatal(errout)
// fmt.Println(out)
// fmt.Println(errout)
log.Fatal("Error pushing to remote")
}

loading.Stop()
fmt.Println(out)
}

func Push() {
Expand Down
29 changes: 11 additions & 18 deletions pkg/shell/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package shell

import (
"bufio"
"bytes"
"fmt"
"io"
"log"
"os"
"os/exec"
"runtime"

"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/pkg/events"
)

Expand All @@ -35,28 +35,21 @@ func Out(command string) (string, string, error) {
return stdout.String(), stderr.String(), err
}

func OutLive(command string) {
func OutLive(command string) (string, string, error) {
cmd := exec.Command(shellToUse, "-c", command)

stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Println(err)
}
var stdoutBuf, stderrBuf bytes.Buffer
cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)

err := cmd.Run()
outStr, errStr := stdoutBuf.String(), stderrBuf.String()

err = cmd.Start()
loading.Start("Running command...")
if err != nil {
fmt.Println(err)
}

scanner := bufio.NewScanner(stdout)
loading.Stop()
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
return outStr, errStr, err
}

cmd.Wait()
return outStr, errStr, nil
}

/*Execute a command and return the output*/
Expand Down

0 comments on commit 7b7102b

Please sign in to comment.