Skip to content

Commit

Permalink
Merge pull request #83 from paketo-buildpacks/skip-git
Browse files Browse the repository at this point in the history
Skip `.git` folders in file listings
  • Loading branch information
Daniel Mikusa authored Sep 3, 2021
2 parents 1e26710 + 9b64107 commit aa87b93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sherpa/file_listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func NewFileListing(roots ...string) ([]FileEntry, error) {
return nil
}

if info.IsDir() && info.Name() == ".git" {
return filepath.SkipDir
}

e := FileEntry{
Path: path,
Mode: info.Mode().String(),
Expand Down
16 changes: 16 additions & 0 deletions sherpa/file_listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ func testFileListing(t *testing.T, context spec.G, it spec.S) {
Expect(e).To(HaveLen(3))
})

it("create listing skipping .git folder", func() {
Expect(os.MkdirAll(filepath.Join(path, ".git"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".git", "HEAD"), []byte{1}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".git", "config"), []byte{1}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha.txt"), []byte{1}, 0644)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(path, "test-directory"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "test-directory", "bravo.txt"), []byte{2}, 0644)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(path, "test-directory", ".git"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "test-directory", ".git", "config"), []byte{1}, 0644)).To(Succeed())

e, err := sherpa.NewFileListing(path)
Expect(err).NotTo(HaveOccurred())

Expect(e).To(HaveLen(3))
})

it("create listing as hash with non-regular file", func() {
Expect(ioutil.WriteFile(filepath.Join(path, "alpha.txt"), []byte{1}, 0644)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(path, "test-directory"), 0755)).To(Succeed())
Expand Down

0 comments on commit aa87b93

Please sign in to comment.