-
Notifications
You must be signed in to change notification settings - Fork 14
fix(render): Scrub submodules from distgits #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmcilvaney
merged 3 commits into
microsoft:main
from
dmcilvaney:damcilva/fix_prep_src_git_submodules
Apr 30, 2026
+225
−6
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
165 changes: 165 additions & 0 deletions
165
internal/app/azldev/core/sources/sourceprep_internal_test.go
This file contains hidden or 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,165 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package sources | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| gogit "github.com/go-git/go-git/v5" | ||
| "github.com/go-git/go-git/v5/plumbing" | ||
| "github.com/go-git/go-git/v5/plumbing/filemode" | ||
| "github.com/go-git/go-git/v5/plumbing/format/index" | ||
| "github.com/go-git/go-git/v5/storage/memory" | ||
| "github.com/microsoft/azure-linux-dev-tools/internal/utils/fileperms" | ||
| "github.com/microsoft/azure-linux-dev-tools/internal/utils/fileutils" | ||
| "github.com/spf13/afero" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestRemoveSubmoduleEntries_StripsGitlinks(t *testing.T) { | ||
| const repoDir = "/fakerepo" | ||
|
|
||
| memFS := afero.NewMemMapFs() | ||
| storer := memory.NewStorage() | ||
|
|
||
| // Initialize a repo with in-memory storage only; this test exercises the | ||
| // index/storer and uses memFS separately for directory cleanup assertions. | ||
| repo, err := gogit.Init(storer, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Manually build an index with a normal file entry and a submodule entry. | ||
| idx := &index.Index{ | ||
| Version: 2, | ||
| Entries: []*index.Entry{ | ||
| { | ||
| Name: "regular-file.spec", | ||
| Mode: filemode.Regular, | ||
| Hash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
| }, | ||
| { | ||
| Name: "tests/at", | ||
| Mode: filemode.Submodule, | ||
| Hash: plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| require.NoError(t, storer.SetIndex(idx)) | ||
|
|
||
| // Create the empty directory that the bogus submodule leaves behind. | ||
| submoduleDir := filepath.Join(repoDir, "tests/at") | ||
| require.NoError(t, memFS.MkdirAll(submoduleDir, fileperms.PublicDir)) | ||
|
|
||
|
dmcilvaney marked this conversation as resolved.
|
||
| // Verify the directory exists before calling removeSubmoduleEntries. | ||
| dirExists, err := fileutils.Exists(memFS, submoduleDir) | ||
| require.NoError(t, err) | ||
| require.True(t, dirExists, "submodule directory should exist before removal") | ||
|
|
||
| // Act | ||
| err = removeSubmoduleEntries(memFS, repo, repoDir) | ||
| require.NoError(t, err) | ||
|
|
||
| // Assert: index should only have the regular file. | ||
| updatedIdx, err := storer.Index() | ||
| require.NoError(t, err) | ||
| require.Len(t, updatedIdx.Entries, 1) | ||
| assert.Equal(t, "regular-file.spec", updatedIdx.Entries[0].Name) | ||
| assert.Equal(t, filemode.Regular, updatedIdx.Entries[0].Mode) | ||
|
|
||
| // Assert: empty directory was removed. | ||
| dirExists, err = fileutils.Exists(memFS, submoduleDir) | ||
| require.NoError(t, err) | ||
| assert.False(t, dirExists, "submodule directory should be removed") | ||
| } | ||
|
|
||
| func TestRemoveSubmoduleEntries_NoOpWithoutSubmodules(t *testing.T) { | ||
| const repoDir = "/fakerepo" | ||
|
|
||
| memFS := afero.NewMemMapFs() | ||
| storer := memory.NewStorage() | ||
|
|
||
| repo, err := gogit.Init(storer, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Index with only normal entries. | ||
| idx := &index.Index{ | ||
| Version: 2, | ||
| Entries: []*index.Entry{ | ||
| { | ||
| Name: "file-a.spec", | ||
| Mode: filemode.Regular, | ||
| Hash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
| }, | ||
| { | ||
| Name: "file-b.patch", | ||
| Mode: filemode.Regular, | ||
| Hash: plumbing.NewHash("cccccccccccccccccccccccccccccccccccccccc"), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| require.NoError(t, storer.SetIndex(idx)) | ||
|
|
||
| err = removeSubmoduleEntries(memFS, repo, repoDir) | ||
| require.NoError(t, err) | ||
|
|
||
| // Index should be untouched. | ||
| updatedIdx, err := storer.Index() | ||
| require.NoError(t, err) | ||
| require.Len(t, updatedIdx.Entries, 2) | ||
| } | ||
|
|
||
| func TestRemoveSubmoduleEntries_PreservesNormalEntriesWithMixedModes(t *testing.T) { | ||
| const repoDir = "/fakerepo" | ||
|
|
||
| memFS := afero.NewMemMapFs() | ||
| storer := memory.NewStorage() | ||
|
|
||
| repo, err := gogit.Init(storer, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Mix of regular files, executable, and submodule entries. | ||
| idx := &index.Index{ | ||
| Version: 2, | ||
| Entries: []*index.Entry{ | ||
| { | ||
| Name: "build.sh", | ||
| Mode: filemode.Executable, | ||
| Hash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
| }, | ||
| { | ||
| Name: "tests/submod1", | ||
| Mode: filemode.Submodule, | ||
| Hash: plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), | ||
| }, | ||
| { | ||
| Name: "pkg.spec", | ||
| Mode: filemode.Regular, | ||
| Hash: plumbing.NewHash("cccccccccccccccccccccccccccccccccccccccc"), | ||
| }, | ||
| { | ||
| Name: "tests/submod2", | ||
| Mode: filemode.Submodule, | ||
| Hash: plumbing.NewHash("dddddddddddddddddddddddddddddddddddddddd"), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| require.NoError(t, storer.SetIndex(idx)) | ||
|
|
||
| // Create empty dirs for both submodules. | ||
| require.NoError(t, memFS.MkdirAll(filepath.Join(repoDir, "tests/submod1"), fileperms.PublicDir)) | ||
| require.NoError(t, memFS.MkdirAll(filepath.Join(repoDir, "tests/submod2"), fileperms.PublicDir)) | ||
|
|
||
| err = removeSubmoduleEntries(memFS, repo, repoDir) | ||
| require.NoError(t, err) | ||
|
|
||
| updatedIdx, err := storer.Index() | ||
| require.NoError(t, err) | ||
| require.Len(t, updatedIdx.Entries, 2) | ||
| assert.Equal(t, "build.sh", updatedIdx.Entries[0].Name) | ||
| assert.Equal(t, "pkg.spec", updatedIdx.Entries[1].Name) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.