mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 23:28:17 +00:00
Implemented a function for developers to specify the --depth
option of
the `git clone` command. refs #55
This commit is contained in:
22
pkg/build/git/git.go
Normal file
22
pkg/build/git/git.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package git
|
||||
|
||||
const (
|
||||
DefaultGitDepth = 50
|
||||
)
|
||||
|
||||
// Git stores the configuration details for
|
||||
// executing Git commands.
|
||||
type Git struct {
|
||||
Depth *int `yaml:"depth,omitempty"`
|
||||
}
|
||||
|
||||
// GitDepth returns GitDefaultDepth
|
||||
// when Git.Depth is empty.
|
||||
// GitDepth returns Git.Depth
|
||||
// when it is not empty.
|
||||
func GitDepth(g *Git) int {
|
||||
if g == nil || g.Depth == nil {
|
||||
return DefaultGitDepth
|
||||
}
|
||||
return *g.Depth
|
||||
}
|
40
pkg/build/git/git_test.go
Normal file
40
pkg/build/git/git_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGitDepth(t *testing.T) {
|
||||
var g *Git
|
||||
var expected int
|
||||
|
||||
expected = DefaultGitDepth
|
||||
g = nil
|
||||
if actual := GitDepth(g); actual != expected {
|
||||
t.Errorf("The result is invalid. [expected: %d][actual: %d]", expected, actual)
|
||||
}
|
||||
|
||||
expected = DefaultGitDepth
|
||||
g = &Git{}
|
||||
if actual := GitDepth(g); actual != expected {
|
||||
t.Errorf("The result is invalid. [expected: %d][actual: %d]", expected, actual)
|
||||
}
|
||||
|
||||
expected = DefaultGitDepth
|
||||
g = &Git{Depth: nil}
|
||||
if actual := GitDepth(g); actual != expected {
|
||||
t.Errorf("The result is invalid. [expected: %d][actual: %d]", expected, actual)
|
||||
}
|
||||
|
||||
expected = 0
|
||||
g = &Git{Depth: &expected}
|
||||
if actual := GitDepth(g); actual != expected {
|
||||
t.Errorf("The result is invalid. [expected: %d][actual: %d]", expected, actual)
|
||||
}
|
||||
|
||||
expected = 1
|
||||
g = &Git{Depth: &expected}
|
||||
if actual := GitDepth(g); actual != expected {
|
||||
t.Errorf("The result is invalid. [expected: %d][actual: %d]", expected, actual)
|
||||
}
|
||||
}
|
@@ -33,6 +33,9 @@ type Repo struct {
|
||||
// will be cloned into (or copied to) inside the
|
||||
// host system (Docker Container).
|
||||
Dir string
|
||||
|
||||
// (optional) The depth of the `git clone` command.
|
||||
Depth int
|
||||
}
|
||||
|
||||
// IsRemote returns true if the Repository is located
|
||||
@@ -88,7 +91,6 @@ func (r *Repo) IsGit() bool {
|
||||
//
|
||||
// TODO we should also enable Mercurial projects and SVN projects
|
||||
func (r *Repo) Commands() []string {
|
||||
|
||||
// get the branch. default to master
|
||||
// if no branch exists.
|
||||
branch := r.Branch
|
||||
@@ -97,7 +99,7 @@ func (r *Repo) Commands() []string {
|
||||
}
|
||||
|
||||
cmds := []string{}
|
||||
cmds = append(cmds, fmt.Sprintf("git clone --recursive --branch=%s %s %s", branch, r.Path, r.Dir))
|
||||
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive --branch=%s %s %s", r.Depth, branch, r.Path, r.Dir))
|
||||
|
||||
switch {
|
||||
// if a specific commit is provided then we'll
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"launchpad.net/goyaml"
|
||||
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
"github.com/drone/drone/pkg/build/git"
|
||||
"github.com/drone/drone/pkg/plugin/deploy"
|
||||
"github.com/drone/drone/pkg/plugin/notify"
|
||||
"github.com/drone/drone/pkg/plugin/publish"
|
||||
@@ -54,6 +55,7 @@ type Build struct {
|
||||
Deploy *deploy.Deploy `yaml:"deploy,omitempty"`
|
||||
Publish *publish.Publish `yaml:"publish,omitempty"`
|
||||
Notifications *notify.Notification `yaml:"notify,omitempty"`
|
||||
Git *git.Git `yaml:"git,omitempty"`
|
||||
}
|
||||
|
||||
// Write adds all the steps to the build script, including
|
||||
|
Reference in New Issue
Block a user