mirror of
https://github.com/grdl/git-get.git
synced 2026-02-11 12:59:15 +00:00
Rename git package to repo package
This commit is contained in:
@@ -2,12 +2,12 @@ package print
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git-get/pkg/git"
|
||||
"git-get/pkg/repo"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Printer interface {
|
||||
Print(root string, repos []*git.Repo) string
|
||||
Print(root string, repos []*repo.Repo) string
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -17,35 +17,35 @@ const (
|
||||
ColorYellow = "\033[1;33m%s\033[0m"
|
||||
)
|
||||
|
||||
func printWorktreeStatus(repo *git.Repo) string {
|
||||
func printWorktreeStatus(r *repo.Repo) string {
|
||||
clean := true
|
||||
var status []string
|
||||
|
||||
// if current branch status can't be found it's probably a detached head
|
||||
// TODO: what if current HEAD points to a tag?
|
||||
if current := repo.CurrentBranchStatus(); current == nil {
|
||||
status = append(status, fmt.Sprintf(ColorYellow, repo.Status.CurrentBranch))
|
||||
if current := r.CurrentBranchStatus(); current == nil {
|
||||
status = append(status, fmt.Sprintf(ColorYellow, r.Status.CurrentBranch))
|
||||
} else {
|
||||
status = append(status, printBranchStatus(current))
|
||||
}
|
||||
|
||||
// TODO: this is ugly
|
||||
// unset clean flag to use it to render braces around worktree status and remove "ok" from branch status if it's there
|
||||
if repo.Status.HasUncommittedChanges || repo.Status.HasUntrackedFiles {
|
||||
if r.Status.HasUncommittedChanges || r.Status.HasUntrackedFiles {
|
||||
clean = false
|
||||
}
|
||||
|
||||
if !clean {
|
||||
status[len(status)-1] = strings.TrimSuffix(status[len(status)-1], git.StatusOk)
|
||||
status[len(status)-1] = strings.TrimSuffix(status[len(status)-1], repo.StatusOk)
|
||||
status = append(status, "[")
|
||||
}
|
||||
|
||||
if repo.Status.HasUntrackedFiles {
|
||||
status = append(status, fmt.Sprintf(ColorRed, git.StatusUntracked))
|
||||
if r.Status.HasUntrackedFiles {
|
||||
status = append(status, fmt.Sprintf(ColorRed, repo.StatusUntracked))
|
||||
}
|
||||
|
||||
if repo.Status.HasUncommittedChanges {
|
||||
status = append(status, fmt.Sprintf(ColorRed, git.StatusUncommitted))
|
||||
if r.Status.HasUncommittedChanges {
|
||||
status = append(status, fmt.Sprintf(ColorRed, repo.StatusUncommitted))
|
||||
}
|
||||
|
||||
if !clean {
|
||||
@@ -55,7 +55,7 @@ func printWorktreeStatus(repo *git.Repo) string {
|
||||
return strings.Join(status, " ")
|
||||
}
|
||||
|
||||
func printBranchStatus(branch *git.BranchStatus) string {
|
||||
func printBranchStatus(branch *repo.BranchStatus) string {
|
||||
// ok indicates that the branch has upstream and is not ahead or behind it
|
||||
ok := true
|
||||
var status []string
|
||||
@@ -64,21 +64,21 @@ func printBranchStatus(branch *git.BranchStatus) string {
|
||||
|
||||
if branch.Upstream == "" {
|
||||
ok = false
|
||||
status = append(status, fmt.Sprintf(ColorYellow, git.StatusNoUpstream))
|
||||
status = append(status, fmt.Sprintf(ColorYellow, repo.StatusNoUpstream))
|
||||
}
|
||||
|
||||
if branch.Behind != 0 {
|
||||
ok = false
|
||||
status = append(status, fmt.Sprintf(ColorYellow, fmt.Sprintf("%d %s", branch.Behind, git.StatusBehind)))
|
||||
status = append(status, fmt.Sprintf(ColorYellow, fmt.Sprintf("%d %s", branch.Behind, repo.StatusBehind)))
|
||||
}
|
||||
|
||||
if branch.Ahead != 0 {
|
||||
ok = false
|
||||
status = append(status, fmt.Sprintf(ColorYellow, fmt.Sprintf("%d %s", branch.Ahead, git.StatusAhead)))
|
||||
status = append(status, fmt.Sprintf(ColorYellow, fmt.Sprintf("%d %s", branch.Ahead, repo.StatusAhead)))
|
||||
}
|
||||
|
||||
if ok {
|
||||
status = append(status, fmt.Sprintf(ColorGreen, git.StatusOk))
|
||||
status = append(status, fmt.Sprintf(ColorGreen, repo.StatusOk))
|
||||
}
|
||||
|
||||
return strings.Join(status, " ")
|
||||
|
||||
Reference in New Issue
Block a user