repowatch 0.4.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {repowatch-0.4.0/repowatch.egg-info → repowatch-0.5.0}/PKG-INFO +34 -9
- {repowatch-0.4.0 → repowatch-0.5.0}/README.md +33 -8
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/__init__.py +1 -1
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/cli.py +38 -9
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/config.py +3 -1
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/core.py +27 -3
- repowatch-0.5.0/repowatch/sync.py +312 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/tui.py +29 -11
- {repowatch-0.4.0 → repowatch-0.5.0/repowatch.egg-info}/PKG-INFO +34 -9
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch.egg-info/SOURCES.txt +1 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/tests/test_cli.py +11 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/tests/test_core.py +18 -0
- repowatch-0.5.0/tests/test_push.py +103 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/tests/test_sync.py +40 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/tests/test_tui.py +15 -0
- repowatch-0.4.0/repowatch/sync.py +0 -182
- {repowatch-0.4.0 → repowatch-0.5.0}/LICENSE +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/pyproject.toml +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/__main__.py +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/prune.py +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch/render.py +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch.egg-info/dependency_links.txt +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch.egg-info/entry_points.txt +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch.egg-info/requires.txt +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/repowatch.egg-info/top_level.txt +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/setup.cfg +0 -0
- {repowatch-0.4.0 → repowatch-0.5.0}/tests/test_prune.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: repowatch
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Every git repo under a folder, compared across all its remotes, with fast-forward-only sync and safe branch pruning.
|
|
5
5
|
Author: Mark Wharry
|
|
6
6
|
License-Expression: MIT
|
|
@@ -42,7 +42,7 @@ Point repowatch at your code folder. It finds every repo, then shows one row per
|
|
|
42
42
|
It's built for people who keep the same code in more than one place, for example GitHub plus a work or home Gitea, or one machine at work and another at home. It answers three questions:
|
|
43
43
|
|
|
44
44
|
1. **Where does everything stand?** A matrix of every repo against every remote.
|
|
45
|
-
2. **Can it level them for me, safely?** `sync` fast-forwards your secondary
|
|
45
|
+
2. **Can it level them for me, safely?** `sync` fast-forwards your secondary remotes and your local checkout to match the primary, in both directions, and `push` sends your own commits to all of them at once. Neither ever force-pushes or merges.
|
|
46
46
|
3. **What's all this branch clutter?** `prune` deletes branches whose work is already in `main`, including squash-merged ones, and explains every branch it keeps.
|
|
47
47
|
|
|
48
48
|
## Install
|
|
@@ -99,7 +99,7 @@ Each remote cell shows that remote's tip of your current branch, and how your lo
|
|
|
99
99
|
|
|
100
100
|
**Local** shows HEAD plus `+` staged, `~` modified, `?` untracked, `!` conflicts and `$` stashes, or `✓` when clean.
|
|
101
101
|
|
|
102
|
-
**Columns are labelled by host, not remote name.** `origin → github.com` and `upstream → github.com` both appear under `github`. Map your own hosts in the config.
|
|
102
|
+
**Columns are labelled by host, not remote name.** `origin → github.com` and `upstream → github.com` both appear under `github`. Map your own hosts in the config. If a remote's URL uses a `url.<base>.insteadOf` alias, the host git really connects to is used.
|
|
103
103
|
|
|
104
104
|
### TUI keys
|
|
105
105
|
|
|
@@ -108,6 +108,7 @@ Each remote cell shows that remote's tip of your current branch, and how your lo
|
|
|
108
108
|
| `r` | Rescan (local only, fast) |
|
|
109
109
|
| `f` / `F` | Fetch the selected repo / all repos |
|
|
110
110
|
| `s` / `S` | Sync the selected repo / all repos: shows the plan first, `y` applies it |
|
|
111
|
+
| `p` / `P` | Push the selected repo / all repos to every remote: plan first, `y` applies it |
|
|
111
112
|
| `a` | Add a remote (pre-filled from a template) |
|
|
112
113
|
| `o` | Open the folder |
|
|
113
114
|
| `d` | Show only repos that need attention |
|
|
@@ -115,7 +116,7 @@ Each remote cell shows that remote's tip of your current branch, and how your lo
|
|
|
115
116
|
|
|
116
117
|
## Sync
|
|
117
118
|
|
|
118
|
-
Keeps
|
|
119
|
+
Keeps your **secondary** remotes (e.g. Gitea, a backup) and your local checkout level with a **primary** remote (e.g. GitHub). The primary is the first remote whose label is in `primary_labels`; the secondaries are all remotes whose label is in `mirror_labels`. Any other remote is shown in the matrix but never written to.
|
|
119
120
|
|
|
120
121
|
```bash
|
|
121
122
|
repowatch sync # dry run: the plan, nothing changed
|
|
@@ -129,12 +130,13 @@ Everything is **fast-forward only**:
|
|
|
129
130
|
|---|---|
|
|
130
131
|
| Primary ahead of secondary | Pushes primary's tip to secondary |
|
|
131
132
|
| Branch only on primary | Creates it on secondary |
|
|
132
|
-
| Secondary ahead of primary | Pushes secondary's tip to primary, so work done on the secondary flows up |
|
|
133
|
+
| Secondary ahead of primary | Pushes secondary's tip to primary, so work done on the secondary flows up. The other secondaries follow in the same run |
|
|
134
|
+
| Two secondaries ahead of primary with different commits | Flags it and touches neither |
|
|
133
135
|
| Primary and secondary diverged | Flags it and touches nothing |
|
|
134
|
-
| Branch only on
|
|
136
|
+
| Branch only on secondaries | Flags it: could be new there, or deleted on primary |
|
|
135
137
|
| Local checkout behind and clean | Fast-forwards it |
|
|
136
138
|
| Local dirty, detached or diverged | Leaves it alone and flags it |
|
|
137
|
-
| Local has unpushed commits | Flags it.
|
|
139
|
+
| Local has unpushed commits | Flags it. `repowatch push` sends them, when you ask |
|
|
138
140
|
|
|
139
141
|
By default only `main`/`master` are synced and `dependabot/*` is skipped. Change `sync_branches` and `sync_exclude` (glob lists) in the config.
|
|
140
142
|
|
|
@@ -150,6 +152,28 @@ repowatch schedule --remove
|
|
|
150
152
|
|
|
151
153
|
Output goes to `sync.log` in the config folder and rotates at 1 MB. On macOS and Linux, `schedule` prints a crontab line for you to add.
|
|
152
154
|
|
|
155
|
+
## Push
|
|
156
|
+
|
|
157
|
+
Sends the current branch's commits to the primary remote and then to every secondary, so one command replaces a `git push` per remote.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
repowatch push # dry run: the plan, nothing changed
|
|
161
|
+
repowatch push --apply
|
|
162
|
+
repowatch push --apply --repo my-service
|
|
163
|
+
repowatch push --apply --remote gitea # only this remote (name or column label)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| Situation | What push does |
|
|
167
|
+
|---|---|
|
|
168
|
+
| Remote behind local | Pushes local's tip to it |
|
|
169
|
+
| Branch not on the remote yet | Creates it there. On the primary, the branch starts tracking it |
|
|
170
|
+
| Remote ahead of local | Flags it: run `sync` first |
|
|
171
|
+
| Remote and local diverged | Flags it and touches nothing |
|
|
172
|
+
| Primary refuses, is unreachable or isn't level with local | Leaves the secondaries alone too, so they never end up ahead of the primary |
|
|
173
|
+
| Detached HEAD | Skips the repo |
|
|
174
|
+
|
|
175
|
+
Only the branch you have checked out is pushed, whatever `sync_branches` says. A remote that is neither primary nor secondary is pushed to only when you name it with `--remote`. Scheduled runs never push your work: `schedule` runs `sync` only.
|
|
176
|
+
|
|
153
177
|
## Prune
|
|
154
178
|
|
|
155
179
|
Deletes stale branches on the primary remote.
|
|
@@ -185,7 +209,8 @@ refresh_seconds = 30 # TUI local auto-refresh; 0 = off
|
|
|
185
209
|
fetch_timeout = 25 # seconds, per remote
|
|
186
210
|
column_order = ["github", "gitea"]
|
|
187
211
|
primary_labels = ["github"] # sync's source of truth; prune's target
|
|
188
|
-
mirror_labels = ["gitea"] #
|
|
212
|
+
mirror_labels = ["gitea"] # secondaries, as many as you like: kept level by sync,
|
|
213
|
+
# pushed to by push; lag shown as "mirror lag"
|
|
189
214
|
sync_branches = ["main", "master"]
|
|
190
215
|
sync_exclude = ["dependabot/*"]
|
|
191
216
|
prune_keep = ["main", "master", "develop", "release/*"]
|
|
@@ -203,7 +228,7 @@ Use `repowatch --config other.toml …` to point at a different file.
|
|
|
203
228
|
|
|
204
229
|
## How it behaves
|
|
205
230
|
|
|
206
|
-
- **Remote columns are only as fresh as your last fetch.** `r` and the auto-refresh are local-only; `f`, `F`, `--fetch`, `sync` and `prune` go to the network.
|
|
231
|
+
- **Remote columns are only as fresh as your last fetch.** `r` and the auto-refresh are local-only; `f`, `F`, `--fetch`, `sync`, `push` and `prune` go to the network.
|
|
207
232
|
- **It never prompts.** Terminal prompts, credential-manager pop-ups and interactive SSH are disabled. A remote that needs input shows `✗` and the reason, rather than hanging. Cached credentials (credential managers, keychain, ssh-agent) work normally.
|
|
208
233
|
- **Each remote is fetched separately, with a timeout**, so an unreachable Gitea doesn't hold up GitHub.
|
|
209
234
|
- **Discovery stops at the first `.git`.** It doesn't descend into repos, and it skips `node_modules`, `.venv`, `build` and similar.
|
|
@@ -14,7 +14,7 @@ Point repowatch at your code folder. It finds every repo, then shows one row per
|
|
|
14
14
|
It's built for people who keep the same code in more than one place, for example GitHub plus a work or home Gitea, or one machine at work and another at home. It answers three questions:
|
|
15
15
|
|
|
16
16
|
1. **Where does everything stand?** A matrix of every repo against every remote.
|
|
17
|
-
2. **Can it level them for me, safely?** `sync` fast-forwards your secondary
|
|
17
|
+
2. **Can it level them for me, safely?** `sync` fast-forwards your secondary remotes and your local checkout to match the primary, in both directions, and `push` sends your own commits to all of them at once. Neither ever force-pushes or merges.
|
|
18
18
|
3. **What's all this branch clutter?** `prune` deletes branches whose work is already in `main`, including squash-merged ones, and explains every branch it keeps.
|
|
19
19
|
|
|
20
20
|
## Install
|
|
@@ -71,7 +71,7 @@ Each remote cell shows that remote's tip of your current branch, and how your lo
|
|
|
71
71
|
|
|
72
72
|
**Local** shows HEAD plus `+` staged, `~` modified, `?` untracked, `!` conflicts and `$` stashes, or `✓` when clean.
|
|
73
73
|
|
|
74
|
-
**Columns are labelled by host, not remote name.** `origin → github.com` and `upstream → github.com` both appear under `github`. Map your own hosts in the config.
|
|
74
|
+
**Columns are labelled by host, not remote name.** `origin → github.com` and `upstream → github.com` both appear under `github`. Map your own hosts in the config. If a remote's URL uses a `url.<base>.insteadOf` alias, the host git really connects to is used.
|
|
75
75
|
|
|
76
76
|
### TUI keys
|
|
77
77
|
|
|
@@ -80,6 +80,7 @@ Each remote cell shows that remote's tip of your current branch, and how your lo
|
|
|
80
80
|
| `r` | Rescan (local only, fast) |
|
|
81
81
|
| `f` / `F` | Fetch the selected repo / all repos |
|
|
82
82
|
| `s` / `S` | Sync the selected repo / all repos: shows the plan first, `y` applies it |
|
|
83
|
+
| `p` / `P` | Push the selected repo / all repos to every remote: plan first, `y` applies it |
|
|
83
84
|
| `a` | Add a remote (pre-filled from a template) |
|
|
84
85
|
| `o` | Open the folder |
|
|
85
86
|
| `d` | Show only repos that need attention |
|
|
@@ -87,7 +88,7 @@ Each remote cell shows that remote's tip of your current branch, and how your lo
|
|
|
87
88
|
|
|
88
89
|
## Sync
|
|
89
90
|
|
|
90
|
-
Keeps
|
|
91
|
+
Keeps your **secondary** remotes (e.g. Gitea, a backup) and your local checkout level with a **primary** remote (e.g. GitHub). The primary is the first remote whose label is in `primary_labels`; the secondaries are all remotes whose label is in `mirror_labels`. Any other remote is shown in the matrix but never written to.
|
|
91
92
|
|
|
92
93
|
```bash
|
|
93
94
|
repowatch sync # dry run: the plan, nothing changed
|
|
@@ -101,12 +102,13 @@ Everything is **fast-forward only**:
|
|
|
101
102
|
|---|---|
|
|
102
103
|
| Primary ahead of secondary | Pushes primary's tip to secondary |
|
|
103
104
|
| Branch only on primary | Creates it on secondary |
|
|
104
|
-
| Secondary ahead of primary | Pushes secondary's tip to primary, so work done on the secondary flows up |
|
|
105
|
+
| Secondary ahead of primary | Pushes secondary's tip to primary, so work done on the secondary flows up. The other secondaries follow in the same run |
|
|
106
|
+
| Two secondaries ahead of primary with different commits | Flags it and touches neither |
|
|
105
107
|
| Primary and secondary diverged | Flags it and touches nothing |
|
|
106
|
-
| Branch only on
|
|
108
|
+
| Branch only on secondaries | Flags it: could be new there, or deleted on primary |
|
|
107
109
|
| Local checkout behind and clean | Fast-forwards it |
|
|
108
110
|
| Local dirty, detached or diverged | Leaves it alone and flags it |
|
|
109
|
-
| Local has unpushed commits | Flags it.
|
|
111
|
+
| Local has unpushed commits | Flags it. `repowatch push` sends them, when you ask |
|
|
110
112
|
|
|
111
113
|
By default only `main`/`master` are synced and `dependabot/*` is skipped. Change `sync_branches` and `sync_exclude` (glob lists) in the config.
|
|
112
114
|
|
|
@@ -122,6 +124,28 @@ repowatch schedule --remove
|
|
|
122
124
|
|
|
123
125
|
Output goes to `sync.log` in the config folder and rotates at 1 MB. On macOS and Linux, `schedule` prints a crontab line for you to add.
|
|
124
126
|
|
|
127
|
+
## Push
|
|
128
|
+
|
|
129
|
+
Sends the current branch's commits to the primary remote and then to every secondary, so one command replaces a `git push` per remote.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
repowatch push # dry run: the plan, nothing changed
|
|
133
|
+
repowatch push --apply
|
|
134
|
+
repowatch push --apply --repo my-service
|
|
135
|
+
repowatch push --apply --remote gitea # only this remote (name or column label)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Situation | What push does |
|
|
139
|
+
|---|---|
|
|
140
|
+
| Remote behind local | Pushes local's tip to it |
|
|
141
|
+
| Branch not on the remote yet | Creates it there. On the primary, the branch starts tracking it |
|
|
142
|
+
| Remote ahead of local | Flags it: run `sync` first |
|
|
143
|
+
| Remote and local diverged | Flags it and touches nothing |
|
|
144
|
+
| Primary refuses, is unreachable or isn't level with local | Leaves the secondaries alone too, so they never end up ahead of the primary |
|
|
145
|
+
| Detached HEAD | Skips the repo |
|
|
146
|
+
|
|
147
|
+
Only the branch you have checked out is pushed, whatever `sync_branches` says. A remote that is neither primary nor secondary is pushed to only when you name it with `--remote`. Scheduled runs never push your work: `schedule` runs `sync` only.
|
|
148
|
+
|
|
125
149
|
## Prune
|
|
126
150
|
|
|
127
151
|
Deletes stale branches on the primary remote.
|
|
@@ -157,7 +181,8 @@ refresh_seconds = 30 # TUI local auto-refresh; 0 = off
|
|
|
157
181
|
fetch_timeout = 25 # seconds, per remote
|
|
158
182
|
column_order = ["github", "gitea"]
|
|
159
183
|
primary_labels = ["github"] # sync's source of truth; prune's target
|
|
160
|
-
mirror_labels = ["gitea"] #
|
|
184
|
+
mirror_labels = ["gitea"] # secondaries, as many as you like: kept level by sync,
|
|
185
|
+
# pushed to by push; lag shown as "mirror lag"
|
|
161
186
|
sync_branches = ["main", "master"]
|
|
162
187
|
sync_exclude = ["dependabot/*"]
|
|
163
188
|
prune_keep = ["main", "master", "develop", "release/*"]
|
|
@@ -175,7 +200,7 @@ Use `repowatch --config other.toml …` to point at a different file.
|
|
|
175
200
|
|
|
176
201
|
## How it behaves
|
|
177
202
|
|
|
178
|
-
- **Remote columns are only as fresh as your last fetch.** `r` and the auto-refresh are local-only; `f`, `F`, `--fetch`, `sync` and `prune` go to the network.
|
|
203
|
+
- **Remote columns are only as fresh as your last fetch.** `r` and the auto-refresh are local-only; `f`, `F`, `--fetch`, `sync`, `push` and `prune` go to the network.
|
|
179
204
|
- **It never prompts.** Terminal prompts, credential-manager pop-ups and interactive SSH are disabled. A remote that needs input shows `✗` and the reason, rather than hanging. Cached credentials (credential managers, keychain, ssh-agent) work normally.
|
|
180
205
|
- **Each remote is fetched separately, with a timeout**, so an unreachable Gitea doesn't hold up GitHub.
|
|
181
206
|
- **Discovery stops at the first `.git`.** It doesn't descend into repos, and it skips `node_modules`, `.venv`, `build` and similar.
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
repowatch [ROOT] interactive matrix (default)
|
|
4
4
|
repowatch status [ROOT] [--fetch] [--json] [--attention]
|
|
5
5
|
repowatch sync [ROOT] [--apply] [--repo NAME ...]
|
|
6
|
-
level
|
|
6
|
+
level every secondary remote and local with the primary
|
|
7
|
+
(fast-forward only)
|
|
8
|
+
repowatch push [ROOT] [--apply] [--repo NAME ...] [--remote NAME ...]
|
|
9
|
+
push the current branch to the primary and every secondary
|
|
7
10
|
repowatch prune [ROOT] [--apply] [--include-unmerged DAYS]
|
|
8
11
|
delete merged / squash-merged branches on GitHub
|
|
9
12
|
repowatch schedule [--every MIN] [--remove]
|
|
@@ -22,7 +25,7 @@ from pathlib import Path
|
|
|
22
25
|
from . import __version__, core
|
|
23
26
|
from .config import config_dir, config_path, load_config, write_example_config
|
|
24
27
|
|
|
25
|
-
COMMANDS = {"tui", "status", "sync", "prune", "schedule", "init"}
|
|
28
|
+
COMMANDS = {"tui", "status", "sync", "push", "prune", "schedule", "init"}
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
def _root(arg: str | None, cfg) -> Path:
|
|
@@ -64,17 +67,30 @@ def cmd_status(args, cfg) -> int:
|
|
|
64
67
|
|
|
65
68
|
|
|
66
69
|
def cmd_sync(args, cfg) -> int:
|
|
70
|
+
from .sync import sync_all
|
|
71
|
+
|
|
72
|
+
root = _root(args.root, cfg)
|
|
73
|
+
results = sync_all(str(root), cfg, apply=args.apply, names=args.repo)
|
|
74
|
+
return _report("sync", root, results, args)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def cmd_push(args, cfg) -> int:
|
|
78
|
+
from .sync import push_all
|
|
79
|
+
|
|
80
|
+
root = _root(args.root, cfg)
|
|
81
|
+
results = push_all(str(root), cfg, apply=args.apply, names=args.repo, remotes=args.remote)
|
|
82
|
+
return _report("push", root, results, args)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _report(what: str, root: Path, results: list, args) -> int:
|
|
86
|
+
"""Print (or log) one block per repo for `sync` and `push`; exit 1 if anything needs a human."""
|
|
67
87
|
import datetime
|
|
68
88
|
|
|
69
89
|
from rich.console import Console
|
|
70
90
|
|
|
71
91
|
from .render import sync_text
|
|
72
|
-
from .sync import sync_all
|
|
73
92
|
|
|
74
|
-
|
|
75
|
-
results = sync_all(str(root), cfg, apply=args.apply, names=args.repo)
|
|
76
|
-
|
|
77
|
-
log_path = Path(args.log) if args.log else (config_dir() / "sync.log" if sys.stdout is None else None)
|
|
93
|
+
log_path = Path(args.log) if args.log else (config_dir() / f"{what}.log" if sys.stdout is None else None)
|
|
78
94
|
if log_path:
|
|
79
95
|
log_path.parent.mkdir(parents=True, exist_ok=True)
|
|
80
96
|
if log_path.exists() and log_path.stat().st_size > 1_000_000:
|
|
@@ -85,7 +101,7 @@ def cmd_sync(args, cfg) -> int:
|
|
|
85
101
|
con = Console(highlight=False)
|
|
86
102
|
stamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
|
|
87
103
|
mode = "applied" if args.apply else "dry run — nothing changed, add --apply to do it"
|
|
88
|
-
con.print(f"[bold]repowatch
|
|
104
|
+
con.print(f"[bold]repowatch {what}[/] {root} · {stamp} · {mode}")
|
|
89
105
|
shown = 0
|
|
90
106
|
for r in results:
|
|
91
107
|
if args.quiet and not r.steps and not r.skipped:
|
|
@@ -229,7 +245,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
229
245
|
ps.add_argument("--attention", action="store_true", help="only repos that need something (exit 1 if any)")
|
|
230
246
|
ps.add_argument("--depth", type=int)
|
|
231
247
|
|
|
232
|
-
py = sub.add_parser("sync", help="level
|
|
248
|
+
py = sub.add_parser("sync", help="level every secondary remote and local with the primary (fast-forward only)")
|
|
233
249
|
py.add_argument("root", nargs="?")
|
|
234
250
|
py.add_argument("--apply", action="store_true", help="actually push / fast-forward (default is a dry run)")
|
|
235
251
|
py.add_argument("--repo", action="append", help="only this repo (repeatable)")
|
|
@@ -237,6 +253,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
237
253
|
py.add_argument("--log", help="append output to this file instead of the screen")
|
|
238
254
|
py.add_argument("--depth", type=int)
|
|
239
255
|
|
|
256
|
+
pu = sub.add_parser("push", help="push the current branch to every remote (fast-forward only)")
|
|
257
|
+
pu.add_argument("root", nargs="?")
|
|
258
|
+
pu.add_argument("--apply", action="store_true", help="actually push (default is a dry run)")
|
|
259
|
+
pu.add_argument("--repo", action="append", help="only this repo (repeatable)")
|
|
260
|
+
pu.add_argument("--remote", action="append", metavar="NAME",
|
|
261
|
+
help="only this remote, by name or column label (repeatable); "
|
|
262
|
+
"default is the primary and every secondary")
|
|
263
|
+
pu.add_argument("--quiet", action="store_true", help="hide repos with nothing to do")
|
|
264
|
+
pu.add_argument("--log", help="append output to this file instead of the screen")
|
|
265
|
+
pu.add_argument("--depth", type=int)
|
|
266
|
+
|
|
240
267
|
pp = sub.add_parser("prune", help="delete merged / squash-merged branches on GitHub")
|
|
241
268
|
pp.add_argument("root", nargs="?")
|
|
242
269
|
pp.add_argument("--apply", action="store_true", help="actually delete (default is a dry run)")
|
|
@@ -270,6 +297,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
270
297
|
return cmd_status(args, cfg)
|
|
271
298
|
if args.cmd == "sync":
|
|
272
299
|
return cmd_sync(args, cfg)
|
|
300
|
+
if args.cmd == "push":
|
|
301
|
+
return cmd_push(args, cfg)
|
|
273
302
|
if args.cmd == "prune":
|
|
274
303
|
return cmd_prune(args, cfg)
|
|
275
304
|
if args.cmd == "schedule":
|
|
@@ -37,7 +37,9 @@ column_order = ["github", "gitea"]
|
|
|
37
37
|
primary_labels = ["github"]
|
|
38
38
|
|
|
39
39
|
# Secondary copies kept level with the primary by `repowatch sync` (fast-forward only,
|
|
40
|
-
# both directions)
|
|
40
|
+
# both directions) and pushed to by `repowatch push`. List as many labels as you have
|
|
41
|
+
# copies, e.g. ["gitea", "backup"]. Their differences are reported as "mirror lag"
|
|
42
|
+
# rather than "push". Remotes with any other label are shown but never written to.
|
|
41
43
|
mirror_labels = ["gitea"]
|
|
42
44
|
|
|
43
45
|
# Which branches `repowatch sync` keeps level between primary and secondary.
|
|
@@ -103,6 +103,15 @@ class RepoStatus:
|
|
|
103
103
|
def remote(self, label: str) -> RemoteStatus | None:
|
|
104
104
|
return next((r for r in self.remotes if r.label == label), None)
|
|
105
105
|
|
|
106
|
+
def primary(self, cfg: Config) -> RemoteStatus | None:
|
|
107
|
+
"""The remote work normally lands on (the first one with a primary label)."""
|
|
108
|
+
return next((r for r in self.remotes if r.label.split(":")[0] in cfg.primary_labels), None)
|
|
109
|
+
|
|
110
|
+
def secondaries(self, cfg: Config) -> list[RemoteStatus]:
|
|
111
|
+
"""Every remote kept level with the primary (all remotes with a mirror label)."""
|
|
112
|
+
primary = self.primary(cfg)
|
|
113
|
+
return [r for r in self.remotes if r.mirror and r is not primary]
|
|
114
|
+
|
|
106
115
|
def flags(self) -> list[str]:
|
|
107
116
|
if self.error:
|
|
108
117
|
return ["error"]
|
|
@@ -202,7 +211,8 @@ def url_owner_repo(url: str) -> tuple[str, str] | None:
|
|
|
202
211
|
return parts[-2], repo
|
|
203
212
|
|
|
204
213
|
|
|
205
|
-
def
|
|
214
|
+
def host_label(url: str, hosts: dict[str, str]) -> str | None:
|
|
215
|
+
"""The column label for a URL's host, or None if the host isn't recognised."""
|
|
206
216
|
host = url_host(url)
|
|
207
217
|
if host:
|
|
208
218
|
if host in hosts:
|
|
@@ -214,7 +224,17 @@ def label_for(remote_name: str, url: str, hosts: dict[str, str]) -> str:
|
|
|
214
224
|
return "gitea"
|
|
215
225
|
if "github" in host:
|
|
216
226
|
return "github"
|
|
217
|
-
return
|
|
227
|
+
return None
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def label_for(remote_name: str, url: str, hosts: dict[str, str]) -> str:
|
|
231
|
+
return host_label(url, hosts) or remote_name
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def effective_url(path: Path | str, remote_name: str) -> str:
|
|
235
|
+
"""The URL git really fetches from, after any url.<base>.insteadOf rewriting."""
|
|
236
|
+
cp = git(path, "remote", "get-url", remote_name)
|
|
237
|
+
return cp.stdout.strip() if cp.returncode == 0 else ""
|
|
218
238
|
|
|
219
239
|
|
|
220
240
|
def list_remotes(path: Path | str) -> dict[str, str]:
|
|
@@ -289,7 +309,11 @@ def repo_status(
|
|
|
289
309
|
|
|
290
310
|
used_labels: set[str] = set()
|
|
291
311
|
for rname, url in remotes.items():
|
|
292
|
-
|
|
312
|
+
# A URL written with an insteadOf alias (git@work:team/x.git) has a host nobody
|
|
313
|
+
# mapped; fall back to the host git actually connects to before giving up.
|
|
314
|
+
label = (host_label(url, cfg.hosts)
|
|
315
|
+
or host_label(effective_url(path, rname), cfg.hosts)
|
|
316
|
+
or rname)
|
|
293
317
|
if label in used_labels:
|
|
294
318
|
label = f"{label}:{rname}"
|
|
295
319
|
used_labels.add(label)
|