Skip to content

Commit

Permalink
feat(turbine): Warn about uncommitted changes (#275)
Browse files Browse the repository at this point in the history
* feat(turbine): Warn about uncommitted changes
  • Loading branch information
janelletavares authored Mar 15, 2022
1 parent a0fcd03 commit 74ca6ce
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"strings"

"github.com/volatiletech/null/v8"

Expand Down Expand Up @@ -143,6 +145,42 @@ func (d *Deploy) createApplication(ctx context.Context) error {
return nil
}

// gitChecks prints warnings about uncommitted tracked and untracked files.
func (d *Deploy) gitChecks(ctx context.Context) error {
// temporarily switching to the app's directory
pwd, err := os.Getwd()
if err != nil {
return err
}
err = os.Chdir(d.path)
if err != nil {
return err
}

cmd := exec.Command("git", "status", "--porcelain=v2")
output, err := cmd.Output()
if err != nil {
return err
}
all := string(output)
lines := strings.Split(strings.TrimSpace(all), "\n")
if len(lines) > 0 && lines[0] != "" {
cmd = exec.Command("git", "status")
output, err = cmd.Output()
if err != nil {
return err
}
d.logger.Error(ctx, string(output))
err = os.Chdir(pwd)
if err != nil {
return err
}
return fmt.Errorf("unable to proceed with deployment because of uncommitted changes")
}

return os.Chdir(pwd)
}

func (d *Deploy) Execute(ctx context.Context) error {
err := d.checkRequiredEnvVars()
if err != nil {
Expand All @@ -155,6 +193,11 @@ func (d *Deploy) Execute(ctx context.Context) error {
return err
}

err = d.gitChecks(ctx)
if err != nil {
return err
}

switch d.lang {
case GoLang:
err = d.goDeploy.DeployGoApp(ctx, d.path, d.logger)
Expand Down

0 comments on commit 74ca6ce

Please sign in to comment.