Skip to content

Commit 7953a94

Browse files
committed
modify git subcommands and add new docs
1 parent 62446cf commit 7953a94

23 files changed

Lines changed: 367 additions & 673 deletions

File tree

AGENTS.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
**Spark** 是一个 CLI 工具,用于管理多个 Git 仓库。它提供以下核心功能:
88

99
1. **多仓库更新** - 批量更新多个 Git 仓库到最新版本
10-
2. **Mono-repo 管理** - 将多个仓库添加为子模块,统一管理
10+
2. **Submodule 管理** - 将本地仓库或远程 URL 添加为子模块
1111
3. **子模块同步** - 同步 Mono 仓库中的所有子模块
1212
4. **Git 用户配置** - 配置仓库的 Git 用户信息
1313
5. **任务管理** - 任务分发、同步和 GitHub 仓库创建
@@ -35,15 +35,14 @@ spark/
3535
│ ├── git.go # Git 父命令
3636
│ ├── config.go # Git 用户配置
3737
│ ├── update.go # 仓库更新命令
38-
│ ├── mono.go # mono 子命令组
39-
│ ├── mono_add.go # mono add 命令
38+
4039
│ ├── sync.go # 子模块同步命令
4140
│ └── gitcode.go # Gitcode 远程管理
4241
├── internal/ # 内部业务逻辑
4342
│ ├── agent/ # AI Agent 管理器
4443
│ ├── config/ # 配置管理
4544
│ ├── git/ # Git 操作封装
46-
│ ├── mono/ # Mono-repo 操作
45+
4746
│ ├── task/ # 任务管理器
4847
│ └── tui/ # 终端 UI 组件
4948
├── docs/ # 文档
@@ -92,8 +91,8 @@ Git 仓库管理命令的父命令,包含以下子命令:
9291

9392
```bash
9493
spark git update # 更新多个仓库
95-
spark git mono add # 添加现有仓库为子模块
96-
spark git mono sync # 同步子模块
94+
spark git submodule add # 添加现有仓库为子模块
95+
spark git sync # 同步子模块
9796
spark git gitcode # 添加 Gitcode 远程
9897
spark git config # 配置 Git 用户
9998
spark git url # 获取仓库 URL
@@ -112,32 +111,31 @@ spark git update -p ~/workspace -p ~/projects
112111

113112
详细文档: [docs/usage/update.md](docs/usage/update.md)
114113

115-
#### `spark git mono add`
114+
#### `spark git submodule`
116115
将本地 Git 仓库添加为子模块,或克隆远程仓库并添加为子模块。
117116

118117
**本地模式**
119118
```bash
120-
spark git mono add # 添加当前目录下的仓库
121-
spark git mono add -p /path/to/repos # 添加指定目录下的仓库
119+
spark git submodule add # 添加当前目录下的仓库
120+
spark git submodule add -p /path/to/repos # 添加指定目录下的仓库
122121
```
123122

124123
**远程模式**
125124
```bash
126-
spark git mono add https://github.com/user/repo # 添加远程仓库
127-
spark git mono add https://github.com/user/repo --name my-submodule # 指定路径名
128-
spark git mono add git@github.com:user/repo.git # 使用 SSH URL
125+
spark git submodule add https://github.com/user/repo # 添加远程仓库
126+
spark git submodule add https://github.com/user/repo --name my-submodule # 指定路径名
127+
spark git submodule add git@github.com:user/repo.git # 使用 SSH URL
129128
```
130129

131130
| 选项 | 说明 |
132131
|------|------|
133-
| `-p, --path` | Mono-repo 目录 (默认: 当前目录) |
134132
| `-n, --name` | 子模块路径名称 (默认: 仓库名) |
135133

136-
#### `spark git mono sync`
137-
同步 Mono 仓库中的所有子模块到最新版本
134+
#### `spark git sync`
135+
同步当前仓库中所有子模块到最新版本
138136

139137
```bash
140-
spark git mono sync /path/to/mono-repo
138+
spark git sync ./my-repo
141139
```
142140

143141
#### `spark git gitcode`

CLAUDE.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ Spark is a Go CLI tool (`module spark`, binary `spark`) for managing multiple Gi
3434
- **`internal/`** — Business logic, separated by domain:
3535
- `agent/` — AI agent config management module (currently command entry disabled)
3636
- `config/` — Configuration loading and management
37-
- `git/` — Core Git operations (find repos, update, remote management, URL conversion)
37+
- `git/` — Core Git operations (find repos, update, remote management, submodule, URL conversion)
3838
- `github/` — GitHub API interactions (list org repos, parse org URLs)
39-
- `mono/` — Mono-repo creation and submodule management
4039
- `script/` — Script discovery (from config and `scripts/` dir) and execution
4140
- `task/` — Task init/dispatch/sync, issue CRUD, and implementation via `kimi` CLI
4241
- `tui/` — Shared terminal UI components (spinner, dialogs, selector)
@@ -46,8 +45,7 @@ Spark is a Go CLI tool (`module spark`, binary `spark`) for managing multiple Gi
4645

4746
```
4847
spark
49-
├── git [init|update|mono|gitcode|config|url|batch-clone|issues|update-org-status]
50-
│ └── mono [add|sync]
48+
├── git [init|update|submodule|sync|gitcode|config|url|batch-clone|issues|update-org-status]
5149
├── task [list|init|dispatch|sync|create|delete|impl]
5250
├── script [list|run]
5351
└── magic [flush-dns|pip|go|node] # Mirror source switching + DNS

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ main.go → cmd.Execute()
3333
│ ├── config/ Config loading & migration
3434
│ ├── git/ Core git operations
3535
│ ├── github/ GitHub API interactions
36-
│ ├── mono/ Mono-repo & submodule management
36+
3737
│ ├── script/ Script discovery & execution
3838
│ ├── task/ Task dispatch/sync/issue CRUD
3939
│ └── tui/ Shared terminal UI components
@@ -74,8 +74,8 @@ go test ./internal/git/... -v -run TestFunctionName
7474
| Command | Description |
7575
|---------|-------------|
7676
| `spark git update` | Update all repos to latest version |
77-
| `spark git mono add [-p <path>]` | Add existing repos as submodules |
78-
| `spark git mono sync <mono-path>` | Sync all submodules to latest |
77+
| `spark git submodule add [-p <path>]` | Add existing repos as submodules |
78+
| `spark git sync [repo]` | Sync all submodules to latest |
7979
| `spark git gitcode [-p <path>]` | Add Gitcode remote to repos |
8080
| `spark git init [--owner <owner>] [--skip-gh]` | Initialize git repo, create GitHub remote |
8181
| `spark git config [--username --email]` | Configure git user for repo |

cmd/git/git.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var GitCmd = &cobra.Command{
1212
This includes:
1313
- update: Update multiple git repositories
1414
- init: Initialize a git repo and create a GitHub remote
15-
- mono: Mono repo management (add/sync submodules)
15+
- submodule: Add local repos or URLs as git submodules
16+
- sync: Sync all submodules to the latest versions
1617
- gitcode: Add Gitcode as remote
1718
- config: Configure git user for repository
1819
- url: Get repository remote URL

cmd/git/init.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ var initCmd = &cobra.Command{
2121
Use: "init",
2222
Short: "Initialize a git repository and create a GitHub remote",
2323
Long: `Initialize the current directory as a git repository:
24-
1. Run 'git init'
24+
1. Run 'git init' (skipped if already a git repo with GitHub remote)
2525
2. Configure git user (name/email)
2626
3. Add child GitHub repos as git submodules
2727
4. Generate a .gitignore with common patterns
2828
5. Create an initial commit
2929
6. Create a GitHub remote repository via 'gh repo create --push'
3030
31+
If the current directory is already a git repository with a GitHub remote,
32+
steps 1, 4, 5, and 6 are skipped — only submodules are added and committed.
33+
3134
The repo name defaults to the current directory name.
3235
Owner defaults to the 'github-owner' config value in ~/.spark.yaml.`,
3336
RunE: func(cmd *cobra.Command, args []string) error {
@@ -37,9 +40,6 @@ Owner defaults to the 'github-owner' config value in ~/.spark.yaml.`,
3740
if owner == "" {
3841
owner = viper.GetString("github-owner")
3942
}
40-
if owner == "" {
41-
return fmt.Errorf("GitHub owner is required. Set --owner flag or 'github-owner' in ~/.spark.yaml")
42-
}
4343

4444
repoName := initRepo
4545
if repoName == "" {
@@ -50,15 +50,24 @@ Owner defaults to the 'github-owner' config value in ~/.spark.yaml.`,
5050
}
5151
}
5252

53-
fmt.Printf("Initializing git repository: %s/%s\n", owner, repoName)
54-
fmt.Println()
53+
alreadyGitRepo := git.IsGitRepository(repoPath)
54+
hasGitHub, _ := git.IsGitHubRepo(repoPath)
5555

56-
fmt.Println("Step 1/6: Running git init...")
57-
if err := git.InitRepo(repoPath); err != nil {
58-
return fmt.Errorf("git init failed: %w", err)
56+
if alreadyGitRepo && hasGitHub {
57+
fmt.Printf("Existing GitHub repository detected: %s\n\n", repoPath)
58+
fmt.Println("Step 1/3: Configuring git user...")
59+
} else {
60+
if owner == "" {
61+
return fmt.Errorf("GitHub owner is required. Set --owner flag or 'github-owner' in ~/.spark.yaml")
62+
}
63+
fmt.Printf("Initializing git repository: %s/%s\n\n", owner, repoName)
64+
fmt.Println("Step 1/6: Running git init...")
65+
if err := git.InitRepo(repoPath); err != nil {
66+
return fmt.Errorf("git init failed: %w", err)
67+
}
68+
fmt.Println("Step 2/6: Configuring git user...")
5969
}
6070

61-
fmt.Println("Step 2/6: Configuring git user...")
6271
username := viper.GetString("git.username")
6372
email := viper.GetString("git.email")
6473
if username != "" && email != "" {
@@ -72,6 +81,20 @@ Owner defaults to the 'github-owner' config value in ~/.spark.yaml.`,
7281
fmt.Println(" No git user configured in ~/.spark.yaml. Skipping.")
7382
}
7483

84+
if alreadyGitRepo && hasGitHub {
85+
fmt.Println("Step 2/3: Scanning for child GitHub repos to add as submodules...")
86+
if err := git.AddChildReposAsSubmodules(repoPath); err != nil {
87+
fmt.Printf("Warning: %v\n", err)
88+
}
89+
fmt.Println("Step 3/3: Committing submodule changes...")
90+
if err := git.InitialCommit(repoPath, "chore: add existing repos as submodules"); err != nil {
91+
fmt.Printf("Warning: commit failed: %v\n", err)
92+
}
93+
fmt.Println()
94+
fmt.Println("Done! Submodules added to existing repository.")
95+
return nil
96+
}
97+
7598
fmt.Println("Step 3/6: Scanning for child GitHub repos to add as submodules...")
7699
if err := git.AddChildReposAsSubmodules(repoPath); err != nil {
77100
fmt.Printf("Warning: %v\n", err)

cmd/git/mono.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

cmd/git/mono_add.go

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)