Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tdstein/rename
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Sep 13, 2023
2 parents 0b9dc41 + d1395ff commit 561bfad
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 12 deletions.
10 changes: 8 additions & 2 deletions internal/bundles/gitignore/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,14 @@ func (ign *GitIgnoreList) match(path string, info os.FileInfo) *Match {

// Match returns whether any of the globs in the ignore list match the
// specified path. Uses the same matching rules as .gitignore files.
func (ign *GitIgnoreList) Match(path string) *Match {
return ign.match(path, nil)
func (ign *GitIgnoreList) Match(path string) (*Match, error) {
stat, err := ign.fs.Stat(path)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
}
return ign.match(path, stat), nil
}

// Walk walks the file tree with the specified root and calls fn on each file
Expand Down
23 changes: 20 additions & 3 deletions internal/bundles/gitignore/gitignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,39 @@ func (s *GitIgnoreSuite) TestMatch() {
s.NoError(err)

// Match returns nil if no match
m := ign.Match("app.py")
m, err := ign.Match("app.py")
s.NoError(err)
s.Nil(m)

// File matches include file info
m = ign.Match(".Rhistory")
m, err = ign.Match(".Rhistory")
s.NoError(err)
s.NotNil(m)
s.Equal(MatchSourceFile, m.Source)
s.Equal(".Rhistory", m.Pattern)
s.Equal(gitignorePath.Path(), m.FilePath)
s.Equal(1, m.Line)

// Non-file matches don't include file info
m = ign.Match("app.py.bak")
m, err = ign.Match("app.py.bak")
s.NoError(err)
s.NotNil(m)
s.Equal(MatchSourceUser, m.Source)
s.Equal("*.bak", m.Pattern)
s.Equal("", m.FilePath)
s.Equal(0, m.Line)

ignoredir := s.cwd.Join("ignoredir")
err = ignoredir.MkdirAll(0700)
s.NoError(err)
err = ign.AppendGlobs([]string{"ignoredir/"}, MatchSourceUser)
s.NoError(err)

m, err = ign.Match(ignoredir.Path())
s.NoError(err)
s.NotNil(m)
s.Equal(MatchSourceUser, m.Source)
s.Equal("ignoredir/", m.Pattern)
s.Equal("", m.FilePath)
s.Equal(0, m.Line)
}
8 changes: 5 additions & 3 deletions internal/bundles/gitignore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type IgnoreList interface {
Append(path util.Path) error
AppendGlobs(patterns []string, source MatchSource) error
AppendGit() error
Match(path string) *Match
Match(path string) (*Match, error)
Walk(root util.Path, fn util.WalkFunc) error
}

Expand All @@ -38,16 +38,18 @@ func (m *MockGitIgnoreList) AppendGit() error {
return args.Error(0)
}

func (m *MockGitIgnoreList) Match(path string) bool {
func (m *MockGitIgnoreList) Match(path string) (*Match, error) {
args := m.Called(path)
return args.Bool(0)
return args.Get(0).(*Match), args.Error(1)
}

func (m *MockGitIgnoreList) Walk(root util.Path, fn util.WalkFunc) error {
args := m.Called(root, fn)
return args.Error(0)
}

var _ IgnoreList = &MockGitIgnoreList{}

// Maintain a reference to the original gitignore so it
// and its license remain in our vendor directory.
type _ gitignore.IgnoreList
6 changes: 5 additions & 1 deletion internal/services/api/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func (f *File) insert(root util.Path, path util.Path, ignore gitignore.IgnoreLis
}

// otherwise, create it
exclusion := ignore.Match(path.Path())
exclusion, err := ignore.Match(path.Path())
if err != nil {
return nil, err
}

child, err := CreateFile(root, path, exclusion)
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion internal/services/api/files/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ type filesService struct {

func (s filesService) GetFile(p util.Path) (*File, error) {
p = p.Clean()
m := s.ignore.Match(p.String())
m, err := s.ignore.Match(p.String())
if err != nil {
return nil, err
}

file, err := CreateFile(s.root, p, m)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions test/sample-content/fastapi-simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
10 changes: 8 additions & 2 deletions web/src/components/panels/FilesToPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const deploymentStore = useDeploymentStore();
const files = ref<QTreeNode[]>([]);
const expanded = ref<string[]>([]);

type FileInfo = Pick<DeploymentFile, 'size' | 'isEntrypoint' | 'exclusion'>;
type FileInfo = Pick<DeploymentFile, 'size' | 'isEntrypoint' | 'exclusion' | 'isFile' >;

const fileMap = ref(new Map<string, FileInfo>());

Expand All @@ -56,9 +56,14 @@ const selectedFileTotalSize = computed(() : string => {
});

const fileSummary = computed(() => {
const count = deploymentStore.files.length;
const path = deploymentStore.deployment?.sourcePath;

// Calculate the number of files that are "files" (i.e., regular files, not directories, symlinks, etc.)
const count = deploymentStore.files
.map(file => fileMap.value.get(file))
.filter(info => info?.isFile)
.length;

if (count) {
return `${count} files selected from ${path} (total = ${selectedFileTotalSize.value})`;
} else if (path) {
Expand All @@ -83,6 +88,7 @@ function populateFileMap(file: DeploymentFile) {
size: file.size,
isEntrypoint: file.isEntrypoint,
exclusion: file.exclusion,
isFile: file.isFile
};
fileMap.value.set(file.id, info);
file.files.forEach(populateFileMap);
Expand Down

0 comments on commit 561bfad

Please sign in to comment.