Skip to content

Commit

Permalink
Detect merge commits (as in PRs) and switch to first parent if so
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfenner committed Sep 24, 2024
1 parent f89905d commit 0756232
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/render.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ jobs:
echo OUTPUT_FILENAME="${filename}" >> "$GITHUB_OUTPUT"
echo output filename: ${filename}
# For pull requests, check out the head ref of the source branch from the source repo.
- name: Checkout
if: inputs.workflow == 'pr'
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
fetch-tags: true
# For other workflows, check out the requested revision (which defaults to
# head of the default branch).
- name: Checkout
if: inputs.workflow != 'pr'
uses: actions/checkout@v4
Expand Down
11 changes: 11 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ fi
# figure out git version and revision if needed.
EXTRA_PANDOC_OPTIONS=""
if test "${DO_GITVERSION}" == "yes"; then
# If HEAD is a merge commit, go to the first parent.
if $(git rev-parse HEAD^2 >/dev/null 2>/dev/null); then
parent1=$(git rev-parse HEAD^1 2>/dev/null)
parent2=$(git rev-parse HEAD^2 2>/dev/null)
echo "Merge commit detected:"
echo "1: $parent1"
echo "2: $parent2"
echo "Checking out $parent1."
git checkout $parent1
fi

# TODO: Should we fail if dirty?
raw_version="$(git describe --always --tags)"
echo "Git version: ${raw_version}"
Expand Down

0 comments on commit 0756232

Please sign in to comment.