Skip to content

Commit

Permalink
GitTools#1069 - add shallow clone check for gitversion execute
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Mar 11, 2024
1 parent 6e5f96b commit c2a2bfa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .azure/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:

steps:
- checkout: self
displayName: Checkout
fetchDepth: '0'
- pwsh: |
npm install
Expand Down
19 changes: 19 additions & 0 deletions docs/cloning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
In order for the gitversion to properly work you need to clone the repository with the entire history:

```yaml
# GitHub Actions syntax
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
```
```yaml
# Azure DevOps syntax
steps:
- checkout: self
displayName: Checkout
fetchDepth: '0'
```
2 changes: 1 addition & 1 deletion docs/examples/github/gitversion/setup/usage-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ In order for the gitversion to properly work you need to clone the repository wi
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
```
Expand Down
3 changes: 2 additions & 1 deletion src/core/dotnet-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ISetupSettings } from '../tools/common/models'

export interface IDotnetTool {
disableTelemetry(): void

toolInstall(toolName: string, versionRange: string, setupSettings: ISetupSettings): Promise<string>
}

Expand Down Expand Up @@ -54,7 +55,7 @@ export class DotnetTool implements IDotnetTool {
if (!this.versionManager.satisfies(version, versionRange, { includePrerelease: setupSettings.includePrerelease })) {
throw new Error(
`Version spec '${setupSettings.versionSpec}' resolved as '${version}' does not satisfy the range '${versionRange}'.` +
'Check https://raw.githubusercontent.com/GitTools/actions/main/docs/versions.md for more information'
'See https://raw.githubusercontent.com/GitTools/actions/main/docs/versions.md for more information.'
)
}

Expand Down
10 changes: 8 additions & 2 deletions src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
await this.toolInstall('GitVersion.Tool', '>=5.2.0 <6.1.0', setupSettings)
}

public run(options: GitVersionSettings): Promise<IExecResult> {
public async run(options: GitVersionSettings): Promise<IExecResult> {
const isShallowResult = await this.execute('git', ['rev-parse', '--is-shallow-repository'])
if (isShallowResult.code === 0 && isShallowResult.stdout.trim() === 'true') {
throw new Error(
'The repository is shallow. Consider disabling shallow clones. See https://raw.githubusercontent.com/GitTools/actions/main/docs/cloning.md for more information.'
)
}
const workDir = this.getRepoDir(options)

const args = this.getArguments(workDir, options)

return this.execute('dotnet-gitversion', args)
return await this.execute('dotnet-gitversion', args)
}

private getRepoDir(options: GitVersionSettings): string {
Expand Down

0 comments on commit c2a2bfa

Please sign in to comment.