Skip to content

Commit

Permalink
Verbose UI for info about git plan
Browse files Browse the repository at this point in the history
  • Loading branch information
emilingerslev committed Oct 10, 2018
1 parent bb684a2 commit c138d7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
11 changes: 6 additions & 5 deletions pkg/git/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ func GetGitPlan(plan string, localShuttleDirectoryPath string, uii ui.UI, skipGi
}

if fileAvailable(planPath) {
if skipGitPlanPulling {
uii.VerboseLn("Skipping git plan pulling")
return planPath
}

status := getStatus(planPath)

if status.mergeState {
Expand All @@ -90,7 +85,13 @@ func GetGitPlan(plan string, localShuttleDirectoryPath string, uii ui.UI, skipGi
uii.EmphasizeInfoLn("Found %v files locally changed in plan", len(status.files))
uii.EmphasizeInfoLn("Skipping plan pull because of changes")
} else {
if skipGitPlanPulling {
uii.VerboseLn("Skipping git plan pulling")
return planPath
}

uii.InfoLn("Pulling latest plan changes")
uii.VerboseLn("Using %s - branch %s - commit %s", plan, status.branch, status.commit)
gitCmd("pull origin", planPath, uii)
}
return planPath
Expand Down
28 changes: 21 additions & 7 deletions pkg/git/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
go_cmd "github.com/go-cmd/cmd"
)

func gitCmd2(command string, dir string) go_cmd.Status {
func syncGitCmd(command string, dir string) go_cmd.Status {
cmdOptions := go_cmd.Options{
Buffered: true,
}
Expand All @@ -30,9 +30,12 @@ const (
)

type Status struct {
changes bool
files []FileStatus
mergeState bool
changes bool
files []FileStatus
mergeState bool
commit string
branch string
remoteBranch string
}

type FileStatus struct {
Expand All @@ -44,16 +47,27 @@ type FileStatus struct {

func getStatus(dir string) Status {
// 1 M. N... 100755 100755 100755 df43166016aa8f73ff348175fb11c8f061ebd871 79e6ffe9583d538fdf957b5e7595ba9aa9ed9929 scripts/env.sh
cmdStatus := gitCmd2("status --porcelain=v2 --branch", dir)
cmdStatus := syncGitCmd("status --porcelain=v2 --branch", dir)

status := Status{}

for _, line := range cmdStatus.Stdout {
var x, y, sub, path, origPath string // mH, mI, mW, hH, hI, score
var merge bool = false
var merge = false
switch line[0] {
case '#':
// header
parts := strings.SplitN(line, " ", 3)
switch parts[1] {
case "branch.oid":
status.commit = parts[2]
case "branch.head":
status.branch = parts[2]
case "branch.upsteam":
status.remoteBranch = parts[2]
case "branch.ab":
// # branch.ab +1 -0
//status.remoteBranch = parts[2]
}
continue
case '1':
// Ordinary changed entries
Expand Down

0 comments on commit c138d7d

Please sign in to comment.