submod 0.2.0

A headache-free submodule management tool, built on top of gitoxide. Manage sparse checkouts, submodule updates, and adding/removing submodules with ease.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<!--
SPDX-FileCopyrightText: 2025 Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>

SPDX-License-Identifier: LicenseRef-PlainMIT OR MIT
-->

# `submod`

[![Crates.io](https://img.shields.io/crates/v/submod.svg)](https://crates.io/crates/submod)
[![Documentation](https://docs.rs/submod/badge.svg)](https://docs.rs/submod)
[![Static Badge](https://img.shields.io/badge/Plain-MIT-15db95?style=flat-square&labelColor=0d19a3&cacheSeconds=86400&link=https%3A%2F%2Fplainlicense.org%2Flicenses%2Fpermissive%2Fmit%2Fmit%2F)](https://plainlicense.org/licenses/permissive/mit/)
[![Rust](https://img.shields.io/badge/rust-1.87%2B-blue.svg)](https://www.rust-lang.org)
[![codecov](https://codecov.io/gh/bashandbone/submod/branch/main/graph/badge.svg?token=MOW92KKK0G)](https://codecov.io/gh/bashandbone/submod)
![Crates.io Downloads (latest version)](https://img.shields.io/crates/dv/submod)

A lightweight, fast CLI tool for managing git submodules with advanced sparse checkout support. Built on top of `gitoxide` and `git2` libraries for maximum performance and reliability.

## πŸš€ Features

- **TOML-based configuration** - Define submodules, sparse-checkout paths, and settings in a simple config file
- **Global defaults with overrides** - Set project-wide submodule settings with per-submodule customization
- **Sparse checkout support** - Efficiently checkout only the parts of submodules you need
- **Fast operations** - Leverages `gitoxide` for high-performance git operations
- **Robust fallbacks** - Automatic fallback to `git2` and CLI when needed
- **Comprehensive commands** - Add, check, init, update, reset, and sync submodules with ease
- **Developer-friendly** - Clear status reporting and error messages

## πŸ“‹ Table of Contents

- [Installation]#-installation
- [Quick Start]#-quick-start
- [Configuration]#-configuration
- [Commands]#-commands
- [Usage Examples]#-usage-examples
- [Development]#-development
- [Contributing]#-contributing
- [License]#-license

## πŸ”§ Installation

### Using Cargo

```bash
cargo install submod
```

### Using Mise

[Mise](https://mise.jdx.dev/) is a project management tool and package manager that can manage your development environment.

```bash
# Global installation
mise use -g cargo:submod@latest

# Project-specific installation
mise use cargo:submod@latest
```

### From Source

```bash
git clone https://github.com/yourusername/submod.git
cd submod
cargo install --path .
```

## πŸš€ Quick Start

1. **Initialize a config file** in your git repository:

    ```bash
    # Create a basic submod.toml configuration
    cat > submod.toml << EOF
    [defaults]
    ignore = "dirty"

    [my-submodule]
    path = "vendor/my-lib"
    url = "https://github.com/example/my-lib.git"
    sparse_paths = ["src/", "include/", "*.md"]
    EOF
    ```

2. **Initialize your submodules**:

    ```bash
    submod init
    ```

3. **Check status**:

    ```bash
    submod check
    ```

## βš™οΈ Configuration

Create a `submod.toml` file in your repository root:

```toml
# Global defaults applied to all submodules
[defaults]
ignore = "dirty"          # ignore dirty state in status
update = "checkout"       # update method
branch = "main"          # default branch to track

# Individual submodule configuration
[vendor-utils]
path = "vendor/utils"
url = "https://github.com/example/utils.git"
sparse_paths = ["src/", "include/", "*.md"]
ignore = "all"           # override default ignore setting
active = true            # whether submodule is active

[my-submodule]
path = "libs/my-submodule"
url = "https://github.com/example/my-submodule.git"
sparse_paths = ["src/core/", "docs/"]
branch = "develop"       # track specific branch
```

### Configuration Options

#### Global Defaults

- `ignore`: How to handle dirty submodules (`all`, `dirty`, `untracked`, `none`)
- `update`: Update strategy (`checkout`, `rebase`, `merge`, `none`, `!command`)
- `branch`: Default branch to track (`.` for current superproject branch)
- `fetchRecurse`: Fetch recursion (`always`, `on-demand`, `never`)

#### Per-Submodule Settings

- `path`: Local path where submodule should be placed
- `url`: Git repository URL
- `sparse_paths`: Array of paths to include in sparse checkout
- `active`: Whether the submodule is active (default: `true`)
- All global defaults can be overridden per submodule

## πŸ“– Commands

### `submod add`

Add a new submodule to your configuration and repository:

```bash
# Basic add
submod add https://github.com/example/my-lib.git --name my-lib --path libs/my-lib

# With sparse checkout paths and extra options
submod add https://github.com/example/my-lib.git \
  --name my-lib \
  --path libs/my-lib \
  --sparse-paths "src/,include/" \
  --branch main \
  --ignore all \
  --fetch on-demand
```

**Options:**

| Flag | Short | Description |
|------|-------|-------------|
| `<URL>` | | *(required)* URL or local path of the submodule repository |
| `--name` | `-n` | Nickname for the submodule used in your config and commands |
| `--path` | `-p` | Local directory path where the submodule should be placed |
| `--branch` | `-b` | Branch to track |
| `--ignore` | `-i` | Dirty-state ignore level (`all`, `dirty`, `untracked`, `none`) |
| `--sparse-paths` | `-x` | Comma-separated sparse checkout paths or globs |
| `--fetch` | `-f` | Recursive fetch behavior (`always`, `on-demand`, `never`) |
| `--update` | `-u` | Update strategy (`checkout`, `rebase`, `merge`, `none`) |
| `--shallow` | `-s` | Shallow clone (last commit only) |
| `--no-init` | | Add to config only; do not clone/initialize |

### `submod check`

Check the status of all configured submodules:

```bash
submod check
```

### `submod init`

Initialize all missing submodules:

```bash
submod init
```

### `submod update`

Update all submodules to their latest commits:

```bash
submod update
```

### `submod reset`

Hard reset submodules (stash changes, reset --hard, clean):

```bash
# Reset all submodules
submod reset --all

# Reset specific submodules (comma-separated)
submod reset my-lib,vendor-utils
```

### `submod sync`

Run a complete sync (check + init + update):

```bash
submod sync
```

### `submod change`

Change the configuration of an existing submodule:

```bash
submod change my-lib --branch main --sparse-paths "src/,include/" --fetch always
```

### `submod change-global`

Change global defaults for all submodules:

```bash
submod change-global --ignore dirty --update checkout
```

### `submod list`

List all configured submodules:

```bash
submod list
submod list --recursive
```

### `submod delete`

Delete a submodule from configuration and filesystem:

```bash
submod delete my-lib
```

### `submod disable`

Disable a submodule without deleting files (sets `active = false`):

```bash
submod disable my-lib
```

### `submod nuke-it-from-orbit`

Delete all or specific submodules from config and filesystem, with optional reinit:

```bash
# Nuke all submodules (re-initializes by default)
submod nuke-it-from-orbit --all

# Nuke specific submodules permanently
submod nuke-it-from-orbit --kill my-lib,old-dep
```

### `submod generate-config`

Generate a new configuration file:

```bash
# From current git submodule setup
submod generate-config --from-setup .

# As a template with defaults
submod generate-config --template --output my-config.toml
```

### `submod completeme`

Generate shell completion scripts:

```bash
submod completeme bash   # or: zsh, fish, powershell, elvish, nushell
```

## πŸ’» Usage Examples

### Basic Workflow

```bash
# Start with checking current state
submod check

# Initialize any missing submodules
submod init

# Update everything to latest
submod update

# Or do it all at once
submod sync
```

### Adding Submodules with Sparse Checkout

```bash
# Add a submodule that only checks out specific directories
submod add https://github.com/company/react-components.git \
  --name react-components \
  --path src/components \
  --sparse-paths "src/Button/,src/Input/,README.md"
```

### Working with Different Configurations

```bash
# Use a custom config file
submod --config my-custom.toml check

# Check status with custom config
submod --config production.toml sync
```

### Handling Problematic Submodules

```bash
# Reset a problematic submodule
submod reset my-problematic-submodule

# Check what's wrong
submod check

# Re-sync everything
submod sync
```

## πŸ› οΈ Development

### Prerequisites

- Rust 1.87 or later
- Git
- [Mise]https://mise.jdx.dev/ (recommended) - for tool management and task running

### Quick Setup with Mise (Recommended)

```bash
# Clone the repository
git clone https://github.com/bashandbone/submod.git
cd submod

# Install mise if you haven't already
curl https://mise.run | sh

# Install all development tools and dependencies
mise install

# Build the project
mise run build
# or: mise run b (alias)

# Run tests
mise run test

# Run the full CI suite (build + lint + test)
mise run ci
```

### Available Mise Tasks

```bash
# Build the project
mise run build          # or: mise run b

# Run tests
mise run test

# Lint with clippy
mise run lint

# Run full CI pipeline
mise run ci

# Clean build artifacts
mise run clean

# Cut a new release (maintainers only)
mise run release
```

### Git Hooks with hk

This project uses [hk](https://github.com/jdx/hk) for automated git hooks that ensure code quality:

```bash
# Install git hooks (done automatically with mise install)
hk install

# Run pre-commit checks manually
hk run pre-commit

# Run all linters and checks
hk check

# Auto-fix issues where possible
hk fix

# Run CI checks locally
hk run ci
```

The pre-commit hooks automatically run:
- **cargo fmt** - Code formatting
- **cargo clippy** - Linting
- **cargo test** - Test suite
- **typos** - Spell checking
- **prettier** - TOML/YAML formatting
- **cargo deny** - Security and license auditing

### Manual Setup (Alternative)

If you prefer not to use mise:

```bash
# Clone the repository
git clone https://github.com/bashandbone/submod.git
cd submod

# Install Rust if needed
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build the project
cargo build

# Run tests
cargo test
# or hk run test

# Or use the comprehensive test runner
./scripts/run-tests.sh --verbose
```

### Running Tests

```bash
# Using mise (recommended)
mise run test           # Run all tests
mise run ci             # Run full CI suite

# Using hk
hk run test                 # Run tests only
hk run ci                   # Run CI checks

# Using cargo directly
cargo test              # Run all tests
cargo test --test integration_tests  # Integration tests only

# Using the test script
./scripts/run-tests.sh --verbose     # Comprehensive reporting
./scripts/run-tests.sh --performance # Include performance tests
./scripts/run-tests.sh --filter sparse_checkout  # Filter tests
```

### Project Structure

```plaintext
submod/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs              # CLI entry point
β”‚   β”œβ”€β”€ commands.rs          # Command definitions (clap)
β”‚   β”œβ”€β”€ config.rs            # TOML configuration handling
β”‚   β”œβ”€β”€ git_manager.rs       # High-level submodule operations
β”‚   └── git_ops/             # Git backend abstraction
β”‚       β”œβ”€β”€ mod.rs           # GitOpsManager (gixβ†’git2β†’CLI fallback)
β”‚       β”œβ”€β”€ gix_ops.rs       # gitoxide backend
β”‚       └── git2_ops.rs      # libgit2 backend
β”œβ”€β”€ tests/                   # Integration tests
β”œβ”€β”€ sample_config/           # Example configurations
β”œβ”€β”€ scripts/                 # Development scripts
└── docs/                    # Documentation
```

## 🀝 Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Quick Contributing Steps

1. **Fork the repository**
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Set up development environment**: `mise install` (installs all tools and git hooks)
4. **Make your changes** and add tests if applicable
5. **Commit your changes**: `git commit -m 'Add amazing feature'` (hooks run automatically)
6. **Push to your branch**: `git push origin feature/amazing-feature` (they'll actually run again in check mode, so they need to pass)
7. **Open a Pull Request**

### Development Guidelines

- Follow Rust best practices and idioms
- Add tests for new functionality. I'm not big on unit tests, but integration tests are essential.
- Update documentation for user-facing changes
- Use conventional commit messages
- Run `mise run ci` or `hk run ci` before submitting PR
- Pre-commit hooks will automatically format code and run basic checks
- All automated checks must pass before PR can be merged

## πŸ” Troubleshooting

### Common Issues

**Submodule not initializing:**

```bash
# Check if the URL is accessible
git ls-remote <submodule-url>

# Verify your configuration
submod check
```

**Sparse checkout not working:**

- Ensure paths in `sparse_paths` are relative to the submodule root
- Check that the submodule repository contains the specified paths
- Verify sparse checkout is enabled: `git config core.sparseCheckout` in the submodule

**Permission issues:**

- Ensure you have proper SSH keys set up for private repositories
- Check if your Git credentials are configured correctly

## πŸ“‹ Motivation

Managing git submodules, especially with sparse checkouts, can be complex and error-prone. Traditional git submodule commands require multiple steps and careful attention to configuration details.

This tool was created to:

- **Reduce barriers to contribution** - Make it easier for new developers to work with projects using submodules
- **Simplify complex workflows** - Handle initialization, updates, and sparse checkout configuration automatically
- **Provide better tooling** - Clear status reporting and error messages
- **Leverage modern Git libraries** - Use `gitoxide` for better performance and reliability

The tool is actively used in multiple projects at [@knitli](https://github.com/knitli) and [@plainlicense](https://github.com/plainlicense), where submodules are essential for sharing core functionality across repositories.

## πŸ“„ License

This project is licensed under the [Plain MIT License](https://plainlicense.org/licenses/permissive/mit/).

## πŸ™ Acknowledgments

- [gitoxide]https://github.com/Byron/gitoxide - Fast and safe pure Rust implementation of Git
- [git2-rs]https://github.com/rust-lang/git2-rs - Rust bindings to libgit2
- [clap]https://github.com/clap-rs/clap - Command line argument parser

---

<div align="center">

**[Homepage](https://github.com/bashandbone/submod)** β€’ **[Documentation](https://docs.rs/submod)** β€’ **[Crate](https://crates.io/crates/submod)**

Made with ❀️ for the Rust and Git communities

</div>