mirror of
https://github.com/grdl/git-get.git
synced 2026-02-07 17:34:18 +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:
committed by
GitHub
parent
2ef739ea49
commit
8c132cdafa
@@ -1,31 +1,40 @@
|
||||
package print
|
||||
|
||||
import (
|
||||
"git-get/pkg/repo"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DumpPrinter implements Printer interface and provides method for printing list of repos in dump file format.
|
||||
// DumpRepo is a git repository printable into a dump file.
|
||||
type DumpRepo interface {
|
||||
Path() string
|
||||
Remote() (string, error)
|
||||
CurrentBranch() (string, error)
|
||||
}
|
||||
|
||||
// DumpPrinter prints a list of repos in a dump file format.
|
||||
type DumpPrinter struct{}
|
||||
|
||||
// NewDumpPrinter creates a DumpPrinter.
|
||||
func NewDumpPrinter() *DumpPrinter {
|
||||
return &DumpPrinter{}
|
||||
}
|
||||
|
||||
// Print generates a list of repos URLs. Each line contains a URL and, if applicable, a currently checked out branch name.
|
||||
// It's a way to dump all repositories managed by git-get and is supposed to be consumed by `git get --dump`.
|
||||
func (p *DumpPrinter) Print(_ string, repos []*repo.Repo) string {
|
||||
func (p *DumpPrinter) Print(repos []DumpRepo) string {
|
||||
var str strings.Builder
|
||||
|
||||
for i, r := range repos {
|
||||
remotes, err := r.Remotes()
|
||||
if err != nil || len(remotes) == 0 {
|
||||
url, err := r.Remote()
|
||||
if err != nil {
|
||||
continue
|
||||
// TODO: handle error?
|
||||
}
|
||||
|
||||
// TODO: Needs work. Right now we're just assuming the first remote is the origin one and the one from which the current branch is checked out.
|
||||
url := remotes[0].Config().URLs[0]
|
||||
current := r.Status.CurrentBranch
|
||||
|
||||
str.WriteString(url)
|
||||
|
||||
if current != repo.StatusDetached && current != repo.StatusUnknown {
|
||||
current, err := r.CurrentBranch()
|
||||
if err != nil || current != detached {
|
||||
str.WriteString(" " + current)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user