Skip to content

AddPack: Extract shared validate-and-register sequence from performGitAdd/performLocalAdd #206

@bguidolim

Description

@bguidolim

Severity: MEDIUM

performGitAdd and performLocalAdd in PackCommand.swift share a near-identical 5-step sequence:

  1. Validate manifest → do/catch → error + throw
  2. Load registry → check duplicate → check collisions → collision prompt
  3. Display summary → preview bail-out
  4. Trust verification → do/catch → guard approved
  5. Build PackEntry → register + save → success message

The differences are:

  • Git path: has clone/move/temp-cleanup logic, uses fetcher.remove() on failure
  • Local path: skips ref, sets isLocal: true, uses localCommitSentinel, no temp cleanup needed

The registry-save block is character-for-character identical. The collision-check and duplicate-check call sites are also structurally identical.

Fix: Extract a shared helper that accepts a closure or strategy for the source-specific bits (clone vs. read-in-place, cleanup on failure).

Found during review of #109.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DRYCode duplication / DRY violationtech-debtTechnical debt and code quality improvements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions