-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc7ff6c
commit 7229570
Showing
19 changed files
with
488 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package git | ||
|
||
// GetSubModules get all the submodules of current revision git tree | ||
func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error) { | ||
if c.submoduleCache != nil { | ||
return c.submoduleCache, nil | ||
} | ||
|
||
entry, err := c.GetTreeEntryByPath(".gitmodules") | ||
if err != nil { | ||
if _, ok := err.(ErrNotExist); ok { | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
|
||
rd, err := entry.Blob().DataAsync() | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer rd.Close() | ||
|
||
c.submoduleCache, err = configParseSubModules(rd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return c.submoduleCache, nil | ||
} | ||
|
||
// GetSubModule get the submodule according entry name | ||
func (c *Commit) GetSubModule(entryName string) (*SubModule, error) { | ||
modules, err := c.GetSubModules() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if modules != nil { | ||
if module, has := modules.Get(entryName); has { | ||
return module, nil | ||
} | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,7 @@ author KN4CK3R <[email protected]> 1711702962 +0100 | |
committer KN4CK3R <[email protected]> 1711702962 +0100 | ||
encoding ISO-8859-1 | ||
gpgsig -----BEGIN PGP SIGNATURE----- | ||
iQGzBAABCgAdFiEE9HRrbqvYxPT8PXbefPSEkrowAa8FAmYGg7IACgkQfPSEkrow | ||
Aa9olwv+P0HhtCM6CRvlUmPaqswRsDPNR4i66xyXGiSxdI9V5oJL7HLiQIM7KrFR | ||
gizKa2COiGtugv8fE+TKqXKaJx6uJUJEjaBd8E9Af9PrAzjWj+A84lU6/PgPS8hq | ||
|
@@ -362,48 +362,3 @@ func Test_GetCommitBranchStart(t *testing.T) { | |
assert.NotEmpty(t, startCommitID) | ||
assert.EqualValues(t, "9c9aef8dd84e02bc7ec12641deb4c930a7c30185", startCommitID) | ||
} | ||
|
||
func Test_parseSubmoduleContent(t *testing.T) { | ||
submoduleFiles := []struct { | ||
fileContent string | ||
expectedPath string | ||
expectedURL string | ||
expectedBranch string | ||
}{ | ||
{ | ||
fileContent: `[submodule "jakarta-servlet"] | ||
url = ../../ALP-pool/jakarta-servlet | ||
path = jakarta-servlet`, | ||
expectedPath: "jakarta-servlet", | ||
expectedURL: "../../ALP-pool/jakarta-servlet", | ||
expectedBranch: "", | ||
}, | ||
{ | ||
fileContent: `[submodule "jakarta-servlet"] | ||
path = jakarta-servlet | ||
url = ../../ALP-pool/jakarta-servlet`, | ||
expectedPath: "jakarta-servlet", | ||
expectedURL: "../../ALP-pool/jakarta-servlet", | ||
expectedBranch: "", | ||
}, | ||
{ | ||
fileContent: `[submodule "jakarta-servlet"] | ||
path = jakarta-servlet | ||
url = ../../ALP-pool/jakarta-servlet | ||
branch = stable`, | ||
expectedPath: "jakarta-servlet", | ||
expectedURL: "../../ALP-pool/jakarta-servlet", | ||
expectedBranch: "stable", | ||
}, | ||
} | ||
for _, kase := range submoduleFiles { | ||
submodule, err := parseSubmoduleContent(strings.NewReader(kase.fileContent)) | ||
assert.NoError(t, err) | ||
v, ok := submodule.Get(kase.expectedPath) | ||
assert.True(t, ok) | ||
subModule := v.(*SubModule) | ||
assert.Equal(t, kase.expectedPath, subModule.Path) | ||
assert.Equal(t, kase.expectedURL, subModule.URL) | ||
assert.Equal(t, kase.expectedBranch, subModule.Branch) | ||
} | ||
} |
Oops, something went wrong.