microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-broken-file-references

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.github/skills/shared/pr-reference/scripts/shared.psm1

37lines · modecode

1# Copyright (c) Microsoft Corporation.
2# SPDX-License-Identifier: MIT
3
4function Get-RepositoryRoot {
5<#
6.SYNOPSIS
7Gets the repository root path.
8.DESCRIPTION
9Runs git rev-parse --show-toplevel to locate the repository root.
10In default mode, falls back to the current directory when git fails.
11With -Strict, throws a terminating error instead.
12.PARAMETER Strict
13When set, throws instead of falling back to the current directory.
14.OUTPUTS
15System.String
16#>
17 [OutputType([string])]
18 param(
19 [switch]$Strict
20 )
21
22 if ($Strict) {
23 $repoRoot = (& git rev-parse --show-toplevel).Trim()
24 if (-not $repoRoot) {
25 throw "Unable to determine repository root."
26 }
27 return $repoRoot
28 }
29
30 $root = & git rev-parse --show-toplevel 2>$null
31 if ($LASTEXITCODE -eq 0 -and $root) {
32 return $root.Trim()
33 }
34 return $PWD.Path
35}
36
37Export-ModuleMember -Function Get-RepositoryRoot
38