6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-05 21:42:57 +00:00
Files
git-get/pkg/print/flat.go
Grzegorz Dlugoszewski 8c132cdafa Remove gogit and major refactoring (#2)
* Fix typo in readme

* Reimplement all git methods without go-git

* Rename repo pkg to git, add gitconfig methods

* Improve tests for configuration reading

* Rename package file to io and move RepoFinder there

* Refactor printers

- Remove smart printer
- Decouple printers from git repos with interfaces
- Update printer functions
- Remove unnecessary flags
- Add better remote URL detection

* Update readme and go.mod

* Add author to git commit in tests

Otherwise tests will fail in CI.

* Install git before running tests and don't use cgo

* Add better error message, revert installing git

* Ensure commit message is in quotes

* Set up git config before running tests
2020-06-24 23:54:44 +02:00

53 lines
1.1 KiB
Go

package print
import (
"fmt"
"strings"
)
// FlatPrinter prints a list of repos in a flat format.
type FlatPrinter struct{}
// NewFlatPrinter creates a FlatPrinter.
func NewFlatPrinter() *FlatPrinter {
return &FlatPrinter{}
}
// Print generates a flat list of repositories and their statuses - each repo in new line with full path.
func (p *FlatPrinter) Print(repos []Repo) string {
var str strings.Builder
for _, r := range repos {
str.WriteString(fmt.Sprintf("\n%s %s", r.Path(), printCurrentBranchLine(r)))
branches, err := r.Branches()
if err != nil {
str.WriteString(printErr(err))
continue
}
current, err := r.CurrentBranch()
if err != nil {
str.WriteString(printErr(err))
continue
}
for _, branch := range branches {
// Don't print the status of the current branch. It was already printed above.
if branch == current {
continue
}
status, err := printBranchStatus(r, branch)
if err != nil {
status = printErr(err)
}
indent := strings.Repeat(" ", len(r.Path()))
str.WriteString(fmt.Sprintf("\n%s %s %s", indent, printBranchName(branch), status))
}
}
return str.String()
}