Skip to content

feat: Initialize-GitDefaults.ps1 -- compose .gitattributes/.gitignore from upstream templates #160

Description

@MarkMichaelis

Goal

Ship Initialize-GitDefaults.ps1 (repo root) that interactively (or via -Language) composes .gitattributes and .gitignore for a consumer project by combining per-language templates from upstream community repos plus a curated PowerShell block.

Replaces shipping a static .gitattributes.template from upstream IntelliSDLC.ai. Language stacks vary per consumer; the per-language templates already exist upstream -- we just need to compose them.

Source Repos (Pinned)

  • .gitignore: github/gitignore @ dcc0fc7bc2b5ba480cf117ad1be31bafceeaff46 (GitHub-org authoritative; powers GitHub's UI picker).
  • .gitattributes: alexkaratarakis/gitattributes @ fddc586cf0f10ec4485028d0d2dd6f73197a4258 (community de facto; github/gitattributes does not exist).

Ecosystem Background

Tool .gitignore .gitattributes
gibo (simonwhitaker/gibo) yes -- fetches from github/gitignore no
gh repo create --gitignore X yes -- creation-time only no
Any other CLI no no

Initialize-GitDefaults.ps1 integrates with gibo when present (for .gitignore) and fills the ecosystem gap for .gitattributes ourselves.

Required Language Coverage

Language gitattributes gitignore
CSharp CSharp.gitattributes VisualStudio.gitignore
PowerShell curated in-script block curated in-script block
TypeScript Web.gitattributes Node.gitignore
ASP.NET +VisualStudio.gitattributes (layered on CSharp) VisualStudio.gitignore (shared)

Dependency graph: ASP.NET -> CSharp. TypeScript uses Web + Node directly.

Bundled Offline Snapshots

Under .github/templates/git-defaults/ at pinned SHAs:

  • From alexkaratarakis/gitattributes: Common.gitattributes, CSharp.gitattributes, VisualStudio.gitattributes, Web.gitattributes
  • From github/gitignore: VisualStudio.gitignore, Node.gitignore, Global/Backup.gitignore
  • SOURCES.md documenting pinned SHAs + authority distinction + refresh procedure.
  • PowerShell blocks NOT bundled -- embedded in script.

Script Spec -- Initialize-GitDefaults.ps1

[CmdletBinding(SupportsShouldProcess)]
param(
    [string[]] $Language,
    [switch]   $IncludeGitignore     = $true,
    [switch]   $IncludeGitattributes = $true,
    [string]   $GitattributesRef     = 'fddc586cf0f10ec4485028d0d2dd6f73197a4258',
    [string]   $GitignoreRef         = 'dcc0fc7bc2b5ba480cf117ad1be31bafceeaff46',
    [switch]   $Refresh,
    [switch]   $Force
)

Behaviour (summary):

  1. Pre-flight: validate cwd is a git repo.
  2. Language selection: -Language validated against known set; else interactive multi-select picker with heuristic pre-selection; else abort.
  3. Dependency expansion: ASP.NET -> CSharp etc.
  4. Compose .gitattributes: header -> Common -> per-lang (stable alpha) -> curated PowerShell block.
  5. Compose .gitignore: prefer gibo dump when present and not -Refresh, else assemble from bundled snapshots / network.
  6. Header on both files lists pinned SHAs, authority labels, languages, curated additions.
  7. Backup-and-replace: if target exists and not -Force, abort; with -Force, copy to <file>.bak (timestamp suffix on collision).
  8. Honour -WhatIf.
  9. Cache: $env:LOCALAPPDATA\IntelliSDLC.ai\cache\git-defaults\<SHA>\ with tasks/.cache/git-defaults/<SHA>/ fallback.

Pull-SDLC.ai.ps1 Integration

  • git rm .gitattributes.template.
  • Remove .gitattributes.template from $script:TemplateScaffoldMap and $script:UpstreamManagedPaths.
  • Confirm .gitattributes on $script:AlwaysLocalPaths (already there).
  • Add .github/templates/git-defaults/ to $script:UpstreamManagedPaths.
  • Post-sync hint when missing .gitattributes/.gitignore: print exactly once a one-liner instructing the user to run ./Initialize-GitDefaults.ps1. Do NOT auto-invoke.

Acceptance Criteria

  • Invoke-Pester on Initialize-GitDefaults.Tests.ps1 and Pull-SDLC.ai.Tests.ps1 passes 100%.
  • PSScriptAnalyzer reports zero new findings vs main on both scripts.
  • ./Initialize-GitDefaults.ps1 -Language CSharp,PowerShell,TypeScript -Force in a fresh temp dir composes both files end-to-end, exit 0.
  • ./Initialize-GitDefaults.ps1 -Language ASP.NET -Force includes CSharp content.
  • .gitattributes.template gone from repo.
  • Fresh sync into consumer worktree without .gitattributes prints the hint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions