repowatch 0.4.0__py3-none-any.whl

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/tui.py ADDED
@@ -0,0 +1,402 @@
1
+ """Textual front end: one row per repo, one column per remote label."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ from rich.text import Text
11
+ from textual import work
12
+ from textual.app import App, ComposeResult
13
+ from textual.binding import Binding
14
+ from textual.containers import Horizontal, Vertical, VerticalScroll
15
+ from textual.screen import ModalScreen
16
+ from textual.widgets import Button, DataTable, Footer, Header, Input, Label, Static
17
+
18
+ from . import core
19
+ from . import sync as syncmod
20
+ from .config import Config
21
+ from .render import branch_cell, flags_cell, local_cell, remote_cell, sync_text
22
+
23
+ LEGEND = (
24
+ "[green]=[/] in sync [magenta]↑n[/] local ahead (push) [yellow]↓n[/] remote ahead (pull) "
25
+ "[bold red]↑↓[/] diverged [cyan]cyan[/] mirror lagging [dim]—[/] not on remote [red dim]✗[/] fetch failed "
26
+ "local: [green]+[/]staged [yellow]~[/]modified [dim yellow]?[/]untracked [cyan]$[/]stash"
27
+ )
28
+
29
+
30
+ class AddRemoteScreen(ModalScreen[tuple[str, str] | None]):
31
+ DEFAULT_CSS = """
32
+ AddRemoteScreen { align: center middle; }
33
+ #dialog { width: 80; height: auto; border: thick $accent; padding: 1 2; background: $surface; }
34
+ #dialog Input { margin-bottom: 1; }
35
+ #buttons { height: auto; align-horizontal: right; }
36
+ #buttons Button { margin-left: 1; }
37
+ """
38
+ BINDINGS = [Binding("escape", "cancel", "Cancel")]
39
+
40
+ def __init__(self, repo_name: str, name: str, url: str) -> None:
41
+ super().__init__()
42
+ self.repo_name, self.default_name, self.default_url = repo_name, name, url
43
+
44
+ def compose(self) -> ComposeResult:
45
+ with Vertical(id="dialog"):
46
+ yield Label(f"Add remote to [b]{self.repo_name}[/b]")
47
+ yield Input(value=self.default_name, placeholder="remote name, e.g. gitea", id="rname")
48
+ yield Input(value=self.default_url, placeholder="URL", id="rurl")
49
+ with Horizontal(id="buttons"):
50
+ yield Button("Cancel", id="cancel")
51
+ yield Button("Add & fetch", variant="primary", id="ok")
52
+
53
+ def on_mount(self) -> None:
54
+ self.query_one("#rurl" if self.default_name else "#rname", Input).focus()
55
+
56
+ def on_button_pressed(self, event: Button.Pressed) -> None:
57
+ if event.button.id == "ok":
58
+ self._submit()
59
+ else:
60
+ self.dismiss(None)
61
+
62
+ def on_input_submitted(self, event: Input.Submitted) -> None:
63
+ self._submit()
64
+
65
+ def _submit(self) -> None:
66
+ name = self.query_one("#rname", Input).value.strip()
67
+ url = self.query_one("#rurl", Input).value.strip()
68
+ if name and url:
69
+ self.dismiss((name, url))
70
+
71
+ def action_cancel(self) -> None:
72
+ self.dismiss(None)
73
+
74
+
75
+ class SyncScreen(ModalScreen[bool]):
76
+ """Shows the dry-run plan; Apply returns True."""
77
+ DEFAULT_CSS = """
78
+ SyncScreen { align: center middle; }
79
+ #sdialog { width: 110; max-width: 95%; height: auto; max-height: 85%; border: thick $accent;
80
+ padding: 1 2; background: $surface; }
81
+ #splan { height: auto; max-height: 30; margin: 1 0; }
82
+ #sbuttons { height: auto; align-horizontal: right; }
83
+ #sbuttons Button { margin-left: 1; }
84
+ """
85
+ BINDINGS = [Binding("escape", "cancel", "Cancel"), Binding("y", "apply", "Apply")]
86
+
87
+ def __init__(self, plan: Text, can_apply: bool) -> None:
88
+ super().__init__()
89
+ self.plan, self.can_apply = plan, can_apply
90
+
91
+ def compose(self) -> ComposeResult:
92
+ with Vertical(id="sdialog"):
93
+ yield Label("[b]Sync plan[/b] — fast-forward only, nothing is force-pushed")
94
+ with VerticalScroll(id="splan"):
95
+ yield Static(self.plan)
96
+ with Horizontal(id="sbuttons"):
97
+ yield Button("Close" if not self.can_apply else "Cancel", id="cancel")
98
+ if self.can_apply:
99
+ yield Button("Apply (y)", variant="primary", id="apply")
100
+
101
+ def on_button_pressed(self, event: Button.Pressed) -> None:
102
+ self.dismiss(event.button.id == "apply")
103
+
104
+ def action_apply(self) -> None:
105
+ if self.can_apply:
106
+ self.dismiss(True)
107
+
108
+ def action_cancel(self) -> None:
109
+ self.dismiss(False)
110
+
111
+
112
+ class RepoWatch(App):
113
+ TITLE = "repowatch"
114
+ CSS = """
115
+ DataTable { height: 1fr; }
116
+ #detail { height: auto; max-height: 14; border: round $primary-darken-2; padding: 0 1; }
117
+ #legend { height: auto; color: $text-muted; padding: 0 1; }
118
+ """
119
+ BINDINGS = [
120
+ Binding("r", "rescan", "Rescan"),
121
+ Binding("f", "fetch_one", "Fetch"),
122
+ Binding("F", "fetch_all", "Fetch all"),
123
+ Binding("s", "sync_one", "Sync"),
124
+ Binding("S", "sync_all", "Sync all"),
125
+ Binding("a", "add_remote", "Add remote"),
126
+ Binding("o", "open_folder", "Open folder"),
127
+ Binding("d", "toggle_dirty", "Only attention"),
128
+ Binding("q", "quit", "Quit"),
129
+ ]
130
+
131
+ def __init__(self, root: Path, cfg: Config, fetch_on_start: bool = False) -> None:
132
+ super().__init__()
133
+ self.root, self.cfg, self.fetch_on_start = root, cfg, fetch_on_start
134
+ self.statuses: dict[str, core.RepoStatus] = {}
135
+ self.order: list[str] = []
136
+ self.fetch_errors: dict[str, dict[str, str]] = {}
137
+ self.attention_only = False
138
+ self.busy: set[str] = set()
139
+
140
+ # ------------------------------------------------------------------ layout
141
+
142
+ def compose(self) -> ComposeResult:
143
+ yield Header()
144
+ yield DataTable(id="table", cursor_type="row", zebra_stripes=True)
145
+ yield Static(id="detail")
146
+ yield Static(LEGEND, id="legend")
147
+ yield Footer()
148
+
149
+ def on_mount(self) -> None:
150
+ self.sub_title = str(self.root)
151
+ if self.fetch_on_start:
152
+ self.action_fetch_all()
153
+ else:
154
+ self.action_rescan()
155
+ if self.cfg.refresh_seconds > 0:
156
+ self.set_interval(self.cfg.refresh_seconds, self._auto_refresh)
157
+
158
+ # ------------------------------------------------------------------- table
159
+
160
+ def _visible(self) -> list[str]:
161
+ if not self.attention_only:
162
+ return self.order
163
+ return [p for p in self.order if self.statuses[p].flags()]
164
+
165
+ def _render_table(self) -> None:
166
+ table = self.query_one(DataTable)
167
+ cursor_key = self._selected_path()
168
+ table.clear(columns=True)
169
+ labels = core.all_labels(list(self.statuses.values()), self.cfg.column_order)
170
+ table.add_column("Repo", key="repo")
171
+ table.add_column("Branch", key="branch")
172
+ table.add_column("Local", key="local")
173
+ for lab in labels:
174
+ table.add_column(lab, key=f"r:{lab}")
175
+ table.add_column("Status", key="flags")
176
+
177
+ rows = self._visible()
178
+ for p in rows:
179
+ s = self.statuses[p]
180
+ name = Text(s.name)
181
+ if p in self.busy:
182
+ name.append(" ⟳", style="cyan")
183
+ cells = [name, branch_cell(s), local_cell(s)]
184
+ cells += [remote_cell(s.remote(lab)) for lab in labels]
185
+ cells.append(flags_cell(s))
186
+ table.add_row(*cells, key=p)
187
+
188
+ if cursor_key in rows:
189
+ table.move_cursor(row=rows.index(cursor_key))
190
+ self._render_detail()
191
+ n_att = sum(1 for p in self.order if self.statuses[p].flags())
192
+ self.sub_title = f"{self.root} · {len(self.order)} repos, {n_att} need attention" + (
193
+ " · filtered" if self.attention_only else "")
194
+
195
+ def _selected_path(self) -> str | None:
196
+ table = self.query_one(DataTable)
197
+ if table.row_count == 0:
198
+ return None
199
+ try:
200
+ return table.coordinate_to_cell_key(table.cursor_coordinate).row_key.value
201
+ except Exception:
202
+ return None
203
+
204
+ def _render_detail(self) -> None:
205
+ detail = self.query_one("#detail", Static)
206
+ p = self._selected_path()
207
+ if not p or p not in self.statuses:
208
+ detail.update("No repos found." if not self.order else "")
209
+ return
210
+ s = self.statuses[p]
211
+ t = Text()
212
+ t.append(s.name, style="bold")
213
+ t.append(f" {s.path}\n", style="dim")
214
+ if s.error:
215
+ t.append(f"Error: {s.error}\n", style="red")
216
+ br = "(detached)" if s.detached else (s.branch or "?")
217
+ t.append(f"Branch {br}")
218
+ t.append(f" → {s.upstream}" if s.upstream else " (no upstream)", style="dim")
219
+ t.append(f" · last fetch {core.ago(s.last_fetch)}\n", style="dim")
220
+ for r in s.remotes:
221
+ t.append(f" {r.label:<10}", style="bold")
222
+ t.append(f"{r.name:<10}", style="dim")
223
+ t.append_text(remote_cell(r))
224
+ t.append(f" {r.url}", style="dim")
225
+ if r.state == "missing":
226
+ t.append(f" (no {s.branch or 'HEAD'} on this remote)", style="dim")
227
+ if r.error:
228
+ t.append(f"\n {r.error}", style="red dim")
229
+ t.append("\n")
230
+ tips = {}
231
+ for r in s.remotes:
232
+ if r.sha:
233
+ tips.setdefault(r.sha, []).append(r.label)
234
+ if len(tips) > 1:
235
+ t.append("Remotes disagree: ", style="bold cyan")
236
+ t.append(" vs ".join(f"{'/'.join(v)} @ {k[:7]}" for k, v in tips.items()))
237
+ detail.update(t)
238
+
239
+ def on_data_table_row_highlighted(self, _event: DataTable.RowHighlighted) -> None:
240
+ self._render_detail()
241
+
242
+ # ----------------------------------------------------------------- workers
243
+
244
+ @work(thread=True, exclusive=True, group="scan")
245
+ def action_rescan(self) -> None:
246
+ statuses = core.scan(self.root, self.cfg, fetch_errors=self.fetch_errors)
247
+ self.call_from_thread(self._apply_scan, statuses)
248
+
249
+ def _apply_scan(self, statuses: list[core.RepoStatus]) -> None:
250
+ self.statuses = {s.path: s for s in statuses}
251
+ self.order = [s.path for s in statuses]
252
+ self._render_table()
253
+
254
+ def _auto_refresh(self) -> None:
255
+ if not self.busy:
256
+ self.action_rescan()
257
+
258
+ def _refresh_one(self, p: str) -> None:
259
+ s = core.repo_status(Path(p), self.root, self.cfg, self.fetch_errors.get(p))
260
+ self.call_from_thread(self._apply_one, s)
261
+
262
+ def _apply_one(self, s: core.RepoStatus) -> None:
263
+ self.busy.discard(s.path)
264
+ if s.path not in self.statuses:
265
+ self.order.append(s.path)
266
+ self.statuses[s.path] = s
267
+ self._render_table()
268
+
269
+ def _mark_busy(self, paths: list[str]) -> None:
270
+ self.busy.update(paths)
271
+ self._render_table()
272
+
273
+ @work(thread=True, group="fetch")
274
+ def _fetch_paths(self, paths: list[str]) -> None:
275
+ from concurrent.futures import ThreadPoolExecutor
276
+
277
+ def one(p: str) -> None:
278
+ self.fetch_errors[p] = core.fetch_repo(p, self.cfg.fetch_timeout)
279
+ self._refresh_one(p)
280
+
281
+ with ThreadPoolExecutor(max_workers=6) as pool:
282
+ list(pool.map(one, paths))
283
+ self.call_from_thread(self.notify, f"Fetched {len(paths)} repo(s)", timeout=3)
284
+
285
+ # ----------------------------------------------------------------- actions
286
+
287
+ def action_fetch_one(self) -> None:
288
+ p = self._selected_path()
289
+ if p:
290
+ self._mark_busy([p])
291
+ self._fetch_paths([p])
292
+
293
+ def action_fetch_all(self) -> None:
294
+ if not self.order:
295
+ # first run with --fetch: discover, then fetch everything
296
+ repos = [str(p) for p in core.find_repos(self.root, self.cfg.depth)]
297
+ self.order = repos
298
+ self.statuses = {p: core.RepoStatus(path=p, name=Path(p).name) for p in repos}
299
+ self._mark_busy(list(self.order))
300
+ self._fetch_paths(list(self.order))
301
+
302
+ # -------------------------------------------------------------------- sync
303
+
304
+ def action_sync_one(self) -> None:
305
+ p = self._selected_path()
306
+ if p:
307
+ self._mark_busy([p])
308
+ self._sync_plan([p])
309
+
310
+ def action_sync_all(self) -> None:
311
+ if self.order:
312
+ self._mark_busy(list(self.order))
313
+ self._sync_plan(list(self.order))
314
+
315
+ @work(thread=True, exclusive=True, group="sync")
316
+ def _sync_plan(self, paths: list[str]) -> None:
317
+ from concurrent.futures import ThreadPoolExecutor
318
+
319
+ root = str(self.root)
320
+ with ThreadPoolExecutor(max_workers=6) as pool:
321
+ results = list(pool.map(lambda p: syncmod.plan_and_run(p, root, self.cfg, apply=False), paths))
322
+ # fetch happened as part of planning: refresh rows now
323
+ for p in paths:
324
+ self._refresh_one(p)
325
+ text = Text()
326
+ for r in results:
327
+ if len(results) > 1 and not r.steps and not r.skipped:
328
+ continue
329
+ text.append_text(sync_text(r, applied=False))
330
+ if not text.plain:
331
+ text = Text("Everything is in step.", style="green")
332
+ can_apply = any(r.actions for r in results)
333
+ to_apply = [r.path for r in results if r.actions]
334
+
335
+ def done(ok: bool | None) -> None:
336
+ if ok:
337
+ self._mark_busy(to_apply)
338
+ self._sync_apply(to_apply)
339
+
340
+ self.call_from_thread(self.push_screen, SyncScreen(text, can_apply), done)
341
+
342
+ @work(thread=True, group="sync")
343
+ def _sync_apply(self, paths: list[str]) -> None:
344
+ root = str(self.root)
345
+ failed = 0
346
+ for p in paths:
347
+ r = syncmod.plan_and_run(p, root, self.cfg, apply=True, fetch=False)
348
+ failed += len(r.failed)
349
+ self._refresh_one(p)
350
+ msg = f"Synced {len(paths)} repo(s)" + (f", {failed} step(s) failed — run sync again to see why" if failed else "")
351
+ self.call_from_thread(self.notify, msg, severity="error" if failed else "information", timeout=5)
352
+
353
+ def action_toggle_dirty(self) -> None:
354
+ self.attention_only = not self.attention_only
355
+ self._render_table()
356
+
357
+ def action_open_folder(self) -> None:
358
+ p = self._selected_path()
359
+ if not p:
360
+ return
361
+ try:
362
+ if sys.platform == "win32":
363
+ os.startfile(p) # type: ignore[attr-defined]
364
+ elif sys.platform == "darwin":
365
+ subprocess.Popen(["open", p])
366
+ else:
367
+ subprocess.Popen(["xdg-open", p])
368
+ except Exception as exc:
369
+ self.notify(f"Couldn't open folder: {exc}", severity="error")
370
+
371
+ def action_add_remote(self) -> None:
372
+ p = self._selected_path()
373
+ if not p:
374
+ return
375
+ s = self.statuses[p]
376
+ existing = {r.label for r in s.remotes} | {r.name for r in s.remotes}
377
+ name, url = "", ""
378
+ owner_repo = next((core.url_owner_repo(r.url) for r in s.remotes if core.url_owner_repo(r.url)), None)
379
+ for tname, tmpl in self.cfg.remote_templates.items():
380
+ if tname not in existing:
381
+ name = tname
382
+ if owner_repo:
383
+ url = tmpl.format(owner=owner_repo[0], repo=owner_repo[1])
384
+ break
385
+
386
+ def done(result: tuple[str, str] | None) -> None:
387
+ if not result:
388
+ return
389
+ rname, rurl = result
390
+ err = core.add_remote(p, rname, rurl)
391
+ if err:
392
+ self.notify(err, severity="error")
393
+ return
394
+ self.notify(f"Added remote {rname}", timeout=3)
395
+ self._mark_busy([p])
396
+ self._fetch_paths([p])
397
+
398
+ self.push_screen(AddRemoteScreen(s.name, name, url), done)
399
+
400
+
401
+ def run(root: Path, cfg: Config, fetch: bool = False) -> None:
402
+ RepoWatch(root, cfg, fetch_on_start=fetch).run()
@@ -0,0 +1,218 @@
1
+ Metadata-Version: 2.4
2
+ Name: repowatch
3
+ Version: 0.4.0
4
+ Summary: Every git repo under a folder, compared across all its remotes, with fast-forward-only sync and safe branch pruning.
5
+ Author: Mark Wharry
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/markgwharry/repowatch
8
+ Project-URL: Issues, https://github.com/markgwharry/repowatch/issues
9
+ Project-URL: Changelog, https://github.com/markgwharry/repowatch/blob/main/CHANGELOG.md
10
+ Keywords: git,multi-repo,remotes,mirror,gitea,github,tui,textual
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Version Control :: Git
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: textual>=0.80
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8; extra == "dev"
26
+ Requires-Dist: ruff>=0.6; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # repowatch
30
+
31
+ [![CI](https://github.com/markgwharry/repowatch/actions/workflows/ci.yml/badge.svg)](https://github.com/markgwharry/repowatch/actions/workflows/ci.yml)
32
+ [![PyPI](https://img.shields.io/pypi/v/repowatch)](https://pypi.org/project/repowatch/)
33
+ [![Python](https://img.shields.io/pypi/pyversions/repowatch)](https://pypi.org/project/repowatch/)
34
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
35
+
36
+ **Every git repo under a folder, compared across all of its remotes.**
37
+
38
+ Point repowatch at your code folder. It finds every repo, then shows one row per repo with a column per remote, so you can see at a glance where each copy stands: local, GitHub, a self-hosted Gitea, a backup.
39
+
40
+ ![repowatch TUI](docs/screenshot.png)
41
+
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
+
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 remote and your local checkout to match the primary, in both directions. It never force-pushes or merges.
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
+
48
+ ## Install
49
+
50
+ Requires Python 3.11+ and `git` on your PATH.
51
+
52
+ ```bash
53
+ pipx install repowatch # or: uv tool install repowatch
54
+ ```
55
+
56
+ From source:
57
+
58
+ ```bash
59
+ git clone https://github.com/markgwharry/repowatch && cd repowatch
60
+ pipx install .
61
+ ```
62
+
63
+ > On Windows, use Windows Terminal, which is the default on Windows 11. The legacy console mangles the arrows. In Git Bash, write paths with forward slashes (`./repowatch`), because backslashes get eaten.
64
+
65
+ ## Quick start
66
+
67
+ ```bash
68
+ repowatch ~/code # interactive matrix
69
+ repowatch ~/code --fetch # fetch every remote first
70
+ repowatch status ~/code # print the matrix once
71
+ repowatch status ~/code --json # machine-readable, for scripts and dashboards
72
+ repowatch init # write a commented config file
73
+ ```
74
+
75
+ Set `root` in the config and plain `repowatch` opens your code folder.
76
+
77
+ ## Reading the matrix
78
+
79
+ ```
80
+ Repo Branch Local github gitea Status
81
+ core-lib main 965f254 ✓ 965f254 = 965f254 = ok
82
+ cli-tool main e5c17be ✓ f4a93cd ↑2 f4a93cd ↑2 push
83
+ ticker main 5cd32d9 ✓ 5cd32d9 = e88d620 ↑1 mirror lag
84
+ work/tracker main 577c22d ✓ 5296d38 ↓1 577c22d = pull mirror lag
85
+ work/analysis main fe0af99 ~1 ?1 $1 883a7b7 ↑1 ↓1 c458ab1 ↑1 dirty untracked stash diverged
86
+ ```
87
+
88
+ Each remote cell shows that remote's tip of your current branch, and how your local HEAD compares with it:
89
+
90
+ | Symbol | Meaning |
91
+ |---|---|
92
+ | `=` | Same commit |
93
+ | `↑n` | Local has n commits the remote doesn't (push) |
94
+ | `↓n` | Remote has n commits local doesn't (pull) |
95
+ | `↑n ↓m` | Diverged |
96
+ | `—` | Branch doesn't exist on that remote |
97
+ | `✗` | Last fetch failed (offline, VPN down, auth) |
98
+ | cyan | A mirror remote is lagging. Expected; `sync` deals with it |
99
+
100
+ **Local** shows HEAD plus `+` staged, `~` modified, `?` untracked, `!` conflicts and `$` stashes, or `✓` when clean.
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.
103
+
104
+ ### TUI keys
105
+
106
+ | Key | Action |
107
+ |---|---|
108
+ | `r` | Rescan (local only, fast) |
109
+ | `f` / `F` | Fetch the selected repo / all repos |
110
+ | `s` / `S` | Sync the selected repo / all repos: shows the plan first, `y` applies it |
111
+ | `a` | Add a remote (pre-filled from a template) |
112
+ | `o` | Open the folder |
113
+ | `d` | Show only repos that need attention |
114
+ | `q` | Quit |
115
+
116
+ ## Sync
117
+
118
+ Keeps a **secondary** remote (e.g. Gitea) and your local checkout level with a **primary** remote (e.g. GitHub).
119
+
120
+ ```bash
121
+ repowatch sync # dry run: the plan, nothing changed
122
+ repowatch sync --apply
123
+ repowatch sync --apply --repo my-service --repo docs
124
+ ```
125
+
126
+ Everything is **fast-forward only**:
127
+
128
+ | Situation | What sync does |
129
+ |---|---|
130
+ | Primary ahead of secondary | Pushes primary's tip to secondary |
131
+ | 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
+ | Primary and secondary diverged | Flags it and touches nothing |
134
+ | Branch only on secondary | Flags it: could be new there, or deleted on primary |
135
+ | Local checkout behind and clean | Fast-forwards it |
136
+ | Local dirty, detached or diverged | Leaves it alone and flags it |
137
+ | Local has unpushed commits | Flags it. Pushing your own work stays your decision |
138
+
139
+ By default only `main`/`master` are synced and `dependabot/*` is skipped. Change `sync_branches` and `sync_exclude` (glob lists) in the config.
140
+
141
+ A protected branch on the primary rejects a secondary-ahead push. That's reported as a failed step and nothing else is affected. Unattended runs over SSH need a key without a passphrase, or a running agent; otherwise that remote shows as unreachable and is skipped.
142
+
143
+ ### Run sync on a schedule
144
+
145
+ ```bash
146
+ repowatch schedule # hourly via Windows Task Scheduler (silent, via pythonw)
147
+ repowatch schedule --every 30
148
+ repowatch schedule --remove
149
+ ```
150
+
151
+ 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
+
153
+ ## Prune
154
+
155
+ Deletes stale branches on the primary remote.
156
+
157
+ ```bash
158
+ repowatch prune # dry run: what goes, and why the rest stay
159
+ repowatch prune --apply
160
+ repowatch prune --include-unmerged 180 # also abandoned branches, >180 days old, with no open PR
161
+ repowatch prune -v # also list merged branches it keeps
162
+ ```
163
+
164
+ | Kind | Meaning | Default |
165
+ |---|---|---|
166
+ | **merged** | Tip already in the default branch (merge, fast-forward or rebase) | Deleted |
167
+ | **squash-merged** | Its combined change is already in the default branch as one commit | Deleted |
168
+ | **unmerged** | Has commits the default branch doesn't | Kept and listed |
169
+
170
+ It never deletes the default branch, anything matching `prune_keep` (default `main`, `master`, `develop`, `release/*`), anything younger than `prune_min_age_days` (default 7), or the branch you have checked out. Unmerged branches are only deleted with `--include-unmerged`, and only after the GitHub CLI (`gh`) confirms they have no open PR. Without `gh`, they're never touched. Deletions are verified against the remote afterwards.
171
+
172
+ To stop branches piling up again: `gh repo edit OWNER/REPO --delete-branch-on-merge`.
173
+
174
+ ## Configuration
175
+
176
+ `repowatch init` writes a commented file to:
177
+
178
+ - Windows: `%APPDATA%\repowatch\config.toml`
179
+ - macOS / Linux: `~/.config/repowatch/config.toml`, or `$XDG_CONFIG_HOME/repowatch/config.toml`
180
+
181
+ ```toml
182
+ root = "~/code"
183
+ depth = 3 # folder levels to search
184
+ refresh_seconds = 30 # TUI local auto-refresh; 0 = off
185
+ fetch_timeout = 25 # seconds, per remote
186
+ column_order = ["github", "gitea"]
187
+ primary_labels = ["github"] # sync's source of truth; prune's target
188
+ mirror_labels = ["gitea"] # kept level by sync; lag shown as "mirror lag"
189
+ sync_branches = ["main", "master"]
190
+ sync_exclude = ["dependabot/*"]
191
+ prune_keep = ["main", "master", "develop", "release/*"]
192
+ prune_min_age_days = 7
193
+
194
+ [hosts] # host -> column label (exact match, then substring)
195
+ "git.example.internal" = "gitea"
196
+ "192.168.1.20" = "gitea"
197
+
198
+ [remote_templates] # pre-fills the TUI's add-remote dialog
199
+ gitea = "https://git.example.internal/{owner}/{repo}.git"
200
+ ```
201
+
202
+ Use `repowatch --config other.toml …` to point at a different file.
203
+
204
+ ## How it behaves
205
+
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.
207
+ - **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
+ - **Each remote is fetched separately, with a timeout**, so an unreachable Gitea doesn't hold up GitHub.
209
+ - **Discovery stops at the first `.git`.** It doesn't descend into repos, and it skips `node_modules`, `.venv`, `build` and similar.
210
+ - **Don't keep repos in a cloud-synced folder** (OneDrive, Dropbox, iCloud). Sync clients lock and duplicate files inside `.git`. Your remotes are the backup.
211
+
212
+ ## Contributing
213
+
214
+ Issues and PRs are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md). The test suite builds throwaway repos with GitHub- and Gitea-style remotes for every state repowatch distinguishes, and runs on Windows, macOS and Linux.
215
+
216
+ ## Licence
217
+
218
+ [MIT](LICENSE)
@@ -0,0 +1,15 @@
1
+ repowatch/__init__.py,sha256=oYSrpQkvTDLB_2IXjv12tH8g_QaKYXa_D4Yv-0MABZs,119
2
+ repowatch/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
3
+ repowatch/cli.py,sha256=C9flBBgd9Qu4z4IdusCNrMBuTKUszlfEkARXwslGx9w,11914
4
+ repowatch/config.py,sha256=oW-lwsb03d5OBcHa8SaPniGlPpRMCuJcVgttsLDoLd8,4640
5
+ repowatch/core.py,sha256=yl9komOMeGnTpF91rYWHVhCumUc5LsdVNRz2lhRs50Y,13526
6
+ repowatch/prune.py,sha256=cuBBqvKN0R7q98qU-IhXaVkLdE_kEyaCGsYwiWPh92c,8555
7
+ repowatch/render.py,sha256=8WJYVXD79umgpED9qx_c_HqgeiBvSAoR3nJa9VT1qPg,3507
8
+ repowatch/sync.py,sha256=GdWrmX-zUutGvu_8_nq5tJQrZBpkTONHwtUvH61NIyw,7680
9
+ repowatch/tui.py,sha256=mbqr8alcLNfNBG-NERlb4ebpVAOmK0x6UORUaEATNx8,15582
10
+ repowatch-0.4.0.dist-info/licenses/LICENSE,sha256=N4SrDhXetPRq2cjEoF2owkvhXogz3yXqSb4-IJX0JiE,1068
11
+ repowatch-0.4.0.dist-info/METADATA,sha256=lq84VRjP1vhhEK1lqF4YVjo6bTeQlUF35B-u9U6NQ-M,10213
12
+ repowatch-0.4.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
13
+ repowatch-0.4.0.dist-info/entry_points.txt,sha256=DcD6_sK-7cFH4Cg1ThdjlkyJA53_M2eThHPUvG109bY,49
14
+ repowatch-0.4.0.dist-info/top_level.txt,sha256=DBkkpdnOvG7PH2Teb_9CxGXAAS_XIjtO0GXoSnUPf08,10
15
+ repowatch-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ repowatch = repowatch.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Wharry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ repowatch