Skip to content

Commit c207024

Browse files
authored
Merge pull request #1 from mxstack/docs/improve-readme
Improve README with comprehensive documentation
2 parents 2a4f224 + 7726ac0 commit c207024

1 file changed

Lines changed: 141 additions & 32 deletions

File tree

README.md

Lines changed: 141 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,180 @@
11
# mxrepo
22

3-
Simple helper script for working on multiple git repositories in a specific
4-
directory.
3+
Helper script for working on multiple git repositories in a specific directory.
54

6-
This script is useful if you work with 'mxdev' sources for project
7-
development or if you want to perform backups of a github account.
5+
This script is useful if you work with [mxdev](https://github.com/mxstack/mxdev) sources for project development or if you want to perform backups of a GitHub account.
6+
7+
The tool operates on all git repositories found in the current directory (those containing a `.git` folder) and executes git commands across them in batch.
8+
9+
## Features
10+
11+
- **Batch Operations**: Execute git commands across multiple repositories at once
12+
- **GitHub Integration**: Clone or backup all repositories from a GitHub organization or user
13+
- **Zero Dependencies**: Uses only Python standard library (no external packages required)
14+
- **Smart API Access**: Automatically tries organization endpoint first, then falls back to user endpoint
15+
- **Selective Operations**: Target specific repositories or operate on all found repos
16+
- **Works with mxdev**: Designed for managing mxdev source checkouts during development
17+
18+
## Prerequisites
19+
20+
- **Python 3.9 or higher**
21+
- **Git** must be installed and available in PATH
22+
- **GitHub Access**: For `clone` and `backup` commands, repositories must be accessible via GitHub's public API (no authentication is performed)
23+
24+
## Installation
25+
26+
### From PyPI
27+
28+
```bash
29+
pip install mxrepo
30+
```
31+
32+
### For Development
33+
34+
```bash
35+
git clone https://github.com/mxstack/mxrepo
36+
cd mxrepo
37+
make install # Sets up virtual environment and installs dependencies
38+
```
839

940
## Usage
1041

11-
Clone repositories:
42+
### Parameters
43+
44+
- **`<CONTEXT>`**: GitHub organization or user name (e.g., `mxstack`, `octocat`)
45+
- **`[<PACKAGE>]`**: Optional repository name(s) to filter operations. When omitted, operates on all repositories found in the current directory
46+
47+
### Commands
48+
49+
| Command | Description | Usage | Example |
50+
|---------|-------------|-------|---------|
51+
| `clone` | Clone repositories from GitHub org/user | `mxrepo clone <CONTEXT> [<PACKAGE>...]` | `mxrepo clone mxstack mxdev` |
52+
| `backup` | Backup all repos from org/user (bare mirrors) | `mxrepo backup <CONTEXT>` | `mxrepo backup myorganization` |
53+
| `pull` | Pull latest changes from origin | `mxrepo pull [<PACKAGE>...]` | `mxrepo pull` |
54+
| `status` | Show git status for repositories | `mxrepo status [<PACKAGE>...]` | `mxrepo status myproject` |
55+
| `branch` | List branches in repositories | `mxrepo branch [<PACKAGE>...]` | `mxrepo branch` |
56+
| `diff` | Show git diff for repositories | `mxrepo diff [<PACKAGE>...]` | `mxrepo diff` |
57+
| `commit` | Commit all changes with message | `mxrepo commit "<MESSAGE>" [<PACKAGE>...]` | `mxrepo commit "Fix: update deps"` |
58+
| `push` | Push committed changes to origin | `mxrepo push [<PACKAGE>...]` | `mxrepo push` |
59+
| `checkout` | **⚠️ Discard all uncommitted changes** | `mxrepo checkout [<PACKAGE>...]` | `mxrepo checkout` |
60+
61+
**⚠️ Warning**: The `checkout`, `commit`, and `push` commands are destructive operations. Use with caution.
62+
63+
## Examples
64+
65+
### Clone all repositories from an organization
66+
67+
```bash
68+
mxrepo clone mxstack
69+
```
70+
71+
This fetches all repositories from the GitHub organization `mxstack` and clones them into the current directory.
72+
73+
### Clone specific repositories only
1274

13-
```shell
14-
mxrepo clone <CONTEXT> [<PACKAGE>]
75+
```bash
76+
mxrepo clone mxstack mxdev mxmake
1577
```
1678

17-
Update repositories:
79+
Clones only `mxdev` and `mxmake` from the `mxstack` organization.
1880

19-
```shell
20-
mxrepo pull [<PACKAGE>]
81+
### Backup all repositories from a user account
82+
83+
```bash
84+
mkdir backups
85+
cd backups
86+
mxrepo backup octocat
2187
```
2288

23-
Backup of context:
89+
Creates bare mirror clones of all repositories belonging to the GitHub user `octocat`. The backup command creates a subfolder named after the context.
90+
91+
### Update all local repositories
2492

25-
```shell
26-
mxrepo backup <CONTEXT>
93+
```bash
94+
mxrepo pull
2795
```
2896

29-
Check repository state:
97+
Executes `git pull origin <current-branch>` in all git repositories found in the current directory.
3098

31-
```shell
32-
mxrepo status [<PACKAGE>]
99+
### Check status across all projects
100+
101+
```bash
102+
mxrepo status
33103
```
34104

35-
Listing repository branch:
105+
Shows `git status` for each repository, useful for seeing which projects have uncommitted changes.
106+
107+
### Commit changes across multiple repositories
36108

37-
```shell
38-
mxrepo branch [<PACKAGE>]
109+
```bash
110+
mxrepo commit "Update dependencies to latest versions"
39111
```
40112

41-
Show repository diff:
113+
Commits all changes in each repository with the same commit message. Equivalent to `git commit -am "message"` in each repo.
114+
115+
### Update only specific repositories
42116

43-
```shell
44-
mxrepo diff [<PACKAGE>]
117+
```bash
118+
mxrepo pull project1 project2
45119
```
46120

47-
Commit all repository changes:
121+
Pulls changes only for `project1` and `project2` repositories.
122+
123+
## How It Works
124+
125+
1. **Repository Discovery**: Scans the current directory for subdirectories containing a `.git` folder
126+
2. **Batch Execution**: Changes into each repository directory and executes the git command
127+
3. **GitHub API**: For `clone` and `backup` commands, queries GitHub's REST API to fetch repository lists:
128+
- Tries organization endpoint: `https://api.github.com/orgs/{context}/repos`
129+
- Falls back to user endpoint: `https://api.github.com/users/{context}/repos`
130+
- Handles pagination (50 repos per page)
131+
4. **Branch Detection**: Automatically detects the current branch for pull and push operations
48132

49-
```shell
50-
mxrepo commit "<MESSAGE>" [<PACKAGE>]
133+
## Development
134+
135+
This project uses the MXStack tooling ([mxdev](https://github.com/mxstack/mxdev) and [mxmake](https://github.com/mxstack/mxmake)) for development.
136+
137+
### Setup
138+
139+
```bash
140+
make install # Set up virtual environment and install dependencies
51141
```
52142

53-
Push all committed changes:
143+
### Code Quality
54144

55-
```shell
56-
mxrepo push [<PACKAGE>]
145+
```bash
146+
make check # Run all checks (ruff + isort)
147+
make format # Auto-format code (ruff + isort)
57148
```
58149

59-
Discard all changes:
150+
### Cleanup
60151

61-
```shell
62-
mxrepo checkout [<PACKAGE>]
152+
```bash
153+
make clean # Remove virtual environment and generated files
154+
make runtime-clean # Remove Python cache files (__pycache__, *.pyc)
63155
```
64156

157+
### Tools Used
158+
159+
- **[ruff](https://github.com/astral-sh/ruff)**: Linting and formatting
160+
- **[isort](https://pycqa.github.io/isort/)**: Import sorting (black profile, single-line imports)
161+
- **[uv](https://github.com/astral-sh/uv)**: Fast Python package installer
162+
163+
### Project Structure
164+
165+
- `src/mxrepo/main.py`: Single-module implementation with all functionality
166+
- No external dependencies (uses only Python stdlib)
167+
- Simple argparse-based CLI with subcommands
168+
169+
## Related Projects
170+
171+
- **[mxdev](https://github.com/mxstack/mxdev)**: Tools for managing multiple Python packages in development
172+
- **[githelper](https://github.com/rnixx/githelper)**: Original project that mxrepo was based on
173+
65174
## Copyright
66175

67176
- Copyright (c) 2025 mxstack Contributors
68-
- BSD 2-clause license (see below)
177+
- BSD 2-clause license (see [LICENSE.md](LICENSE.md))
69178

70179
## Contributors
71180

0 commit comments

Comments
 (0)