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 1 commit
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
Next Next commit
Include common example for fetching PR base-ref
Since this seems to be a common scenario and is generating a lot of discussion (#93), it seems worthwhile to add it to the readme as an example.

I placed it before the other fetch examples because this use-case still only fetches minimal history (only adding one additional ref); so it seems helpful to place this above the other fetch examples which all do deeper fetches.
  • Loading branch information
jasonkarns authored Apr 9, 2020
commit 11d9aa95eb60f32a2ec2e21ded0a02a810204f5c
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -112,15 +112,18 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous

- [Checkout a different branch](#Checkout-a-different-branch)
- [Checkout HEAD^](#Checkout-HEAD)

- [Checkout multiple repos (side by side)](#Checkout-multiple-repos-side-by-side)
- [Checkout multiple repos (nested)](#Checkout-multiple-repos-nested)
- [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)


## Checkout a different branch

```yaml
@@ -207,6 +210,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