diff --git a/api-docs.yml b/api-docs.yml index 1ea8ebe67..ea5ec241f 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -745,6 +745,8 @@ definitions: example: master ssh_key_id: type: integer + pull_submodules: + type: boolean Repository: type: object @@ -764,6 +766,8 @@ definitions: example: master ssh_key_id: type: integer + pull_submodules: + type: boolean Task: type: object diff --git a/db/Migration.go b/db/Migration.go index d8fdcb95c..644e8fbd1 100644 --- a/db/Migration.go +++ b/db/Migration.go @@ -121,6 +121,7 @@ func GetMigrations(dialect string) []Migration { {Version: "2.17.2"}, {Version: "2.17.15"}, {Version: "2.17.16"}, + {Version: "2.18.0"}, } return append(initScripts, commonScripts...) diff --git a/db/Repository.go b/db/Repository.go index 9d41885e4..e3e987747 100644 --- a/db/Repository.go +++ b/db/Repository.go @@ -22,12 +22,13 @@ const ( // Repository is the model for code stored in a git repository type Repository struct { - ID int `db:"id" json:"id" backup:"-"` - Name string `db:"name" json:"name" binding:"required"` - ProjectID int `db:"project_id" json:"project_id" backup:"-"` - GitURL string `db:"git_url" json:"git_url" binding:"required"` - GitBranch string `db:"git_branch" json:"git_branch" binding:"required"` - SSHKeyID int `db:"ssh_key_id" json:"ssh_key_id" binding:"required" backup:"-"` + ID int `db:"id" json:"id" backup:"-"` + Name string `db:"name" json:"name" binding:"required"` + ProjectID int `db:"project_id" json:"project_id" backup:"-"` + GitURL string `db:"git_url" json:"git_url" binding:"required"` + GitBranch string `db:"git_branch" json:"git_branch" binding:"required"` + SSHKeyID int `db:"ssh_key_id" json:"ssh_key_id" binding:"required" backup:"-"` + PullSubmodules bool `db:"pull_submodules" json:"pull_submodules"` SSHKey AccessKey `db:"-" json:"-" backup:"-"` } diff --git a/db/sql/migrations/v2.18.0.err.sql b/db/sql/migrations/v2.18.0.err.sql new file mode 100644 index 000000000..6279b96e8 --- /dev/null +++ b/db/sql/migrations/v2.18.0.err.sql @@ -0,0 +1 @@ +alter table `project__repository` drop column `pull_submodules`; diff --git a/db/sql/migrations/v2.18.0.sql b/db/sql/migrations/v2.18.0.sql new file mode 100644 index 000000000..cb4b8abdf --- /dev/null +++ b/db/sql/migrations/v2.18.0.sql @@ -0,0 +1 @@ +alter table `project__repository` add `pull_submodules` boolean not null DEFAULT true; diff --git a/db/sql/repository.go b/db/sql/repository.go index 1c2ed5247..fca1b2253 100644 --- a/db/sql/repository.go +++ b/db/sql/repository.go @@ -63,11 +63,12 @@ func (d *SqlDb) UpdateRepository(repository db.Repository) error { } _, err = d.exec( - "update project__repository set name=?, git_url=?, git_branch=?, ssh_key_id=? where id=?", + "update project__repository set name=?, git_url=?, git_branch=?, ssh_key_id=?, pull_submodules=? where id=?", repository.Name, repository.GitURL, repository.GitBranch, repository.SSHKeyID, + repository.PullSubmodules, repository.ID) return err @@ -82,12 +83,13 @@ func (d *SqlDb) CreateRepository(repository db.Repository) (newRepo db.Repositor insertID, err := d.insert( "id", - "insert into project__repository(project_id, git_url, git_branch, ssh_key_id, name) values (?, ?, ?, ?, ?)", + "insert into project__repository(project_id, git_url, git_branch, ssh_key_id, name, pull_submodules) values (?, ?, ?, ?, ?, ?)", repository.ProjectID, repository.GitURL, repository.GitBranch, repository.SSHKeyID, - repository.Name) + repository.Name, + repository.PullSubmodules) if err != nil { return diff --git a/db_lib/CmdGitClient.go b/db_lib/CmdGitClient.go index ef8561c37..0162398f0 100644 --- a/db_lib/CmdGitClient.go +++ b/db_lib/CmdGitClient.go @@ -100,9 +100,17 @@ func (c CmdGitClient) Clone(r GitRepository) error { dirName = r.TmpDirName } + if r.Repository.PullSubmodules { + return c.run(r, GitRepositoryTmpPath, + "clone", + "--recursive", + "--branch", + r.Repository.GitBranch, + r.Repository.GetGitURL(false), + dirName) + } return c.run(r, GitRepositoryTmpPath, "clone", - "--recursive", "--branch", r.Repository.GitBranch, r.Repository.GetGitURL(false), @@ -116,7 +124,11 @@ func (c CmdGitClient) Pull(r GitRepository) error { if err != nil { return err } - return c.run(r, GitRepositoryFullPath, "submodule", "update", "--init", "--recursive") + + if r.Repository.PullSubmodules { + return c.run(r, GitRepositoryFullPath, "submodule", "update", "--init", "--recursive") + } + return nil } func (c CmdGitClient) Checkout(r GitRepository, target string) error { diff --git a/db_lib/GoGitClient.go b/db_lib/GoGitClient.go index cb4c29400..b1ac71c4f 100644 --- a/db_lib/GoGitClient.go +++ b/db_lib/GoGitClient.go @@ -102,10 +102,15 @@ func (c GoGitClient) Clone(r GitRepository) error { return authErr } + submoduleDepth := git.DefaultSubmoduleRecursionDepth + if !r.Repository.PullSubmodules { + submoduleDepth = git.NoRecurseSubmodules + } + cloneOpt := &git.CloneOptions{ URL: r.Repository.GetGitURL(true), Progress: ProgressWrapper{r.Logger}, - RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, + RecurseSubmodules: submoduleDepth, ReferenceName: plumbing.NewBranchReferenceName(r.Repository.GitBranch), Auth: authMethod, } @@ -137,9 +142,16 @@ func (c GoGitClient) Pull(r GitRepository) error { } // Pull the latest changes from the origin remote and merge into the current branch - err = wt.Pull(&git.PullOptions{RemoteName: "origin", + pullOpts := &git.PullOptions{ + RemoteName: "origin", Auth: authMethod, - RecurseSubmodules: git.DefaultSubmoduleRecursionDepth}) + RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, + } + if !r.Repository.PullSubmodules { + pullOpts.RecurseSubmodules = git.NoRecurseSubmodules + } + + err = wt.Pull(pullOpts) if err != nil && err != git.NoErrAlreadyUpToDate { r.Logger.Log("Unable to pull latest changes") return err diff --git a/web/public/swagger/api-docs.yml b/web/public/swagger/api-docs.yml index 38821a89a..43900c469 100644 --- a/web/public/swagger/api-docs.yml +++ b/web/public/swagger/api-docs.yml @@ -745,6 +745,8 @@ definitions: example: master ssh_key_id: type: integer + pull_submodules: + type: boolean Repository: type: object @@ -764,6 +766,8 @@ definitions: example: master ssh_key_id: type: integer + pull_submodules: + type: boolean Task: type: object diff --git a/web/src/components/RepositoryForm.vue b/web/src/components/RepositoryForm.vue index 8988397fc..ad9273baa 100644 --- a/web/src/components/RepositoryForm.vue +++ b/web/src/components/RepositoryForm.vue @@ -69,6 +69,12 @@ dense > + +