6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-07 01:30:37 +00:00

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
This commit is contained in:
Grzegorz Dlugoszewski
2020-06-24 23:54:44 +02:00
committed by GitHub
parent 2ef739ea49
commit 8c132cdafa
26 changed files with 1452 additions and 1648 deletions

View File

@@ -2,32 +2,49 @@ package print
import (
"fmt"
"git-get/pkg/repo"
"path/filepath"
"strings"
)
// FlatPrinter implements Printer interface and provides method for printing list of repos in flat format.
// 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(root string, repos []*repo.Repo) string {
func (p *FlatPrinter) Print(repos []Repo) string {
var str strings.Builder
for _, r := range repos {
path := strings.TrimPrefix(r.Path, root)
path = strings.Trim(path, string(filepath.Separator))
str.WriteString(fmt.Sprintf("\n%s %s", r.Path(), printCurrentBranchLine(r)))
str.WriteString(fmt.Sprintf("\n%s %s", path, printWorktreeStatus(r)))
branches, err := r.Branches()
if err != nil {
str.WriteString(printErr(err))
continue
}
for _, branch := range r.Status.Branches {
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.Name == r.Status.CurrentBranch {
if branch == current {
continue
}
indent := strings.Repeat(" ", len(path))
str.WriteString(fmt.Sprintf("\n%s %s", indent, printBranchStatus(branch)))
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))
}
}