Skip to content

Commit 0918e75

Browse files
committed
fix
1 parent 8e2e491 commit 0918e75

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

modules/git/submodule.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import (
99
"code.gitea.io/gitea/modules/log"
1010
)
1111

12-
// SubModuleCommit submodule name and commit from a repository
13-
type SubModuleCommit struct {
12+
type TemplateSubmoduleCommit struct {
1413
Path string
1514
Commit string
1615
}
1716

18-
// GetSubmoduleCommits returns a list of submodules paths and their commits from a repository
17+
// GetTemplateSubmoduleCommits returns a list of submodules paths and their commits from a repository
1918
// This function is only for generating new repos based on existing template, the template couldn't be too large.
20-
func GetSubmoduleCommits(ctx context.Context, repoPath string) (submoduleCommits []SubModuleCommit, _ error) {
19+
func GetTemplateSubmoduleCommits(ctx context.Context, repoPath string) (submoduleCommits []TemplateSubmoduleCommit, _ error) {
2120
stdoutReader, stdoutWriter, err := os.Pipe()
2221
if err != nil {
2322
return nil, err
@@ -37,21 +36,22 @@ func GetSubmoduleCommits(ctx context.Context, repoPath string) (submoduleCommits
3736
return err
3837
}
3938
if entry.IsSubModule() {
40-
submoduleCommits = append(submoduleCommits, SubModuleCommit{Path: entry.Name(), Commit: entry.ID.String()})
39+
submoduleCommits = append(submoduleCommits, TemplateSubmoduleCommit{Path: entry.Name(), Commit: entry.ID.String()})
4140
}
4241
}
4342
return scanner.Err()
4443
},
4544
}
4645
err = NewCommand(ctx, "ls-tree", "-r", "--", "HEAD").Run(opts)
4746
if err != nil {
48-
return nil, fmt.Errorf("GetSubmoduleCommits: error running git ls-tree: %v", err)
47+
return nil, fmt.Errorf("GetTemplateSubmoduleCommits: error running git ls-tree: %v", err)
4948
}
5049
return submoduleCommits, nil
5150
}
5251

53-
// AddSubmoduleIndexes Adds the given submodules to the git index. Requires the .gitmodules file to be already present.
54-
func AddSubmoduleIndexes(ctx context.Context, repoPath string, submodules []SubModuleCommit) error {
52+
// AddTemplateSubmoduleIndexes Adds the given submodules to the git index.
53+
// It is only for generating new repos based on existing template, requires the .gitmodules file to be already present in the work dir.
54+
func AddTemplateSubmoduleIndexes(ctx context.Context, repoPath string, submodules []TemplateSubmoduleCommit) error {
5555
for _, submodule := range submodules {
5656
cmd := NewCommand(ctx, "update-index", "--add", "--cacheinfo", "160000").AddDynamicArguments(submodule.Commit, submodule.Path)
5757
if stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath}); err != nil {

modules/git/submodule_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestRepository_GetSubmoduleCommits(t *testing.T) {
1212
testRepoPath := filepath.Join(testReposDir, "repo4_submodules")
13-
submodules, err := GetSubmoduleCommits(DefaultContext, testRepoPath)
13+
submodules, err := GetTemplateSubmoduleCommits(DefaultContext, testRepoPath)
1414
require.NoError(t, err)
1515

1616
assert.EqualValues(t, len(submodules), 2)

services/repository/generate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
210210
}
211211

212212
// Get active submodules from the template
213-
submodules, err := git.GetSubmoduleCommits(ctx, tmpDir)
213+
submodules, err := git.GetTemplateSubmoduleCommits(ctx, tmpDir)
214214
if err != nil {
215-
return fmt.Errorf("GetSubmoduleCommits: %w", err)
215+
return fmt.Errorf("GetTemplateSubmoduleCommits: %w", err)
216216
}
217217

218218
if err = util.RemoveAll(filepath.Join(tmpDir, ".git")); err != nil {
@@ -242,7 +242,7 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
242242
return fmt.Errorf("git remote add: %w", err)
243243
}
244244

245-
if err = git.AddSubmoduleIndexes(ctx, tmpDir, submodules); err != nil {
245+
if err = git.AddTemplateSubmoduleIndexes(ctx, tmpDir, submodules); err != nil {
246246
return fmt.Errorf("failed to add submodules: %v", err)
247247
}
248248

templates/repo/view_list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
{{svg "octicon-file-submodule"}}
2020
{{$refURL := $subModuleFile.RefURL AppUrl $.Repository.FullName $.SSHDomain}} {{/* FIXME: the usage of AppUrl seems incorrect, it would be fixed in the future, use AppSubUrl instead */}}
2121
{{if $refURL}}
22-
<a class="muted" href="{{$refURL}}">{{$entry.Name}}</a><span class="at">@</span><a href="{{$refURL}}/commit/{{PathEscape $subModuleFile.RefID}}">{{ShortSha $subModuleFile.RefID}}</a>
22+
<a class="muted" href="{{$refURL}}">{{$entry.Name}}</a> <span class="at">@</span> <a href="{{$refURL}}/commit/{{PathEscape $subModuleFile.RefID}}">{{ShortSha $subModuleFile.RefID}}</a>
2323
{{else}}
24-
{{$entry.Name}}<span class="at">@</span>{{ShortSha $subModuleFile.RefID}}
24+
{{$entry.Name}} <span class="at">@</span> {{ShortSha $subModuleFile.RefID}}
2525
{{end}}
2626
{{else}}
2727
{{if $entry.IsDir}}

0 commit comments

Comments
 (0)