Skip to content

Commit af5e1a4

Browse files
aclark4lifeCopilot
andcommitted
Fix sync -a output to show synced and skipped counts
When repos are skipped (no upstream remote or detached HEAD), the summary now correctly reports both synced and skipped counts, e.g. '✨ Done! Synced 3 repository(ies), skipped 3' instead of incorrectly reporting all repos as synced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 86783a9 commit af5e1a4

1 file changed

Lines changed: 40 additions & 17 deletions

File tree

src/dbx_python_cli/commands/sync.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,29 @@ def sync_callback(
142142
f"Syncing {len(target_repos)} repository(ies) across {len(non_global_groups)} group(s):\n"
143143
)
144144

145+
synced_count = 0
146+
skipped_count = 0
145147
for i, repo_info in enumerate(target_repos):
146148
# Add separator between repos (not before first or after last)
147149
if i > 0:
148150
typer.echo("─" * 60)
149-
_sync_repository(
151+
status = _sync_repository(
150152
repo_info["path"], repo_info["name"], verbose, force, dry_run
151153
)
154+
if status == "skipped":
155+
skipped_count += 1
156+
elif status in ("synced", "dry_run"):
157+
synced_count += 1
152158

153159
if dry_run:
154-
typer.echo(
155-
f"\n✨ Dry run complete! Checked {len(target_repos)} repository(ies)"
160+
summary = (
161+
f"\n✨ Dry run complete! Checked {synced_count} repository(ies)"
156162
)
157163
else:
158-
typer.echo(f"\n✨ Done! Synced {len(target_repos)} repository(ies)")
164+
summary = f"\n✨ Done! Synced {synced_count} repository(ies)"
165+
if skipped_count:
166+
summary += f", skipped {skipped_count}"
167+
typer.echo(summary)
159168
finally:
160169
if use_pager:
161170
sys.stdout = old_stdout
@@ -240,20 +249,29 @@ def sync_callback(
240249
f"Syncing {len(group_repos)} repository(ies) in group '{group}':\n"
241250
)
242251

252+
synced_count = 0
253+
skipped_count = 0
243254
for i, repo_info in enumerate(group_repos):
244255
# Add separator between repos (not before first or after last)
245256
if i > 0:
246257
typer.echo("─" * 60)
247-
_sync_repository(
258+
status = _sync_repository(
248259
repo_info["path"], repo_info["name"], verbose, force, dry_run
249260
)
261+
if status == "skipped":
262+
skipped_count += 1
263+
elif status in ("synced", "dry_run"):
264+
synced_count += 1
250265

251266
if dry_run:
252-
typer.echo(
253-
f"\n✨ Dry run complete! Checked {len(group_repos)} repository(ies)"
267+
summary = (
268+
f"\n✨ Dry run complete! Checked {synced_count} repository(ies)"
254269
)
255270
else:
256-
typer.echo(f"\n✨ Done! Synced {len(group_repos)} repository(ies)")
271+
summary = f"\n✨ Done! Synced {synced_count} repository(ies)"
272+
if skipped_count:
273+
summary += f", skipped {skipped_count}"
274+
typer.echo(summary)
257275
finally:
258276
if use_pager:
259277
sys.stdout = old_stdout
@@ -316,11 +334,14 @@ def _sync_repository(
316334
verbose: bool = False,
317335
force: bool = False,
318336
dry_run: bool = False,
319-
):
337+
) -> str:
320338
"""Sync a single repository with upstream.
321339
322340
For main/master branches: rebases to upstream/<branch_name>
323341
For feature branches: rebases to upstream's default branch (main/master)
342+
343+
Returns:
344+
"synced", "skipped", "failed", or "dry_run"
324345
"""
325346
if dry_run:
326347
typer.echo(f"🔍 Checking {repo_name}")
@@ -349,14 +370,14 @@ def _sync_repository(
349370
"⚠️ No 'upstream' remote found (skipping)",
350371
err=True,
351372
)
352-
return
373+
return "skipped"
353374

354375
except subprocess.CalledProcessError as e:
355376
typer.echo(
356377
f"❌ Failed to check remotes: {e.stderr}",
357378
err=True,
358379
)
359-
return
380+
return "failed"
360381

361382
# Get current branch
362383
try:
@@ -373,7 +394,7 @@ def _sync_repository(
373394
"⚠️ Not on a branch (detached HEAD), skipping",
374395
err=True,
375396
)
376-
return
397+
return "skipped"
377398

378399
if verbose:
379400
typer.echo(f"[verbose] Current branch: {current_branch}")
@@ -383,7 +404,7 @@ def _sync_repository(
383404
f"❌ Failed to get current branch: {e.stderr}",
384405
err=True,
385406
)
386-
return
407+
return "failed"
387408

388409
# Fetch from upstream
389410
try:
@@ -402,7 +423,7 @@ def _sync_repository(
402423
f"❌ Failed to fetch from upstream: {e.stderr if not verbose else ''}",
403424
err=True,
404425
)
405-
return
426+
return "failed"
406427

407428
# Determine which branch to rebase onto
408429
# For main/master: rebase to upstream/<current_branch>
@@ -445,7 +466,7 @@ def _sync_repository(
445466
"❌ Could not determine upstream default branch",
446467
err=True,
447468
)
448-
return
469+
return "failed"
449470

450471
rebase_target = f"upstream/{upstream_default}"
451472
if verbose:
@@ -458,7 +479,7 @@ def _sync_repository(
458479
_show_commit_comparison(
459480
repo_path, repo_name, current_branch, rebase_target, verbose
460481
)
461-
return
482+
return "dry_run"
462483

463484
# Rebase on target branch
464485
try:
@@ -483,7 +504,7 @@ def _sync_repository(
483504
f" You may need to resolve conflicts manually in {repo_path}",
484505
err=True,
485506
)
486-
return
507+
return "failed"
487508

488509
# Push to origin
489510
try:
@@ -506,6 +527,7 @@ def _sync_repository(
506527
)
507528

508529
typer.echo("✅ Synced and pushed successfully")
530+
return "synced"
509531

510532
except subprocess.CalledProcessError as e:
511533
typer.echo(
@@ -518,6 +540,7 @@ def _sync_repository(
518540
f" Try running: dbx sync {repo_name} --force",
519541
err=True,
520542
)
543+
return "synced"
521544

522545

523546
def _get_upstream_default_branch(repo_path: Path, verbose: bool = False) -> str | None:

0 commit comments

Comments
 (0)