|
43 | 43 | printf '%s\n' "${p//\\//}" |
44 | 44 | fi |
45 | 45 | } |
| 46 | + detect_and_store_repo_depth_mode() { |
| 47 | + local shallow |
| 48 | + if ! shallow="$(git rev-parse --is-shallow-repository 2>/dev/null)"; then |
| 49 | + echo "gitcoverage requires Git 2.15.0 or newer (missing 'git rev-parse --is-shallow-repository')." >&2 |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + if [[ "$shallow" != "true" && "$shallow" != "false" ]]; then |
| 53 | + echo "Unexpected result from 'git rev-parse --is-shallow-repository': '$shallow'" >&2 |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + echo "GITCOVERAGE_IS_SHALLOW_REPOSITORY=$shallow" >> "$GITHUB_ENV" |
| 57 | + } |
| 58 | +
|
| 59 | + detect_and_store_repo_depth_mode |
46 | 60 |
|
47 | 61 | WORKSPACE_PATH="${GITHUB_WORKSPACE:-$PWD}" |
48 | 62 | WORKSPACE_PATH="$(to_posix_path "$WORKSPACE_PATH")" |
@@ -125,9 +139,20 @@ runs: |
125 | 139 | local b="$1" |
126 | 140 | git check-ref-format --branch "$b" >/dev/null 2>&1 |
127 | 141 | } |
| 142 | + validate_windows_safe_branch_path_or_fail() { |
| 143 | + local b="$1" |
| 144 | + # Only enforce this compatibility check on Windows runners. |
| 145 | + if [[ "${RUNNER_OS:-}" == "Windows" ]]; then |
| 146 | + # Keep this intentionally strict and simple for filesystem safety. |
| 147 | + if ! [[ "$b" =~ ^[A-Za-z0-9._/+-]+$ ]]; then |
| 148 | + echo "On Windows runners, branch '$b' must match: [A-Za-z0-9._/+-]+" >&2 |
| 149 | + return 1 |
| 150 | + fi |
| 151 | + fi |
| 152 | + } |
128 | 153 | ensure_tag_resolution_refs() { |
129 | 154 | # Only tag-triggered auto-mapping needs full remote-branch refs. |
130 | | - if git rev-parse --is-shallow-repository >/dev/null 2>&1 && [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then |
| 155 | + if [[ "$GITCOVERAGE_IS_SHALLOW_REPOSITORY" == "true" ]]; then |
131 | 156 | # Fully unshallow if possible so --contains works reliably. |
132 | 157 | git fetch --prune --tags --unshallow origin || git fetch --prune --tags --depth=1000 origin |
133 | 158 | else |
@@ -161,19 +186,19 @@ runs: |
161 | 186 | exit 1 |
162 | 187 | fi |
163 | 188 | echo "Using explicit branch input: $BRANCH" |
164 | | - echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" |
165 | | - exit 0 |
166 | 189 | fi |
167 | 190 |
|
168 | 191 | # --- Fast paths: branch refs; never let PR head-ref override tag context --- |
169 | | - if [[ "$REF_TYPE" == "tag" || "$REF_FULL" == refs/tags/* ]]; then |
170 | | - BRANCH="" |
171 | | - elif [[ -n "$HEAD_REF" ]]; then |
172 | | - BRANCH="${HEAD_REF}" |
173 | | - elif [[ "$REF_TYPE" == "branch" && -n "$REF_NAME" ]]; then |
174 | | - BRANCH="${REF_NAME}" |
175 | | - else |
176 | | - BRANCH="" |
| 192 | + if [[ -z "$BRANCH" ]]; then |
| 193 | + if [[ "$REF_TYPE" == "tag" || "$REF_FULL" == refs/tags/* ]]; then |
| 194 | + BRANCH="" |
| 195 | + elif [[ -n "$HEAD_REF" ]]; then |
| 196 | + BRANCH="${HEAD_REF}" |
| 197 | + elif [[ "$REF_TYPE" == "branch" && -n "$REF_NAME" ]]; then |
| 198 | + BRANCH="${REF_NAME}" |
| 199 | + else |
| 200 | + BRANCH="" |
| 201 | + fi |
177 | 202 | fi |
178 | 203 |
|
179 | 204 | # --- Tag path: map tag -> containing branch --- |
@@ -254,6 +279,9 @@ runs: |
254 | 279 | echo "Could not determine branch (still detached at a tag). Consider actions/checkout with 'fetch-depth: 0'." >&2 |
255 | 280 | exit 1 |
256 | 281 | fi |
| 282 | + if ! validate_windows_safe_branch_path_or_fail "$BRANCH"; then |
| 283 | + exit 1 |
| 284 | + fi |
257 | 285 |
|
258 | 286 | echo "Resolved branch: $BRANCH" |
259 | 287 | echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" |
|
0 commit comments