Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include common example for fetching PR base-ref #213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -117,6 +117,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
- [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
- [Fetch pull request base-ref in addition to merge commit (for diffing)](#Fetch-pull-request-base-ref-in-addition-to-merge-commit-for-diffing)
- [Fetch all tags](#Fetch-all-tags)
- [Fetch all branches](#Fetch-all-branches)
- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches)
@@ -207,6 +208,15 @@ jobs:
- uses: actions/checkout@v2
```

## Fetch pull request base-ref in addition to merge commit (for diffing)

```yml
- uses: actions/checkout@v2
- name: Fetch base_ref HEAD
run: git fetch --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}}
Copy link
Author

@jasonkarns jasonkarns Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could actually be simplified to

git fetch --depth=1 origin +${{github.base_ref}}

or

git fetch --depth=1 origin +refs/heads/${{github.base_ref}}

since the destination is the conventional remote ref. But I'm unsure if there are any edge cases with that shortened form that users would encounter... (Then again, since this is supposed to be for "common scenarios", perhaps the short form is better?)

- run: git diff origin/${{github.base_ref}}..HEAD
```

## Fetch all tags

```yaml