Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ definitions:
example: master
ssh_key_id:
type: integer
pull_submodules:
type: boolean

Repository:
type: object
Expand All @@ -764,6 +766,8 @@ definitions:
example: master
ssh_key_id:
type: integer
pull_submodules:
type: boolean

Task:
type: object
Expand Down
1 change: 1 addition & 0 deletions db/Migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
13 changes: 7 additions & 6 deletions db/Repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zero value of bool in Go is false, so any code path that constructs a Repository struct without explicitly setting PullSubmodules (e.g. direct API calls, backup restore, or internal tooling) will silently disable submodule pulling. The database default of 1 only applies to rows inserted without that column, not to the application layer.

Consider whether the API handler that reads the request body into a Repository struct needs to default this field to true when it is absent from the JSON payload. A JSON omitempty tag would also prevent the frontend from explicitly sending false when unchecked. At minimum, this edge case is worth a comment.

PullSubmodules bool `db:"pull_submodules" json:"pull_submodules"`

SSHKey AccessKey `db:"-" json:"-" backup:"-"`
}
Expand Down
1 change: 1 addition & 0 deletions db/sql/migrations/v2.18.0.err.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table `project__repository` drop column `pull_submodules`;
Comment thread
stith marked this conversation as resolved.
1 change: 1 addition & 0 deletions db/sql/migrations/v2.18.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table `project__repository` add `pull_submodules` boolean not null DEFAULT true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues here:

  1. The column type is int but the Go struct field is bool. Other parts of the codebase use boolean (or tinyint(1)) for boolean columns, which maps more naturally to Go's bool. Change to:
alter table `project__repository` add `pull_submodules` boolean not null default true;
  1. The backtick syntax is MySQL-specific. Since db/Migration.go accepts a dialect parameter, the project likely supports multiple databases (e.g. PostgreSQL). Check whether this migration needs a PostgreSQL variant, or whether the project has a mechanism to handle dialect differences for migrations.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who are you

8 changes: 5 additions & 3 deletions db/sql/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions db_lib/CmdGitClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ func (c CmdGitClient) Clone(r GitRepository) error {
dirName = r.TmpDirName
}

if r.Repository.PullSubmodules {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Clone function now has two nearly identical c.run(...) calls that diverge only by the presence of --recursive. This is harder to maintain and easy to accidentally desync. The GoGitClient approach is better -- build the args list conditionally before calling run:

args := []string{"clone", "--branch", r.Repository.GitBranch, r.Repository.GetGitURL(false), dirName}
if r.Repository.PullSubmodules {
    args = append([]string{"clone", "--recursive", "--branch", r.Repository.GitBranch, r.Repository.GetGitURL(false), dirName}, []string{}...)
    // or build args slice and insert --recursive at position 1
}
return c.run(r, GitRepositoryTmpPath, args...)

A cleaner approach:

cloneArgs := []string{"clone"}
if r.Repository.PullSubmodules {
    cloneArgs = append(cloneArgs, "--recursive")
}
cloneArgs = append(cloneArgs, "--branch", r.Repository.GitBranch, r.Repository.GetGitURL(false), dirName)
return c.run(r, GitRepositoryTmpPath, cloneArgs...)

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),
Expand All @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions db_lib/GoGitClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor redundancy: RecurseSubmodules is set to git.DefaultSubmoduleRecursionDepth in the struct literal, then immediately overridden to git.NoRecurseSubmodules if !PullSubmodules. It reads more clearly to initialize it to git.NoRecurseSubmodules and only set the recursive depth when needed -- matching the pattern used in the Clone method above:

pullOpts := &git.PullOptions{
    RemoteName:        "origin",
    Auth:              authMethod,
    RecurseSubmodules: git.NoRecurseSubmodules,
}
if r.Repository.PullSubmodules {
    pullOpts.RecurseSubmodules = git.DefaultSubmoduleRecursionDepth
}

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
Expand Down
4 changes: 4 additions & 0 deletions web/public/swagger/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ definitions:
example: master
ssh_key_id:
type: integer
pull_submodules:
type: boolean

Repository:
type: object
Expand All @@ -764,6 +766,8 @@ definitions:
example: master
ssh_key_id:
type: integer
pull_submodules:
type: boolean

Task:
type: object
Expand Down
10 changes: 10 additions & 0 deletions web/src/components/RepositoryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
dense
></v-text-field>

<v-checkbox
v-model="item.pull_submodules"
:label="$t('pullSubmodules')"
v-if="item.git_url && type !== 'local'"
/>

<v-autocomplete
v-model="item.ssh_key_id"
:label="$t('accessKey')"
Expand Down Expand Up @@ -174,6 +180,10 @@ export default {
this.helpDialog = true;
},

getNewItem() {
Comment thread
stith marked this conversation as resolved.
return { pull_submodules: true };
},

getItemsUrl() {
return `/api/project/${this.projectId}/repositories`;
},
Expand Down
1 change: 1 addition & 0 deletions web/src/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default {
absPath: 'abs. path',
branch: 'Branch',
accessKey: 'Access Key',
pullSubmodules: 'Pull Submodules',
credentialsToAccessToTheGitRepositoryItShouldBe: 'Credentials to access to the Git repository. It should be:',
ifYouUseGitOrSshUrl: 'if you use Git or SSH URL.',
ifYouUseHttpsOrFileUrl: 'if you use HTTPS or file URL.',
Expand Down
Loading