mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 19:09:45 +00:00
Add a "dump" output option to git-list
It prints a list of all repos URL and is supposed to be consumed by `git get --dump` option.
This commit is contained in:
@@ -18,12 +18,12 @@ const GitgetPrefix = "gitget"
|
||||
const (
|
||||
KeyBranch = "branch"
|
||||
DefBranch = "master"
|
||||
KeyBundle = "bundle"
|
||||
KeyDump = "dump"
|
||||
KeyDefaultHost = "defaultHost"
|
||||
DefDefaultHost = "github.com"
|
||||
KeyFetch = "fetch"
|
||||
KeyOutput = "out"
|
||||
DefOutput = OutSimple
|
||||
DefOutput = OutTree
|
||||
KeyPrivateKey = "privateKey"
|
||||
DefPrivateKey = "id_rsa"
|
||||
KeyReposRoot = "reposRoot"
|
||||
@@ -32,9 +32,10 @@ const (
|
||||
|
||||
// Allowed values for the --out flag
|
||||
const (
|
||||
OutFlat = "flat"
|
||||
OutSmart = "smart"
|
||||
OutSimple = "simple"
|
||||
OutDump = "dump"
|
||||
OutFlat = "flat"
|
||||
OutTree = "tree"
|
||||
OutSmart = "smart"
|
||||
)
|
||||
|
||||
// Version metadata set by ldflags during the build.
|
||||
|
||||
37
pkg/print/dump.go
Normal file
37
pkg/print/dump.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package print
|
||||
|
||||
import (
|
||||
"git-get/pkg/git"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DumpPrinter struct{}
|
||||
|
||||
// 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 []*git.Repo) string {
|
||||
var str strings.Builder
|
||||
|
||||
for i, repo := range repos {
|
||||
remotes, err := repo.Remotes()
|
||||
if err != nil || len(remotes) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 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 := repo.Status.CurrentBranch
|
||||
|
||||
str.WriteString(url)
|
||||
|
||||
if current != git.StatusDetached && current != git.StatusUnknown {
|
||||
str.WriteString(" " + current)
|
||||
}
|
||||
|
||||
if i < len(repos)-1 {
|
||||
str.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return str.String()
|
||||
}
|
||||
Reference in New Issue
Block a user