half-orm-dev 1.0.0a35__py3-none-any.whl → 1.0.0a38__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.
- half_orm_dev/cli/commands/check.py +107 -41
- half_orm_dev/cli/commands/restore.py +11 -16
- half_orm_dev/cli/main.py +21 -2
- half_orm_dev/cli_extension.py +6 -1
- half_orm_dev/hgit.py +110 -33
- half_orm_dev/migration_manager.py +12 -21
- half_orm_dev/migrations/1/0/0/a36/00_drop_release_schemas.py +123 -0
- half_orm_dev/patch_manager.py +166 -342
- half_orm_dev/release_file.py +58 -0
- half_orm_dev/release_manager.py +155 -88
- half_orm_dev/repo.py +68 -175
- half_orm_dev/version.txt +1 -1
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/METADATA +1 -1
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/RECORD +19 -18
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/WHEEL +0 -0
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/entry_points.txt +0 -0
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/licenses/AUTHORS +0 -0
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/licenses/LICENSE +0 -0
- {half_orm_dev-1.0.0a35.dist-info → half_orm_dev-1.0.0a38.dist-info}/top_level.txt +0 -0
|
@@ -104,12 +104,28 @@ def _display_check_results(repo, result: dict, dry_run: bool, verbose: bool):
|
|
|
104
104
|
click.echo(f"✓ {utils.Color.green(f'half_orm_dev: {current} (latest)')}")
|
|
105
105
|
click.echo()
|
|
106
106
|
|
|
107
|
-
# Production version
|
|
107
|
+
# Production version (read on ho-prod)
|
|
108
108
|
production_version = result.get('production_version')
|
|
109
109
|
if production_version:
|
|
110
110
|
click.echo(f"📦 {utils.Color.bold('Production version:')} {utils.Color.green(production_version)}")
|
|
111
111
|
click.echo()
|
|
112
112
|
|
|
113
|
+
# The current branch's .hop/ predates that production version: say so
|
|
114
|
+
# instead of letting the numbers above look like this branch's state.
|
|
115
|
+
behind = result.get('branch_behind_ho_prod')
|
|
116
|
+
if behind:
|
|
117
|
+
click.echo(
|
|
118
|
+
f"⚠️ {utils.Color.bold(behind['branch'])} still records production "
|
|
119
|
+
f"{utils.Color.red(behind['branch_version'])}, "
|
|
120
|
+
f"while ho-prod is on {utils.Color.green(behind['production_version'])}."
|
|
121
|
+
)
|
|
122
|
+
click.echo(
|
|
123
|
+
f" Its .hop/ stopped receiving updates, so the release context "
|
|
124
|
+
f"rebuilt from it is stale."
|
|
125
|
+
)
|
|
126
|
+
click.echo(f" Bring it up to date: {utils.Color.bold('git merge ho-prod')}")
|
|
127
|
+
click.echo()
|
|
128
|
+
|
|
113
129
|
# Hooks
|
|
114
130
|
hooks = result.get('hooks', {})
|
|
115
131
|
if hooks.get('installed'):
|
|
@@ -186,54 +202,104 @@ def _display_check_results(repo, result: dict, dry_run: bool, verbose: bool):
|
|
|
186
202
|
# Stale branches detection and cleanup
|
|
187
203
|
stale_branches = result.get('stale_branches', {})
|
|
188
204
|
candidates = stale_branches.get('candidates', [])
|
|
205
|
+
unmerged = stale_branches.get('unmerged', [])
|
|
206
|
+
current_branch = repo.hgit.branch if repo.hgit else None
|
|
189
207
|
|
|
190
|
-
|
|
208
|
+
def _label(branch):
|
|
209
|
+
"""Mark the branch the developer is standing on."""
|
|
210
|
+
return f"{branch} (current branch)" if branch == current_branch else branch
|
|
211
|
+
|
|
212
|
+
if candidates or unmerged:
|
|
191
213
|
click.echo()
|
|
214
|
+
click.echo(
|
|
215
|
+
f"⚠️ {utils.Color.bold(f'Found {len(candidates) + len(unmerged)} stale local branch(es)')}"
|
|
216
|
+
f" (no longer on remote):"
|
|
217
|
+
)
|
|
218
|
+
for branch in candidates[:10]:
|
|
219
|
+
click.echo(f" {'○' if dry_run else '•'} {_label(branch)}")
|
|
220
|
+
if len(candidates) > 10:
|
|
221
|
+
click.echo(f" ... and {len(candidates) - 10} more")
|
|
222
|
+
|
|
223
|
+
# Branches carrying commits that are nowhere else are never part
|
|
224
|
+
# of the blanket confirmation: deleting them destroys the work.
|
|
225
|
+
if unmerged:
|
|
226
|
+
click.echo()
|
|
227
|
+
click.echo(
|
|
228
|
+
f" {utils.Color.red('These carry commits that exist nowhere else:')}"
|
|
229
|
+
)
|
|
230
|
+
for branch, count in unmerged[:10]:
|
|
231
|
+
plural = 's' if count != 1 else ''
|
|
232
|
+
click.echo(f" ⚠ {_label(branch)} - {count} unmerged commit{plural}")
|
|
233
|
+
if len(unmerged) > 10:
|
|
234
|
+
click.echo(f" ... and {len(unmerged) - 10} more")
|
|
235
|
+
|
|
192
236
|
if dry_run:
|
|
193
|
-
click.echo(f"⚠️ {utils.Color.bold(f'Found {len(candidates)} stale local branch(es)')} (no longer on remote):")
|
|
194
|
-
for branch in candidates[:10]:
|
|
195
|
-
click.echo(f" ○ {branch}")
|
|
196
|
-
if len(candidates) > 10:
|
|
197
|
-
click.echo(f" ... and {len(candidates) - 10} more")
|
|
198
237
|
click.echo(f"\n Run without --dry-run to be prompted for deletion")
|
|
199
|
-
|
|
200
|
-
# Show stale branches and prompt for deletion
|
|
201
|
-
click.echo(f"⚠️ {utils.Color.bold(f'Found {len(candidates)} stale local branch(es)')} (no longer on remote):")
|
|
202
|
-
for branch in candidates[:10]:
|
|
203
|
-
click.echo(f" • {branch}")
|
|
204
|
-
if len(candidates) > 10:
|
|
205
|
-
click.echo(f" ... and {len(candidates) - 10} more")
|
|
206
|
-
click.echo()
|
|
238
|
+
return
|
|
207
239
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
240
|
+
click.echo()
|
|
241
|
+
|
|
242
|
+
deleted = []
|
|
243
|
+
errors = []
|
|
244
|
+
switched_to = None
|
|
245
|
+
|
|
246
|
+
try:
|
|
247
|
+
if candidates and click.confirm(
|
|
248
|
+
f"Delete these {len(candidates)} branch(es)?", default=False
|
|
249
|
+
):
|
|
250
|
+
delete_result = repo.hgit.prune_local_branches(
|
|
251
|
+
pattern="ho-*",
|
|
252
|
+
dry_run=False,
|
|
253
|
+
exclude_current=False
|
|
254
|
+
)
|
|
255
|
+
deleted = delete_result.get('deleted', [])
|
|
256
|
+
errors = delete_result.get('errors', [])
|
|
257
|
+
switched_to = delete_result.get('switched_to')
|
|
258
|
+
|
|
259
|
+
if unmerged:
|
|
260
|
+
click.echo()
|
|
261
|
+
click.echo(
|
|
262
|
+
utils.Color.red(
|
|
263
|
+
f"⚠ {len(unmerged)} branch(es) hold work that only exists locally. "
|
|
264
|
+
f"Deleting them loses it."
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
click.echo(" To keep that work, merge or push those branches first.")
|
|
268
|
+
if click.confirm(
|
|
269
|
+
f"Delete these {len(unmerged)} branch(es) anyway, losing their commits?",
|
|
270
|
+
default=False
|
|
271
|
+
):
|
|
272
|
+
force_result = repo.hgit.prune_local_branches(
|
|
215
273
|
pattern="ho-*",
|
|
216
274
|
dry_run=False,
|
|
217
|
-
exclude_current=
|
|
275
|
+
exclude_current=False,
|
|
276
|
+
force=True
|
|
218
277
|
)
|
|
219
|
-
deleted
|
|
220
|
-
errors
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
278
|
+
deleted.extend(force_result.get('deleted', []))
|
|
279
|
+
errors.extend(force_result.get('errors', []))
|
|
280
|
+
switched_to = switched_to or force_result.get('switched_to')
|
|
281
|
+
|
|
282
|
+
if deleted:
|
|
283
|
+
click.echo(f"\n✓ {utils.Color.green(f'Deleted {len(deleted)} stale branch(es)')}")
|
|
284
|
+
if verbose:
|
|
285
|
+
for branch in deleted[:10]:
|
|
286
|
+
click.echo(f" ✓ {branch}")
|
|
287
|
+
if len(deleted) > 10:
|
|
288
|
+
click.echo(f" ... and {len(deleted) - 10} more")
|
|
289
|
+
|
|
290
|
+
if switched_to:
|
|
291
|
+
click.echo(
|
|
292
|
+
f" ℹ You were on a deleted branch - now on "
|
|
293
|
+
f"{utils.Color.bold(switched_to)}"
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
if errors:
|
|
297
|
+
click.echo(f"\n⚠ {utils.Color.red('Some errors occurred during cleanup')}")
|
|
298
|
+
if verbose:
|
|
299
|
+
for branch, error in errors[:3]:
|
|
300
|
+
click.echo(f" {branch}: {error}")
|
|
301
|
+
except Exception as e:
|
|
302
|
+
click.echo(utils.Color.red(f"\n❌ Error deleting branches: {e}"), err=True)
|
|
237
303
|
|
|
238
304
|
|
|
239
305
|
def _display_release_branches_grouped(branches: list, verbose: bool):
|
|
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
import click
|
|
8
8
|
from half_orm_dev.repo import Repo, RepoError
|
|
9
|
+
from half_orm_dev.release_manager import ReleaseManagerError
|
|
9
10
|
from half_orm import utils
|
|
10
11
|
|
|
11
12
|
|
|
@@ -16,16 +17,17 @@ def restore(release: str) -> None:
|
|
|
16
17
|
Restore the database to the state of RELEASE.
|
|
17
18
|
|
|
18
19
|
Drops all user schemas and reloads them, picking the most precise
|
|
19
|
-
|
|
20
|
+
source available for RELEASE:
|
|
20
21
|
|
|
21
22
|
\b
|
|
22
|
-
1. .hop/model/
|
|
23
|
-
|
|
24
|
-
2.
|
|
25
|
-
|
|
23
|
+
1. .hop/model/schema-RELEASE.sql + data-RELEASE.sql (published
|
|
24
|
+
snapshot of that exact released version)
|
|
25
|
+
2. otherwise, for a release still in preparation: the production
|
|
26
|
+
baseline replayed with the validated patches of every release in
|
|
27
|
+
preparation up to RELEASE (patch -> minor -> major)
|
|
26
28
|
|
|
27
29
|
Fails with an error, rather than silently loading a different
|
|
28
|
-
version, if neither
|
|
30
|
+
version, if RELEASE is neither published nor in preparation.
|
|
29
31
|
|
|
30
32
|
\b
|
|
31
33
|
Examples:
|
|
@@ -39,22 +41,15 @@ def restore(release: str) -> None:
|
|
|
39
41
|
repo = Repo()
|
|
40
42
|
click.echo(f"Restoring database to release {utils.Color.bold(release)}...")
|
|
41
43
|
|
|
42
|
-
release_schema_path = repo.get_release_schema_path(release)
|
|
43
44
|
schema_path = Path(repo.model_dir) / f"schema-{release}.sql"
|
|
44
45
|
|
|
45
|
-
if
|
|
46
|
-
repo.restore_database_from_release_schema(release)
|
|
47
|
-
elif schema_path.exists():
|
|
46
|
+
if schema_path.exists():
|
|
48
47
|
repo.restore_database_from_version_schema(release)
|
|
49
48
|
else:
|
|
50
|
-
|
|
51
|
-
f"No schema found for release '{release}': neither "
|
|
52
|
-
f"{release_schema_path.name} nor {schema_path.name} "
|
|
53
|
-
f"exists in {repo.model_dir}."
|
|
54
|
-
)
|
|
49
|
+
repo.release_manager.restore_to_release(release)
|
|
55
50
|
|
|
56
51
|
click.echo(f"✓ {utils.Color.green('Database restored to')} {utils.Color.bold(release)}")
|
|
57
|
-
except RepoError as e:
|
|
52
|
+
except (RepoError, ReleaseManagerError) as e:
|
|
58
53
|
click.echo(utils.Color.red(f"\n❌ {e}"), err=True)
|
|
59
54
|
raise click.Abort()
|
|
60
55
|
except Exception as e:
|
half_orm_dev/cli/main.py
CHANGED
|
@@ -7,6 +7,10 @@ import functools
|
|
|
7
7
|
import os
|
|
8
8
|
import subprocess
|
|
9
9
|
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import half_orm_dev as _half_orm_dev
|
|
13
|
+
from half_orm_dev.utils import hop_version
|
|
10
14
|
from half_orm_dev.repo import Repo, OutdatedHalfORMDevError
|
|
11
15
|
from half_orm import utils
|
|
12
16
|
from .commands import ALL_COMMANDS
|
|
@@ -139,7 +143,6 @@ def create_cli_group():
|
|
|
139
143
|
return cmd
|
|
140
144
|
# Unknown command — show a specific message when migration is needed.
|
|
141
145
|
if hop.repo_checked and hop._Hop__repo.needs_migration():
|
|
142
|
-
from half_orm_dev.utils import hop_version
|
|
143
146
|
installed_version = hop_version()
|
|
144
147
|
config_version = hop._Hop__repo.repo.config.hop_version
|
|
145
148
|
|
|
@@ -166,9 +169,26 @@ def create_cli_group():
|
|
|
166
169
|
return None
|
|
167
170
|
|
|
168
171
|
@click.group(cls=VersionCheckGroup, invoke_without_command=True)
|
|
172
|
+
@click.version_option(
|
|
173
|
+
version=hop_version(),
|
|
174
|
+
prog_name='half_orm dev',
|
|
175
|
+
# The package path is what settles the recurring question: an
|
|
176
|
+
# editable install runs the working tree, a released wheel does
|
|
177
|
+
# not, and `half_orm --version` answers for the ORM, not for
|
|
178
|
+
# half_orm_dev.
|
|
179
|
+
message=f'%(prog)s %(version)s ({Path(_half_orm_dev.__file__).resolve().parent})',
|
|
180
|
+
)
|
|
169
181
|
@click.pass_context
|
|
170
182
|
def dev(ctx):
|
|
171
183
|
"""halfORM development tools - Git-centric patch management and database synchronization"""
|
|
184
|
+
# Which half_orm_dev is running, on every command: a stale
|
|
185
|
+
# install silently answers for the working tree otherwise, and
|
|
186
|
+
# the output looks like a bug in the tool rather than in the
|
|
187
|
+
# environment. `check` is left out - it already opens with the
|
|
188
|
+
# same version plus whether a newer one exists.
|
|
189
|
+
if ctx.invoked_subcommand not in (None, 'check'):
|
|
190
|
+
click.echo(utils.Color.blue(f"half_orm dev {hop_version()}"))
|
|
191
|
+
|
|
172
192
|
if hop.needs_hop_upgrade:
|
|
173
193
|
error = hop.hop_upgrade_error
|
|
174
194
|
required = error.required_version
|
|
@@ -195,7 +215,6 @@ def create_cli_group():
|
|
|
195
215
|
# Check if migration is needed
|
|
196
216
|
if hop._Hop__repo.needs_migration():
|
|
197
217
|
# Propose automatic migration
|
|
198
|
-
from half_orm_dev.utils import hop_version
|
|
199
218
|
from half_orm_dev.repo import RepoError
|
|
200
219
|
installed_version = hop_version()
|
|
201
220
|
config_version = hop._Hop__repo.repo.config.hop_version
|
half_orm_dev/cli_extension.py
CHANGED
|
@@ -35,4 +35,9 @@ def add_commands(main_group):
|
|
|
35
35
|
dev.add_command(command)
|
|
36
36
|
|
|
37
37
|
# Copy the callback from the created group
|
|
38
|
-
dev.callback = dev_group.callback
|
|
38
|
+
dev.callback = dev_group.callback
|
|
39
|
+
|
|
40
|
+
# ...and the group's own options, which the registration above would
|
|
41
|
+
# otherwise drop: create_cli_group() declares --version there, and a
|
|
42
|
+
# group rebuilt from commands and callback alone would not have it.
|
|
43
|
+
dev.params = list(dev_group.params)
|
half_orm_dev/hgit.py
CHANGED
|
@@ -1358,40 +1358,62 @@ class HGit:
|
|
|
1358
1358
|
|
|
1359
1359
|
def prune_local_branches(
|
|
1360
1360
|
self,
|
|
1361
|
-
pattern:
|
|
1361
|
+
pattern: str = "ho-*",
|
|
1362
1362
|
dry_run: bool = False,
|
|
1363
|
-
exclude_current: bool = True
|
|
1363
|
+
exclude_current: bool = True,
|
|
1364
|
+
force: bool = False
|
|
1364
1365
|
) -> dict:
|
|
1365
1366
|
"""
|
|
1366
|
-
Delete local branches that no longer exist on remote origin.
|
|
1367
|
+
Delete local hop branches that no longer exist on remote origin.
|
|
1367
1368
|
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1369
|
+
Origin is the source of truth: a branch deleted there has no
|
|
1370
|
+
reason to survive locally. Only ho-* branches are ever considered
|
|
1371
|
+
- a developer's own branches are none of this method's business -
|
|
1372
|
+
and ho-prod is always kept.
|
|
1373
|
+
|
|
1374
|
+
Deletion uses `git branch -d`, so a branch carrying commits that
|
|
1375
|
+
exist nowhere else is refused rather than destroyed. Those are
|
|
1376
|
+
reported under 'unmerged' for the caller to raise explicitly;
|
|
1377
|
+
force=True then deletes them with `git branch -D`. This matters:
|
|
1378
|
+
a patch branch whose remote was deleted before its work was
|
|
1379
|
+
merged is the only remaining copy of that work, and it used to be
|
|
1380
|
+
removed by a single blanket confirmation.
|
|
1381
|
+
|
|
1382
|
+
When exclude_current is False and the branch to delete is the one
|
|
1383
|
+
checked out, this switches to ho-prod first - you cannot delete
|
|
1384
|
+
the branch you stand on, and leaving it behind would defeat the
|
|
1385
|
+
point of the sync.
|
|
1371
1386
|
|
|
1372
1387
|
Args:
|
|
1373
|
-
pattern:
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1388
|
+
pattern: Glob pattern limiting the branches considered
|
|
1389
|
+
(default "ho-*"). Non-hop branches are skipped
|
|
1390
|
+
whatever the pattern says.
|
|
1391
|
+
dry_run: If True, only report what would be deleted
|
|
1392
|
+
exclude_current: If True, never touch the current branch
|
|
1393
|
+
force: If True, delete even branches carrying unmerged
|
|
1394
|
+
commits (git branch -D)
|
|
1377
1395
|
|
|
1378
1396
|
Returns:
|
|
1379
1397
|
dict with keys:
|
|
1380
1398
|
'deleted': List of deleted branch names
|
|
1381
|
-
'
|
|
1382
|
-
|
|
1399
|
+
'unmerged': List of (branch_name, commit_count) for branches
|
|
1400
|
+
kept because they carry unmerged commits
|
|
1401
|
+
'skipped': List of (branch_name, reason) tuples
|
|
1402
|
+
'errors': List of (branch_name, error_message) tuples
|
|
1403
|
+
'switched_to': Branch checked out to allow deleting the
|
|
1404
|
+
current one, or None
|
|
1383
1405
|
|
|
1384
1406
|
Examples:
|
|
1385
|
-
#
|
|
1386
|
-
result = hgit.prune_local_branches(
|
|
1407
|
+
# What would go (dry run)
|
|
1408
|
+
result = hgit.prune_local_branches(dry_run=True)
|
|
1387
1409
|
print(f"Would delete: {result['deleted']}")
|
|
1410
|
+
print(f"Would keep (unmerged): {result['unmerged']}")
|
|
1388
1411
|
|
|
1389
|
-
#
|
|
1390
|
-
result = hgit.prune_local_branches(
|
|
1391
|
-
print(f"Deleted: {result['deleted']}")
|
|
1412
|
+
# Delete, current branch included, work preserved
|
|
1413
|
+
result = hgit.prune_local_branches(exclude_current=False)
|
|
1392
1414
|
|
|
1393
|
-
#
|
|
1394
|
-
result = hgit.prune_local_branches()
|
|
1415
|
+
# Delete unmerged ones too, on explicit demand
|
|
1416
|
+
result = hgit.prune_local_branches(exclude_current=False, force=True)
|
|
1395
1417
|
"""
|
|
1396
1418
|
# Fetch from remote to get up-to-date branch list
|
|
1397
1419
|
try:
|
|
@@ -1399,18 +1421,21 @@ class HGit:
|
|
|
1399
1421
|
except GitCommandError as e:
|
|
1400
1422
|
return {
|
|
1401
1423
|
'deleted': [],
|
|
1424
|
+
'unmerged': [],
|
|
1402
1425
|
'skipped': [],
|
|
1403
|
-
'errors': [('fetch', f"Failed to fetch from origin: {e}")]
|
|
1426
|
+
'errors': [('fetch', f"Failed to fetch from origin: {e}")],
|
|
1427
|
+
'switched_to': None
|
|
1404
1428
|
}
|
|
1405
1429
|
|
|
1406
|
-
#
|
|
1430
|
+
# Always needed: to exclude the current branch when asked, and
|
|
1431
|
+
# otherwise to know we must leave it before deleting it - git
|
|
1432
|
+
# refuses to delete a branch used by a worktree.
|
|
1407
1433
|
current_branch = None
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
pass
|
|
1434
|
+
try:
|
|
1435
|
+
current_branch = str(self.__git_repo.active_branch)
|
|
1436
|
+
except TypeError:
|
|
1437
|
+
# active_branch raises TypeError when HEAD is detached
|
|
1438
|
+
pass
|
|
1414
1439
|
|
|
1415
1440
|
# Get local and remote branches
|
|
1416
1441
|
local_branches = self.get_local_branches(pattern=pattern)
|
|
@@ -1422,8 +1447,10 @@ class HGit:
|
|
|
1422
1447
|
}
|
|
1423
1448
|
|
|
1424
1449
|
deleted = []
|
|
1450
|
+
unmerged = []
|
|
1425
1451
|
skipped = []
|
|
1426
1452
|
errors = []
|
|
1453
|
+
switched_to = None
|
|
1427
1454
|
|
|
1428
1455
|
for branch in local_branches:
|
|
1429
1456
|
# Skip ho-prod (always keep)
|
|
@@ -1431,6 +1458,12 @@ class HGit:
|
|
|
1431
1458
|
skipped.append((branch, 'protected branch'))
|
|
1432
1459
|
continue
|
|
1433
1460
|
|
|
1461
|
+
# Never touch branches outside the hop namespace, whatever
|
|
1462
|
+
# the pattern allows
|
|
1463
|
+
if not branch.startswith('ho-'):
|
|
1464
|
+
skipped.append((branch, 'not a hop branch'))
|
|
1465
|
+
continue
|
|
1466
|
+
|
|
1434
1467
|
# Skip current branch if requested
|
|
1435
1468
|
if exclude_current and branch == current_branch:
|
|
1436
1469
|
skipped.append((branch, 'currently checked out'))
|
|
@@ -1441,22 +1474,66 @@ class HGit:
|
|
|
1441
1474
|
skipped.append((branch, 'exists on remote'))
|
|
1442
1475
|
continue
|
|
1443
1476
|
|
|
1444
|
-
# Branch doesn't exist on remote -
|
|
1477
|
+
# Branch doesn't exist on remote - it should go, unless it
|
|
1478
|
+
# carries commits that exist nowhere else.
|
|
1479
|
+
unmerged_count = self.count_unmerged_commits(branch)
|
|
1480
|
+
|
|
1445
1481
|
if dry_run:
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
self.__git_repo.git.branch('-D', branch)
|
|
1482
|
+
if unmerged_count and not force:
|
|
1483
|
+
unmerged.append((branch, unmerged_count))
|
|
1484
|
+
else:
|
|
1450
1485
|
deleted.append(branch)
|
|
1486
|
+
continue
|
|
1487
|
+
|
|
1488
|
+
# Deleting the branch we stand on requires leaving it first.
|
|
1489
|
+
if branch == current_branch:
|
|
1490
|
+
try:
|
|
1491
|
+
self.__git_repo.git.checkout('ho-prod')
|
|
1492
|
+
switched_to = 'ho-prod'
|
|
1493
|
+
current_branch = 'ho-prod'
|
|
1451
1494
|
except GitCommandError as e:
|
|
1495
|
+
errors.append((branch, f"Could not leave {branch}: {e}"))
|
|
1496
|
+
continue
|
|
1497
|
+
|
|
1498
|
+
try:
|
|
1499
|
+
# -d refuses a branch that is not fully merged: git is
|
|
1500
|
+
# the backstop even when the count above says otherwise
|
|
1501
|
+
self.__git_repo.git.branch('-D' if force else '-d', branch)
|
|
1502
|
+
deleted.append(branch)
|
|
1503
|
+
except GitCommandError as e:
|
|
1504
|
+
if not force and 'not fully merged' in str(e):
|
|
1505
|
+
unmerged.append((branch, unmerged_count))
|
|
1506
|
+
else:
|
|
1452
1507
|
errors.append((branch, str(e)))
|
|
1453
1508
|
|
|
1454
1509
|
return {
|
|
1455
1510
|
'deleted': deleted,
|
|
1511
|
+
'unmerged': unmerged,
|
|
1456
1512
|
'skipped': skipped,
|
|
1457
|
-
'errors': errors
|
|
1513
|
+
'errors': errors,
|
|
1514
|
+
'switched_to': switched_to
|
|
1458
1515
|
}
|
|
1459
1516
|
|
|
1517
|
+
def count_unmerged_commits(self, branch: str, base: str = 'ho-prod') -> int:
|
|
1518
|
+
"""
|
|
1519
|
+
Number of commits on branch that are not in base.
|
|
1520
|
+
|
|
1521
|
+
Used to tell a stale branch that can be dropped without loss from
|
|
1522
|
+
one that is the last copy of somebody's work.
|
|
1523
|
+
|
|
1524
|
+
Args:
|
|
1525
|
+
branch: Branch to inspect
|
|
1526
|
+
base: Branch to compare against (default ho-prod)
|
|
1527
|
+
|
|
1528
|
+
Returns:
|
|
1529
|
+
Commit count, 0 when everything is already in base or when
|
|
1530
|
+
the comparison cannot be made
|
|
1531
|
+
"""
|
|
1532
|
+
try:
|
|
1533
|
+
return int(self.__git_repo.git.rev_list('--count', f'{base}..{branch}'))
|
|
1534
|
+
except (GitCommandError, ValueError):
|
|
1535
|
+
return 0
|
|
1536
|
+
|
|
1460
1537
|
def get_active_branches_status(self, stage_files: list = None) -> dict:
|
|
1461
1538
|
"""
|
|
1462
1539
|
Get status of active Half-ORM branches (branches that can still be modified).
|
|
@@ -479,10 +479,11 @@ class MigrationManager:
|
|
|
479
479
|
) -> None:
|
|
480
480
|
"""Regenerate the project modules after a migration on all active branches.
|
|
481
481
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
482
|
+
Every branch is regenerated against the production schema
|
|
483
|
+
(schema.sql). Release and patch branches may carry relations that
|
|
484
|
+
only exist once their patches are applied, so modules are not
|
|
485
|
+
regenerated on ho-patch/* at all - the developer re-runs
|
|
486
|
+
`hop patch apply` there.
|
|
486
487
|
|
|
487
488
|
Stale local branches (no longer on remote) are skipped to avoid pre-commit
|
|
488
489
|
hook failures.
|
|
@@ -493,11 +494,8 @@ class MigrationManager:
|
|
|
493
494
|
"on a production server.\nModule regeneration (which includes database "
|
|
494
495
|
"restoration) must never run in production."
|
|
495
496
|
)
|
|
496
|
-
import re as _re
|
|
497
497
|
from half_orm_dev import modules as _modules
|
|
498
498
|
|
|
499
|
-
_RELEASE_RE = _re.compile(r'^ho-release/(.+)$')
|
|
500
|
-
|
|
501
499
|
repo = self._repo
|
|
502
500
|
git_repo = repo.hgit._HGit__git_repo
|
|
503
501
|
package_name = repo.name
|
|
@@ -541,20 +539,13 @@ class MigrationManager:
|
|
|
541
539
|
try:
|
|
542
540
|
repo.hgit.checkout(branch)
|
|
543
541
|
|
|
544
|
-
# Restore the DB to the schema
|
|
545
|
-
#
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
repo.restore_database_from_release_schema(release_version)
|
|
552
|
-
else:
|
|
553
|
-
repo.restore_database_from_schema()
|
|
554
|
-
else:
|
|
555
|
-
#XXX EST-CE QUE POUR ho-patch/* on ne devrait pas utiliser from_release_schema ?
|
|
556
|
-
# ho-prod and ho-patch/*: use production schema
|
|
557
|
-
repo.restore_database_from_schema()
|
|
542
|
+
# Restore the DB to the production schema so generate()
|
|
543
|
+
# introspects a known set of relations. Release and patch
|
|
544
|
+
# branches may carry relations that only exist once their
|
|
545
|
+
# patches are applied; the developer re-runs
|
|
546
|
+
# `hop patch apply` there to regenerate with the full
|
|
547
|
+
# release context.
|
|
548
|
+
repo.restore_database_from_schema()
|
|
558
549
|
|
|
559
550
|
if not branch in patch_branches:
|
|
560
551
|
_modules.generate(repo)
|