Skip to content

Commit a107958

Browse files
committed
Guard git call with try/catch in PowerShell scripts
With $ErrorActionPreference = 'Stop', an unguarded git rev-parse throws a terminating CommandNotFoundException when git is not installed, preventing the .specify walk-up fallback from running. Wrap the git call in try/catch across all 20 update-context.ps1 scripts so the fallback works reliably without git.
1 parent 85bc4e5 commit a107958

20 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/specify_cli/integrations/amp/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/auggie/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/bob/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/claude/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/codebuddy/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/copilot/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $ErrorActionPreference = 'Stop'
1616

1717
# Derive repo root from script location (walks up to find .specify/)
1818
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
19-
$repoRoot = git rev-parse --show-toplevel 2>$null
19+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
2020
# If git did not return a repo root, or the git root does not contain .specify,
2121
# fall back to walking up from the script directory to find the initialized project root.
2222
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/cursor-agent/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/iflow/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/junie/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

src/specify_cli/integrations/kilocode/scripts/update-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
99

1010
# Derive repo root from script location (walks up to find .specify/)
1111
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
12-
$repoRoot = git rev-parse --show-toplevel 2>$null
12+
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
1313
# If git did not return a repo root, or the git root does not contain .specify,
1414
# fall back to walking up from the script directory to find the initialized project root.
1515
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {

0 commit comments

Comments
 (0)