diff --git a/internal/commands/status_cmd.go b/internal/commands/status_cmd.go index d98fcf2..b514878 100644 --- a/internal/commands/status_cmd.go +++ b/internal/commands/status_cmd.go @@ -2,11 +2,11 @@ package commands import ( "fmt" - "gitlab.com/revalus/grm/internal/config" - "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" + "gitlab.com/revalus/grm/internal/config" + "sort" ) type StatusChecker struct { @@ -116,14 +116,14 @@ func (sc StatusChecker) Command(repoCfg config.RepositoryConfig) CommandStatus { err error } - remotesStatus := make(map[string]remoteStatus) + var remoteNames []string + remoteStatues := make(map[string]remoteStatus) for _, remote := range remotes { remoteName := remote.Config().Name - remoteRevision, err := repo.ResolveRevision(plumbing.Revision(fmt.Sprintf("%v/%v", remoteName, headReference.Name().Short()))) if err != nil { - remotesStatus[remoteName] = remoteStatus{ + remoteStatues[remoteName] = remoteStatus{ err: err, } continue @@ -131,7 +131,7 @@ func (sc StatusChecker) Command(repoCfg config.RepositoryConfig) CommandStatus { remoteBranchCommit, err := repo.CommitObject(*remoteRevision) if err != nil { - remotesStatus[remoteName] = remoteStatus{ + remoteStatues[remoteName] = remoteStatus{ err: err, } continue @@ -144,11 +144,14 @@ func (sc StatusChecker) Command(repoCfg config.RepositoryConfig) CommandStatus { if status.ahead > 0 || status.behind > 0 { cmdStatus.Changed = true } - remotesStatus[remoteName] = status + remoteNames = append(remoteNames, remoteName) + remoteStatues[remoteName] = status } + sort.Strings(remoteNames) cmdStatus.Message = fmt.Sprintf("branch %v", headReference.Name().Short()) - for remoteName, status := range remotesStatus { + for _, remoteName := range remoteNames { + status := remoteStatues[remoteName] if status.err != nil { cmdStatus.Message = fmt.Sprintf("%v - ( | %v | problem: %v )", cmdStatus.Message, remoteName, status.err.Error()) continue