mangrove

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mangrove (mgv)

複数リポジトリの git worktree をまとめて管理する CLI ツール

Go

概要

mgv は、複数の Git リポジトリにまたがる開発ワークスペースを git worktree で一括管理するコマンドラインツールです。

フロントエンドとバックエンドなど、複数リポジトリをセットで並行開発する際に、以下の課題を解決します。

  • 各リポで個別に git worktree add/remove するのが面倒
  • リポごとに派生元ブランチが異なる(frontend は main から、backend は develop からなど)
  • 「この作業はどのリポのどのブランチだったか」を把握しづらい

mgv では プロファイル にリポジトリの組み合わせを定義し、ワークスペース としてまとめて worktree を作成・削除・管理できます。fzf を使った対話式のブランチ選択により、操作もスムーズです。

インストール

go install
go install github.com/Koutaro-Hanabusa/mangrove/cmd/mgv@latest
ソースからビルド
git clone https://github.com/Koutaro-Hanabusa/mangrove.git
cd mangrove
go build -o mgv ./cmd/mgv

ビルドされた mgv バイナリを $PATH の通った場所に配置してください。

前提条件

ツール 必須/任意 用途
git 必須 worktree 操作全般
fzf 対話モードで必須、--yes 時は不要 ブランチ/ワークスペースの選択

fzf のインストール:

# macOS
brew install fzf

# Linux
sudo apt install fzf

設定

設定ファイルの場所: ~/.config/mgv/config.yaml

base_dir: ~/mgv-workspaces
default_profile: project-a

profiles:
  project-a:
    repos:
      - name: frontend-A
        path: ~/repos/frontend-A
        default_base: main
      - name: backend
        path: ~/repos/backend
        default_base: develop
    hooks:
      post_create:
        - repo: frontend-A
          run: npm install
        - repo: backend
          run: go mod download

  project-b:
    repos:
      - name: frontend-B
        path: ~/repos/frontend-B
      - name: backend
        path: ~/repos/backend
        default_base: develop
設定項目
キー 説明 デフォルト値
base_dir ワークスペースの親ディレクトリ ~/mgv-workspaces
default_profile --profile 省略時に使われるプロファイル (なし)
profiles プロファイルの定義 {}
profiles.*.repos[].name リポジトリの表示名 (worktree ディレクトリ名にも使用)
profiles.*.repos[].path ベアリポジトリまたはクローン済みリポジトリのパス
profiles.*.repos[].default_base 派生元のデフォルトブランチ main
profiles.*.hooks.post_create ワークスペース作成後に実行するフック []

使い方

すべてのコマンドで --profile (-p) フラグを使ってプロファイルを指定できます。省略時は default_profile が使用されます。

mgv new - ワークスペースの作成

対話モードでは、プロファイル選択、ワークスペース名の入力、各リポの派生元ブランチを fzf で選択できます。

# 対話モード (fzf でブランチ選択)
mgv new

# ワークスペース名を指定して対話モード
mgv new feature-login

# 非対話モード (default_base を自動使用)
mgv new feature-login --yes

# プロファイルを指定して非対話モード
mgv new feature-login --profile project-a --yes

# 全リポ共通で派生元ブランチを指定
mgv new feature-login --base develop --yes

フラグ:

フラグ 短縮形 説明
--yes -y 非対話モード (デフォルトブランチを自動使用)
--base -b 全リポ共通の派生元ブランチ
--profile -p 使用するプロファイル

ワークスペース作成後、hooks.post_create に定義されたコマンドが各リポのディレクトリ内で実行されます。

mgv rm - ワークスペースの削除
# 対話モード (fzf でワークスペース選択 → 確認)
mgv rm

# ワークスペース名を指定
mgv rm feature-login

# ブランチも一緒に削除
mgv rm feature-login --with-branch

# 非対話モード (確認なし)
mgv rm feature-login --profile project-a --with-branch --yes

# 未コミット変更があっても強制削除
mgv rm feature-login --force --yes

フラグ:

フラグ 短縮形 説明
--yes -y 非対話モード (確認をスキップ)
--with-branch ローカルブランチも合わせて削除
--force -f 未コミット変更があっても強制削除
--profile -p 使用するプロファイル

対話モードでは、未コミット変更がある場合に警告を表示し、強制削除するかどうか確認します。

mgv list - ワークスペースの一覧

エイリアス: mgv ls

# 全プロファイルのワークスペースを一覧表示
mgv list

# プロファイルで絞り込み
mgv list --profile project-a

出力例:

project-a:
  feature-login      [frontend-A: ✓ clean] [backend: ● 2 changed]
  feature-payment    [frontend-A: ✓ clean] [backend: ✓ clean]

project-b:
  hotfix-123         [frontend-B: ✓ clean] [backend: ✓ clean]
mgv cd - ワークスペースへの移動

ワークスペースのパスを標準出力に出力します。cd と組み合わせて使用します。

# 対話モード (fzf でワークスペース選択)
cd $(mgv cd)

# ワークスペース名を直接指定
cd $(mgv cd feature-login)

# プロファイルも指定
cd $(mgv cd feature-login --profile project-a)
mgv exec - ワークスペース内でのコマンド実行

ワークスペースの各リポジトリで同じコマンドを実行します。-- の後にコマンドを記述します。

# 対話モード (fzf でワークスペース選択)
mgv exec -- git status

# ワークスペース名を指定
mgv exec feature-login -- git status

# プロファイルも指定
mgv exec feature-login --profile project-a -- make build

出力例:

[frontend-A]
On branch feature-login
nothing to commit, working tree clean

[backend]
On branch feature-login
Changes not staged for commit:
  modified: main.go
mgv status - 詳細なステータス表示

各リポのブランチ名、変更状態、ahead/behind を表示します。

# 対話モード (fzf でワークスペース選択)
mgv status

# ワークスペース名を指定
mgv status feature-login

# プロファイルも指定
mgv status feature-login --profile project-a

出力例:

project-a/feature-login:
  frontend-A        feature-login  ✓ clean      (2 commits ahead of main)
  backend           feature-login  ● 3 changed  (1 commit ahead of develop)
mgv profile - プロファイルの管理
# プロファイル一覧 (* はデフォルト)
mgv profile list

# プロファイルの詳細表示
mgv profile show project-a

profile list の出力例:

 * project-a  (2 repos)
   project-b  (2 repos)

profile show の出力例:

project-a (default)

  Repositories
    frontend-A
      path:         /Users/you/repos/frontend-A
      default_base: main
    backend
      path:         /Users/you/repos/backend
      default_base: develop

  Hooks (post_create)
    frontend-A: npm install
    backend: go mod download

コマンドまとめ

コマンド 対話式 非対話 説明
mgv new [name] profile / name / base branch を対話選択 --yes --base --profile ワークスペース作成
mgv rm [name] workspace 選択 / 確認 --yes --force --with-branch --profile ワークスペース削除
mgv list - --profile 一覧表示
mgv cd [name] fzf でワークスペース選択 引数で直接指定 パス出力
mgv exec [name] -- cmd fzf でワークスペース選択 引数で直接指定 一括コマンド実行
mgv status [name] fzf でワークスペース選択 引数で直接指定 git status まとめ表示
mgv profile list - - プロファイル一覧
mgv profile show <name> - - プロファイル詳細

ディレクトリ構成

ワークスペースのレイアウト
{base_dir}/
├── {profile}/
│   ├── {workspace-name}/
│   │   ├── {repo-name}/     ← git worktree
│   │   └── {repo-name}/     ← git worktree
│   └── {workspace-name}/
│       └── ...
└── {profile}/
    └── ...

例:

~/mgv-workspaces/
├── project-a/
│   ├── feature-login/
│   │   ├── frontend-A/      ← git worktree (main → feature-login)
│   │   └── backend/         ← git worktree (develop → feature-login)
│   └── feature-payment/
│       ├── frontend-A/
│       └── backend/
└── project-b/
    └── hotfix-123/
        ├── frontend-B/
        └── backend/
プロジェクトのソース構成
mangrove/
├── cmd/
│   └── mgv/
│       └── main.go          # エントリーポイント
├── command/
│   ├── root.go              # ルートコマンド + グローバルフラグ
│   ├── new.go               # mgv new
│   ├── rm.go                # mgv rm
│   ├── list.go              # mgv list
│   ├── cd.go                # mgv cd
│   ├── exec.go              # mgv exec
│   ├── status.go            # mgv status
│   └── profile.go           # mgv profile list / show
├── config.go                # 設定読み込み、Profile / Repo 構造体
├── git.go                   # git コマンド呼び出しラッパー
├── workspace.go             # ワークスペース操作ロジック
├── fzf.go                   # fzf 呼び出しヘルパー
├── ui.go                    # lipgloss スタイル定義、出力ヘルパー
├── go.mod
├── go.sum
├── LICENSE
└── README.md

ライセンス

MIT License - Copyright (c) 2026 1126buri

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SuccessStyle is used for success messages (green).
	SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("2"))

	// WarningStyle is used for warning messages (yellow).
	WarningStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("3"))

	// ErrorStyle is used for error messages (red).
	ErrorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("1"))

	// InfoStyle is used for informational messages (blue).
	InfoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("4"))

	// RepoNameStyle is used for rendering repository names (bold).
	RepoNameStyle = lipgloss.NewStyle().Bold(true)

	// BranchNameStyle is used for rendering branch names (cyan).
	BranchNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("6"))

	// ProfileNameStyle is used for rendering profile names (magenta bold).
	ProfileNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("5")).Bold(true)

	// DimStyle is used for less important text.
	DimStyle = lipgloss.NewStyle().Faint(true)

	// CleanBadge shows a clean status indicator.
	CleanBadge = SuccessStyle.Render("\u2713 clean")

	// HeaderStyle is used for section headers.
	HeaderStyle = lipgloss.NewStyle().Bold(true).Underline(true)
)

Style definitions using lipgloss.

Functions

func AheadBehind

func AheadBehind(repoPath, base, branch string) (ahead int, behind int, err error)

AheadBehind returns the number of commits ahead and behind between branch and base. Equivalent to: git -C <repoPath> rev-list --count --left-right <base>...<branch>

func BranchDelete

func BranchDelete(repoPath, branch string, force bool) error

BranchDelete deletes a local branch. Equivalent to: git -C <repoPath> branch -d <branch>

func BranchList

func BranchList(repoPath string) ([]string, error)

BranchList returns the list of local branch names for a repository. Equivalent to: git -C <repoPath> branch --list --format=%(refname:short)

func ChangedBadge

func ChangedBadge(count int) string

ChangedBadge returns a styled changed files indicator.

func CollapsePath added in v0.2.0

func CollapsePath(path string) string

CollapsePath replaces the home directory prefix with ~/ for portable storage.

func CreateWorkspace

func CreateWorkspace(cfg *Config, profile *Profile, profileName, name string, baseBranches map[string]string) error

CreateWorkspace creates a new workspace with worktrees for all repos in the profile.

func CurrentBranch

func CurrentBranch(path string) (string, error)

CurrentBranch returns the current branch name of a worktree or repo.

func DetectDefaultBranch added in v0.2.0

func DetectDefaultBranch(repoPath string) string

DetectDefaultBranch detects the default branch of a remote repository. Falls back to "main" on error.

func ExpandPath

func ExpandPath(path string) string

ExpandPath expands ~ to the user's home directory.

func FetchAll

func FetchAll(repoPath string) error

FetchAll fetches from all remotes. Equivalent to: git -C <repoPath> fetch --all

func FormatRepoStatusCompact

func FormatRepoStatusCompact(repoName string, changedCount int) string

FormatRepoStatusCompact returns a compact repo status string for list view.

func GetWorkspacePath

func GetWorkspacePath(cfg *Config, profileName, name string) string

GetWorkspacePath returns the full path for a workspace.

func IsFzfAvailable

func IsFzfAvailable() bool

IsFzfAvailable checks whether fzf is installed and available in PATH.

func ParseWorkspaceLabel

func ParseWorkspaceLabel(label string) (profileName, workspaceName string, err error)

ParseWorkspaceLabel extracts profile and workspace name from a label.

func PrintError

func PrintError(format string, args ...interface{})

PrintError prints an error message with a red cross.

func PrintHeader

func PrintHeader(format string, args ...interface{})

PrintHeader prints a section header.

func PrintInfo

func PrintInfo(format string, args ...interface{})

PrintInfo prints an informational message.

func PrintRepoStatus

func PrintRepoStatus(repoName, branchName string, changedCount int, ahead, behind int, defaultBase string)

PrintRepoStatus prints a formatted status line for a repo within a workspace.

func PrintSuccess

func PrintSuccess(format string, args ...interface{})

PrintSuccess prints a success message with a green checkmark.

func PrintWarning

func PrintWarning(format string, args ...interface{})

PrintWarning prints a warning message with a yellow warning sign.

func RemoteBranchList

func RemoteBranchList(repoPath string) ([]string, error)

RemoteBranchList returns the list of remote branch names for a repository. Equivalent to: git -C <repoPath> branch -r --format=%(refname:short)

func RemoveWorkspace

func RemoveWorkspace(cfg *Config, profile *Profile, profileName, name string, deleteBranch, force bool) error

RemoveWorkspace removes a workspace and optionally deletes its branches.

func SaveConfig added in v0.2.0

func SaveConfig(cfg *Config) error

SaveConfig writes the Config struct to ~/.config/mgv/config.yaml.

func SelectBranch

func SelectBranch(repoPath, prompt, defaultBranch string) (string, error)

SelectBranch gets the branch list for a repo, puts defaultBranch first, and lets the user select via fzf.

func SelectDirectory added in v0.3.0

func SelectDirectory(prompt, walkerRoot string) (string, error)

SelectDirectory lets the user pick a directory using fzf's directory walker. walkerRoot sets the starting directory for browsing. If empty, defaults to the user's home directory.

func SelectProfile

func SelectProfile(names []string) (string, error)

SelectProfile lets the user select a profile from a list of profile names via fzf.

func SelectWithFzf

func SelectWithFzf(items []string, prompt, header string) (string, error)

SelectWithFzf presents a list of items via fzf for the user to select from. Returns the selected item or an error if fzf exits non-zero (e.g., user pressed Esc).

func SelectWorkspace

func SelectWorkspace(items []string) (string, error)

SelectWorkspace lets the user select a workspace from a list of workspace labels via fzf.

func StatusChangedCount

func StatusChangedCount(path string) (int, error)

StatusChangedCount returns the number of changed files in a worktree.

func StatusPorcelain

func StatusPorcelain(path string) (string, error)

StatusPorcelain returns the porcelain status output for a given path. Equivalent to: git -C <path> status --porcelain

func WorkspaceLabels

func WorkspaceLabels(workspaces []WorkspaceInfo) []string

WorkspaceLabels returns a list of formatted workspace labels for fzf selection.

func WorktreeAdd

func WorktreeAdd(repoPath, worktreePath, branch, base string) error

WorktreeAdd creates a new worktree with a new branch. Equivalent to: git -C <repoPath> worktree add <worktreePath> -b <branch> <base>

func WorktreeRemove

func WorktreeRemove(repoPath, worktreePath string, force bool) error

WorktreeRemove removes an existing worktree. Equivalent to: git -C <repoPath> worktree remove <worktreePath>

Types

type Config

type Config struct {
	BaseDir        string             `mapstructure:"base_dir"        yaml:"base_dir"`
	DefaultProfile string             `mapstructure:"default_profile" yaml:"default_profile"`
	Profiles       map[string]Profile `mapstructure:"profiles"        yaml:"profiles"`
}

Config is the top-level configuration structure.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig reads the configuration from ~/.config/mgv/config.yaml.

func (*Config) GetProfile

func (c *Config) GetProfile(name string) (*Profile, string, error)

GetProfile returns the named profile from the config. If name is empty, returns the default profile.

func (*Config) ProfileNames

func (c *Config) ProfileNames() []string

ProfileNames returns a sorted list of profile names.

type Hook

type Hook struct {
	Repo string `mapstructure:"repo" yaml:"repo"`
	Run  string `mapstructure:"run"  yaml:"run"`
}

Hook represents a post-create hook to run after workspace creation.

type Hooks

type Hooks struct {
	PostCreate []Hook `mapstructure:"post_create" yaml:"post_create"`
}

Hooks holds the different hook stages.

type Profile

type Profile struct {
	Repos []Repo `mapstructure:"repos" yaml:"repos"`
	Hooks Hooks  `mapstructure:"hooks" yaml:"hooks"`
}

Profile represents a named collection of repositories and their hooks.

type Repo

type Repo struct {
	Name        string `mapstructure:"name"         yaml:"name"`
	Path        string `mapstructure:"path"         yaml:"path"`
	DefaultBase string `mapstructure:"default_base" yaml:"default_base"`
}

Repo represents a single git repository within a profile.

func (*Repo) GetDefaultBase

func (r *Repo) GetDefaultBase() string

GetRepoDefaultBase returns the default base branch for a repo, falling back to "main" if not set.

type RepoStatus

type RepoStatus struct {
	RepoName     string
	BranchName   string
	ChangedCount int
	Ahead        int
	Behind       int
	DefaultBase  string
	Exists       bool
}

RepoStatus represents the status of a single repo within a workspace.

type WorkspaceInfo

type WorkspaceInfo struct {
	ProfileName   string
	WorkspaceName string
	Path          string
	RepoStatuses  []RepoStatus
}

WorkspaceInfo represents summary info about a workspace.

func ListWorkspaces

func ListWorkspaces(cfg *Config, profileName string) ([]WorkspaceInfo, error)

ListWorkspaces scans the base_dir for workspaces and returns their info. If profileName is empty, all profiles are scanned.

type WorktreeEntry

type WorktreeEntry struct {
	Worktree string
	HEAD     string
	Branch   string
	Bare     bool
	Detached bool
}

WorktreeEntry represents a single worktree from porcelain output.

func WorktreeList

func WorktreeList(repoPath string) ([]WorktreeEntry, error)

WorktreeList lists worktrees for a repository in porcelain format. Equivalent to: git -C <repoPath> worktree list --porcelain

Directories

Path Synopsis
cmd
mgv command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL