Skip to content

Commit c1649f7

Browse files
committed
support relative origin paths
1 parent d0b138d commit c1649f7

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

.github/workflows/self-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
git add reports/report.html
5252
git commit -m "init fixture"
5353
54-
git remote add origin "$PWD/remote.git"
54+
git remote add origin "remote.git"
5555
git push -u origin main
5656
5757
git tag v-test

action.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ runs:
145145
if ! git remote get-url origin >/dev/null 2>&1; then
146146
git remote add origin "${GITHUB_SERVER_URL:-https://github.com}/${GITHUB_REPOSITORY}.git"
147147
fi
148+
REPO_ROOT="$(git rev-parse --show-toplevel)"
149+
echo "GITCOVERAGE_REPO_ROOT=$REPO_ROOT" >> "$GITHUB_ENV"
148150
149151
# Explicit override: useful for tag workflows where multiple branches may contain the tag.
150152
BRANCH="${INPUT_BRANCH:-}"
@@ -302,12 +304,13 @@ runs:
302304
git -c commit.gpgsign=false commit -m 'Add README.md'
303305
# Push with auth via checkout action's token/remote config.
304306
# If another concurrent run creates 'coverage' first, treat that as success.
305-
if git push origin coverage; then
307+
COVERAGE_HEAD="$(git rev-parse HEAD)"
308+
if git -C "$GITCOVERAGE_REPO_ROOT" push origin "${COVERAGE_HEAD}:refs/heads/coverage"; then
306309
echo "Created 'coverage' branch."
307310
else
308311
echo "Initial push failed; checking whether 'coverage' was created concurrently..."
309-
git fetch origin +refs/heads/coverage:refs/remotes/origin/coverage >/dev/null 2>&1 || true
310-
if git ls-remote --exit-code --heads origin coverage >/dev/null 2>&1; then
312+
git -C "$GITCOVERAGE_REPO_ROOT" fetch origin +refs/heads/coverage:refs/remotes/origin/coverage >/dev/null 2>&1 || true
313+
if git -C "$GITCOVERAGE_REPO_ROOT" ls-remote --exit-code --heads origin coverage >/dev/null 2>&1; then
311314
echo "'coverage' branch was created by another run."
312315
else
313316
echo "Failed to create 'coverage' branch." >&2
@@ -321,7 +324,7 @@ runs:
321324
fi
322325
323326
# Ensure local remote-tracking ref exists (actions/checkout often fetches only one branch).
324-
if ! git fetch --no-tags origin +refs/heads/coverage:refs/remotes/origin/coverage; then
327+
if ! git -C "$GITCOVERAGE_REPO_ROOT" fetch --no-tags origin +refs/heads/coverage:refs/remotes/origin/coverage; then
325328
echo "Failed to fetch refs/remotes/origin/coverage." >&2
326329
exit 1
327330
fi
@@ -536,7 +539,8 @@ runs:
536539
max_attempts=5
537540
attempt=1
538541
while true; do
539-
if git push origin HEAD:coverage; then
542+
WORKTREE_HEAD="$(git rev-parse HEAD)"
543+
if git -C "$GITCOVERAGE_REPO_ROOT" push origin "${WORKTREE_HEAD}:refs/heads/coverage"; then
540544
break
541545
fi
542546
@@ -546,7 +550,7 @@ runs:
546550
fi
547551
548552
echo "Push rejected (attempt ${attempt}/${max_attempts}). Rebasing onto latest origin/coverage..."
549-
git fetch origin +refs/heads/coverage:refs/remotes/origin/coverage
553+
git -C "$GITCOVERAGE_REPO_ROOT" fetch origin +refs/heads/coverage:refs/remotes/origin/coverage
550554
# Prefer this run's regenerated files if both runs touched the same paths.
551555
if ! git rebase -X theirs refs/remotes/origin/coverage; then
552556
git rebase --abort || true

0 commit comments

Comments
 (0)