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

Clone ref if ref setting is set #117

Merged
merged 10 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 1 addition & 2 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ clone:
| `home` | | Change HOME var for commands executed, fail if it does not exist |
| `remote` | $CI_REPO_CLONE_URL | Set the git remote url |
| `remote-ssh` | $CI_REPO_CLONE_SSH_URL | Set the git SSH remote url |
| `sha` | $CI_COMMIT_SHA | git commit hash to retrieve (use `sha: ''` to clone the `ref`) |
| `ref` | $CI_COMMIT_REF | Set the git reference to retrieve (use `ref: refs/heads/a_branch` and `sha: ''` to retrieve the head commit from the "a_branch" branch) |
| `ref` | _none_ | Set the git reference to retrieve |
| `path` | $CI_WORKSPACE | Set destination path to clone to |
| `use-ssh` | `false` | Clone using SSH |
| `ssh-key` | _none_ | SSH key for SSH clone |
Expand Down
5 changes: 2 additions & 3 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ var globalFlags = []cli.Flag{
&cli.StringFlag{
Name: "sha",
Usage: "git commit sha",
EnvVars: []string{"PLUGIN_SHA", "CI_COMMIT_SHA"},
EnvVars: []string{"CI_COMMIT_SHA"},
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
},
&cli.StringFlag{
Name: "ref",
Value: "refs/heads/master",
Usage: "git commit ref",
EnvVars: []string{"PLUGIN_REF", "CI_COMMIT_REF"},
EnvVars: []string{"PLUGIN_REF"},
},
&cli.StringFlag{
Name: "event",
Expand Down
4 changes: 2 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func (p Plugin) Exec() error {

}

if p.Pipeline.Commit == "" {
if p.Pipeline.Ref != "" {
// fetch and checkout by ref
fmt.Println("no commit information: using head checkout")
fmt.Println("using head checkout")
cmds = append(cmds, fetch(p.Pipeline.Ref, p.Config.Tags, p.Config.Depth, p.Config.filter))
cmds = append(cmds, checkoutHead())
} else {
Expand Down
16 changes: 8 additions & 8 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var commits = []struct {
event: "push",
branch: "master",
commit: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
ref: "refs/heads/master",
ref: "",
file: "README",
data: "Hello World!",
},
Expand All @@ -39,7 +39,7 @@ var commits = []struct {
event: "push",
branch: "master",
commit: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
ref: "refs/heads/master",
ref: "",
file: "README",
data: "Hello World!\n",
},
Expand All @@ -50,7 +50,7 @@ var commits = []struct {
event: "pull_request",
branch: "master",
commit: "762941318ee16e59dabbacb1b4049eec22f0d303",
ref: "refs/pull/6/merge",
ref: "",
file: "README",
data: "Hello World!\n",
},
Expand All @@ -61,7 +61,7 @@ var commits = []struct {
event: "push",
branch: "test",
commit: "b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf",
ref: "refs/heads/test",
ref: "",
file: "CONTRIBUTING.md",
data: "## Contributing\n",
},
Expand All @@ -72,7 +72,7 @@ var commits = []struct {
event: "tag",
branch: "master",
commit: "bf68d60215a167c935bc5976b7d06a7ffb290926",
ref: "refs/tags/v1.17",
ref: "",
file: ".gitignore",
data: "*.swp\n*~\n.rake_tasks~\nhtml\ndoc\npkg\npublish\ncoverage\n",
},
Expand All @@ -83,7 +83,7 @@ var commits = []struct {
event: "push",
branch: "main",
commit: "cc020eb6aaa601c13ca7b0d5db9d1ca694e7a003",
ref: "refs/heads/main",
ref: "",
file: "Hello-World/README",
data: "Hello World!\n",
recursive: true,
Expand All @@ -105,7 +105,7 @@ var commits = []struct {
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
event: "push",
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
ref: "refs/heads/main",
ref: "",
file: "4M.bin",
dataSize: 132,
},
Expand All @@ -115,7 +115,7 @@ var commits = []struct {
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
event: "push",
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
ref: "refs/heads/main",
ref: "",
file: "4M.bin",
dataSize: 4194304,
lfs: true,
Expand Down