diff --git a/sherpa/file_listing.go b/sherpa/file_listing.go index 4684505..ba74cad 100644 --- a/sherpa/file_listing.go +++ b/sherpa/file_listing.go @@ -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(), diff --git a/sherpa/file_listing_test.go b/sherpa/file_listing_test.go index 0cd6660..b62163d 100644 --- a/sherpa/file_listing_test.go +++ b/sherpa/file_listing_test.go @@ -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())