Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: actions/checkout
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.1
Choose a base ref
...
head repository: actions/checkout
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.2.0
Choose a head ref
  • 5 commits
  • 11 files changed
  • 2 contributors

Commits on May 19, 2020

  1. Copy the full SHA
    97b30c4 View commit details

Commits on May 20, 2020

  1. fix readme (#251)

    ericsciple authored May 20, 2020
    Copy the full SHA
    df86c82 View commit details

Commits on May 21, 2020

  1. Copy the full SHA
    2ff2fbd View commit details

Commits on May 27, 2020

  1. Copy the full SHA
    e52d022 View commit details
  2. changelog

    ericsciple committed May 27, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aabbfeb View commit details
Showing with 561 additions and 95 deletions.
  1. +3 −0 CHANGELOG.md
  2. +10 −27 README.md
  3. +2 −0 __test__/git-auth-helper.test.ts
  4. +72 −18 __test__/git-directory-helper.test.ts
  5. +1 −1 adrs/0153-checkout-v2.md
  6. +211 −22 dist/index.js
  7. +2 −2 package.json
  8. +33 −15 src/git-command-manager.ts
  9. +22 −6 src/git-directory-helper.ts
  10. +31 −4 src/git-source-provider.ts
  11. +174 −0 src/ref-helper.ts
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v2.2.0
- [Fetch all history for all tags and branches when fetch-depth=0](https://github.com/actions/checkout/pull/258)

## v2.1.1
- Changes to support GHES ([here](https://github.com/actions/checkout/pull/236) and [here](https://github.com/actions/checkout/pull/248))

37 changes: 10 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.

Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set `fetch-depth` to fetch more history. Refer [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn which commit `$GITHUB_SHA` points to for different events.
Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set `fetch-depth: 0` to fetch all history for all branches and tags. Refer [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn which commit `$GITHUB_SHA` points to for different events.

The auth token is persisted in the local git config. This enables your scripts to run authenticated git commands. The token is removed during post-job cleanup. Set `persist-credentials: false` to opt-out.

@@ -110,16 +110,22 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
# Scenarios
- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches)
- [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 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)
## Fetch all history for all tags and branches
```yaml
- uses: actions/checkout@v2
with:
fetch-depth: 0
```
## Checkout a different branch
@@ -207,29 +213,6 @@ jobs:
- uses: actions/checkout@v2
```

## Fetch all tags

```yaml
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
```

## Fetch all branches

```yaml
- uses: actions/checkout@v2
- run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
```

## Fetch all history for all tags and branches

```yaml
- uses: actions/checkout@v2
- run: |
git fetch --prune --unshallow
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
2 changes: 2 additions & 0 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
@@ -722,9 +722,11 @@ async function setup(testName: string): Promise<void> {
log1: jest.fn(),
remoteAdd: jest.fn(),
removeEnvironmentVariable: jest.fn((name: string) => delete git.env[name]),
revParse: jest.fn(),
setEnvironmentVariable: jest.fn((name: string, value: string) => {
git.env[name] = value
}),
shaExists: jest.fn(),
submoduleForeach: jest.fn(async () => {
return ''
}),
90 changes: 72 additions & 18 deletions __test__/git-directory-helper.test.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
let repositoryPath: string
let repositoryUrl: string
let clean: boolean
let ref: string
let git: IGitCommandManager

describe('git-directory-helper tests', () => {
@@ -41,7 +42,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -63,7 +65,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -88,7 +91,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -109,7 +113,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -137,7 +142,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -163,7 +169,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
differentRepositoryUrl,
clean
clean,
ref
)

// Assert
@@ -187,7 +194,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -212,7 +220,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -236,7 +245,8 @@ describe('git-directory-helper tests', () => {
undefined,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -260,7 +270,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -290,7 +301,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
@@ -305,29 +317,66 @@ describe('git-directory-helper tests', () => {
expect(git.tryReset).not.toHaveBeenCalled()
})

const removesRemoteBranches = 'removes local branches'
it(removesRemoteBranches, async () => {
const removesAncestorRemoteBranch = 'removes ancestor remote branch'
it(removesAncestorRemoteBranch, async () => {
// Arrange
await setup(removesRemoteBranches)
await setup(removesAncestorRemoteBranch)
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
const mockBranchList = git.branchList as jest.Mock<any, any>
mockBranchList.mockImplementation(async (remote: boolean) => {
return remote ? ['remote-branch-1', 'remote-branch-2'] : []
return remote ? ['origin/remote-branch-1', 'origin/remote-branch-2'] : []
})
ref = 'remote-branch-1/conflict'

// Act
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
repositoryUrl,
clean
clean,
ref
)

// Assert
const files = await fs.promises.readdir(repositoryPath)
expect(files.sort()).toEqual(['.git', 'my-file'])
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1')
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2')
expect(git.branchDelete).toHaveBeenCalledTimes(1)
expect(git.branchDelete).toHaveBeenCalledWith(
true,
'origin/remote-branch-1'
)
})

const removesDescendantRemoteBranches = 'removes descendant remote branch'
it(removesDescendantRemoteBranches, async () => {
// Arrange
await setup(removesDescendantRemoteBranches)
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
const mockBranchList = git.branchList as jest.Mock<any, any>
mockBranchList.mockImplementation(async (remote: boolean) => {
return remote
? ['origin/remote-branch-1/conflict', 'origin/remote-branch-2']
: []
})
ref = 'remote-branch-1'

// Act
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
repositoryUrl,
clean,
ref
)

// Assert
const files = await fs.promises.readdir(repositoryPath)
expect(files.sort()).toEqual(['.git', 'my-file'])
expect(git.branchDelete).toHaveBeenCalledTimes(1)
expect(git.branchDelete).toHaveBeenCalledWith(
true,
'origin/remote-branch-1/conflict'
)
})
})

@@ -344,6 +393,9 @@ async function setup(testName: string): Promise<void> {
// Clean
clean = true

// Ref
ref = ''

// Git command manager
git = {
branchDelete: jest.fn(),
@@ -364,7 +416,9 @@ async function setup(testName: string): Promise<void> {
log1: jest.fn(),
remoteAdd: jest.fn(),
removeEnvironmentVariable: jest.fn(),
revParse: jest.fn(),
setEnvironmentVariable: jest.fn(),
shaExists: jest.fn(),
submoduleForeach: jest.fn(),
submoduleSync: jest.fn(),
submoduleUpdate: jest.fn(),
2 changes: 1 addition & 1 deletion adrs/0153-checkout-v2.md
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
default: true
fetch-depth:
description: 'Number of commits to fetch. 0 indicates all history.'
description: 'Number of commits to fetch. 0 indicates all history for all tags and branches.'
default: 1
lfs:
description: 'Whether to download Git-LFS files'
Loading